Skip to content

Commit af80b7e

Browse files
committed
Merge branch 'cap/fix-wi199-lock-waits' into 'main'
fix(metrics): label lock wait session pids Closes #199 See merge request postgres-ai/postgresai!278
2 parents afbc4f6 + 2a2b3c1 commit af80b7e

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

config/pgwatch-prometheus/metrics.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ metrics:
996996
order by pid, locktype
997997
)
998998
select
999-
blocked.pid as blocked_pid,
999+
blocked.pid::text as tag_blocked_pid,
10001000
current_database() as tag_datname,
10011001
blocked_stm.usename::text as tag_blocked_user,
10021002
blocked_stm.application_name::text as tag_blocked_appname,
@@ -1005,7 +1005,7 @@ metrics:
10051005
coalesce(blocked.relation::regclass::text, blocked_tbl.table_name, '') as tag_blocked_table,
10061006
blocked_stm.query_id::text as tag_blocked_query_id,
10071007
(extract(epoch from (clock_timestamp() - blocked_stm.state_change)) * 1000)::bigint as blocked_ms,
1008-
blocker.pid as blocker_pid,
1008+
blocker.pid::text as tag_blocker_pid,
10091009
blocker_stm.usename::text as tag_blocker_user,
10101010
blocker_stm.application_name::text as tag_blocker_appname,
10111011
blocker.mode as blocker_mode,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Regression coverage for work item 199 lock_waits metric labels."""
2+
3+
from __future__ import annotations
4+
5+
from pathlib import Path
6+
7+
8+
PROJECT_ROOT = Path(__file__).resolve().parents[2]
9+
METRICS_FILE = PROJECT_ROOT / "config" / "pgwatch-prometheus" / "metrics.yml"
10+
11+
12+
def test_lock_waits_session_pids_are_labels_not_metric_values() -> None:
13+
metrics = METRICS_FILE.read_text()
14+
lock_waits_sql = metrics.split(" lock_waits:", 1)[1].split(" xmin_horizon:", 1)[0]
15+
16+
assert "blocked.pid::text as tag_blocked_pid" in lock_waits_sql
17+
assert "blocker.pid::text as tag_blocker_pid" in lock_waits_sql
18+
assert "blocked.pid as blocked_pid" not in lock_waits_sql
19+
assert "blocker.pid as blocker_pid" not in lock_waits_sql
20+
21+
gauges = lock_waits_sql.split(" gauges:", 1)[1].split(" statement_timeout_seconds:", 1)[0]
22+
assert "blocked_pid" not in gauges
23+
assert "blocker_pid" not in gauges
24+
assert "blocked_ms" in gauges
25+
assert "blocker_tx_ms" in gauges

0 commit comments

Comments
 (0)