metrics/prometheus: fix for latest HEAD (#885)
github.com/prometheus/client_golang/prometheus recently removed some
deprecated functions including UninstrumentedHandler, and changed the
way summaries work: now, by default, they don't report any quantiles,
and you have to specify precisely which quantiles you want to see.
Peter Bourgon authored 4 years ago
GitHub committed 4 years ago
13 | 13 | |
14 | 14 | "github.com/go-kit/kit/metrics/teststat" |
15 | 15 | stdprometheus "github.com/prometheus/client_golang/prometheus" |
16 | "github.com/prometheus/client_golang/prometheus/promhttp" | |
16 | 17 | ) |
17 | 18 | |
18 | 19 | func TestCounter(t *testing.T) { |
19 | s := httptest.NewServer(stdprometheus.UninstrumentedHandler()) | |
20 | s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{})) | |
20 | 21 | defer s.Close() |
21 | 22 | |
22 | 23 | scrape := func() string { |
47 | 48 | } |
48 | 49 | |
49 | 50 | func TestGauge(t *testing.T) { |
50 | s := httptest.NewServer(stdprometheus.UninstrumentedHandler()) | |
51 | s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{})) | |
51 | 52 | defer s.Close() |
52 | 53 | |
53 | 54 | scrape := func() string { |
78 | 79 | } |
79 | 80 | |
80 | 81 | func TestSummary(t *testing.T) { |
81 | s := httptest.NewServer(stdprometheus.UninstrumentedHandler()) | |
82 | s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{})) | |
82 | 83 | defer s.Close() |
83 | 84 | |
84 | 85 | scrape := func() string { |
93 | 94 | re99 := regexp.MustCompile(namespace + `_` + subsystem + `_` + name + `{a="a",b="b",quantile="0.99"} ([0-9\.]+)`) |
94 | 95 | |
95 | 96 | summary := NewSummaryFrom(stdprometheus.SummaryOpts{ |
96 | Namespace: namespace, | |
97 | Subsystem: subsystem, | |
98 | Name: name, | |
99 | Help: "This is the help string for the summary.", | |
97 | Namespace: namespace, | |
98 | Subsystem: subsystem, | |
99 | Name: name, | |
100 | Help: "This is the help string for the summary.", | |
101 | Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, | |
100 | 102 | }, []string{"a", "b"}).With("b", "b").With("a", "a") |
101 | 103 | |
102 | 104 | quantiles := func() (float64, float64, float64, float64) { |
122 | 124 | // limit. That is, the count monotonically increases over the buckets. This |
123 | 125 | // requires a different strategy to test. |
124 | 126 | |
125 | s := httptest.NewServer(stdprometheus.UninstrumentedHandler()) | |
127 | s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{})) | |
126 | 128 | defer s.Close() |
127 | 129 | |
128 | 130 | scrape := func() string { |
162 | 164 | |
163 | 165 | // Then, we use ExpectedObservationsLessThan to validate. |
164 | 166 | for _, line := range strings.Split(scrape(), "\n") { |
165 | t.Logf("### %s", line) | |
166 | 167 | match := re.FindStringSubmatch(line) |
167 | 168 | if match == nil { |
168 | 169 | continue |