(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestPromProviderDeleteLabelValues(t *testing.T) { |
| 12 | // Create a new registry to avoid conflicts with other tests |
| 13 | reg := prometheus.NewRegistry() |
| 14 | |
| 15 | // Create histogram directly (not via provider to control registration) |
| 16 | hv := prometheus.NewHistogramVec(prometheus.HistogramOpts{ |
| 17 | Namespace: "test", |
| 18 | Name: "route", |
| 19 | Help: "test histogram", |
| 20 | Buckets: prometheus.DefBuckets, |
| 21 | }, []string{"service", "host", "path", "target"}) |
| 22 | reg.MustRegister(hv) |
| 23 | |
| 24 | ph := &promHistogram{hv: hv} |
| 25 | |
| 26 | // Create metrics for two targets |
| 27 | h1 := ph.With("service", "svc1", "host", "host1", "path", "/path1", "target", "http://target1/") |
| 28 | h2 := ph.With("service", "svc2", "host", "host2", "path", "/path2", "target", "http://target2/") |
| 29 | |
| 30 | // Observe some values |
| 31 | h1.Observe(0.1) |
| 32 | h1.Observe(0.2) |
| 33 | h2.Observe(0.3) |
| 34 | |
| 35 | // Verify both metrics exist |
| 36 | count := testutil.CollectAndCount(hv) |
| 37 | t.Logf("Metric count before delete: %d", count) |
| 38 | if count == 0 { |
| 39 | t.Fatal("Expected metrics to be registered") |
| 40 | } |
| 41 | |
| 42 | // Gather metrics to check labels |
| 43 | metrics, _ := reg.Gather() |
| 44 | t.Logf("Metrics before delete:") |
| 45 | for _, m := range metrics { |
| 46 | for _, metric := range m.GetMetric() { |
| 47 | var labels []string |
| 48 | for _, l := range metric.GetLabel() { |
| 49 | labels = append(labels, l.GetName()+"="+l.GetValue()) |
| 50 | } |
| 51 | t.Logf(" %s{%s}", m.GetName(), strings.Join(labels, ", ")) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Delete the first target's metrics (note: values only, not key-value pairs) |
| 56 | deleted := ph.DeleteLabelValues("svc1", "host1", "/path1", "http://target1/") |
| 57 | t.Logf("DeleteLabelValues returned: %v", deleted) |
| 58 | |
| 59 | // Gather metrics after delete |
| 60 | metrics, _ = reg.Gather() |
| 61 | t.Logf("Metrics after delete:") |
| 62 | foundSvc1 := false |
| 63 | foundSvc2 := false |
| 64 | for _, m := range metrics { |
| 65 | for _, metric := range m.GetMetric() { |
| 66 | var labels []string |
| 67 | for _, l := range metric.GetLabel() { |
| 68 | labels = append(labels, l.GetName()+"="+l.GetValue()) |
nothing calls this directly
no test coverage detected