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

Nil pointer dereference when using Summary metric #42

Open
manuelpepe opened this issue Jul 24, 2024 · 1 comment · May be fixed by #43
Open

Nil pointer dereference when using Summary metric #42

manuelpepe opened this issue Jul 24, 2024 · 1 comment · May be fixed by #43

Comments

@manuelpepe
Copy link

When initializing a Summary metric like this:

func AddMetric(m *ginmetrics.Monitor) error {
	metric := &ginmetrics.Metric{
		Type:        ginmetrics.Summary,
		Name:        metricName,
		Description: "description",
		Labels:      []string{"label"},
		Objectives: map[float64]float64{
			0.5:  0.05,  
			0.9:  0.01, 
			0.99: 0.001, 
		},
	}
	return m.AddMetric(metric)
}

I get a nil pointer dereference with this error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x5aa56c]

goroutine 51 [running]:
github.com/prometheus/client_golang/prometheus.(*Registry).Register.func1()
       /go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:279 +0x2c
created by github.com/prometheus/client_golang/prometheus.(*Registry).Register
       /go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:278 +0x124

I've found that the summaryHandler() function is missing the initialization of the metric.vec attribute as the other metric types do.

I'll try the fix and open a PR in a bit.

@manuelpepe
Copy link
Author

@penglongli I've also found an old PR (#33) trying to fix the same issue. Please consider merging one of them and creating a new release, or archiving the repository if you're no longer accepting contributions.

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

Successfully merging a pull request may close this issue.

1 participant