@@ -730,52 +730,11 @@ func (c *CLI) GetMirrorLogs(ctx context.Context, in *GetMirrorLogsRequest) (*Get
730730}
731731
732732func (c * CLI ) AddMetric (ctx context.Context , in * Metric ) (* empty.Empty , error ) {
733- conn , err := c .redis .Connect ()
734- if err != nil {
735- return nil , err
736- }
737- defer conn .Close ()
738-
739- exists , err := redis .Int (conn .Do ("SISMEMBER" , "FILES" , in .Filename ))
740- if err != nil {
741- return nil , errors .Wrap (err , "failed to check for file presence" )
742- } else if exists == 0 {
743- return nil , status .Error (codes .FailedPrecondition ,
744- "file does not exist" )
745- }
746-
747- exists , err = redis .Int (conn .Do ("SADD" , "TRACKED_FILES" , in .Filename ))
748- if err != nil {
749- return nil , errors .Wrap (err , "failed to add file to metrics" )
750- } else if exists == 0 {
751- return nil , status .Error (codes .AlreadyExists ,
752- "file already is in metrics" )
753- }
754-
755- return & empty.Empty {}, nil
733+ return & empty.Empty {}, c .redis .AddTrackedFile (in .Filename )
756734}
757735
758736func (c * CLI ) DelMetric (ctx context.Context , in * Metric ) (* empty.Empty , error ) {
759- conn , err := c .redis .Connect ()
760- if err != nil {
761- return nil , err
762- }
763- defer conn .Close ()
764-
765- exists , err := redis .Int (conn .Do ("SISMEMBER" , "TRACKED_FILES" , in .Filename ))
766- if err != nil {
767- return nil , errors .Wrap (err , "failed to check for file presence" )
768- } else if exists == 0 {
769- return nil , status .Error (codes .FailedPrecondition ,
770- "file is not part of tracked files" )
771- }
772-
773- _ , err = conn .Do ("SREM" , "TRACKED_FILES" , in .Filename )
774- if err != nil {
775- return nil , errors .Wrap (err , "failed to remove file from tracked files" )
776- }
777-
778- return & empty.Empty {}, nil
737+ return & empty.Empty {}, c .redis .DeleteTrackedFile (in .Filename )
779738}
780739
781740func (c * CLI ) ListMetrics (ctx context.Context , in * Metric ) (* MetricsList , error ) {
@@ -799,3 +758,17 @@ func (c *CLI) ListMetrics(ctx context.Context, in *Metric) (*MetricsList, error)
799758
800759 return & MetricsList {Filename : files }, nil
801760}
761+
762+ func (c * CLI ) EnableAuto (context.Context , * empty.Empty ) (* empty.Empty , error ) {
763+ GetConfig ().MetricsAutoTrackedFiles = true
764+ return & empty.Empty {}, nil
765+ }
766+
767+ func (c * CLI ) DisableAuto (context.Context , * empty.Empty ) (* empty.Empty , error ) {
768+ GetConfig ().MetricsAutoTrackedFiles = false
769+ return & empty.Empty {}, nil
770+ }
771+
772+ func (c * CLI ) GetStatusAuto (context.Context , * empty.Empty ) (* StatusAuto , error ) {
773+ return & StatusAuto {Status : GetConfig ().MetricsAutoTrackedFiles }, nil
774+ }
0 commit comments