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
…#1644)

Also updates initial array size for debug output and reorders output fields.

* Expect alternative deprecation message for PHP 7.4

* Remove redundant comments for APM event methods
  • Loading branch information
jmikola committed Sep 16, 2024
1 parent c394d37 commit 1869a72
Show file tree
Hide file tree
Showing 20 changed files with 320 additions and 118 deletions.
44 changes: 24 additions & 20 deletions src/MongoDB/Monitoring/CommandFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ zend_class_entry* php_phongo_commandfailedevent_ce;

PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandFailedEvent)

/* Returns the command name for this event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -43,7 +42,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName)
RETVAL_STRING(intern->command_name);
}

/* Returns the database name for this event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -55,7 +53,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName)
RETVAL_STRING(intern->database_name);
}

/* Returns the event's duration in microseconds */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicros)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -67,7 +64,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicro
RETURN_LONG(intern->duration_micros);
}

/* Returns the error document associated with the event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -79,7 +75,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
RETURN_ZVAL(&intern->z_error, 1, 0);
}

/* Returns the event's operation ID */
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);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -93,7 +97,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
RETVAL_STRING(operation_id);
}

/* Returns the reply document associated with the event */
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);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -113,7 +125,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
RETURN_ZVAL(&state.zchild, 0, 1);
}

/* Returns the event's request ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -127,7 +138,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
RETVAL_STRING(request_id);
}

/* Returns the Server from which the event originated */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -139,7 +149,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
phongo_server_init(return_value, &intern->manager, intern->server_id);
}

/* Returns the event's service ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServiceId)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
Expand All @@ -153,7 +162,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServiceId)
phongo_objectid_new(return_value, &intern->service_id);
}

/* Returns the event's server connection ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServerConnectionId)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
Expand All @@ -174,12 +182,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServerConnect
RETURN_LONG(intern->server_connection_id);
}

/**
* Event thrown when a command has failed to execute.
*
* This class is only constructed internally.
*/

/* MongoDB\Driver\Monitoring\CommandFailedEvent object handlers */
static zend_object_handlers php_phongo_handler_commandfailedevent;

Expand Down Expand Up @@ -233,24 +235,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.

42 changes: 24 additions & 18 deletions src/MongoDB/Monitoring/CommandStartedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ zend_class_entry* php_phongo_commandstartedevent_ce;

PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandStartedEvent)

/* Returns the command document associated with the event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand)
{
php_phongo_commandstartedevent_t* intern;
Expand All @@ -51,7 +50,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand)
RETURN_ZVAL(&state.zchild, 0, 1);
}

/* Returns the command name for this event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName)
{
php_phongo_commandstartedevent_t* intern;
Expand All @@ -63,7 +61,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName)
RETVAL_STRING(intern->command_name);
}

/* Returns the database name for this event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName)
{
php_phongo_commandstartedevent_t* intern;
Expand All @@ -75,7 +72,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName
RETVAL_STRING(intern->database_name);
}

/* Returns the event's operation ID */
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);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
{
php_phongo_commandstartedevent_t* intern;
Expand All @@ -89,7 +94,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
RETVAL_STRING(operation_id);
}

/* Returns the event's request ID */
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);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
{
php_phongo_commandstartedevent_t* intern;
Expand All @@ -103,7 +116,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
RETVAL_STRING(request_id);
}

/* Returns the Server from which the event originated */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer)
{
php_phongo_commandstartedevent_t* intern;
Expand All @@ -115,7 +127,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer)
phongo_server_init(return_value, &intern->manager, intern->server_id);
}

/* Returns the event's service ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId)
{
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
Expand All @@ -129,7 +140,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId)
phongo_objectid_new(return_value, &intern->service_id);
}

/* Returns the event's server connection ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServerConnectionId)
{
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
Expand All @@ -150,12 +160,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServerConnec
RETURN_LONG(intern->server_connection_id);
}

/**
* Event thrown when a command has started to execute.
*
* This class is only constructed internally.
*/

/* MongoDB\Driver\Monitoring\CommandStartedEvent object handlers */
static zend_object_handlers php_phongo_handler_commandstartedevent;

Expand Down Expand Up @@ -205,7 +209,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 +223,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.

Loading

0 comments on commit 1869a72

Please sign in to comment.