Codebase list golang-github-go-kit-kit / aba2075
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
1 changed file(s) with 10 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1313
1414 "github.com/go-kit/kit/metrics/teststat"
1515 stdprometheus "github.com/prometheus/client_golang/prometheus"
16 "github.com/prometheus/client_golang/prometheus/promhttp"
1617 )
1718
1819 func TestCounter(t *testing.T) {
19 s := httptest.NewServer(stdprometheus.UninstrumentedHandler())
20 s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{}))
2021 defer s.Close()
2122
2223 scrape := func() string {
4748 }
4849
4950 func TestGauge(t *testing.T) {
50 s := httptest.NewServer(stdprometheus.UninstrumentedHandler())
51 s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{}))
5152 defer s.Close()
5253
5354 scrape := func() string {
7879 }
7980
8081 func TestSummary(t *testing.T) {
81 s := httptest.NewServer(stdprometheus.UninstrumentedHandler())
82 s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{}))
8283 defer s.Close()
8384
8485 scrape := func() string {
9394 re99 := regexp.MustCompile(namespace + `_` + subsystem + `_` + name + `{a="a",b="b",quantile="0.99"} ([0-9\.]+)`)
9495
9596 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},
100102 }, []string{"a", "b"}).With("b", "b").With("a", "a")
101103
102104 quantiles := func() (float64, float64, float64, float64) {
122124 // limit. That is, the count monotonically increases over the buckets. This
123125 // requires a different strategy to test.
124126
125 s := httptest.NewServer(stdprometheus.UninstrumentedHandler())
127 s := httptest.NewServer(promhttp.HandlerFor(stdprometheus.DefaultGatherer, promhttp.HandlerOpts{}))
126128 defer s.Close()
127129
128130 scrape := func() string {
162164
163165 // Then, we use ExpectedObservationsLessThan to validate.
164166 for _, line := range strings.Split(scrape(), "\n") {
165 t.Logf("### %s", line)
166167 match := re.FindStringSubmatch(line)
167168 if match == nil {
168169 continue