Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clickhouse/changelog.d/23553.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip emitting empty storage_health payloads when every parts-and-merges collection is empty.
2 changes: 2 additions & 0 deletions clickhouse/datadog_checks/clickhouse/parts_and_merges.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,8 @@ def _emit_events(
thresholds: list[dict] | None = None,
) -> None:
"""Emit a per-cycle row-level payload consumed by dbm-events-processor."""
if not (parts or merges or mutations or replication_queue or detached_parts or thresholds):
return
now_ms = int(time.time() * 1000)
payload = {
"host": self._check.reported_hostname,
Expand Down
40 changes: 39 additions & 1 deletion clickhouse/tests/test_parts_and_merges.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,27 @@ def test_emit_events_uses_query_activity_channel_not_metadata(check):
mock.patch('datadog_checks.clickhouse.parts_and_merges.datadog_agent') as agent_mock,
):
agent_mock.get_version.return_value = '7.64.0'
job._emit_events([], [], [], [], [])
job._emit_events(_collected_parts(), [], [], [], [])

activity_mock.assert_called_once()
metadata_mock.assert_not_called()


def test_emit_events_skips_when_all_collections_empty(check):
job = check.parts_and_merges
job.tags = ['test:clickhouse']
job._tags_no_db = ['test:clickhouse']

with (
mock.patch.object(check, 'database_monitoring_query_activity') as activity_mock,
mock.patch('datadog_checks.clickhouse.parts_and_merges.datadog_agent') as agent_mock,
):
agent_mock.get_version.return_value = '7.64.0'
job._emit_events([], [], [], [], [], [])

activity_mock.assert_not_called()


# -----------------------------------------------------------------------------
# Error handling
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -907,6 +922,29 @@ def test_collect_and_emit_runs_with_partial_failures(check):
assert payload['clickhouse']['active_merges'] == _collected_merges()


def test_collect_and_emit_skips_when_all_collectors_empty(check):
job = check.parts_and_merges
job.tags = ['test:clickhouse']
job._tags_no_db = ['test:clickhouse']

with (
mock.patch.object(job, '_collect_parts', return_value=[]),
mock.patch.object(job, '_collect_merges', return_value=[]),
mock.patch.object(job, '_collect_mutations', return_value=[]),
mock.patch.object(job, '_collect_mutations_aggregated', return_value=[]),
mock.patch.object(job, '_collect_replication_queue', return_value=[]),
mock.patch.object(job, '_collect_replication_queue_aggregated', return_value=[]),
mock.patch.object(job, '_collect_detached_parts', return_value=[]),
mock.patch.object(job, '_collect_thresholds', return_value=[]),
mock.patch.object(check, 'database_monitoring_query_activity') as activity_mock,
mock.patch('datadog_checks.clickhouse.parts_and_merges.datadog_agent') as agent_mock,
):
agent_mock.get_version.return_value = '7.64.0'
job._collect_and_emit()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make every collector empty


activity_mock.assert_not_called()


# -----------------------------------------------------------------------------
# Cluster routing
# -----------------------------------------------------------------------------
Expand Down
Loading