Skip to content

Commit

Permalink
Set a default statement timeout for postgres to 5s (#9847)
Browse files Browse the repository at this point in the history
* 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 <ofekmeister@gmail.com>

Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
  • Loading branch information
justiniso and ofek committed Aug 6, 2021
1 parent 04eaebb commit 6977867
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions postgres/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion postgres/datadog_checks/postgres/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
2 changes: 1 addition & 1 deletion postgres/datadog_checks/postgres/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions postgres/datadog_checks/postgres/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6977867

Please sign in to comment.