diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-29 10:50:43 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-30 07:33:28 +0300 |
commit | 7bd5df3e66acab70f89dca0a2d23d63f957f40d0 (patch) | |
tree | 8c23c011074a50f5c7aa14dbdb9f64eac8543afe /internal/httprange | |
parent | 8dcfd518cf1a1a5f570fe43718a3cff8d8cd5ca0 (diff) |
Add tests for new metrics
DRY transport.
Add buckets to responsiveness metric.
Diffstat (limited to 'internal/httprange')
-rw-r--r-- | internal/httprange/transport.go | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/internal/httprange/transport.go b/internal/httprange/transport.go index ffe47d7c..90c1a46c 100644 --- a/internal/httprange/transport.go +++ b/internal/httprange/transport.go @@ -26,37 +26,37 @@ func (tr *tracedTransport) RoundTrip(r *http.Request) (*http.Response, error) { func newTracer(start time.Time) *httptrace.ClientTrace { trace := &httptrace.ClientTrace{ GetConn: func(host string) { - metrics.ObjectStorageResponsiveness.WithLabelValues("get_connection").Observe(float64(time.Since(start))) + observe("get_connection", start) log.WithFields(log.Fields{ "host": host, }).Traceln("get_connection") }, GotConn: func(connInfo httptrace.GotConnInfo) { - metrics.ObjectStorageResponsiveness.WithLabelValues("get_connection").Observe(float64(time.Since(start))) + observe("get_connection", start) log.WithFields(log.Fields{ "reused": connInfo.Reused, "was_idle": connInfo.WasIdle, "idle_time_ms": connInfo.IdleTime.Milliseconds(), - }).Traceln("got_connection") + }).Traceln("get_connection") }, PutIdleConn: nil, GotFirstResponseByte: func() { - metrics.ObjectStorageResponsiveness.WithLabelValues("got_first_response_byte").Observe(float64(time.Since(start))) + observe("got_first_response_byte", start) }, Got100Continue: nil, Got1xxResponse: nil, DNSStart: func(d httptrace.DNSStartInfo) { - metrics.ObjectStorageResponsiveness.WithLabelValues("dns_lookup_start").Observe(float64(time.Since(start))) + observe("dns_lookup_start", start) }, DNSDone: func(d httptrace.DNSDoneInfo) { - metrics.ObjectStorageResponsiveness.WithLabelValues("dns_lookup_done").Observe(float64(time.Since(start))) + observe("dns_lookup_done", start) - log.WithFields(log.Fields{}).WithError(d.Err).Traceln("connect_start") + log.WithFields(log.Fields{}).WithError(d.Err).Traceln("dns_lookup_done") }, ConnectStart: func(net, addr string) { - metrics.ObjectStorageResponsiveness.WithLabelValues("connect_start").Observe(float64(time.Since(start))) + observe("connect_start", start) log.WithFields(log.Fields{ "network": net, @@ -64,7 +64,7 @@ func newTracer(start time.Time) *httptrace.ClientTrace { }).Traceln("connect_start") }, ConnectDone: func(net string, addr string, err error) { - metrics.ObjectStorageResponsiveness.WithLabelValues("connect_done").Observe(float64(time.Since(start))) + observe("connect_done", start) log.WithFields(log.Fields{ "network": net, @@ -72,10 +72,10 @@ func newTracer(start time.Time) *httptrace.ClientTrace { }).WithError(err).Traceln("connect_done") }, TLSHandshakeStart: func() { - metrics.ObjectStorageResponsiveness.WithLabelValues("tls_handshake_start").Observe(float64(time.Since(start))) + observe("tls_handshake_start", start) }, TLSHandshakeDone: func(connState tls.ConnectionState, err error) { - metrics.ObjectStorageResponsiveness.WithLabelValues("tls_handshake_done").Observe(float64(time.Since(start))) + observe("tls_handshake_done", start) log.WithFields(log.Fields{ "version": connState.Version, @@ -90,3 +90,7 @@ func newTracer(start time.Time) *httptrace.ClientTrace { return trace } + +func observe(label string, start time.Time) { + metrics.ObjectStorageResponsiveness.WithLabelValues(label).Observe(float64(time.Since(start).Milliseconds())) +} |