Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Better database query logs and logarithmic scale in grafana store panels #3048

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions metrics/waku-fleet-dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -3948,7 +3948,8 @@
"lineWidth": 2,
"pointSize": 10,
"scaleDistribution": {
"type": "linear"
"log": 10,
"type": "log"
},
"showPoints": "auto",
"spanNulls": false,
Expand All @@ -3973,7 +3974,32 @@
},
"unit": "s"
},
"overrides": []
"overrides": [
{
"__systemRef": "hideSeriesFrom",
"matcher": {
"id": "byNames",
"options": {
"mode": "exclude",
"names": [
"query_tag_ANALYZEmessages"
],
"prefix": "All except:",
"readOnly": true
}
},
"properties": [
{
"id": "custom.hideFrom",
"value": {
"legend": false,
"tooltip": false,
"viz": true
}
}
]
}
]
},
"gridPos": {
"h": 11,
Expand Down Expand Up @@ -4048,7 +4074,8 @@
"lineWidth": 2,
"pointSize": 10,
"scaleDistribution": {
"type": "linear"
"log": 10,
"type": "log"
},
"showPoints": "auto",
"spanNulls": false,
Expand Down Expand Up @@ -4109,6 +4136,7 @@
"editorMode": "code",
"exemplar": true,
"expr": "query_time_secs{instance=~\"[[host]].([[dc:pipe]]).([[fleet:pipe]])\", phase=\"waitFinish\"} and deriv(query_time_secs{instance=~\"[[host]].([[dc:pipe]]).([[fleet:pipe]])\", phase=\"waitFinish\"}[45s]) != 0",
"hide": false,
"interval": "",
"legendFormat": "{{query}}",
"range": true,
Expand Down Expand Up @@ -4147,7 +4175,8 @@
"lineWidth": 2,
"pointSize": 10,
"scaleDistribution": {
"type": "linear"
"log": 10,
"type": "log"
},
"showPoints": "auto",
"spanNulls": false,
Expand Down Expand Up @@ -4246,7 +4275,8 @@
"lineWidth": 2,
"pointSize": 10,
"scaleDistribution": {
"type": "linear"
"log": 10,
"type": "log"
},
"showPoints": "auto",
"spanNulls": false,
Expand Down Expand Up @@ -5456,8 +5486,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
Expand Down Expand Up @@ -5551,8 +5580,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
Expand Down Expand Up @@ -5643,8 +5671,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
Expand Down Expand Up @@ -5897,8 +5924,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
Expand Down Expand Up @@ -6022,8 +6048,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
Expand Down Expand Up @@ -7346,7 +7371,7 @@
"type": "row"
}
],
"refresh": "30s",
"refresh": false,
"schemaVersion": 37,
"style": "dark",
"tags": [],
Expand Down Expand Up @@ -7428,10 +7453,10 @@
"current": {
"selected": true,
"text": [
"All"
"ac-cn-hongkong-c"
],
"value": [
"$__all"
"ac-cn-hongkong-c"
]
},
"datasource": {
Expand Down Expand Up @@ -7461,8 +7486,8 @@
]
},
"time": {
"from": "now-24h",
"to": "now"
"from": "2024-09-20T12:34:03.849Z",
"to": "2024-09-20T13:52:30.721Z"
},
"timepicker": {
"refresh_intervals": [
Expand All @@ -7480,6 +7505,6 @@
"timezone": "browser",
"title": "Nim-Waku V2",
"uid": "qrp_ZCTGz",
"version": 150,
"version": 151,
"weekStart": ""
}
37 changes: 26 additions & 11 deletions waku/common/databases/db_postgres/dbconn.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import std/[times, strutils, asyncnet, os, sequtils], results, chronos, metrics, re
import
std/[times, strutils, asyncnet, os, sequtils],
results,
chronos,
metrics,
re,
chronicles
import ./query_metrics

include db_connector/db_postgres
Expand Down Expand Up @@ -167,21 +173,26 @@ proc dbConnQuery*(
(await db.sendQuery(query, args)).isOkOr:
return err("error in dbConnQuery calling sendQuery: " & $error)

query_time_secs.set(
getTime().toUnixFloat() - queryStartTime, [querySummary, "sendQuery"]
)
let sendDuration = getTime().toUnixFloat() - queryStartTime
query_time_secs.set(sendDuration, [querySummary, "sendQuery"])

queryStartTime = getTime().toUnixFloat()

(await db.waitQueryToFinish(rowCallback)).isOkOr:
return err("error in dbConnQuery calling waitQueryToFinish: " & $error)

query_time_secs.set(
getTime().toUnixFloat() - queryStartTime, [querySummary, "waitFinish"]
)
let waitDuration = getTime().toUnixFloat() - queryStartTime
query_time_secs.set(waitDuration, [querySummary, "waitFinish"])

query_count.inc(labelValues = [querySummary])

if "insert" notin ($query).toLower():
debug "dbConnQuery",
query = $query,
querySummary,
waitDurationSecs = waitDuration,
sendDurationSecs = sendDuration

return ok()

proc dbConnQueryPrepared*(
Expand All @@ -196,17 +207,21 @@ proc dbConnQueryPrepared*(
db.sendQueryPrepared(stmtName, paramValues, paramLengths, paramFormats).isOkOr:
return err("error in dbConnQueryPrepared calling sendQuery: " & $error)

query_time_secs.set(getTime().toUnixFloat() - queryStartTime, [stmtName, "sendQuery"])
let sendDuration = getTime().toUnixFloat() - queryStartTime
query_time_secs.set(sendDuration, [stmtName, "sendQuery"])

queryStartTime = getTime().toUnixFloat()

(await db.waitQueryToFinish(rowCallback)).isOkOr:
return err("error in dbConnQueryPrepared calling waitQueryToFinish: " & $error)

query_time_secs.set(
getTime().toUnixFloat() - queryStartTime, [stmtName, "waitFinish"]
)
let waitDuration = getTime().toUnixFloat() - queryStartTime
query_time_secs.set(waitDuration, [stmtName, "waitFinish"])

query_count.inc(labelValues = [stmtName])

if "insert" notin stmtName.toLower():
debug "dbConnQueryPrepared",
stmtName, waitDurationSecs = waitDuration, sendDurationSecs = sendDuration

return ok()
Loading
Loading