Skip to content

Expose additional HTTP metrics #3698

@IvoGoman

Description

@IvoGoman

Preflight Checklist

  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

Currently dex exposes only http_requests_total{handler="", code="",method=""} as a metric. The method used to calculate these metrics also collect the Duration and Response size written. https://github.com/felixge/httpsnoop/blob/master/capture_metrics.go#L46-L82
These metrics are not exposed.

Proposed Solution

Additional histogram metrics:

  • http_request_duration_seconds{handler="", code="", method=""}
  • http_response_size_bytes{handler="", code="", method=""}.

Which can be added to the handler instrumentalization here:

dex/server/server.go

Lines 335 to 356 in 5c66c71

instrumentHandlerCounter := func(_ string, handler http.Handler) http.HandlerFunc {
return handler.ServeHTTP
}
if c.PrometheusRegistry != nil {
requestCounter := prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "http_requests_total",
Help: "Count of all HTTP requests.",
}, []string{"handler", "code", "method"})
err = c.PrometheusRegistry.Register(requestCounter)
if err != nil {
return nil, fmt.Errorf("server: Failed to register Prometheus HTTP metrics: %v", err)
}
instrumentHandlerCounter = func(handlerName string, handler http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
m := httpsnoop.CaptureMetrics(handler, w, r)
requestCounter.With(prometheus.Labels{"handler": handlerName, "code": strconv.Itoa(m.Code), "method": r.Method}).Inc()
}
}
}

Since native histograms are not yet GA, there is the open question of which Buckets make sense for these metrics.

Alternatives Considered

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions