Skip to content

Commit 0a05bbc

Browse files
committed
Simplify interface
Only need to respond to Do, not every other method.
1 parent 7397d02 commit 0a05bbc

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

prometheus/promhttp/client.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ import (
2626
"strings"
2727
)
2828

29-
type httpClient interface {
29+
type doer interface {
3030
Do(*http.Request) (*http.Response, error)
31-
Get(string) (*http.Response, error)
32-
Head(string) (*http.Response, error)
33-
Post(string, string, io.Reader) (*http.Response, error)
34-
PostForm(string, url.Values) (*http.Response, error)
3531
}
3632

3733
// ClientMiddleware is an adapter to allow wrapping an http.Client or other

prometheus/promhttp/middleware.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import (
3030
dto "github.com/prometheus/client_model/go"
3131
)
3232

33-
// ClientTrace accepts an ObserverVec interface and an httpClient, returning a
34-
// new httpClient that wraps the supplied httpClient. The provided ObserverVec
35-
// must be registered in a registry in order to be used. Note: Partitioning
36-
// histograms is expensive.
37-
func ClientTrace(obs prometheus.ObserverVec, next httpClient) httpClient {
33+
// ClientTrace accepts an ObserverVec interface and a doer, returning a
34+
// ClientMiddleware that wraps the supplied httpClient. The provided
35+
// ObserverVec must be registered in a registry in order to be used. Note:
36+
// Partitioning histograms is expensive.
37+
func ClientTrace(obs prometheus.ObserverVec, next doer) ClientMiddleware {
3838
// The supplied ObserverVec NEEDS a label for the httptrace events.
3939
// TODO: Using `event` for now, but any other name is acceptable.
4040

@@ -85,10 +85,10 @@ func ClientTrace(obs prometheus.ObserverVec, next httpClient) httpClient {
8585
})
8686
}
8787

88-
// InFlightC accepts a Gauge and an httpClient, returning a new httpClient that
89-
// wraps the supplied httpClient. The provided Gauge must be registered in a
90-
// registry in order to be used.
91-
func InFlightC(gauge prometheus.Gauge, next httpClient) httpClient {
88+
// InFlightC accepts a Gauge and an doer, returning a new ClientMiddleware that
89+
// wraps the supplied doer. The provided Gauge must be registered in a registry
90+
// in order to be used.
91+
func InFlightC(gauge prometheus.Gauge, next doer) ClientMiddleware {
9292
return ClientMiddleware(func(r *http.Request) (*http.Response, error) {
9393
gauge.Inc()
9494
resp, err := next.Do(r)
@@ -100,10 +100,10 @@ func InFlightC(gauge prometheus.Gauge, next httpClient) httpClient {
100100
})
101101
}
102102

103-
// Counter accepts an CounterVec interface and an httpClient, returning a new
104-
// httpClient that wraps the supplied httpClient. The provided CounterVec
105-
// must be registered in a registry in order to be used.
106-
func CounterC(counter *prometheus.CounterVec, next httpClient) httpClient {
103+
// Counter accepts an CounterVec interface and an doer, returning a new
104+
// ClientMiddleware that wraps the supplied doer. The provided CounterVec must
105+
// be registered in a registry in order to be used.
106+
func CounterC(counter *prometheus.CounterVec, next doer) ClientMiddleware {
107107
code, method := checkLabels(counter)
108108

109109
return ClientMiddleware(func(r *http.Request) (*http.Response, error) {

0 commit comments

Comments
 (0)