Skip to content

Commit

Permalink
[mongo] Properly handle the null value of waiting_for_latch in operat…
Browse files Browse the repository at this point in the history
…ion sampling (#17997)
  • Loading branch information
lu-zhengda authored Jul 9, 2024
1 parent 5ffc1b8 commit 010201c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions mongo/changelog.d/17997.fixed
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion mongo/datadog_checks/mongo/dbm/operation_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions mongo/datadog_checks/mongo/dbm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion mongo/tests/fixtures/$currentOp-standalone
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
}
},
"waitingForFlowControl": false,
"flowControlStats": {}
"flowControlStats": {},
"waitingForLatch": {
"timestamp": {
"$date": "2024-05-16T18:06:38.419Z"
},
"captureName": "FutureResolution"
}
}
]
4 changes: 2 additions & 2 deletions mongo/tests/results/opeartion-activities-mongos.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion mongo/tests/results/opeartion-activities-standalone.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mongo/tests/results/operation-samples-mongos.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion mongo/tests/results/operation-samples-standalone.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 010201c

Please sign in to comment.