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:
Diffstat (limited to 'internal/httptransport/transport.go')
-rw-r--r--internal/httptransport/transport.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/internal/httptransport/transport.go b/internal/httptransport/transport.go
index 304ac1c6..bc871ea7 100644
--- a/internal/httptransport/transport.go
+++ b/internal/httptransport/transport.go
@@ -5,6 +5,7 @@ import (
"crypto/x509"
"net"
"net/http"
+ "net/http/httptrace"
"strconv"
"strings"
"sync"
@@ -27,6 +28,7 @@ var (
type meteredRoundTripper struct {
next http.RoundTripper
name string
+ tracer *prometheus.HistogramVec
durations *prometheus.HistogramVec
counter *prometheus.CounterVec
}
@@ -46,11 +48,13 @@ 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, histogramVec *prometheus.HistogramVec, counterVec *prometheus.CounterVec) http.RoundTripper {
+func NewTransportWithMetrics(name string, tracerVec, durationsVec *prometheus.
+ HistogramVec, counterVec *prometheus.CounterVec) http.RoundTripper {
return &meteredRoundTripper{
next: InternalTransport,
name: name,
- durations: histogramVec,
+ tracer: tracerVec,
+ durations: durationsVec,
counter: counterVec,
}
}
@@ -84,6 +88,8 @@ func loadPool() {
func (mrt *meteredRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
start := time.Now()
+ r = r.WithContext(httptrace.WithClientTrace(r.Context(), mrt.newTracer(start)))
+
resp, err := mrt.next.RoundTrip(r)
if err != nil {
mrt.counter.WithLabelValues("error").Inc()