Skip to content

Commit

Permalink
metrics: do not run bloom fillrate collector when metrics are inactive
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
  • Loading branch information
Kubuxu committed Sep 8, 2016
1 parent 6826255 commit 7f77cc5
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions blocks/blockstore/bloom_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@ func bloomCached(bs Blockstore, ctx context.Context, bloomSize, hashCount int) (
bc.total = metrics.NewCtx(ctx, "bloom_total",
"Total number of requests to bloom cache").Counter()

fill := metrics.NewCtx(ctx, "bloom_fill_ratio",
"Ratio of bloom filter fullnes, (updated once a minute)").Gauge()

bc.Invalidate()
go bc.Rebuild(ctx)
go func() {
<-bc.rebuildChan
t := time.NewTicker(1 * time.Minute)
for {
select {
case <-ctx.Done():
t.Stop()
return
case <-t.C:
fill.Set(bc.bloom.FillRatio())
if metrics.Active() {
go func() {
fill := metrics.NewCtx(ctx, "bloom_fill_ratio",
"Ratio of bloom filter fullnes, (updated once a minute)").Gauge()

<-bc.rebuildChan
t := time.NewTicker(1 * time.Minute)
for {
select {
case <-ctx.Done():
t.Stop()
return
case <-t.C:
fill.Set(bc.bloom.FillRatio())
}
}
}
}()
}()
}
return bc, nil
}

Expand Down

0 comments on commit 7f77cc5

Please sign in to comment.