From 3390f01128df9e62d2ee95c73c4fcabfc251d12c Mon Sep 17 00:00:00 2001 From: eternal-flame-AD Date: Sun, 17 Nov 2024 21:53:54 -0600 Subject: [PATCH] reduce buckets for incoming ap Signed-off-by: eternal-flame-AD --- packages/backend/src/postgres.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/postgres.ts b/packages/backend/src/postgres.ts index ed1fccddf0..b1cb25224b 100644 --- a/packages/backend/src/postgres.ts +++ b/packages/backend/src/postgres.ts @@ -95,7 +95,6 @@ const sqlLogger = dbLogger.createSubLogger('sql', 'gray'); type QueryTagCache = { join: string; from: string; - hash: string; }; function dedupConsecutive(arr: T[]): T[] { @@ -107,40 +106,34 @@ function simplifyIdentifiers(sql: string) { } function extractQueryTags(query: string): QueryTagCache { - const joins = query.matchAll(/(LEFT|RIGHT|INNER|OUTER) JOIN ([a-zA-Z0-9_"`.\s]+) ON/ig); - const froms = query.matchAll(/FROM ([a-zA-Z0-9_"`.]+)/ig); + const joins = query.matchAll(/(LEFT|RIGHT|INNER|OUTER)[\s\S]+JOIN[\s\r\n]+([a-zA-Z0-9_"`.]+)/ig); + const froms = query.matchAll(/FROM[\s\r\n]+([a-zA-Z0-9_"`.]+)/ig); const join = Array.from(joins).map(j => `${j[1]}:${simplifyIdentifiers(j[2])}`).join('|'); const from = dedupConsecutive(Array.from(froms).map(f => simplifyIdentifiers(f[1]))).join('|'); - // this is not for security just to reduce metrics size just for confirmation in local environment - // all the code is public there is nothing secret in the query itself - const hash = createHash('md5'); - hash.update(query); - return { join, from, - hash: hash.digest('hex'), }; } const mQueryCounter = metricCounter({ name: 'misskey_postgres_query_total', help: 'Total queries to postgres', - labelNames: ['join', 'from', 'hash'], + labelNames: ['join', 'from'], }); const mQueryErrorCounter = metricCounter({ name: 'misskey_postgres_query_error_total', help: 'Total errors in queries to postgres', - labelNames: ['join', 'from', 'hash'], + labelNames: ['join', 'from'], }); const mSlowQueryHisto = metricHistogram({ name: 'misskey_postgres_query_slow_duration_seconds', help: 'Duration of slow queries to postgres', - labelNames: ['join', 'from', 'hash'], + labelNames: ['join', 'from'], buckets: [0.1, 0.5, 1, 2, 5, 10, 30, 300], });