Closed acpana closed 3 years ago
Test to repro:
err
s out with err = duplicate metrics collector registration attempted
func TestNewPrometheusSink(t *testing.T) {
gaugeDef := GaugeDefinition{
Name: []string{"my", "test", "gauge"},
Help: "A gauge for testing? How helpful!",
}
// PrometheusSink config w/ definitions for each metric type
cfg := PrometheusOpts{
Expiration: 5 * time.Second,
GaugeDefinitions: append([]GaugeDefinition{}, gaugeDef),
SummaryDefinitions: append([]SummaryDefinition{}),
CounterDefinitions: append([]CounterDefinition{}),
}
sink1, err := NewPrometheusSinkFrom(cfg)
reg := prometheus.DefaultRegisterer
if err != nil {
t.Fatalf("err = %v, want nil", err)
}
gaugeDef2 := GaugeDefinition{
Name: []string{"my2", "test", "gauge"},
Help: "A gauge for testing? How helpful!",
}
cfg2 := PrometheusOpts{
Expiration: 15 * time.Second,
GaugeDefinitions: append([]GaugeDefinition{}, gaugeDef2),
SummaryDefinitions: append([]SummaryDefinition{}),
CounterDefinitions: append([]CounterDefinition{}),
}
sink2, err := NewPrometheusSinkFrom(cfg2) // errors out
...
}
Overview
IIUC these lines https://github.com/armon/go-metrics/blob/master/prometheus/prometheus.go#L129-L134 will create a collision for the
Collector
type if we attempt to register more than onePrometheusSink
.Repro
One repro scenario is described here https://github.com/hashicorp/consul/issues/11273 .
Also, I have a test can repro this and will comment below
Proposed Fixes
.Describe()
needs to be reworked