diff --git a/stats.go b/stats.go index a21cb0d..e379270 100644 --- a/stats.go +++ b/stats.go @@ -331,7 +331,10 @@ func (s *statStore) Flush() { s.genMtx.RUnlock() s.counters.Range(func(key, v interface{}) bool { - s.sink.FlushCounter(key.(string), v.(*counter).latch()) + // do not flush counters that are set to zero + if value := v.(*counter).latch(); value != 0 { + s.sink.FlushCounter(key.(string), value) + } return true }) diff --git a/stats_test.go b/stats_test.go index 2b8a677..80f4372 100644 --- a/stats_test.go +++ b/stats_test.go @@ -73,14 +73,14 @@ func TestMilliTimer(t *testing.T) { } } -// Ensure 0 counters are flushed +// Ensure 0 counters are not flushed func TestZeroCounters(t *testing.T) { sink := &testStatSink{} store := NewStore(sink, true) store.NewCounter("test") store.Flush() - expected := "test:0|c\n" + expected := "" counter := sink.record if counter != expected { t.Errorf("wanted %q got %q", expected, counter)