11package adam
22
33import (
4+ "context"
45 "encoding/json"
56 "fmt"
67 "net/url"
@@ -10,6 +11,7 @@ import (
1011 "strings"
1112 "time"
1213
14+ "github.com/go-redis/redis/v9"
1315 "github.com/lf-edge/eden/pkg/controller/cachers"
1416 "github.com/lf-edge/eden/pkg/controller/eapps"
1517 "github.com/lf-edge/eden/pkg/controller/eflowlog"
@@ -405,3 +407,66 @@ func (adam *Ctx) GetGlobalOptions() (*types.GlobalOptions, error) {
405407 }
406408 return & globalOptions , nil
407409}
410+
411+ func (adam * Ctx ) cleanRedisStream (stream string ) error {
412+ addr , password , databaseID , err := parseRedisURL (adam .AdamRedisURLEden )
413+ if err != nil {
414+ return err
415+ }
416+ client := redis .NewClient (& redis.Options {
417+ Addr : addr ,
418+ Password : password ,
419+ DB : databaseID ,
420+ MaxRetries : defaults .DefaultRepeatCount ,
421+ MinRetryBackoff : defaults .DefaultRepeatTimeout / 2 ,
422+ MaxRetryBackoff : defaults .DefaultRepeatTimeout * 2 ,
423+ })
424+ n , err := client .XTrimMaxLenApprox (context .TODO (), stream , 0 , 0 ).Result ()
425+ log .Debugf ("XTrimMaxLenApprox(%s): %d" , stream , n )
426+ return err
427+ }
428+
429+ // CleanInfo removes all info messages of device from controller
430+ func (adam * Ctx ) CleanInfo (devUUID uuid.UUID ) (err error ) {
431+ if adam .AdamRemoteRedis {
432+ stream := adam .getInfoRedisStream (devUUID )
433+ return adam .cleanRedisStream (stream )
434+ }
435+ panic ("implement me" )
436+ }
437+
438+ // CleanMetrics removes all metric messages of device from controller
439+ func (adam * Ctx ) CleanMetrics (devUUID uuid.UUID ) (err error ) {
440+ if adam .AdamRemoteRedis {
441+ stream := adam .getMetricsRedisStream (devUUID )
442+ return adam .cleanRedisStream (stream )
443+ }
444+ panic ("implement me" )
445+ }
446+
447+ // CleanLogs removes all logs messages of device from controller
448+ func (adam * Ctx ) CleanLogs (devUUID uuid.UUID ) (err error ) {
449+ if adam .AdamRemoteRedis {
450+ stream := adam .getLogsRedisStream (devUUID )
451+ return adam .cleanRedisStream (stream )
452+ }
453+ panic ("implement me" )
454+ }
455+
456+ // CleanFlowLogs removes all flow logs messages of device from controller
457+ func (adam * Ctx ) CleanFlowLogs (devUUID uuid.UUID ) (err error ) {
458+ if adam .AdamRemoteRedis {
459+ stream := adam .getFlowLogRedisStream (devUUID )
460+ return adam .cleanRedisStream (stream )
461+ }
462+ panic ("implement me" )
463+ }
464+
465+ // CleanAppLogs removes all app logs messages of app of device from controller
466+ func (adam * Ctx ) CleanAppLogs (devUUID uuid.UUID , appUUID uuid.UUID ) (err error ) {
467+ if adam .AdamRemoteRedis {
468+ stream := adam .getAppsLogsRedisStream (devUUID , appUUID )
469+ return adam .cleanRedisStream (stream )
470+ }
471+ panic ("implement me" )
472+ }
0 commit comments