-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Description
Repository: [IBM/Portieris]
Issue Description:
In the NewMetrics function of metrics.go, the call to prometheus.MustRegister(p.allMetrics...) happens before any metrics are added to allMetrics. Since allMetrics is initially empty, this can cause a panic or unexpected behavior.
Steps to Reproduce:
- Instantiate
PortierisMetricsusingNewMetrics(). - Observe a runtime error if
allMetricsis empty at registration time.
Proposed Fix:
Register each metric immediately upon creation in the counter method instead of registering them in NewMetrics().
func (p *PortierisMetrics) counter(name, help string) prometheus.Counter {
result := prometheus.NewCounter(prometheus.CounterOpts{
Name: metricName(name),
Help: metricHelp(help),
})
prometheus.MustRegister(result) // Register the metric immediately
p.allMetrics = append(p.allMetrics, result)
return result
}Expected Behavior After Fix:
- Each metric gets registered as soon as it is created, avoiding any issues with an empty
allMetricsslice. NewMetrics()initializes correctly without errors.
Additional Context:
This issue aligns with Prometheus best practices, ensuring that metrics are registered as they are defined rather than in bulk.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels