Skip to content

Commit 07cb185

Browse files
authored
CDRIVER-4059 service_id on command monitoring events (#834)
1 parent 635be2f commit 07cb185

16 files changed

+339
-13
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
:man_page: mongoc_apm_command_failed_get_service_id
2+
3+
mongoc_apm_command_failed_get_service_id()
4+
==========================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
const bson_oid_t *
12+
mongoc_apm_command_failed_get_service_id (
13+
const mongoc_apm_command_failed_t *event);
14+
15+
Returns this event's service ID, which identifies the MongoDB service behind a
16+
load balancer, or ``NULL`` if not connected to a load balanced cluster.
17+
18+
Parameters
19+
----------
20+
21+
* ``event``: A :symbol:`mongoc_apm_command_failed_t`.
22+
23+
Returns
24+
-------
25+
26+
A :symbol:`bson_oid_t` that should not be modified or freed or ``NULL``.

src/libmongoc/doc/mongoc_apm_command_failed_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ An event notification sent when the driver fails to execute a MongoDB command.
2828
mongoc_apm_command_failed_get_reply
2929
mongoc_apm_command_failed_get_request_id
3030
mongoc_apm_command_failed_get_server_id
31+
mongoc_apm_command_failed_get_service_id
3132

3233
.. seealso::
3334

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
:man_page: mongoc_apm_command_started_get_service_id
2+
3+
mongoc_apm_command_started_get_service_id()
4+
===========================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
const bson_oid_t *
12+
mongoc_apm_command_started_get_service_id (
13+
const mongoc_apm_command_started_t *event);
14+
15+
Returns this event's service ID, which identifies the MongoDB service behind a
16+
load balancer, or ``NULL`` if not connected to a load balanced cluster.
17+
18+
Parameters
19+
----------
20+
21+
* ``event``: A :symbol:`mongoc_apm_command_started_t`.
22+
23+
Returns
24+
-------
25+
26+
A :symbol:`bson_oid_t` that should not be modified or freed or ``NULL``.

src/libmongoc/doc/mongoc_apm_command_started_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ An event notification sent when the driver begins executing a MongoDB command.
3131
mongoc_apm_command_started_get_operation_id
3232
mongoc_apm_command_started_get_request_id
3333
mongoc_apm_command_started_get_server_id
34+
mongoc_apm_command_started_get_service_id
3435

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
:man_page: mongoc_apm_command_succeeded_get_service_id
2+
3+
mongoc_apm_command_succeeded_get_service_id()
4+
=============================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
const bson_oid_t *
12+
mongoc_apm_command_succeeded_get_service_id (
13+
const mongoc_apm_command_succeeded_t *event);
14+
15+
Returns this event's service ID, which identifies the MongoDB service behind a
16+
load balancer, or ``NULL`` if not connected to a load balanced cluster.
17+
18+
Parameters
19+
----------
20+
21+
* ``event``: A :symbol:`mongoc_apm_command_succeeded_t`.
22+
23+
Returns
24+
-------
25+
26+
A :symbol:`bson_oid_t` that should not be modified or freed or ``NULL``.

src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ An event notification sent when the driver successfully executes a MongoDB comma
3131
mongoc_apm_command_succeeded_get_reply
3232
mongoc_apm_command_succeeded_get_request_id
3333
mongoc_apm_command_succeeded_get_server_id
34+
mongoc_apm_command_succeeded_get_service_id
3435

src/libmongoc/src/mongoc/mongoc-apm-private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct _mongoc_apm_command_started_t {
5555
int64_t operation_id;
5656
const mongoc_host_list_t *host;
5757
uint32_t server_id;
58+
bson_oid_t service_id;
5859
void *context;
5960
};
6061

@@ -67,6 +68,7 @@ struct _mongoc_apm_command_succeeded_t {
6768
int64_t operation_id;
6869
const mongoc_host_list_t *host;
6970
uint32_t server_id;
71+
bson_oid_t service_id;
7072
void *context;
7173
};
7274

@@ -80,6 +82,7 @@ struct _mongoc_apm_command_failed_t {
8082
int64_t operation_id;
8183
const mongoc_host_list_t *host;
8284
uint32_t server_id;
85+
bson_oid_t service_id;
8386
void *context;
8487
};
8588

@@ -155,6 +158,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
155158
int64_t operation_id,
156159
const mongoc_host_list_t *host,
157160
uint32_t server_id,
161+
const bson_oid_t *service_id,
158162
bool *is_redacted, /* out */
159163
void *context);
160164

