-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Closed
Copy link
Description
It looks like v0.13.0 introduced a bug in promhttp.InstrumentRoundTripperCounter
(from #1055, it appears).
Instead of replacing the Inc()
call with a wrapped call to exemplarAdd(...)
, the Inc()
call was left in:
The impact is that counter metrics are now double-counted when instrumented with promhttp.InstrumentRoundTripperCounter
.
The bug can be observed with this test:
func TestBug(t *testing.T) {
counter := prometheus.NewCounterVec(
prometheus.CounterOpts{Name: "requests_total", Help: "A request counter"},
[]string{"method", "code"},
)
reg := prometheus.NewRegistry()
reg.MustRegister(counter)
rt := promhttp.InstrumentRoundTripperCounter(counter, http.DefaultTransport)
c := &http.Client{Transport: rt}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, srv.URL, nil)
resp, _ := c.Do(req)
defer resp.Body.Close()
expected := `
# HELP requests_total A request counter
# TYPE requests_total counter
requests_total{code="200",method="get"} 1
`
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
"requests_total",
); err != nil {
t.Fatal(err)
}
}
The output is:
[...]
Diff:
--- metric output does not match expectation; want
+++ got:
@@ -2,3 +2,3 @@
# TYPE requests_total counter
-requests_total{code="200",method="get"} 1
+requests_total{code="200",method="get"} 2
I'll try to issue a fix for this today!
josejibin
Metadata
Metadata
Assignees
Labels
No labels