Skip to content

Commit

Permalink
PHPC-2442: Deprecate getServer, add getHost and getPort to APM events
Browse files Browse the repository at this point in the history
Also updates initial array size for debug output and reorders output fields.
  • Loading branch information
jmikola committed Sep 11, 2024
1 parent 7ba3371 commit e92961d
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 58 deletions.
30 changes: 26 additions & 4 deletions src/MongoDB/Monitoring/CommandFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
RETURN_ZVAL(&intern->z_error, 1, 0);
}

/* Returns this event's host */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getHost)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host.host);
}

/* Returns the event's operation ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
{
Expand All @@ -93,6 +103,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
RETVAL_STRING(operation_id);
}

/* Returns this event's port */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getPort)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->host.port);
}

/* Returns the reply document associated with the event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
{
Expand Down Expand Up @@ -233,24 +253,26 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(phongo_compat_obj

intern = Z_OBJ_COMMANDFAILEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
*is_temp = 1;
array_init_size(&retval, 6);
array_init_size(&retval, 11);

ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);

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

snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}

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

snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);

Expand Down
5 changes: 5 additions & 0 deletions src/MongoDB/Monitoring/CommandFailedEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ final public function getDurationMicros(): int {}

final public function getError(): \Exception {}

final public function getHost(): string {}

final public function getOperationId(): string {}

final public function getPort(): int {}

final public function getReply(): object {}

final public function getRequestId(): string {}

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

final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}
Expand Down
12 changes: 10 additions & 2 deletions src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 26 additions & 4 deletions src/MongoDB/Monitoring/CommandStartedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName
RETVAL_STRING(intern->database_name);
}

/* Returns this event's host */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getHost)
{
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host.host);
}

/* Returns the event's operation ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
{
Expand All @@ -89,6 +99,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
RETVAL_STRING(operation_id);
}

/* Returns this event's port */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getPort)
{
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->host.port);
}

/* Returns the event's request ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
{
Expand Down Expand Up @@ -205,7 +225,12 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob

intern = Z_OBJ_COMMANDSTARTEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
*is_temp = 1;
array_init_size(&retval, 6);
array_init_size(&retval, 10);

ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name);

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

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

ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name);

snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

Expand Down
5 changes: 5 additions & 0 deletions src/MongoDB/Monitoring/CommandStartedEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ final public function getCommandName(): string {}

final public function getDatabaseName(): string {}

final public function getHost(): string {}

final public function getOperationId(): string {}

final public function getPort(): int {}

final public function getRequestId(): string {}

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

final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}
Expand Down
13 changes: 11 additions & 2 deletions src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 26 additions & 4 deletions src/MongoDB/Monitoring/CommandSucceededEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDurationMi
RETURN_LONG(intern->duration_micros);
}

/* Returns this event's host */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getHost)
{
php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host.host);
}

/* Returns the event's operation ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationId)
{
Expand All @@ -81,6 +91,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationI
RETVAL_STRING(operation_id);
}

/* Returns this event's port */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getPort)
{
php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->host.port);
}

/* Returns the reply document associated with the event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getReply)
{
Expand Down Expand Up @@ -217,21 +237,23 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(phongo_compat_

intern = Z_OBJ_COMMANDSUCCEEDEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
*is_temp = 1;
array_init_size(&retval, 6);
array_init_size(&retval, 10);

ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);

snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}

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

snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);

Expand Down
5 changes: 5 additions & 0 deletions src/MongoDB/Monitoring/CommandSucceededEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ final public function getDatabaseName(): string {}

final public function getDurationMicros(): int {}

final public function getHost(): string {}

final public function getOperationId(): string {}

final public function getPort(): int {}

final public function getReply(): object {}

final public function getRequestId(): string {}

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

final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}
Expand Down
Loading

0 comments on commit e92961d

Please sign in to comment.