Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eranharel opened this issue Dec 11, 2018 · 0 comments

Comments

@eranharel
Copy link
Contributor

eranharel commented Dec 11, 2018

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)
	}
}
eranharel added a commit to eranharel/go-metrics that referenced this issue Dec 11, 2018
eranharel added a commit to eranharel/go-metrics that referenced this issue Dec 11, 2018
eranharel added a commit to eranharel/go-metrics that referenced this issue Dec 12, 2018
@mihasya mihasya closed this as completed in 615496d Jul 4, 2019
mihasya added a commit that referenced this issue Jul 4, 2019
Fixed #252 - guard against multiple registrations of runtime and debug stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant