mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
chore: better implementation to properly convert database query metrics (#3314)
This commit is contained in:
parent
05b46239ba
commit
564b6466a8
@ -5,11 +5,12 @@ import std/[options, sequtils], testutils/unittests, chronos, libp2p/crypto/cryp
|
||||
import
|
||||
waku/[
|
||||
common/databases/db_sqlite,
|
||||
common/databases/db_postgres/dbconn,
|
||||
common/paging,
|
||||
waku_core,
|
||||
waku_core/message/digest,
|
||||
waku_archive/driver/sqlite_driver,
|
||||
waku_archive,
|
||||
waku_archive
|
||||
],
|
||||
../waku_archive/archive_utils,
|
||||
../testlib/wakucore
|
||||
@ -109,6 +110,19 @@ suite "Waku Archive - message handling":
|
||||
check:
|
||||
(waitFor driver.getMessagesCount()).tryGet() == 0
|
||||
|
||||
test "convert query to label":
|
||||
check:
|
||||
convertQueryToMetricLabel("SELECT version();") == "select_version"
|
||||
convertQueryToMetricLabel("SELECT messageHash FROM messages WHERE pubsubTopic = ? AND timestamp >= ? AND timestamp <= ? ORDER BY timestamp DESC, messageHash DESC LIMIT ?") == "msg_hash_no_ctopic"
|
||||
convertQueryToMetricLabel(""" SELECT child.relname AS partition_name
|
||||
FROM pg_inherits
|
||||
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
|
||||
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
|
||||
JOIN pg_namespace nmsp_parent ON nmsp_parent.oid = parent.relnamespace
|
||||
JOIN pg_namespace nmsp_child ON nmsp_child.oid = child.relnamespace
|
||||
WHERE parent.relname='messages""") == "get_partitions_list"
|
||||
|
||||
|
||||
procSuite "Waku Archive - find messages":
|
||||
## Fixtures
|
||||
let timeOrigin = now()
|
||||
|
||||
@ -235,10 +235,10 @@ proc isSecureString(input: string): bool =
|
||||
|
||||
return true
|
||||
|
||||
proc convertQueryToMetricLabel(query: string): string =
|
||||
proc convertQueryToMetricLabel*(query: string): string =
|
||||
## Simple query categorization. The output label is the one that should be used in query metrics
|
||||
for snippetQuery, metric in QueriesToMetricMap.pairs():
|
||||
if query.contains($snippetQuery):
|
||||
if $snippetQuery in query:
|
||||
return $metric
|
||||
return "unknown_query_metric"
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import metrics
|
||||
import metrics, tables
|
||||
|
||||
declarePublicGauge query_time_secs,
|
||||
"query time measured in nanoseconds", labels = ["query", "phase"]
|
||||
@ -7,7 +7,7 @@ declarePublicCounter query_count,
|
||||
"number of times a query is being performed", labels = ["query"]
|
||||
|
||||
## Maps parts of the possible known queries with a fixed and shorter query label.
|
||||
const QueriesToMetricMap* = {
|
||||
const QueriesToMetricMap* = toTable({
|
||||
"contentTopic IN": "content_topic",
|
||||
"SELECT version()": "select_version",
|
||||
"WITH min_timestamp": "messages_lookup",
|
||||
@ -28,4 +28,4 @@ const QueriesToMetricMap* = {
|
||||
"SELECT pg_advisory_unlock": "advisory_unlock",
|
||||
"ANALYZE messages": "analyze_messages",
|
||||
"SELECT EXISTS": "check_version_table_exists",
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user