Skip to content

Commit b34b7aa

Browse files
authored
[DBMON-6857] Fix query completions payload always reporting a null service (DataDog#24632)
* Fix query completions payload always reporting a null service * Add changelog
1 parent 7a9914e commit b34b7aa

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

clickhouse/changelog.d/24632.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes query completions payload always reporting a null service.

clickhouse/datadog_checks/clickhouse/query_completions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def _create_batched_payload(self, rows):
336336
'ddtags': self._tags_no_db,
337337
'timestamp': time.time() * 1000,
338338
'clickhouse_version': self._check.dbms_version,
339-
'service': getattr(self._check, 'service', None),
339+
'service': getattr(self._check._config, 'service', None),
340340
'clickhouse_query_completions': query_completions,
341341
}
342342

clickhouse/tests/test_query_completions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ def test_create_batched_payload_structure(check_with_dbm):
214214
assert payload['clickhouse_query_completions'][1]['query_details']['statement'] == 'INSERT INTO events VALUES (?)'
215215

216216

217+
@pytest.mark.parametrize('service', [None, 'test-clickhouse-service'])
218+
def test_create_batched_payload_service_field(check_with_dbm, service):
219+
"""The completions payload carries the configured service, or None when unset."""
220+
check_with_dbm._config = check_with_dbm._config.model_copy(update={'service': service})
221+
222+
rows = [
223+
{
224+
'statement': 'SELECT * FROM users',
225+
'query_signature': 'abc123',
226+
'query_duration_ms': 100.0,
227+
'databases': 'default',
228+
'user': 'default',
229+
},
230+
]
231+
232+
with mock.patch('datadog_checks.clickhouse.query_completions.datadog_agent') as mock_agent:
233+
mock_agent.get_version.return_value = '7.64.0'
234+
payload = check_with_dbm.query_completions._create_batched_payload(rows)
235+
236+
assert payload['service'] == service
237+
238+
217239
def test_rate_limiting(check_with_dbm):
218240
"""Test that query sample rate limiting works correctly"""
219241
query_completions = check_with_dbm.query_completions

0 commit comments

Comments
 (0)