Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2020-09-30 08:24:12 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-09-30 08:24:12 +0300
commit031f6a1e63b52bf18db4087da7f678428f0ffdb8 (patch)
treef6beea5e90337f71dd03c80cd24de25b59cca8ee /internal/httptransport
parent9f34b7999ed3b7c1f1cef6faa42d5d42ea3c5569 (diff)
Use histograms instead of gauges for transport durations
Diffstat (limited to 'internal/httptransport')
-rw-r--r--internal/httptransport/transport.go8
-rw-r--r--internal/httptransport/transport_test.go7
2 files changed, 6 insertions, 9 deletions
diff --git a/internal/httptransport/transport.go b/internal/httptransport/transport.go
index 8f8fa387..304ac1c6 100644
--- a/internal/httptransport/transport.go
+++ b/internal/httptransport/transport.go
@@ -27,7 +27,7 @@ var (
type meteredRoundTripper struct {
next http.RoundTripper
name string
- durations *prometheus.GaugeVec
+ durations *prometheus.HistogramVec
counter *prometheus.CounterVec
}
@@ -46,11 +46,11 @@ func newInternalTransport() *http.Transport {
// NewTransportWithMetrics will create a custom http.RoundTripper that can be used with an http.Client.
// The RoundTripper will report metrics based on the collectors passed.
-func NewTransportWithMetrics(name string, gaugeVec *prometheus.GaugeVec, counterVec *prometheus.CounterVec) http.RoundTripper {
+func NewTransportWithMetrics(name string, histogramVec *prometheus.HistogramVec, counterVec *prometheus.CounterVec) http.RoundTripper {
return &meteredRoundTripper{
next: InternalTransport,
name: name,
- durations: gaugeVec,
+ durations: histogramVec,
counter: counterVec,
}
}
@@ -93,7 +93,7 @@ func (mrt *meteredRoundTripper) RoundTrip(r *http.Request) (*http.Response, erro
mrt.logResponse(r, resp)
statusCode := strconv.Itoa(resp.StatusCode)
- mrt.durations.WithLabelValues(statusCode).Set(time.Since(start).Seconds())
+ mrt.durations.WithLabelValues(statusCode).Observe(time.Since(start).Seconds())
mrt.counter.WithLabelValues(statusCode).Inc()
return resp, nil
diff --git a/internal/httptransport/transport_test.go b/internal/httptransport/transport_test.go
index 60fbbb47..a4105bef 100644
--- a/internal/httptransport/transport_test.go
+++ b/internal/httptransport/transport_test.go
@@ -43,7 +43,7 @@ func Test_withRoundTripper(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- gaugeVec := prometheus.NewGaugeVec(prometheus.GaugeOpts{
+ histVec := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: t.Name(),
}, []string{"status_code"})
@@ -58,7 +58,7 @@ func Test_withRoundTripper(t *testing.T) {
err: tt.err,
}
- mtr := &meteredRoundTripper{next: next, durations: gaugeVec, counter: counterVec}
+ mtr := &meteredRoundTripper{next: next, durations: histVec, counter: counterVec}
r := httptest.NewRequest("GET", "/", nil)
res, err := mtr.RoundTrip(r)
@@ -72,9 +72,6 @@ func Test_withRoundTripper(t *testing.T) {
require.NotNil(t, res)
statusCode := strconv.Itoa(res.StatusCode)
- gaugeValue := testutil.ToFloat64(gaugeVec.WithLabelValues(statusCode))
- require.Greater(t, gaugeValue, float64(0))
-
counterCount := testutil.ToFloat64(counterVec.WithLabelValues(statusCode))
require.Equal(t, float64(1), counterCount, statusCode)
})