@@ -18,6 +18,19 @@ def _duration_seconds(value):
1818
1919
2020def test_pgwatch_sample_limit_allows_capped_full_preset ():
21+ """`sample_limit` is all-or-nothing: one sample over the cap and the WHOLE
22+ scrape is discarded and the target goes `up=0`. It does not truncate.
23+
24+ So the limit must sit well above the largest cardinality normal operation
25+ can legitimately produce — a `full` metric preset on a large database runs
26+ to ~12.7k samples in steady state, which the previous 10000 cap silently
27+ rejected in full, taking every pgwatch series with it.
28+
29+ The real cardinality control is the per-metric top-100 cap in
30+ config/pgwatch-prometheus/metrics.yml. `sample_limit` is only the backstop
31+ against a runaway explosion, so it keeps an upper bound too — it must not
32+ be removed outright.
33+ """
2134 prometheus = yaml .safe_load (
2235 (PROJECT_ROOT / "config/prometheus/prometheus.yml" ).read_text ()
2336 )
@@ -26,8 +39,12 @@ def test_pgwatch_sample_limit_allows_capped_full_preset():
2639 if job ["job_name" ] == "pgwatch-prometheus"
2740 )
2841
29- assert pgwatch_job ["sample_limit" ] >= 10000
30- assert pgwatch_job ["sample_limit" ] < 50000
42+ # Headroom over the observed full-preset steady state, not a snug fit:
43+ # cardinality grows with the monitored schema, and the failure mode is
44+ # total silent loss rather than partial degradation.
45+ assert pgwatch_job ["sample_limit" ] >= 50000
46+ # Still a backstop, not an open door.
47+ assert pgwatch_job ["sample_limit" ] <= 200000
3148
3249 query_info_job = next (
3350 job for job in prometheus ["scrape_configs" ]
0 commit comments