diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-02-09 01:46:24 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-02-09 01:46:24 +0300 |
commit | ac442aa7dc7f603041d6643554576a561062d89a (patch) | |
tree | 2585dc871f5809ae5794a05597d3adad6f2558c1 /internal/httptransport | |
parent | 937ce0e789a5c372f17ec6590a64006e26fb986b (diff) |
Revert "Export MeteredRoundTripper"
This reverts commit de481bad5878862ae6f693190c3aa3d85242b2c9.
Diffstat (limited to 'internal/httptransport')
-rw-r--r-- | internal/httptransport/metered_round_tripper.go | 17 | ||||
-rw-r--r-- | internal/httptransport/trace.go | 4 | ||||
-rw-r--r-- | internal/httptransport/transport.go | 2 | ||||
-rw-r--r-- | internal/httptransport/transport_test.go | 4 |
4 files changed, 10 insertions, 17 deletions
diff --git a/internal/httptransport/metered_round_tripper.go b/internal/httptransport/metered_round_tripper.go index e8facbaa..fc652086 100644 --- a/internal/httptransport/metered_round_tripper.go +++ b/internal/httptransport/metered_round_tripper.go @@ -12,9 +12,7 @@ import ( log "github.com/sirupsen/logrus" ) -// MeteredRoundTripper is a custom http.Transport that implements the http.RoundTripper interface. -// It holds prometheus metrics to report connection usage and durations. -type MeteredRoundTripper struct { +type meteredRoundTripper struct { next http.RoundTripper name string tracer *prometheus.HistogramVec @@ -31,7 +29,7 @@ func NewMeteredRoundTripper(transport *http.Transport, name string, tracerVec, d transport = DefaultTransport } - return &MeteredRoundTripper{ + return &meteredRoundTripper{ next: transport, name: name, tracer: tracerVec, @@ -41,9 +39,9 @@ func NewMeteredRoundTripper(transport *http.Transport, name string, tracerVec, d } } -// RoundTrip wraps the original http.Transport into a MeteredRoundTripper which +// RoundTripper wraps the original http.Transport into a meteredRoundTripper which // reports metrics on request duration, tracing and request count -func (mrt *MeteredRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) { +func (mrt *meteredRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) { start := time.Now() ctx := httptrace.WithClientTrace(r.Context(), mrt.newTracer(start)) @@ -69,7 +67,7 @@ func (mrt *MeteredRoundTripper) RoundTrip(r *http.Request) (*http.Response, erro return resp, nil } -func (mrt *MeteredRoundTripper) logResponse(req *http.Request, resp *http.Response) { +func (mrt *meteredRoundTripper) logResponse(req *http.Request, resp *http.Response) { if log.GetLevel() == log.TraceLevel { l := log.WithFields(log.Fields{ "client_name": mrt.name, @@ -84,8 +82,3 @@ func (mrt *MeteredRoundTripper) logResponse(req *http.Request, resp *http.Respon l.Traceln("response") } } - -// RegisterProtocol calls the RegisterProtocol on the MeteredRoundTripper's next Transport -func (mrt *MeteredRoundTripper) RegisterProtocol(scheme string, rt http.RoundTripper) { - mrt.next.(*http.Transport).RegisterProtocol(scheme, rt) -} diff --git a/internal/httptransport/trace.go b/internal/httptransport/trace.go index f99b282d..9ece5fc4 100644 --- a/internal/httptransport/trace.go +++ b/internal/httptransport/trace.go @@ -8,7 +8,7 @@ import ( "gitlab.com/gitlab-org/labkit/log" ) -func (mrt *MeteredRoundTripper) newTracer(start time.Time) *httptrace. +func (mrt *meteredRoundTripper) newTracer(start time.Time) *httptrace. ClientTrace { trace := &httptrace.ClientTrace{ GetConn: func(host string) { @@ -71,7 +71,7 @@ func (mrt *MeteredRoundTripper) newTracer(start time.Time) *httptrace. return trace } -func (mrt *MeteredRoundTripper) httpTraceObserve(label string, start time.Time) { +func (mrt *meteredRoundTripper) httpTraceObserve(label string, start time.Time) { mrt.tracer.WithLabelValues(label). Observe(time.Since(start).Seconds()) } diff --git a/internal/httptransport/transport.go b/internal/httptransport/transport.go index a462f7ee..fcadc5fe 100644 --- a/internal/httptransport/transport.go +++ b/internal/httptransport/transport.go @@ -12,7 +12,7 @@ import ( ) const ( - // DefaultTTFBTimeout is the timeout used in the MeteredRoundTripper + // DefaultTTFBTimeout is the timeout used in the meteredRoundTripper // when calling http.Transport.RoundTrip. The request will be cancelled // if the response takes longer than this. DefaultTTFBTimeout = 15 * time.Second diff --git a/internal/httptransport/transport_test.go b/internal/httptransport/transport_test.go index 25c27f17..feaf63b6 100644 --- a/internal/httptransport/transport_test.go +++ b/internal/httptransport/transport_test.go @@ -55,7 +55,7 @@ func Test_withRoundTripper(t *testing.T) { timeout: time.Nanosecond, } - mtr := &MeteredRoundTripper{next: next, durations: histVec, counter: counterVec, ttfbTimeout: DefaultTTFBTimeout} + mtr := &meteredRoundTripper{next: next, durations: histVec, counter: counterVec, ttfbTimeout: DefaultTTFBTimeout} r := httptest.NewRequest("GET", "/", nil) res, err := mtr.RoundTrip(r) @@ -86,7 +86,7 @@ func TestRoundTripTTFBTimeout(t *testing.T) { err: nil, } - mtr := &MeteredRoundTripper{next: next, durations: histVec, counter: counterVec, ttfbTimeout: time.Nanosecond} + mtr := &meteredRoundTripper{next: next, durations: histVec, counter: counterVec, ttfbTimeout: time.Nanosecond} req, err := http.NewRequest("GET", "https://gitlab.com", nil) require.NoError(t, err) |