Skip to content

Commit

Permalink
remove instance-level database tag from DBM metrics & events (#9469)
Browse files Browse the repository at this point in the history
Remove the incorrect `db` tag inherited from the check instance tags from postgres DBM statement metrics & FQT events. This tag needs to be excluded because statement metrics & FQT events are collected from all databases on the host as of #9252. DBM statement samples are already doing the right thing here.
  • Loading branch information
djova authored Jun 3, 2021
1 parent 6f73443 commit cffc8ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions postgres/datadog_checks/postgres/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def _db_hostname_cached(self):
return self._db_hostname

def collect_per_statement_metrics(self, db, db_version, tags):
# exclude the default "db" tag from statement metrics & FQT events because this data is collected from
# all databases on the host. For metrics the "db" tag is added during ingestion based on which database
# each query came from.
tags = [t for t in tags if not t.startswith("db:")]
try:
rows = self._collect_metrics_rows(db)
if not rows:
Expand Down
7 changes: 6 additions & 1 deletion postgres/tests/test_pg_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def _should_catch_query(dbname):
assert event['host'] == 'stubbed.hostname'
assert event['timestamp'] > 0
assert event['min_collection_interval'] == dbm_instance['min_collection_interval']
assert set(event['tags']) == {'foo:bar', 'server:{}'.format(HOST), 'port:{}'.format(PORT), 'db:datadog_test'}
expected_dbm_metrics_tags = {'foo:bar', 'server:{}'.format(HOST), 'port:{}'.format(PORT)}
assert set(event['tags']) == expected_dbm_metrics_tags
obfuscated_param = '?' if POSTGRES_VERSION.split('.')[0] == "9" else '$1'

dbm_samples = aggregator.get_event_platform_events("dbm-samples")
Expand Down Expand Up @@ -325,6 +326,10 @@ def _should_catch_query(dbname):
assert fqt_event['postgres']['rolname'] == username
assert fqt_event['timestamp'] > 0
assert fqt_event['host'] == 'stubbed.hostname'
assert set(fqt_event['ddtags'].split(',')) == expected_dbm_metrics_tags | {
"db:" + fqt_event['postgres']['datname'],
"rolname:" + fqt_event['postgres']['rolname'],
}

for conn in connections.values():
conn.close()
Expand Down

0 comments on commit cffc8ac

Please sign in to comment.