Remove timeseries with quantile labels when Unregister is called for summary #14 (#15)

This commit is contained in:
Roman Khavronenko 2020-07-28 19:58:28 +01:00 committed by GitHub
parent 6a144d3619
commit dd0c59c0d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

6
set.go
View File

@ -473,6 +473,12 @@ func (s *Set) UnregisterMetric(name string) bool {
return true return true
} }
// Remove summary metric name including quantile labels from set
for _, q := range sm.quantiles {
quantileValueName := addTag(name, fmt.Sprintf(`quantile="%g"`, q))
delete(s.m, quantileValueName)
}
// Remove sm from s.summaries // Remove sm from s.summaries
found = false found = false
for i, xsm := range s.summaries { for i, xsm := range s.summaries {

View File

@ -88,13 +88,19 @@ func TestSetUnregisterMetric(t *testing.T) {
} }
// Validate metrics are removed // Validate metrics are removed
const cName, smName = "counter_1", "summary_1"
ok := false ok := false
for _, n := range s.ListMetricNames() { for _, n := range s.ListMetricNames() {
if n == "counter_1" || n == "summary_1" { if n == cName || n == smName {
ok = true ok = true
} }
} }
if ok { if ok {
t.Fatalf("Metric counter_1 and summary_1 must not be listed anymore after unregister") t.Fatalf("Metric counter_1 and summary_1 must not be listed anymore after unregister")
} }
// re-register with the same names supposed
// to be successful
s.NewCounter(cName).Inc()
s.NewSummary(smName).Update(float64(1))
} }