Skip to content

Commit 0a93dc0

Browse files
ericallamclaude
andcommitted
fix(webapp): address review on db pool metrics registry
Back the metrics-source registry with singleton() keyed by clientType, matching the app's other process-wide registries and deduping so a re-evaluated module or a repeated label registers once. Document the removal of prisma_* from the Prometheus /metrics endpoint in the server-changes note. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KHjfL7qXHia5DTnxi1RePS
1 parent 5d964b2 commit 0a93dc0

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

.server-changes/db-pool-metrics-per-client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ area: webapp
33
type: improvement
44
---
55

6-
Database connection-pool and query metrics are now reported for every configured database connection rather than only the primary, and keep working regardless of which database driver a connection uses.
6+
Database connection-pool and query metrics are now reported for every configured database connection rather than only the primary, and keep working regardless of which database driver a connection uses. These metrics are now emitted only through the OpenTelemetry exporter; the Prometheus `/metrics` endpoint no longer includes the `prisma_*` series, so if you scrape that endpoint for database metrics, enable the OpenTelemetry metric exporter instead.

apps/webapp/app/utils/databaseMetrics.server.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { singleton } from "./singleton";
2+
13
export type MetricHistogramValue = {
24
buckets: [number, number][];
35
sum: number;
@@ -50,18 +52,21 @@ export type NormalizedDatabaseMetrics = {
5052
};
5153
};
5254

53-
const sources: DatabaseMetricsSource[] = [];
55+
const sources = singleton(
56+
"databaseMetricsSources",
57+
() => new Map<string, DatabaseMetricsSource>()
58+
);
5459

5560
export function registerDatabaseMetricsSource(source: DatabaseMetricsSource): void {
56-
sources.push(source);
61+
sources.set(source.clientType, source);
5762
}
5863

5964
export function listDatabaseMetricsSources(): ReadonlyArray<DatabaseMetricsSource> {
60-
return sources;
65+
return Array.from(sources.values());
6166
}
6267

6368
export function resetDatabaseMetricsSources(): void {
64-
sources.length = 0;
69+
sources.clear();
6570
}
6671

6772
function indexByKey(entries: Array<{ key: string; value: number }>): Record<string, number> {
@@ -130,7 +135,7 @@ export function normalizeDatabaseMetrics(
130135

131136
export async function collectDatabaseClientMetrics(): Promise<NormalizedDatabaseMetrics[]> {
132137
return Promise.all(
133-
sources.map(async (source) => {
138+
Array.from(sources.values()).map(async (source) => {
134139
let json: PrismaMetricsJson | undefined;
135140
try {
136141
json = await source.client.$metrics.json();

0 commit comments

Comments
 (0)