@cryptotaxi247 / kubo / commits / c7d89662a

metrics: do not run bloom fillrate collector when metrics are inactive

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Sep 7, 2016 at 18:32 UTC c7d89662a153cca35fcfd9c57ff64646dd2bb91c
1 file changed +17 -15
blocks/blockstore/bloom_cache.go
+17 -15
@@ -25,24 +25,26 @@ func bloomCached(bs Blockstore, ctx context.Context, bloomSize, hashCount int) (
25 bc.total = metrics.NewCtx(ctx, "bloom_total",
26 "Total number of requests to bloom cache").Counter()
27
28 - fill := metrics.NewCtx(ctx, "bloom_fill_ratio",
29 - "Ratio of bloom filter fullnes, (updated once a minute)").Gauge()
30 -
28 bc.Invalidate()
29 go bc.Rebuild(ctx)
33 - go func() {
34 - <-bc.rebuildChan
35 - t := time.NewTicker(1 * time.Minute)
36 - for {
37 - select {
38 - case <-ctx.Done():
39 - t.Stop()
40 - return
41 - case <-t.C:
42 - fill.Set(bc.bloom.FillRatio())
30 + if metrics.Active() {
31 + go func() {
32 + fill := metrics.NewCtx(ctx, "bloom_fill_ratio",
33 + "Ratio of bloom filter fullnes, (updated once a minute)").Gauge()
34 +
35 + <-bc.rebuildChan
36 + t := time.NewTicker(1 * time.Minute)
37 + for {
38 + select {
39 + case <-ctx.Done():
40 + t.Stop()
41 + return
42 + case <-t.C:
43 + fill.Set(bc.bloom.FillRatio())
44 + }
45 }
44 - }
45 - }()
46 + }()
47 + }
48 return bc, nil
49 }
50