From 9a8e1ef21edebb81342d822cb4c2e8fc8ee1ae9d Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Fri, 7 Feb 2025 20:23:31 +0100 Subject: [PATCH] chore: dbconn truncate possible too long error messages (#3283) * also: dbconn restrict the max metric label value to 128 --- waku/common/databases/db_postgres/dbconn.nim | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/waku/common/databases/db_postgres/dbconn.nim b/waku/common/databases/db_postgres/dbconn.nim index 84584a10dc..287ed4e8da 100644 --- a/waku/common/databases/db_postgres/dbconn.nim +++ b/waku/common/databases/db_postgres/dbconn.nim @@ -49,7 +49,9 @@ proc check(db: DbConn): Result[void, string] = return err("exception in check: " & getCurrentExceptionMsg()) if message.len > 0: - return err($message) + let truncatedErr = message[0 .. 80] + ## libpq sometimes gives extremely long error messages + return err(truncatedErr) return ok() @@ -249,7 +251,7 @@ proc dbConnQuery*( ## remove everything between ' or " all possible sequence of numbers. e.g. rm partition partition var querySummary = cleanedQuery.replace(re2("""(['"]).*?\\1"""), "") querySummary = querySummary.replace(re2"\d+", "") - querySummary = "query_tag_" & querySummary[0 ..< min(querySummary.len, 200)] + querySummary = "query_tag_" & querySummary[0 ..< min(querySummary.len, 128)] var queryStartTime = getTime().toUnixFloat() @@ -300,8 +302,9 @@ proc dbConnQueryPrepared*( error "error in dbConnQueryPrepared", error = $error return err("error in dbConnQueryPrepared calling sendQuery: " & $error) + let stmtNameSummary = stmtName[0 ..< min(stmtName.len, 128)] let sendDuration = getTime().toUnixFloat() - queryStartTime - query_time_secs.set(sendDuration, [stmtName, "sendToDBQuery"]) + query_time_secs.set(sendDuration, [stmtNameSummary, "sendToDBQuery"]) queryStartTime = getTime().toUnixFloat() @@ -309,9 +312,9 @@ proc dbConnQueryPrepared*( return err("error in dbConnQueryPrepared calling waitQueryToFinish: " & $error) let waitDuration = getTime().toUnixFloat() - queryStartTime - query_time_secs.set(waitDuration, [stmtName, "waitFinish"]) + query_time_secs.set(waitDuration, [stmtNameSummary, "waitFinish"]) - query_count.inc(labelValues = [stmtName]) + query_count.inc(labelValues = [stmtNameSummary]) if "insert" notin stmtName.toLower(): debug "dbConnQueryPrepared",