From f2b17e776178a85b9671978ceeb4b5709f11351b Mon Sep 17 00:00:00 2001 From: Zhengda Lu Date: Tue, 9 Jul 2024 07:14:30 -0400 Subject: [PATCH] [mongo] Properly handle the null value of waiting_for_latch in operation sampling (#17997) --- mongo/changelog.d/17997.fixed | 1 + mongo/datadog_checks/mongo/dbm/operation_samples.py | 2 +- mongo/datadog_checks/mongo/dbm/types.py | 8 ++++---- mongo/tests/fixtures/$currentOp-standalone | 8 +++++++- mongo/tests/results/opeartion-activities-mongos.json | 4 ++-- mongo/tests/results/opeartion-activities-standalone.json | 7 ++++++- mongo/tests/results/operation-samples-mongos.json | 2 +- mongo/tests/results/operation-samples-standalone.json | 7 ++++++- 8 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 mongo/changelog.d/17997.fixed diff --git a/mongo/changelog.d/17997.fixed b/mongo/changelog.d/17997.fixed new file mode 100644 index 0000000000000..7b9910c4c92b6 --- /dev/null +++ b/mongo/changelog.d/17997.fixed @@ -0,0 +1 @@ +Fix the default null value for waiting_for_latch in operation sampling. When an operation is not waiting for latch, waiting_for_latch should be an empty dict instead of boolean False. diff --git a/mongo/datadog_checks/mongo/dbm/operation_samples.py b/mongo/datadog_checks/mongo/dbm/operation_samples.py index 889538eae6d47..111febf8a1205 100644 --- a/mongo/datadog_checks/mongo/dbm/operation_samples.py +++ b/mongo/datadog_checks/mongo/dbm/operation_samples.py @@ -368,7 +368,7 @@ def _get_operation_stats(self, operation: dict) -> OperationSampleOperationStats "waiting_for_flow_control": operation.get("waitingForFlowControl", False), # bool "flow_control_stats": self._format_key_name(operation.get("flowControlStats", {})), # dict # Latches - "waiting_for_latch": operation.get("waitingForLatch", False), # bool + "waiting_for_latch": self._format_key_name(operation.get("waitingForLatch", {})), # dict # cursor "cursor": self._get_operation_cursor(operation), # dict } diff --git a/mongo/datadog_checks/mongo/dbm/types.py b/mongo/datadog_checks/mongo/dbm/types.py index 1d5c71ec463f0..8008c0b56d28e 100644 --- a/mongo/datadog_checks/mongo/dbm/types.py +++ b/mongo/datadog_checks/mongo/dbm/types.py @@ -2,7 +2,7 @@ # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) -from typing import List, Optional, TypedDict +from typing import Dict, List, Optional, TypedDict class OperationSampleClientDriver(TypedDict, total=False): @@ -106,9 +106,9 @@ class OperationSampleOperationStatsFlowControlStats(TypedDict, total=False): class OperationSampleOperationStatsWaitingForLatch(TypedDict, total=False): - timestamp: str - captureName: str - backtrace: List[str] + timestamp: Optional[Dict[str, str]] + capture_name: Optional[str] + backtrace: Optional[List[str]] class OperationSampleOperationStatsCursor(TypedDict, total=False): diff --git a/mongo/tests/fixtures/$currentOp-standalone b/mongo/tests/fixtures/$currentOp-standalone index b775a780ea161..a000d54ff6656 100644 --- a/mongo/tests/fixtures/$currentOp-standalone +++ b/mongo/tests/fixtures/$currentOp-standalone @@ -118,6 +118,12 @@ } }, "waitingForFlowControl": false, - "flowControlStats": {} + "flowControlStats": {}, + "waitingForLatch": { + "timestamp": { + "$date": "2024-05-16T18:06:38.419Z" + }, + "captureName": "FutureResolution" + } } ] \ No newline at end of file diff --git a/mongo/tests/results/opeartion-activities-mongos.json b/mongo/tests/results/opeartion-activities-mongos.json index 117e04d930298..031da09e448aa 100644 --- a/mongo/tests/results/opeartion-activities-mongos.json +++ b/mongo/tests/results/opeartion-activities-mongos.json @@ -54,7 +54,7 @@ }, "waiting_for_flow_control": false, "flow_control_stats": {}, - "waiting_for_latch": false, + "waiting_for_latch": {}, "type": "op", "op": "query", "shard": "shard04", @@ -119,7 +119,7 @@ }, "waiting_for_flow_control": false, "flow_control_stats": {}, - "waiting_for_latch": false, + "waiting_for_latch": {}, "cursor": { "cursor_id": 7153547462305880513, "created_date": "2024-06-13T20:50:10.806000", diff --git a/mongo/tests/results/opeartion-activities-standalone.json b/mongo/tests/results/opeartion-activities-standalone.json index 1b632385bdb40..0a505fac9d115 100644 --- a/mongo/tests/results/opeartion-activities-standalone.json +++ b/mongo/tests/results/opeartion-activities-standalone.json @@ -47,7 +47,12 @@ }, "waiting_for_flow_control": false, "flow_control_stats": {}, - "waiting_for_latch": false, + "waiting_for_latch": { + "timestamp": { + "$date": "2024-05-16T18:06:38.419Z" + }, + "capture_name": "FutureResolution" + }, "type": "op", "op": "query", "shard": null, diff --git a/mongo/tests/results/operation-samples-mongos.json b/mongo/tests/results/operation-samples-mongos.json index 5557efdf2eb75..47567e2977a1e 100644 --- a/mongo/tests/results/operation-samples-mongos.json +++ b/mongo/tests/results/operation-samples-mongos.json @@ -750,7 +750,7 @@ }, "waiting_for_flow_control": false, "flow_control_stats": {}, - "waiting_for_latch": false, + "waiting_for_latch": {}, "type": "op", "op": "query", "shard": "shard04", diff --git a/mongo/tests/results/operation-samples-standalone.json b/mongo/tests/results/operation-samples-standalone.json index a5d739b3bf1e1..6a95c8f18da5f 100644 --- a/mongo/tests/results/operation-samples-standalone.json +++ b/mongo/tests/results/operation-samples-standalone.json @@ -168,7 +168,12 @@ }, "waiting_for_flow_control": false, "flow_control_stats": {}, - "waiting_for_latch": false, + "waiting_for_latch": { + "timestamp": { + "$date": "2024-05-16T18:06:38.419Z" + }, + "capture_name": "FutureResolution" + }, "type": "op", "op": "query", "shard": null,