@@ -177,6 +181,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
177181
int64_t operation_id,
178182
const mongoc_host_list_t *host,
179183
uint32_t server_id,
184+
const bson_oid_t *service_id,
180185
bool force_redaction,
181186
void *context);
182187

@@ -193,6 +198,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
193198
int64_t operation_id,
194199
const mongoc_host_list_t *host,
195200
uint32_t server_id,
201+
const bson_oid_t *service_id,
196202
bool force_redaction,
197203
void *context);
198204

src/libmongoc/src/mongoc/mongoc-apm.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "mongoc-cmd-private.h"
2020
#include "mongoc-handshake-private.h"
2121

22+
static bson_oid_t kObjectIdZero = {{0}};
23+
2224
/*
2325
* An Application Performance Management (APM) implementation, complying with
2426
* MongoDB's Command Monitoring Spec:
@@ -74,6 +76,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
7476
int64_t operation_id,
7577
const mongoc_host_list_t *host,
7678
uint32_t server_id,
79+
const bson_oid_t *service_id,
7780
bool *is_redacted, /* out */
7881
void *context)
7982
{
@@ -129,6 +132,8 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
129132
event->host = host;
130133
event->server_id = server_id;
131134
event->context = context;
135+
136+
bson_oid_copy_unsafe (service_id, &event->service_id);
132137
}
133138

134139

@@ -159,6 +164,7 @@ mongoc_apm_command_started_init_with_cmd (mongoc_apm_command_started_t *event,
159164
cmd->operation_id,
160165
&cmd->server_stream->sd->host,
161166
cmd->server_stream->sd->id,
167+
&cmd->server_stream->sd->service_id,
162168
is_redacted,
163169
context);
164170

@@ -197,6 +203,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
197203
int64_t operation_id,
198204
const mongoc_host_list_t *host,
199205
uint32_t server_id,
206+
const bson_oid_t *service_id,
200207
bool force_redaction,
201208
void *context)
202209
{
@@ -220,6 +227,8 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
220227
event->host = host;
221228
event->server_id = server_id;
222229
event->context = context;
230+
231+
bson_oid_copy_unsafe (service_id, &event->service_id);
223232
}
224233

225234

@@ -254,6 +263,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
254263
int64_t operation_id,
255264
const mongoc_host_list_t *host,
256265
uint32_t server_id,
266+
const bson_oid_t *service_id,
257267
bool force_redaction,
258268
void *context)
259269
{
@@ -278,6 +288,8 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
278288
event->host = host;
279289
event->server_id = server_id;
280290
event->context = context;
291+
292+
bson_oid_copy_unsafe (service_id, &event->service_id);
281293
}
282294

283295

@@ -351,6 +363,19 @@ mongoc_apm_command_started_get_server_id (
351363
}
352364

353365

366+
const bson_oid_t *
367+
mongoc_apm_command_started_get_service_id (
368+
const mongoc_apm_command_started_t *event)
369+
{
370+
if (0 == bson_oid_compare (&event->service_id, &kObjectIdZero)) {
371+
/* serviceId is unset. */
372+
return NULL;
373+
}
374+
375+
return &event->service_id;
376+
}
377+
378+
354379
void *
355380
mongoc_apm_command_started_get_context (
356381
const mongoc_apm_command_started_t *event)
@@ -417,6 +442,19 @@ mongoc_apm_command_succeeded_get_server_id (
417442
}
418443

419444

