Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add path & method labels to prometheus metrics for current requests#17362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ibetitsmike merged 7 commits intomainfrommike/17212-prometheus-metrics-path
Apr 16, 2025
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
PR feedback
  • Loading branch information
@ibetitsmike
ibetitsmike committedApr 16, 2025
commit2cb3796e00b590e1c699675ba163895827a8d871
15 changes: 9 additions & 6 deletionscoderd/httpmw/prometheus.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package httpmw
import (
"net/http"
"strconv"
"strings"
"time"

"github.com/go-chi/chi/v5"
Expand DownExpand Up@@ -61,20 +62,19 @@ func Prometheus(register prometheus.Registerer) func(http.Handler) http.Handler
var (
start = time.Now()
method = r.Method
// rctx = chi.RouteContext(r.Context())
)

sw, ok := w.(*tracing.StatusWriter)
if !ok {
panic("dev error: http.ResponseWriter is not *tracing.StatusWriter")
}

path := getRoutePattern(r)

var (
dist *prometheus.HistogramVec
distOpts []string
path = getRoutePattern(r)
)

// We want to count WebSockets separately.
if httpapi.IsWebsocketUpgrade(r) {
websocketsConcurrent.WithLabelValues(path).Inc()
Expand DownExpand Up@@ -119,9 +119,12 @@ func getRoutePattern(r *http.Request) string {
tctx := chi.NewRouteContext()
routes := rctx.Routes
if routes != nil && routes.Match(tctx, r.Method, routePath) {
// No matching pattern, so just return an empty string.
// It is done to avoid returning a static path for frontend requests.
return ""
// No matching pattern. /api/* requests will be matched as "UNKNOWN"
// All other ones will be matched as "STATIC".
if strings.HasPrefix(routePath, "/api/") {
return "UNKNOWN"
}
return "STATIC"
}

// tctx has the updated pattern, since Match mutates it
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp