Skip to content

Commit

Permalink
Instrument AWS S3 requests with standard RED metrics (#776)
Browse files Browse the repository at this point in the history
* Instrument s3 requests with RED metrics

* Update changelog
  • Loading branch information
josephwoodward authored Jun 21, 2021
1 parent 61aa78d commit b22ebdc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [ENHANCEMENT] Performance: improve compaction speed with concurrent reads and writes [#754](https://github.com/grafana/tempo/pull/754) (@mdisibio)
* [ENHANCEMENT] Improve readability of cpu and memory metrics on operational dashboard [#764](https://github.com/grafana/tempo/pull/764) (@bboreham)
* [ENHANCEMENT] Add `azure_request_duration_seconds` metric. [#767](https://github.com/grafana/tempo/pull/767) (@JosephWoodward)
* [ENHANCEMENT] Add `s3_request_duration_seconds` metric. [#776](https://github.com/grafana/tempo/pull/776) (@JosephWoodward)

## v1.0.1

Expand Down
41 changes: 41 additions & 0 deletions tempodb/backend/s3/instrumentation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package s3

import (
"net/http"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
s3RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "tempodb",
Name: "s3_request_duration_seconds",
Help: "Time spent doing AWS S3 requests.",

Buckets: prometheus.ExponentialBuckets(0.005, 4, 6),
}, []string{"operation", "status_code"})
)

type instrumentedTransport struct {
observer prometheus.ObserverVec
next http.RoundTripper
}

func newInstrumentedTransport(next http.RoundTripper) http.RoundTripper {
return instrumentedTransport{
observer: s3RequestDuration,
next: next,
}
}

func (i instrumentedTransport) RoundTrip(req *http.Request) (*http.Response, error) {
start := time.Now()
resp, err := i.next.RoundTrip(req)
if err == nil {
i.observer.WithLabelValues(req.Method, strconv.Itoa(resp.StatusCode)).Observe(time.Since(start).Seconds())
}
return resp, err
}
11 changes: 6 additions & 5 deletions tempodb/backend/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,23 @@ func createCore(cfg *Config, hedge bool) (*minio.Core, error) {
}),
})

transport, err := minio.DefaultTransport(!cfg.Insecure)
customTransport, err := minio.DefaultTransport(!cfg.Insecure)
if err != nil {
return nil, errors.Wrap(err, "create minio.DefaultTransport")
}

var roundtripper http.RoundTripper
roundtripper = transport
// add instrumentation
transport := newInstrumentedTransport(customTransport)

if hedge && cfg.HedgeRequestsAt != 0 {
roundtripper = hedgedhttp.NewRoundTripper(cfg.HedgeRequestsAt, uptoHedgedRequests, roundtripper)
transport = hedgedhttp.NewRoundTripper(cfg.HedgeRequestsAt, uptoHedgedRequests, transport)
}

opts := &minio.Options{
Region: cfg.Region,
Secure: !cfg.Insecure,
Creds: creds,
Transport: roundtripper,
Transport: transport,
}

if cfg.ForcePathStyle {
Expand Down

0 comments on commit b22ebdc

Please sign in to comment.