Skip to content

PHP-1741: Remove getServer from APM event classes #1652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UPGRADE FROM 1.x to 2.0
=======================

* The `getServer()` method has been removed from the CommandFailedEvent,
CommandStartedEvent, and CommandSucceededEvent event classes. The `getHost()`
and `getPort()` methods have been added in its place.
24 changes: 1 addition & 23 deletions src/MongoDB/Monitoring/CommandFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
RETVAL_STRING(request_id);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
{
php_phongo_commandfailedevent_t* intern;

intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

phongo_server_init(return_value, &intern->manager, intern->server_id);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServiceId)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
Expand Down Expand Up @@ -195,10 +184,6 @@ static void php_phongo_commandfailedevent_free_object(zend_object* object)
zval_ptr_dtor(&intern->z_error);
}

if (!Z_ISUNDEF(intern->manager)) {
zval_ptr_dtor(&intern->manager);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove the manager field from the corresponding struct as it's no longer used. Same applies to the other command event structs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for catching that ✌️

}

if (intern->reply) {
bson_destroy(intern->reply);
}
Expand Down Expand Up @@ -235,7 +220,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zend_object* obje

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

ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
Expand All @@ -258,13 +243,6 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zend_object* obje
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);

{
zval server;

phongo_server_init(&server, &intern->manager, intern->server_id);
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
}

if (intern->has_service_id) {
zval service_id;

Expand Down
3 changes: 0 additions & 3 deletions src/MongoDB/Monitoring/CommandFailedEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ 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 {}

final public function getServerConnectionId(): ?int {}
Expand Down
7 changes: 1 addition & 6 deletions src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h

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

24 changes: 1 addition & 23 deletions src/MongoDB/Monitoring/CommandStartedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
RETVAL_STRING(request_id);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer)
{
php_phongo_commandstartedevent_t* intern;

intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

phongo_server_init(return_value, &intern->manager, intern->server_id);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId)
{
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
Expand Down Expand Up @@ -169,10 +158,6 @@ static void php_phongo_commandstartedevent_free_object(zend_object* object)

zend_object_std_dtor(&intern->std);

if (!Z_ISUNDEF(intern->manager)) {
zval_ptr_dtor(&intern->manager);
}

if (intern->command) {
bson_destroy(intern->command);
}
Expand Down Expand Up @@ -209,7 +194,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zend_object* obj

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

ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
Expand All @@ -229,13 +214,6 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zend_object* obj
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);

{
zval server;

phongo_server_init(&server, &intern->manager, intern->server_id);
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
}

if (intern->has_service_id) {
zval service_id;

Expand Down
3 changes: 0 additions & 3 deletions src/MongoDB/Monitoring/CommandStartedEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ 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 {}

final public function getServerConnectionId(): ?int {}
Expand Down
7 changes: 1 addition & 6 deletions src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h

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

24 changes: 1 addition & 23 deletions src/MongoDB/Monitoring/CommandSucceededEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getRequestId)
RETVAL_STRING(request_id);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServer)
{
php_phongo_commandsucceededevent_t* intern;

intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

phongo_server_init(return_value, &intern->manager, intern->server_id);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServiceId)
{
php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis());
Expand Down Expand Up @@ -180,10 +169,6 @@ static void php_phongo_commandsucceededevent_free_object(zend_object* object)

zend_object_std_dtor(&intern->std);

if (!Z_ISUNDEF(intern->manager)) {
zval_ptr_dtor(&intern->manager);
}

if (intern->reply) {
bson_destroy(intern->reply);
}
Expand Down Expand Up @@ -220,7 +205,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zend_object* o

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

ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
Expand All @@ -240,13 +225,6 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zend_object* o
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);

{
zval server;

phongo_server_init(&server, &intern->manager, intern->server_id);
ADD_ASSOC_ZVAL_EX(&retval, "server", &server);
}

