Skip to content

Commit 7b9ae64

Browse files
committed
Added support for upconverting explain method, fixes to adhere to spec
1 parent 64395fb commit 7b9ae64

20 files changed

+1394
-559
lines changed

lib/apm.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,7 @@ var Instrumentation = function(core, options, callback) {
163163
};
164164

165165
// If we have an error
166-
if(err
167-
|| (r && r.result && r.result.writeErrors)
168-
|| (r && r.result && r.result.errmsg)) {
166+
if(err || (r.result.ok == 0)) {
169167
command.failure = err || r.result.writeErrors || r.result;
170168
self.emit('failed', command);
171169
} else {
@@ -245,7 +243,7 @@ var Instrumentation = function(core, options, callback) {
245243

246244
// Command name translation
247245
var commandTranslation = {
248-
'_find': 'find', '_getmore': 'getMore', '_killcursor': 'killCursors'
246+
'_find': 'find', '_getmore': 'getMore', '_killcursor': 'killCursors', '_explain': 'explain'
249247
}
250248

251249
prototypes.forEach(function(proto) {
@@ -317,6 +315,17 @@ var Instrumentation = function(core, options, callback) {
317315
// Override method
318316
if(cmd.explain) command.explain = cmd.explain;
319317
if(cmd.exhaust) command.exhaust = cmd.exhaust;
318+
319+
// If we have a explain flag
320+
if(cmd.explain) {
321+
// Create fake explain command
322+
command = {
323+
explain: command,
324+
verbosity: 'allPlansExecution'
325+
}
326+
// Set up the _explain name for the command
327+
x = '_explain';
328+
}
320329
} else if(x == '_getmore') {
321330
command = {
322331
getMore: this.cursorState.cursorId,

test/functional/apm/bulkWrite.json

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
"data": [
3+
{
4+
"_id": 1,
5+
"x": 11
6+
},
7+
{
8+
"_id": 2,
9+
"x": 22
10+
},
11+
{
12+
"_id": 3,
13+
"x": 33
14+
}
15+
],
16+
"collection_name": "test",
17+
"database_name": "command-monitoring-tests",
18+
"tests": [
19+
{
20+
"description": "A successful mixed bulk write",
21+
"operation": {
22+
"name": "bulkWrite",
23+
"arguments": {
24+
"requests": [
25+
{
26+
"insertOne": {
27+
"document": {
28+
"_id": 4,
29+
"x": 44
30+
}
31+
}
32+
},
33+
{
34+
"updateOne": {
35+
"filter": {
36+
"_id": 3
37+
},
38+
"update": {
39+
"$set": {
40+
"x": 333
41+
}
42+
}
43+
}
44+
}
45+
]
46+
}
47+
},
48+
"expectations": [
49+
{
50+
"command_started_event": {
51+
"command": {
52+
"insert": "test",
53+
"documents": [
54+
{
55+
"_id": 4,
56+
"x": 44
57+
}
58+
],
59+
"ordered": true
60+
},
61+
"command_name": "insert",
62+
"database_name": "command-monitoring-tests"
63+
}
64+
},
65+
{
66+
"command_succeeded_event": {
67+
"reply": {
68+
"ok": 1.0,
69+
"n": 1
70+
},
71+
"command_name": "insert"
72+
}
73+
},
74+
{
75+
"command_started_event": {
76+
"command": {
77+
"update": "test",
78+
"updates": [
79+
{
80+
"q": {
81+
"_id": 3
82+
},
83+
"u": {
84+
"$set": {
85+
"x": 333
86+
}
87+
},
88+
"upsert": false,
89+
"multi": false
90+
}
91+
],
92+
"ordered": true
93+
},
94+
"command_name": "update",
95+
"database_name": "command-monitoring-tests"
96+
}
97+
},
98+
{
99+
"command_succeeded_event": {
100+
"reply": {
101+
"ok": 1.0,
102+
"n": 1
103+
},
104+
"command_name": "update"
105+
}
106+
}
107+
]
108+
},
109+
{
110+
"description": "A successful unordered bulk write with an unacknowledged write concern",
111+
"operation": {
112+
"name": "bulkWrite",
113+
"arguments": {
114+
"requests": [
115+
{
116+
"insertOne": {
117+
"document": {
118+
"_id": 4,
119+
"x": 44
120+
}
121+
}
122+
}
123+
],
124+
"ordered": false,
125+
"writeConcern": {
126+
"w": 0
127+
}
128+
}
129+
},
130+
"expectations": [
131+
{
132+
"command_started_event": {
133+
"command": {
134+
"insert": "test",
135+
"documents": [
136+
{
137+
"_id": 4,
138+
"x": 44
139+
}
140+
],
141+
"ordered": false,
142+
"writeConcern": {
143+
"w": 0
144+
}
145+
},
146+
"command_name": "insert",
147+
"database_name": "command-monitoring-tests"
148+
}
149+
},
150+
{
151+
"command_succeeded_event": {
152+
"reply": {
153+
"ok": 1.0
154+
},
155+
"command_name": "insert"
156+
}
157+
}
158+
]
159+
}
160+
]
161+
}

test/functional/apm/bulkWrite.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
data:
2+
- { _id: 1, x: 11 }
3+
- { _id: 2, x: 22 }
4+
- { _id: 3, x: 33 }
5+
6+
collection_name: &collection_name "test"
7+
database_name: &database_name "command-monitoring-tests"
8+
9+
tests:
10+
-
11+
description: "A successful mixed bulk write"
12+
operation:
13+
name: "bulkWrite"
14+
arguments:
15+
requests:
16+
- insertOne:
17+
document: { _id: 4, x: 44 }
18+
- updateOne:
19+
filter: { _id: 3 }
20+
update: { $set: { x: 333 } }
21+
expectations:
22+
-
23+
command_started_event:
24+
command:
25+
insert: *collection_name
26+
documents:
27+
- { _id: 4, x: 44 }
28+
ordered: true
29+
command_name: "insert"
30+
database_name: *database_name
31+
-
32+
command_succeeded_event:
33+
reply: { ok: 1.0, n: 1 }
34+
command_name: "insert"
35+
-
36+
command_started_event:
37+
command:
38+
update: *collection_name
39+
updates:
40+
- { q: {_id: 3 }, u: { $set: { x: 333 } }, upsert: false, multi: false }
41+
ordered: true
42+
command_name: "update"
43+
database_name: *database_name
44+
-
45+
command_succeeded_event:
46+
reply: { ok: 1.0, n: 1 }
47+
command_name: "update"
48+
-
49+
description: "A successful unordered bulk write with an unacknowledged write concern"
50+
comment: "On a 2.4 server, no GLE is sent and requires a client-side manufactored reply"
51+
operation:
52+
name: "bulkWrite"
53+
arguments:
54+
requests:
55+
- insertOne:
56+
document: { _id: 4, x: 44 }
57+
ordered: false
58+
writeConcern: { w: 0 }
59+
expectations:
60+
-
61+
command_started_event:
62+
command:
63+
insert: *collection_name
64+
documents:
65+
- { _id: 4, x: 44 }
66+
ordered: false
67+
writeConcern: { w: 0 }
68+
command_name: "insert"
69+
database_name: *database_name
70+
-
71+
command_succeeded_event:
72+
reply: { ok: 1.0 }
73+
command_name: "insert"

test/functional/apm/command.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@
3333
},
3434
{
3535
"command_succeeded_event": {
36-
"reply": [
37-
{
38-
"ok": 1,
39-
"n": 1
40-
}
41-
],
42-
"command_name": "count",
43-
"database_name": "command-monitoring-tests"
36+
"reply": {
37+
"ok": 1.0,
38+
"n": 1
39+
},
40+
"command_name": "count"
4441
}
4542
}
4643
]
@@ -70,8 +67,7 @@
7067
},
7168
{
7269
"command_failed_event": {
73-
"command_name": "count",
74-
"database_name": "command-monitoring-tests"
70+
"command_name": "count"
7571
}
7672
}
7773
]

test/functional/apm/command.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ tests:
2121
database_name: *database_name
2222
-
2323
command_succeeded_event:
24-
reply:
25-
- { ok: 1, n: 1 }
24+
reply: { ok: 1.0, n: 1 }
2625
command_name: "count"
27-
database_name: *database_name
2826
-
2927
description: "A failed command event"
3028
operation:
@@ -42,4 +40,3 @@ tests:
4240
-
4341
command_failed_event:
4442
command_name: "count"
45-
database_name: *database_name

0 commit comments

Comments
 (0)