445+
const bson_oid_t *
446+
mongoc_apm_command_succeeded_get_service_id (
447+
const mongoc_apm_command_succeeded_t *event)
448+
{
449+
if (0 == bson_oid_compare (&event->service_id, &kObjectIdZero)) {
450+
/* serviceId is unset. */
451+
return NULL;
452+
}
453+
454+
return &event->service_id;
455+
}
456+
457+
420458
void *
421459
mongoc_apm_command_succeeded_get_context (
422460
const mongoc_apm_command_succeeded_t *event)
@@ -487,6 +525,19 @@ mongoc_apm_command_failed_get_server_id (
487525
}
488526

489527

528+
const bson_oid_t *
529+
mongoc_apm_command_failed_get_service_id (
530+
const mongoc_apm_command_failed_t *event)
531+
{
532+
if (0 == bson_oid_compare (&event->service_id, &kObjectIdZero)) {
533+
/* serviceId is unset. */
534+
return NULL;
535+
}
536+
537+
return &event->service_id;
538+
}
539+
540+
490541
void *
491542
mongoc_apm_command_failed_get_context (const mongoc_apm_command_failed_t *event)
492543
{

src/libmongoc/src/mongoc/mongoc-apm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ mongoc_apm_command_started_get_host (const mongoc_apm_command_started_t *event);
9999
MONGOC_EXPORT (uint32_t)
100100
mongoc_apm_command_started_get_server_id (
101101
const mongoc_apm_command_started_t *event);
102+
MONGOC_EXPORT (const bson_oid_t *)
103+
mongoc_apm_command_started_get_service_id (
104+
const mongoc_apm_command_started_t *event);
102105
MONGOC_EXPORT (void *)
103106
mongoc_apm_command_started_get_context (
104107
const mongoc_apm_command_started_t *event);
@@ -126,6 +129,9 @@ mongoc_apm_command_succeeded_get_host (
126129
MONGOC_EXPORT (uint32_t)
127130
mongoc_apm_command_succeeded_get_server_id (
128131
const mongoc_apm_command_succeeded_t *event);
132+
MONGOC_EXPORT (const bson_oid_t *)
133+
mongoc_apm_command_succeeded_get_service_id (
134+
const mongoc_apm_command_succeeded_t *event);
129135
MONGOC_EXPORT (void *)
130136
mongoc_apm_command_succeeded_get_context (
131137
const mongoc_apm_command_succeeded_t *event);
@@ -155,6 +161,9 @@ mongoc_apm_command_failed_get_host (const mongoc_apm_command_failed_t *event);
155161
MONGOC_EXPORT (uint32_t)
156162
mongoc_apm_command_failed_get_server_id (
157163
const mongoc_apm_command_failed_t *event);
164+
MONGOC_EXPORT (const bson_oid_t *)
165+
mongoc_apm_command_failed_get_service_id (
166+
const mongoc_apm_command_failed_t *event);
158167
MONGOC_EXPORT (void *)
159168
mongoc_apm_command_failed_get_context (
160169
const mongoc_apm_command_failed_t *event);

src/libmongoc/src/mongoc/mongoc-client.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,7 @@ _mongoc_client_monitor_op_killcursors (mongoc_cluster_t *cluster,
23642364
operation_id,
23652365
&server_stream->sd->host,
23662366
server_stream->sd->id,
2367+
&server_stream->sd->service_id,
23672368
NULL,
23682369
client->apm_context);
23692370

@@ -2411,6 +2412,7 @@ _mongoc_client_monitor_op_killcursors_succeeded (
24112412
operation_id,
24122413
&server_stream->sd->host,
24132414
server_stream->sd->id,
2415+
&server_stream->sd->service_id,
24142416
false,
24152417
client->apm_context);
24162418

@@ -2454,6 +2456,7 @@ _mongoc_client_monitor_op_killcursors_failed (
24542456
operation_id,
24552457
&server_stream->sd->host,
24562458
server_stream->sd->id,
2459+
&server_stream->sd->service_id,
24572460
false,
24582461
client->apm_context);
24592462

0 commit comments

Comments
 (0)