forked from mirror/client_golang
Fix double-counting bug in promhttp.InstrumentRoundTripperCounter (#1118)
Signed-off-by: Dave Henderson <dhenderson@gmail.com> Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
parent
64435fc00a
commit
8cc2b6c472
|
@ -78,7 +78,6 @@ func InstrumentRoundTripperCounter(counter *prometheus.CounterVec, next http.Rou
|
||||||
1,
|
1,
|
||||||
rtOpts.getExemplarFn(r.Context()),
|
rtOpts.getExemplarFn(r.Context()),
|
||||||
)
|
)
|
||||||
counter.With(labels(code, method, r.Method, resp.StatusCode, rtOpts.extraMethods...)).Inc()
|
|
||||||
}
|
}
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
@ -250,6 +251,19 @@ func TestClientMiddlewareAPI_WithRequestContext(t *testing.T) {
|
||||||
t.Errorf("metric family %s must not be empty", mf.GetName())
|
t.Errorf("metric family %s must not be empty", mf.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure counters aren't double-incremented (see #1117)
|
||||||
|
expected := `
|
||||||
|
# HELP client_api_requests_total A counter for requests from the wrapped client.
|
||||||
|
# TYPE client_api_requests_total counter
|
||||||
|
client_api_requests_total{code="200",method="get"} 1
|
||||||
|
`
|
||||||
|
|
||||||
|
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
|
||||||
|
"client_api_requests_total",
|
||||||
|
); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientMiddlewareAPIWithRequestContextTimeout(t *testing.T) {
|
func TestClientMiddlewareAPIWithRequestContextTimeout(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue