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

fix: report correct request paths from workspace proxy metrics#21302

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
spikecurtis merged 1 commit intomainfromspike/api-metrics-path
Dec 17, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
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
5 changes: 0 additions & 5 deletionscoderd/httpmw/prometheus.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,11 +106,6 @@ func getRoutePattern(r *http.Request) string {
return ""
}

if pattern := rctx.RoutePattern(); pattern != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

IIRC the idea I had was to avoid double resolution as much as possible, if you are confident that's not going to be the problem - the rest looks good

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It would be nice to avoid, but since we need to get the path in normalized formbefore we actually handle the request, we need to resolve it here.

// Pattern is already available
return pattern
}

routePath := r.URL.Path
if r.URL.RawPath != "" {
routePath = r.URL.RawPath
Expand Down
38 changes: 38 additions & 0 deletionscoderd/httpmw/prometheus_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,13 @@ package httpmw_test

import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"

"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
cm "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert"
Expand DownExpand Up@@ -164,6 +166,42 @@ func TestPrometheus(t *testing.T) {
require.Equal(t, "UNKNOWN", reqProcessed["path"])
require.Equal(t, "GET", reqProcessed["method"])
})

t.Run("Subrouter", func(t *testing.T) {
t.Parallel()
reg := prometheus.NewRegistry()
promMW := httpmw.Prometheus(reg)

r := chi.NewRouter()
r.Use(promMW)
r.Get("/api/v2/workspaceagents/{workspaceagent}/pty", func(w http.ResponseWriter, r *http.Request) {})

// Mount under a root router like wsproxy does.
rootRouter := chi.NewRouter()
rootRouter.Get("/latency-check", func(w http.ResponseWriter, r *http.Request) {})
rootRouter.Mount("/", r)

agentID := uuid.UUID{1}
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v2/workspaceagents/%s/pty", agentID.String()), nil)

sw := &tracing.StatusWriter{ResponseWriter: httptest.NewRecorder()}
rootRouter.ServeHTTP(sw, req)

metrics, err := reg.Gather()
require.NoError(t, err)
require.Greater(t, len(metrics), 0)
metricLabels := getMetricLabels(metrics)

reqProcessed, ok := metricLabels["coderd_api_requests_processed_total"]
require.True(t, ok, "coderd_api_requests_processed_total metric not found")
require.Equal(t, "/api/v2/workspaceagents/{workspaceagent}/pty", reqProcessed["path"])
require.Equal(t, "GET", reqProcessed["method"])

concurrentRequests, ok := metricLabels["coderd_api_concurrent_requests"]
require.True(t, ok, "coderd_api_concurrent_requests metric not found")
require.Equal(t, "/api/v2/workspaceagents/{workspaceagent}/pty", concurrentRequests["path"])
require.Equal(t, "GET", concurrentRequests["method"])
})
}

func getMetricLabels(metrics []*cm.MetricFamily) map[string]map[string]string {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp