Skip to content

Commit

Permalink
Opt in to performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
amw-zero committed May 14, 2024
1 parent 1af5fec commit 32e8a45
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions postgres/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ files:
value:
type: number
example: 10000
- name: incremental_query_metrics
hidden: true
description: |
Enable an experimental performance optimization that reduces the amount of data queried from `pg_stat_statements`
when calculating query metrics. This option is only available for PostgreSQL 10.0 and above.
value:
type: boolean
example: true
- name: query_samples
description: Configure collection of query samples
options:
Expand Down
1 change: 1 addition & 0 deletions postgres/datadog_checks/postgres/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def __init__(self, instance, init_config):
self.log_unobfuscated_queries = is_affirmative(instance.get('log_unobfuscated_queries', False))
self.log_unobfuscated_plans = is_affirmative(instance.get('log_unobfuscated_plans', False))
self.database_instance_collection_interval = instance.get('database_instance_collection_interval', 1800)
self.incremental_query_metrics = is_affirmative(self.statement_metrics_config.get('incremental_query_metrics', False))

def _build_tags(self, custom_tags, agent_tags, propagate_agent_tags=True):
# Clean up tags in case there was a None entry in the instance
Expand Down
2 changes: 1 addition & 1 deletion postgres/datadog_checks/postgres/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def _collect_metrics_rows(self):
self._emit_pg_stat_statements_dealloc()

rows = []
if self._check.version < V10:
if (not self._config.incremental_query_metrics) or self._check.version < V10:
rows = self._load_pg_stat_statements()
rows = self._normalize_queries(rows)
elif len(self._baseline_metrics) == 0:
Expand Down
2 changes: 1 addition & 1 deletion postgres/tests/test_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_statement_metrics_multiple_pgss_rows_single_query_signature(
# don't need samples for this test
dbm_instance['query_samples'] = {'enabled': False}
dbm_instance['query_activity'] = {'enabled': False}
dbm_instance['query_metrics'] = {'enabled': True, 'run_sync': True, 'collection_interval': 0.1}
dbm_instance['query_metrics'] = {'enabled': True, 'run_sync': True, 'incremental_query_metrics': True}
connections = {}

def normalize_query(q):
Expand Down

0 comments on commit 32e8a45

Please sign in to comment.