From 69778675efc41c2e582d1276cc8624e276196f5c Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 6 Aug 2021 12:02:15 -0400 Subject: [PATCH] Set a default statement timeout for postgres to 5s (#9847) * Set a default statement timeout for postgres * Lower default timeout to 2s * Update example conf for query_timeout * Fix postgres spec * Update defaults for postgres * fix the defaults... again * Increase postgres default query timeout to 5s Update spec * Remove default and display_default fields Co-authored-by: Ofek Lev Co-authored-by: Ofek Lev --- postgres/assets/configuration/spec.yaml | 3 +-- postgres/datadog_checks/postgres/config.py | 2 +- postgres/datadog_checks/postgres/config_models/defaults.py | 2 +- postgres/datadog_checks/postgres/data/conf.yaml.example | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/postgres/assets/configuration/spec.yaml b/postgres/assets/configuration/spec.yaml index 90147e2e0fa4c..e2d764caa5f90 100644 --- a/postgres/assets/configuration/spec.yaml +++ b/postgres/assets/configuration/spec.yaml @@ -94,8 +94,7 @@ files: Cancelled queries won't log any metrics. value: type: integer - example: 1000 - display_default: null + example: 5000 - name: relations description: | The list of relations/tables must be specified here to track per-relation (table, index , view, etc.) metrics. diff --git a/postgres/datadog_checks/postgres/config.py b/postgres/datadog_checks/postgres/config.py index 19340632f0215..3b5d6cfa37ea5 100644 --- a/postgres/datadog_checks/postgres/config.py +++ b/postgres/datadog_checks/postgres/config.py @@ -41,7 +41,7 @@ def __init__(self, instance): if not self.isascii(self.application_name): raise ConfigurationError("Application name can include only ASCII characters: %s", self.application_name) - self.query_timeout = instance.get('query_timeout') + self.query_timeout = int(instance.get('query_timeout', 5000)) self.relations = instance.get('relations', []) if self.relations and not self.dbname: raise ConfigurationError('"dbname" parameter must be set when using the "relations" parameter.') diff --git a/postgres/datadog_checks/postgres/config_models/defaults.py b/postgres/datadog_checks/postgres/config_models/defaults.py index c6bddddf9abd2..63a37caf9bb1b 100644 --- a/postgres/datadog_checks/postgres/config_models/defaults.py +++ b/postgres/datadog_checks/postgres/config_models/defaults.py @@ -97,7 +97,7 @@ def instance_query_samples(field, value): def instance_query_timeout(field, value): - return get_default_field_value(field, value) + return 5000 def instance_relations(field, value): diff --git a/postgres/datadog_checks/postgres/data/conf.yaml.example b/postgres/datadog_checks/postgres/data/conf.yaml.example index 75e140183078c..04164895a95e2 100644 --- a/postgres/datadog_checks/postgres/data/conf.yaml.example +++ b/postgres/datadog_checks/postgres/data/conf.yaml.example @@ -77,13 +77,13 @@ instances: # # ssl: 'false' - ## @param query_timeout - integer - optional + ## @param query_timeout - integer - optional - default: 5000 ## Adds a statement_timeout https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STATEMENT-TIMEOUT ## to all metric collection queries. Aborts any statement that takes more than the specified number of milliseconds, ## starting from the time the command arrives at the server from the client. A value of zero turns this off. ## Cancelled queries won't log any metrics. # - # query_timeout: 1000 + # query_timeout: 5000 ## @param relations - (list of string or mapping) - optional ## The list of relations/tables must be specified here to track per-relation (table, index , view, etc.) metrics.