Skip to content

Commit

Permalink
skip samples when replset_state is refreshed and node is recovering
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zhengda committed Nov 18, 2024
1 parent e5add9d commit f7d833b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions mongo/datadog_checks/mongo/dbm/operation_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
15 changes: 9 additions & 6 deletions mongo/tests/test_dbm_operation_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit f7d833b

Please sign in to comment.