rcrowley / go-metrics

Go port of Coda Hale's Metrics library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zero values are reported when RegisterDebugGCStats and RegisterRuntimeMemStats are called more than once

eranharel opened this issue · comments

When RegisterDebugGCStats and RegisterRuntimeMemStats are accidentally called more than once the CaptureXxx function will report zero values due unprotected override of the metrics stored in debugMetrics and runtimeMetrics

Example test case:

func TestDebugGCStatsDoubleRegister(t *testing.T) {
	r := NewRegistry()
	RegisterDebugGCStats(r)
	runtime.GC()
	CaptureDebugGCStatsOnce(r)
	if numGC := debugMetrics.GCStats.NumGC.Value(); 1 != numGC {
		t.Errorf("NumGC got %d, expected 1", numGC)
	}

	RegisterDebugGCStats(r)
	if numGC := debugMetrics.GCStats.NumGC.Value(); 1 != numGC {
		t.Errorf("NumGC got %d, expected 1", numGC)
	}
}