if (intern->has_service_id) {
zval service_id;

Expand Down
3 changes: 0 additions & 3 deletions src/MongoDB/Monitoring/CommandSucceededEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ 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 {}

final public function getServerConnectionId(): ?int {}
Expand Down
7 changes: 1 addition & 6 deletions src/MongoDB/Monitoring/CommandSucceededEvent_arginfo.h

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

48 changes: 0 additions & 48 deletions src/phongo_apm.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,6 @@ static HashTable* phongo_apm_get_subscribers_to_notify(zend_class_entry* subscri
return subscribers;
}

/* Search for a Manager associated with the given client in the request-scoped
* registry. If any Manager is found, copy it to @out, increment its ref-count,
* and return true; otherwise, set @out to undefined and return false. */
static bool phongo_apm_copy_manager_for_client(mongoc_client_t* client, zval* out)
{
php_phongo_manager_t* manager;

ZVAL_UNDEF(out);

if (!MONGODB_G(managers) || zend_hash_num_elements(MONGODB_G(managers)) == 0) {
return false;
}

ZEND_HASH_FOREACH_PTR(MONGODB_G(managers), manager)
{
if (manager->client == client) {
ZVAL_OBJ(out, &manager->std);
Z_ADDREF_P(out);

return true;
}
}
ZEND_HASH_FOREACH_END();

return false;
}

/* Dispatch an event to all subscribers in a HashTable. The caller is
* responsible for ensuring that subscribers implement the correct interface. */
static void phongo_apm_dispatch_event(HashTable* subscribers, const char* function_name, zval* event)
Expand Down Expand Up @@ -158,13 +131,6 @@ static void phongo_apm_command_started(const mongoc_apm_command_started_t* event
bson_oid_copy(mongoc_apm_command_started_get_service_id(event), &p_event->service_id);
}

if (!phongo_apm_copy_manager_for_client(client, &p_event->manager)) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Found no Manager for client in APM event context");
zval_ptr_dtor(&z_event);

goto cleanup;
}

phongo_apm_dispatch_event(subscribers, "commandStarted", &z_event);
zval_ptr_dtor(&z_event);

Expand Down Expand Up @@ -207,13 +173,6 @@ static void phongo_apm_command_succeeded(const mongoc_apm_command_succeeded_t* e
bson_oid_copy(mongoc_apm_command_succeeded_get_service_id(event), &p_event->service_id);
}

if (!phongo_apm_copy_manager_for_client(client, &p_event->manager)) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Found no Manager for client in APM event context");
zval_ptr_dtor(&z_event);

goto cleanup;
}

phongo_apm_dispatch_event(subscribers, "commandSucceeded", &z_event);
zval_ptr_dtor(&z_event);

Expand Down Expand Up @@ -257,13 +216,6 @@ static void phongo_apm_command_failed(const mongoc_apm_command_failed_t* event)
bson_oid_copy(mongoc_apm_command_failed_get_service_id(event), &p_event->service_id);
}

if (!phongo_apm_copy_manager_for_client(client, &p_event->manager)) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Found no Manager for client in APM event context");
zval_ptr_dtor(&z_event);

goto cleanup;
}

/* We need to process and convert the error right here, otherwise
* debug_info will turn into a recursive loop, and with the wrong trace
* locations */
Expand Down
3 changes: 0 additions & 3 deletions src/phongo_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ typedef struct {
} php_phongo_utcdatetime_t;

typedef struct {
zval manager;
char* command_name;
char* database_name;
uint32_t server_id;
Expand All @@ -298,7 +297,6 @@ typedef struct {
} php_phongo_commandfailedevent_t;

typedef struct {
zval manager;
char* command_name;
char* database_name;
uint32_t server_id;
Expand All @@ -313,7 +311,6 @@ typedef struct {
} php_phongo_commandstartedevent_t;

typedef struct {
zval manager;
char* command_name;
char* database_name;
uint32_t server_id;
Expand Down
Loading