Skip to content

Nil pointer dereference when using Summary metric #42

Open
@manuelpepe

Description

@manuelpepe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions