| OLD | NEW |
| (Empty) | |
| 1 package ignore |
| 2 |
| 3 import ( |
| 4 "fmt" |
| 5 "time" |
| 6 |
| 7 "github.com/rcrowley/go-metrics" |
| 8 "github.com/skia-dev/glog" |
| 9 imetrics "go.skia.org/infra/go/metrics" |
| 10 ) |
| 11 |
| 12 func oneStep(store IgnoreStore, metric metrics.Gauge) error { |
| 13 list, err := store.List() |
| 14 if err != nil { |
| 15 return err |
| 16 } |
| 17 n := 0 |
| 18 for _, rule := range list { |
| 19 if time.Now().After(rule.Expires) { |
| 20 n += 1 |
| 21 } |
| 22 } |
| 23 metric.Update(int64(n)) |
| 24 return nil |
| 25 } |
| 26 |
| 27 // StartMonitoring starts a new monitoring routine for the given |
| 28 // ignore store that counts expired ignore rules and pushes |
| 29 // that info into a metric. |
| 30 func StartMonitoring(store IgnoreStore, r metrics.Registry) error { |
| 31 numExpired := metrics.NewRegisteredGauge("num-expired-ignore-rules", r) |
| 32 liveness := imetrics.NewLiveness("expired-ignore-rules-monitoring") |
| 33 |
| 34 err := oneStep(store, numExpired) |
| 35 if err != nil { |
| 36 return fmt.Errorf("Unable to start monitoring ignore rules: %s",
err) |
| 37 } |
| 38 go func() { |
| 39 for _ = range time.Tick(time.Minute) { |
| 40 err = oneStep(store, numExpired) |
| 41 if err != nil { |
| 42 glog.Errorf("Failed one step of monitoring ignor
e rules: %s", err) |
| 43 continue |
| 44 } |
| 45 liveness.Update() |
| 46 } |
| 47 }() |
| 48 |
| 49 return nil |
| 50 } |
| OLD | NEW |