Skip to content

Commit 7532c0a

Browse files
authored
[DBMON-6076] fix collect_wal_metrics default on 9.6 and below (#22377)
* fix collect_wal_metrics default on 9.6 and below * Fix collect_wal_metrics default in tests * Add changelog
1 parent 0b0ab1f commit 7532c0a

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

postgres/assets/configuration/spec.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,20 @@ files:
364364
- name: collect_wal_metrics
365365
description: |
366366
Collect metrics about WAL file age.
367-
NOTE:
368-
For Postgres 9.6 and below, you must run the check local to your database if you want to enable this option.
369-
Starting Postgres 10, WAL file metrics are enabled by default using `pg_ls_waldir` and don't need local access.
367+
368+
When unset, this defaults to `true` for Postgres 10+ (uses `pg_ls_waldir` via SQL) and `false` for
369+
Postgres 9.6 and below (requires local filesystem access to the WAL directory).
370+
371+
Set to `true` explicitly for Postgres 9.6 and below only if the Agent runs on the same host as the
372+
database and has read access to the WAL directory. You must also configure `data_directory`.
370373
value:
371374
type: boolean
372375
example: true
376+
display_default: null
373377
- name: data_directory
374378
description: |
375-
The data directory of your postgres installation
376-
Required when collecting WAL metrics on Postgres 9.6.
379+
The data directory of your postgres installation.
380+
Only used when `collect_wal_metrics` is explicitly set to `true` on Postgres 9.6 and below.
377381
value:
378382
type: string
379383
example: /usr/local/pgsql/data

postgres/changelog.d/22377.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes collect_wal_metrics config default on 9.6 and below to correctly default to disabled

postgres/datadog_checks/postgres/config_models/defaults.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ def instance_collect_function_metrics():
5252
return False
5353

5454

55-
def instance_collect_wal_metrics():
56-
return True
57-
58-
5955
def instance_data_directory():
6056
return '/usr/local/pgsql/data'
6157

postgres/datadog_checks/postgres/data/conf.yaml.example

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,20 @@ instances:
271271
#
272272
collect_bloat_metrics: false
273273

274-
## @param collect_wal_metrics - boolean - optional - default: true
274+
## @param collect_wal_metrics - boolean - optional
275275
## Collect metrics about WAL file age.
276-
## NOTE:
277-
## For Postgres 9.6 and below, you must run the check local to your database if you want to enable this option.
278-
## Starting Postgres 10, WAL file metrics are enabled by default using `pg_ls_waldir` and don't need local access.
276+
##
277+
## When unset, this defaults to `true` for Postgres 10+ (uses `pg_ls_waldir` via SQL) and `false` for
278+
## Postgres 9.6 and below (requires local filesystem access to the WAL directory).
279+
##
280+
## Set to `true` explicitly for Postgres 9.6 and below only if the Agent runs on the same host as the
281+
## database and has read access to the WAL directory. You must also configure `data_directory`.
279282
#
280283
# collect_wal_metrics: true
281284

282285
## @param data_directory - string - optional - default: /usr/local/pgsql/data
283-
## The data directory of your postgres installation
284-
## Required when collecting WAL metrics on Postgres 9.6.
286+
## The data directory of your postgres installation.
287+
## Only used when `collect_wal_metrics` is explicitly set to `true` on Postgres 9.6 and below.
285288
#
286289
# data_directory: /usr/local/pgsql/data
287290

postgres/datadog_checks/postgres/postgres.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ def dynamic_queries(self):
397397
if self.is_aurora is False:
398398
queries.append(QUERY_PG_STAT_WAL_RECEIVER)
399399
if self._config.collect_wal_metrics is not False:
400-
# collect wal metrics for pg >= 10 only if the user has not explicitly disabled it
400+
# collect wal metrics for pg >= 10 by default (uses pg_ls_waldir via SQL)
401+
# unless the user has explicitly disabled it
401402
queries.append(WAL_FILE_METRICS)
402403
if self._config.collect_buffercache_metrics:
403404
queries.append(BUFFERCACHE_METRICS)
@@ -1137,8 +1138,9 @@ def check(self, _):
11371138
self.statement_metrics.run_job_loop(tags)
11381139
self.statement_samples.run_job_loop(tags)
11391140
self.metadata_samples.run_job_loop(tags)
1140-
if self._config.collect_wal_metrics:
1141-
# collect wal metrics for pg < 10, disabled by enabled
1141+
if self._config.collect_wal_metrics is True:
1142+
# collect wal metrics for pg < 10 only when explicitly enabled
1143+
# (requires local filesystem access to the WAL directory)
11421144
self._collect_wal_metrics()
11431145

11441146
if self._query_manager.queries:

postgres/tests/test_config_defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'collect_database_size_metrics': True,
5151
'collect_default_database': True,
5252
'collect_bloat_metrics': False,
53-
'collect_wal_metrics': True,
53+
'collect_wal_metrics': None, # Version-aware: defaults to True for PG 10+, False for PG 9.6 and below
5454
'tag_replication_role': True,
5555
'table_count_limit': 200,
5656
'max_relations': 300,

0 commit comments

Comments
 (0)