Skip to content

Commit c7c2b27

Browse files
committed
fix: Use boot_val for is_default check on lock_timeout
When pgwatch sets lock_timeout during collection, source becomes 'session', causing is_default to incorrectly report non-default. Now we compare reset_val with boot_val to determine the true default status for lock_timeout.
1 parent 7893064 commit c7c2b27

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

config/pgwatch-prometheus/metrics.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ metrics:
377377
category as tag_category,
378378
vartype as tag_vartype,
379379
case when (case when name = 'lock_timeout' then reset_val else setting end) ~ '^-?[0-9]+$' then (case when name = 'lock_timeout' then reset_val else setting end)::bigint else null end as numeric_value,
380-
case when source <> 'default' then 0 else 1 end as is_default,
380+
-- For lock_timeout, compare reset_val with boot_val since source becomes 'session' during collection
381+
case when name = 'lock_timeout' then (case when reset_val = boot_val then 1 else 0 end) else (case when source <> 'default' then 0 else 1 end) end as is_default,
381382
1 as configured
382383
from pg_settings
383384
gauges:

tests/settings/test_settings_metric.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ def test_settings_metric_numeric_value_uses_correct_source_for_lock_timeout(metr
110110
f"CASE expression for lock_timeout should appear at least twice (for tag_setting_value and numeric_value), found {occurrences}"
111111

112112

113+
@pytest.mark.unit
114+
def test_settings_metric_is_default_uses_boot_val_for_lock_timeout(metrics_config: dict) -> None:
115+
"""
116+
Test that is_default compares reset_val with boot_val for lock_timeout.
117+
118+
When pgwatch sets lock_timeout during collection, the source becomes 'session',
119+
which would incorrectly report is_default=0. Instead, we should compare
120+
reset_val with boot_val to determine if the configured value is the default.
121+
122+
See: https://gitlab.com/postgres-ai/postgres_ai/-/issues/61
123+
"""
124+
sql = metrics_config["metrics"]["settings"]["sqls"][11]
125+
126+
# Verify is_default uses boot_val comparison for lock_timeout
127+
assert "boot_val" in sql, "SQL should reference boot_val column for is_default comparison"
128+
129+
# Check for the specific pattern that handles lock_timeout specially
130+
assert "case when name = 'lock_timeout' then" in sql and "boot_val" in sql, \
131+
"SQL should use special handling for lock_timeout in is_default calculation"
132+
133+
113134
@pytest.mark.integration
114135
@pytest.mark.requires_postgres
115136
def test_settings_metric_lock_timeout_returns_actual_value() -> None:

0 commit comments

Comments
 (0)