Skip to content

Commit e92961d

Browse files
committed
PHPC-2442: Deprecate getServer, add getHost and getPort to APM events
Also updates initial array size for debug output and reorders output fields.
1 parent 7ba3371 commit e92961d

17 files changed

+203
-58
lines changed

src/MongoDB/Monitoring/CommandFailedEvent.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
7979
RETURN_ZVAL(&intern->z_error, 1, 0);
8080
}
8181

82+
/* Returns this event's host */
83+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getHost)
84+
{
85+
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
86+
87+
PHONGO_PARSE_PARAMETERS_NONE();
88+
89+
RETVAL_STRING(intern->host.host);
90+
}
91+
8292
/* Returns the event's operation ID */
8393
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
8494
{
@@ -93,6 +103,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
93103
RETVAL_STRING(operation_id);
94104
}
95105

106+
/* Returns this event's port */
107+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getPort)
108+
{
109+
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
110+
111+
PHONGO_PARSE_PARAMETERS_NONE();
112+
113+
RETVAL_LONG(intern->host.port);
114+
}
115+
96116
/* Returns the reply document associated with the event */
97117
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
98118
{
@@ -233,24 +253,26 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(phongo_compat_obj
233253

234254
intern = Z_OBJ_COMMANDFAILEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
235255
*is_temp = 1;
236-
array_init_size(&retval, 6);
256+
array_init_size(&retval, 11);
237257

258+
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
259+
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
238260
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
239261
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
240262

241263
ADD_ASSOC_ZVAL_EX(&retval, "error", &intern->z_error);
242264
Z_ADDREF(intern->z_error);
243265

244-
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
245-
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
246-
247266
if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
248267
zval_ptr_dtor(&reply_state.zchild);
249268
goto done;
250269
}
251270

252271
ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);
253272

273+
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
274+
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
275+
254276
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
255277
ADD_ASSOC_STRING(&retval, "requestId", request_id);
256278

src/MongoDB/Monitoring/CommandFailedEvent.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ final public function getDurationMicros(): int {}
1919

2020
final public function getError(): \Exception {}
2121

22+
final public function getHost(): string {}
23+
2224
final public function getOperationId(): string {}
2325

26+
final public function getPort(): int {}
27+
2428
final public function getReply(): object {}
2529

2630
final public function getRequestId(): string {}
2731

32+
/** @deprecated */
2833
final public function getServer(): \MongoDB\Driver\Server {}
2934

3035
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}

src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Monitoring/CommandStartedEvent.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName
7575
RETVAL_STRING(intern->database_name);
7676
}
7777

78+
/* Returns this event's host */
79+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getHost)
80+
{
81+
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
82+
83+
PHONGO_PARSE_PARAMETERS_NONE();
84+
85+
RETVAL_STRING(intern->host.host);
86+
}
87+
7888
/* Returns the event's operation ID */
7989
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
8090
{
@@ -89,6 +99,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
8999
RETVAL_STRING(operation_id);
90100
}
91101

102+
/* Returns this event's port */
103+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getPort)
104+
{
105+
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
106+
107+
PHONGO_PARSE_PARAMETERS_NONE();
108+
109+
RETVAL_LONG(intern->host.port);
110+
}
111+
92112
/* Returns the event's request ID */
93113
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
94114
{
@@ -205,7 +225,12 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob
205225

206226
intern = Z_OBJ_COMMANDSTARTEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
207227
*is_temp = 1;
208-
array_init_size(&retval, 6);
228+
array_init_size(&retval, 10);
229+
230+
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
231+
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
232+
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
233+
ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name);
209234

210235
if (!php_phongo_bson_to_zval_ex(intern->command, &command_state)) {
211236
zval_ptr_dtor(&command_state.zchild);
@@ -214,9 +239,6 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob
214239

215240
ADD_ASSOC_ZVAL(&retval, "command", &command_state.zchild);
216241

217-
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
218-
ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name);
219-
220242
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
221243
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
222244

src/MongoDB/Monitoring/CommandStartedEvent.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ final public function getCommandName(): string {}
1717

1818
final public function getDatabaseName(): string {}
1919

20+
final public function getHost(): string {}
21+
2022
final public function getOperationId(): string {}
2123

24+
final public function getPort(): int {}
25+
2226
final public function getRequestId(): string {}
2327

28+
/** @deprecated */
2429
final public function getServer(): \MongoDB\Driver\Server {}
2530

2631
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}

src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Monitoring/CommandSucceededEvent.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDurationMi
6767
RETURN_LONG(intern->duration_micros);
6868
}
6969

70+
/* Returns this event's host */
71+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getHost)
72+
{
73+
php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
74+
75+
PHONGO_PARSE_PARAMETERS_NONE();
76+
77+
RETVAL_STRING(intern->host.host);
78+
}
79+
7080
/* Returns the event's operation ID */
7181
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationId)
7282
{
@@ -81,6 +91,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationI
8191
RETVAL_STRING(operation_id);
8292
}
8393

94+
/* Returns this event's port */
95+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getPort)
96+
{
97+
php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
98+
99+
PHONGO_PARSE_PARAMETERS_NONE();
100+
101+
RETVAL_LONG(intern->host.port);
102+
}
103+
84104
/* Returns the reply document associated with the event */
85105
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getReply)
86106
{
@@ -217,21 +237,23 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(phongo_compat_
217237

218238
intern = Z_OBJ_COMMANDSUCCEEDEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
219239
*is_temp = 1;
220-
array_init_size(&retval, 6);
240+
array_init_size(&retval, 10);
221241

242+
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
243+
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
222244
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
223245
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
224246

225-
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
226-
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
227-
228247
if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
229248
zval_ptr_dtor(&reply_state.zchild);
230249
goto done;
231250
}
232251

233252
ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);
234253

254+
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
255+
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
256+
235257
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
236258
ADD_ASSOC_STRING(&retval, "requestId", request_id);
237259

src/MongoDB/Monitoring/CommandSucceededEvent.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ final public function getDatabaseName(): string {}
1717

1818
final public function getDurationMicros(): int {}
1919

20+
final public function getHost(): string {}
21+
2022
final public function getOperationId(): string {}
2123

24+
final public function getPort(): int {}
25+
2226
final public function getReply(): object {}
2327

2428
final public function getRequestId(): string {}
2529

30+
/** @deprecated */
2631
final public function getServer(): \MongoDB\Driver\Server {}
2732

2833
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}

0 commit comments

Comments
 (0)