From dd0c59c0d681d806dcafbf913feb9e722ca1b936 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Tue, 28 Jul 2020 19:58:28 +0100 Subject: [PATCH] Remove timeseries with quantile labels when Unregister is called for `summary` #14 (#15) --- set.go | 6 ++++++ set_test.go | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/set.go b/set.go index 8195d8b..6d36eed 100644 --- a/set.go +++ b/set.go @@ -473,6 +473,12 @@ func (s *Set) UnregisterMetric(name string) bool { 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 found = false for i, xsm := range s.summaries { diff --git a/set_test.go b/set_test.go index 4c96353..8fd9507 100644 --- a/set_test.go +++ b/set_test.go @@ -88,13 +88,19 @@ func TestSetUnregisterMetric(t *testing.T) { } // Validate metrics are removed + const cName, smName = "counter_1", "summary_1" ok := false for _, n := range s.ListMetricNames() { - if n == "counter_1" || n == "summary_1" { + if n == cName || n == smName { ok = true } } if ok { 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)) }