From f7d833b757d147e24f2068bb9aea75c4e4874438 Mon Sep 17 00:00:00 2001 From: Zhengda Lu Date: Mon, 18 Nov 2024 19:22:18 +0000 Subject: [PATCH] skip samples when replset_state is refreshed and node is recovering --- .../datadog_checks/mongo/dbm/operation_samples.py | 3 +++ mongo/tests/test_dbm_operation_samples.py | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mongo/datadog_checks/mongo/dbm/operation_samples.py b/mongo/datadog_checks/mongo/dbm/operation_samples.py index 52806ad830442..9ecc14d09309f 100644 --- a/mongo/datadog_checks/mongo/dbm/operation_samples.py +++ b/mongo/datadog_checks/mongo/dbm/operation_samples.py @@ -108,6 +108,9 @@ def _should_collect_operation_samples(self) -> bool: if isinstance(deployment, ReplicaSetDeployment) and deployment.is_arbiter: self._check.log.debug("Skipping operation samples collection on arbiter node") return False + elif isinstance(deployment, ReplicaSetDeployment) and deployment.replset_state == 3: + self._check.log.debug("Skipping operation samples collection on node in recovering state") + return False return True def _get_operation_samples(self, now, databases_monitored: List[str]): diff --git a/mongo/tests/test_dbm_operation_samples.py b/mongo/tests/test_dbm_operation_samples.py index 5ea4e0614d7da..0621cd7edc32f 100644 --- a/mongo/tests/test_dbm_operation_samples.py +++ b/mongo/tests/test_dbm_operation_samples.py @@ -110,8 +110,8 @@ def test_mongo_operation_samples_arbiter(aggregator, instance_arbiter, check, dd @mock_now(1715911398.1112723) -@common.standalone -def test_mongo_operation_samples_standalone_not_primary( +@common.shard +def test_mongo_operation_samples_not_primary( aggregator, instance_integration_cluster_autodiscovery, check, dd_run_check ): instance_integration_cluster_autodiscovery['dbm'] = True @@ -128,11 +128,14 @@ def test_mongo_operation_samples_standalone_not_primary( aggregator.reset() run_check_once(mongo_check, dd_run_check) - # we will not assert the metrics, as they are already tested in test_integration.py - # we will only assert the operation sample and activity events dbm_activities = aggregator.get_event_platform_events("dbm-activity") - activity_samples = [event for event in dbm_activities if event['dbm_type'] == 'activity'] - assert activity_samples is not None assert len(activity_samples[0]['mongodb_activity']) == 0 + + aggregator.reset() + mongo_check.deployment_type.replset_state = 3 + run_check_once(mongo_check, dd_run_check) + dbm_activities = aggregator.get_event_platform_events("dbm-activity") + activity_samples = [event for event in dbm_activities if event['dbm_type'] == 'activity'] + assert len(activity_samples) == 0