feat(coderd/database/dbmetrics): add query_counts_total metric (#21506)

Adds a new Prometheus metric `coderd_db_query_counts_total` that tracks
the total number of queries by route, method, and query name. This is
aimed at helping us track down potential optimization candidates for
HTTP handlers that may trigger a number of queries. It is expected to be
used alongside `coderd_api_requests_processed_total` for correlation.

Depends upon new middleware introduced in
https://github.com/coder/coder/pull/21498

Relates to https://github.com/coder/internal/issues/1214
This commit is contained in:
Cian Johnston
2026-01-15 10:58:56 +00:00
committed by GitHub
parent 32354261d3
commit 5073493850
2 changed files with 965 additions and 411 deletions
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -55,8 +55,9 @@ func run() error {
start := time.Now()
%s := m.s.%s(%s)
m.queryLatencies.WithLabelValues("%s").Observe(time.Since(start).Seconds())
m.queryCounts.WithLabelValues(httpmw.ExtractHTTPRoute(ctx), httpmw.ExtractHTTPMethod(ctx), "%s").Inc()
return %s
`, params.Returns, params.FuncName, params.Parameters, params.FuncName, params.Returns)
`, params.Returns, params.FuncName, params.Parameters, params.FuncName, params.FuncName, params.Returns)
})
if err != nil {
return xerrors.Errorf("stub dbmetrics: %w", err)