Commit e9ced79a authored by felipe's avatar felipe Committed by GitHub

Merge pull request #7852 from ethereum-optimism/felipe/op-service-http-latency-metric

feat(op-service): new http latency metric
parents 48a01dac 412ac55e
......@@ -44,21 +44,41 @@ func (n *noopHTTPRecorder) RecordHTTPRequest(*HTTPParams) {}
func (n *noopHTTPRecorder) RecordHTTPResponse(*HTTPParams) {}
type PromHTTPRecorder struct {
HTTPRequestDuration *prometheus.HistogramVec
// HTTPRequestDuration is the old metric for request latency
// it was created with too tight buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
// in order to preserve backward compatibility we are keeping this metric for now
// and it will be removed when services opt in to HTTPRequestLatency
// Deprecated: HTTPRequestDuration is deprecated
HTTPRequestDuration *prometheus.HistogramVec
// HTTPRequestLatency measures request execution latency in *seconds*
// buckets are: [.025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50]
HTTPRequestLatency *prometheus.HistogramVec
HTTPResponseSize *prometheus.HistogramVec
HTTPInflightRequests *prometheus.GaugeVec
HTTPRequests *prometheus.CounterVec
HTTPResponses *prometheus.CounterVec
}
var LatencyBuckets = []float64{.025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100}
func NewPromHTTPRecorder(r *prometheus.Registry, ns string) HTTPRecorder {
return &PromHTTPRecorder{
// TODO(INF-509): remove this in the future when services opted in to HTTPRequestLatency
HTTPRequestDuration: promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{
Namespace: ns,
Name: "http_request_duration_ms",
Help: "Tracks HTTP request durations, in ms",
Buckets: prometheus.DefBuckets,
}, httpLabels),
HTTPRequestLatency: promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{
Namespace: ns,
Name: "http_request_latency_seconds",
Help: "Tracks HTTP request execution latency, in seconds",
Buckets: LatencyBuckets,
}, httpLabels),
HTTPResponseSize: promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{
Namespace: ns,
Name: "http_response_size",
......@@ -84,8 +104,12 @@ func NewPromHTTPRecorder(r *prometheus.Registry, ns string) HTTPRecorder {
}
func (p *PromHTTPRecorder) RecordHTTPRequestDuration(params *HTTPParams, dur time.Duration) {
// TODO(INF-509): remove this in the future when services opted in to new metric
p.HTTPRequestDuration.WithLabelValues(params.Method, strconv.Itoa(params.StatusCode)).
Observe(float64(dur.Milliseconds()))
p.HTTPRequestLatency.WithLabelValues(params.Method, strconv.Itoa(params.StatusCode)).
Observe(dur.Seconds())
}
func (p *PromHTTPRecorder) RecordHTTPResponseSize(params *HTTPParams, size int) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment