Skip to content

Commit 276d38c

Browse files
authored
[mongo] fix missing metric attributes for slow operations from logs (#18305)
* fix missing metric attributes from logs * add changelog * remove debug print
1 parent 897a990 commit 276d38c

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

mongo/changelog.d/18305.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix missing metrics `num_yields` and `response_length` for slow operations collected from logs.

mongo/datadog_checks/mongo/dbm/slow_operations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ def _create_slow_operation_event(self, slow_operation):
200200
"plan_cache_key": slow_operation.get("planCacheKey"), # only available with profiling
201201
"query_framework": slow_operation.get("queryFramework"),
202202
# metrics
203+
# mills from profiler, durationMillis from logs
203204
"mills": slow_operation.get("millis", slow_operation.get("durationMillis", 0)),
204-
"num_yields": slow_operation.get("numYield", 0),
205-
"response_length": slow_operation.get("responseLength", 0),
205+
# numYield from profiler, numYields from logs
206+
"num_yields": slow_operation.get("numYield", slow_operation.get("numYields", 0)),
207+
# responseLength from profiler, reslen from logs
208+
"response_length": slow_operation.get("responseLength", slow_operation.get("reslen", 0)),
206209
"nreturned": slow_operation.get("nreturned"),
207210
"nmatched": slow_operation.get("nMatched"),
208211
"nmodified": slow_operation.get("nModified"),

mongo/tests/results/slow-operations-mongos.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"query_signature": "a81f9d3c17192d68",
2323
"statement": "{\"q\": {\"age\": {\"$gt\": 18}}, \"u\": {\"$set\": {\"subscribed\": false}}, \"multi\": true, \"upsert\": false, \"comment\": \"update customers subscription status by age\"}",
2424
"mills": 74,
25-
"num_yields": 0,
25+
"num_yields": 4,
2626
"response_length": 0,
2727
"nmatched": 608,
2828
"nmodified": 441,
@@ -77,8 +77,8 @@
7777
"query_signature": "c5b7bcd45c4d9e9",
7878
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"test\"}",
7979
"mills": 74,
80-
"num_yields": 0,
81-
"response_length": 0,
80+
"num_yields": 4,
81+
"response_length": 60,
8282
"cpu_nanos": 74715957,
8383
"client": {
8484
"hostname": "192.168.65.1:58133"
@@ -130,7 +130,7 @@
130130
"query_signature": "ec24a2e9aacce5a0",
131131
"statement": "{\"q\": {\"age\": {\"$gt\": 35}}, \"u\": {\"$set\": {\"subscribed\": true}}, \"multi\": true, \"upsert\": false, \"comment\": \"update customers subscription status by age\"}",
132132
"mills": 27,
133-
"num_yields": 0,
133+
"num_yields": 2,
134134
"response_length": 0,
135135
"nmatched": 495,
136136
"nmodified": 495,
@@ -185,8 +185,8 @@
185185
"query_signature": "c5b7bcd45c4d9e9",
186186
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"test\"}",
187187
"mills": 27,
188-
"num_yields": 0,
189-
"response_length": 0,
188+
"num_yields": 2,
189+
"response_length": 60,
190190
"cpu_nanos": 27721625,
191191
"client": {
192192
"hostname": "192.168.65.1:58133"
@@ -294,7 +294,7 @@
294294
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"test\"}",
295295
"mills": 15,
296296
"num_yields": 0,
297-
"response_length": 0,
297+
"response_length": 60,
298298
"cpu_nanos": 15198542,
299299
"client": {
300300
"hostname": "192.168.65.1:58133"
@@ -350,7 +350,7 @@
350350
"query_framework": "classic",
351351
"mills": 12,
352352
"num_yields": 0,
353-
"response_length": 0,
353+
"response_length": 14089,
354354
"nreturned": 101,
355355
"keys_examined": 540,
356356
"docs_examined": 540,
@@ -389,7 +389,7 @@
389389
"query_framework": "classic",
390390
"mills": 14,
391391
"num_yields": 0,
392-
"response_length": 0,
392+
"response_length": 110,
393393
"nreturned": 0,
394394
"keys_examined": 612,
395395
"docs_examined": 612,
@@ -420,7 +420,7 @@
420420
"query_signature": "a81f9d3c17192d68",
421421
"statement": "{\"q\": {\"age\": {\"$gt\": 18}}, \"u\": {\"$set\": {\"subscribed\": false}}, \"multi\": true, \"upsert\": false, \"comment\": \"update customers subscription status by age\"}",
422422
"mills": 74,
423-
"num_yields": 0,
423+
"num_yields": 4,
424424
"response_length": 0,
425425
"nmatched": 608,
426426
"nmodified": 441,
@@ -475,8 +475,8 @@
475475
"query_signature": "3583b3bc9478cec2",
476476
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"integration\"}",
477477
"mills": 74,
478-
"num_yields": 0,
479-
"response_length": 0,
478+
"num_yields": 4,
479+
"response_length": 60,
480480
"cpu_nanos": 74715957,
481481
"client": {
482482
"hostname": "192.168.65.1:58133"
@@ -528,7 +528,7 @@
528528
"query_signature": "ec24a2e9aacce5a0",
529529
"statement": "{\"q\": {\"age\": {\"$gt\": 35}}, \"u\": {\"$set\": {\"subscribed\": true}}, \"multi\": true, \"upsert\": false, \"comment\": \"update customers subscription status by age\"}",
530530
"mills": 27,
531-
"num_yields": 0,
531+
"num_yields": 2,
532532
"response_length": 0,
533533
"nmatched": 495,
534534
"nmodified": 495,
@@ -583,8 +583,8 @@
583583
"query_signature": "3583b3bc9478cec2",
584584
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"integration\"}",
585585
"mills": 27,
586-
"num_yields": 0,
587-
"response_length": 0,
586+
"num_yields": 2,
587+
"response_length": 60,
588588
"cpu_nanos": 27721625,
589589
"client": {
590590
"hostname": "192.168.65.1:58133"
@@ -692,7 +692,7 @@
692692
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"integration\"}",
693693
"mills": 15,
694694
"num_yields": 0,
695-
"response_length": 0,
695+
"response_length": 60,
696696
"cpu_nanos": 15198542,
697697
"client": {
698698
"hostname": "192.168.65.1:58133"
@@ -748,7 +748,7 @@
748748
"query_framework": "classic",
749749
"mills": 12,
750750
"num_yields": 0,
751-
"response_length": 0,
751+
"response_length": 14089,
752752
"nreturned": 101,
753753
"keys_examined": 540,
754754
"docs_examined": 540,
@@ -787,7 +787,7 @@
787787
"query_framework": "classic",
788788
"mills": 14,
789789
"num_yields": 0,
790-
"response_length": 0,
790+
"response_length": 110,
791791
"nreturned": 0,
792792
"keys_examined": 612,
793793
"docs_examined": 612,

mongo/tests/results/slow-operations-standalone.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"query_signature": "a81f9d3c17192d68",
214214
"statement": "{\"q\": {\"age\": {\"$gt\": 18}}, \"u\": {\"$set\": {\"subscribed\": false}}, \"multi\": true, \"upsert\": false, \"comment\": \"update customers subscription status by age\"}",
215215
"mills": 74,
216-
"num_yields": 0,
216+
"num_yields": 4,
217217
"response_length": 0,
218218
"nmatched": 608,
219219
"nmodified": 441,
@@ -268,8 +268,8 @@
268268
"query_signature": "c5b7bcd45c4d9e9",
269269
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"test\"}",
270270
"mills": 74,
271-
"num_yields": 0,
272-
"response_length": 0,
271+
"num_yields": 4,
272+
"response_length": 60,
273273
"cpu_nanos": 74715957,
274274
"client": {
275275
"hostname": "192.168.65.1:58133"
@@ -321,7 +321,7 @@
321321
"query_signature": "ec24a2e9aacce5a0",
322322
"statement": "{\"q\": {\"age\": {\"$gt\": 35}}, \"u\": {\"$set\": {\"subscribed\": true}}, \"multi\": true, \"upsert\": false, \"comment\": \"update customers subscription status by age\"}",
323323
"mills": 27,
324-
"num_yields": 0,
324+
"num_yields": 2,
325325
"response_length": 0,
326326
"nmatched": 495,
327327
"nmodified": 495,
@@ -376,8 +376,8 @@
376376
"query_signature": "c5b7bcd45c4d9e9",
377377
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"test\"}",
378378
"mills": 27,
379-
"num_yields": 0,
380-
"response_length": 0,
379+
"num_yields": 2,
380+
"response_length": 60,
381381
"cpu_nanos": 27721625,
382382
"client": {
383383
"hostname": "192.168.65.1:58133"
@@ -485,7 +485,7 @@
485485
"statement": "{\"update\": \"customers\", \"ordered\": true, \"comment\": \"update customers subscription status by age\", \"$db\": \"test\"}",
486486
"mills": 15,
487487
"num_yields": 0,
488-
"response_length": 0,
488+
"response_length": 60,
489489
"cpu_nanos": 15198542,
490490
"client": {
491491
"hostname": "192.168.65.1:58133"
@@ -541,7 +541,7 @@
541541
"query_framework": "classic",
542542
"mills": 12,
543543
"num_yields": 0,
544-
"response_length": 0,
544+
"response_length": 14089,
545545
"nreturned": 101,
546546
"keys_examined": 540,
547547
"docs_examined": 540,
@@ -580,7 +580,7 @@
580580
"query_framework": "classic",
581581
"mills": 14,
582582
"num_yields": 0,
583-
"response_length": 0,
583+
"response_length": 110,
584584
"nreturned": 0,
585585
"keys_examined": 612,
586586
"docs_examined": 612,

0 commit comments

Comments
 (0)