-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose metrics from the kubenurse httpclient (#31)
The following new metrics were added: * kubenurse_httpclient_requests_total - Total issued requests by kubenurse, partitioned by http code/method. * kubenurse_httpclient_trace_request_duration_seconds - Latency histogram for requests from the kubenurse httpclient, partitioned by event. * httpclient_request_duration_seconds - Latency histogram of request latencies from the kubenurse httpclient.
- Loading branch information
Showing
6 changed files
with
154 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package servicecheck | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
func withRequestTracing(registry *prometheus.Registry, transport http.RoundTripper) http.RoundTripper { | ||
counter := prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Namespace: metricsNamespace, | ||
Name: "httpclient_requests_total", | ||
Help: "A counter for requests from the kubenurse http client.", | ||
}, | ||
[]string{"code", "method"}, | ||
) | ||
|
||
latencyVec := prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Name: "httpclient_trace_request_duration_seconds", | ||
Help: "Latency histogram for requests from the kubenurse http client. Time in seconds since the start of the http request.", | ||
Buckets: []float64{.0005, .005, .01, .025, .05, .1, .25, .5, 1}, | ||
}, | ||
[]string{"event"}, | ||
) | ||
|
||
// histVec has no labels, making it a zero-dimensional ObserverVec. | ||
histVec := prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Name: "httpclient_request_duration_seconds", | ||
Help: "A latency histogram of request latencies from the kubenurse http client.", | ||
Buckets: prometheus.DefBuckets, | ||
}, | ||
[]string{}, | ||
) | ||
|
||
// Register all of the metrics in the standard registry. | ||
registry.MustRegister(counter, latencyVec, histVec) | ||
|
||
// Define functions for the available httptrace.ClientTrace hook | ||
// functions that we want to instrument. | ||
trace := &promhttp.InstrumentTrace{ | ||
DNSStart: func(t float64) { | ||
latencyVec.WithLabelValues("dns_start").Observe(t) | ||
}, | ||
DNSDone: func(t float64) { | ||
latencyVec.WithLabelValues("dns_done").Observe(t) | ||
}, | ||
ConnectStart: func(t float64) { | ||
latencyVec.WithLabelValues("connect_start").Observe(t) | ||
}, | ||
ConnectDone: func(t float64) { | ||
latencyVec.WithLabelValues("connect_done").Observe(t) | ||
}, | ||
TLSHandshakeStart: func(t float64) { | ||
latencyVec.WithLabelValues("tls_handshake_start").Observe(t) | ||
}, | ||
TLSHandshakeDone: func(t float64) { | ||
latencyVec.WithLabelValues("tls_handshake_done").Observe(t) | ||
}, | ||
WroteRequest: func(t float64) { | ||
latencyVec.WithLabelValues("wrote_request").Observe(t) | ||
}, | ||
GotFirstResponseByte: func(t float64) { | ||
latencyVec.WithLabelValues("got_first_resp_byte").Observe(t) | ||
}, | ||
} | ||
|
||
// Wrap the default RoundTripper with middleware. | ||
roundTripper := promhttp.InstrumentRoundTripperCounter(counter, | ||
promhttp.InstrumentRoundTripperTrace(trace, | ||
promhttp.InstrumentRoundTripperDuration(histVec, | ||
transport, | ||
), | ||
), | ||
) | ||
|
||
return roundTripper | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters