Skip to content

Commit 63beced

Browse files
committed
PR comments
1 parent 68843dc commit 63beced

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

agent/php_internal_instrument.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,21 +1538,14 @@ NR_INNER_WRAPPER(memcached_add_server) {
15381538
nr_string_len_t host_len = 0;
15391539
zend_long port = 0;
15401540
zend_long weight = 0;
1541-
nr_datastore_instance_t* instance = NULL;
1542-
char* instance_metric = NULL;
15431541
int zcaught = 0;
15441542

15451543
if (SUCCESS
15461544
== zend_parse_parameters_ex(
15471545
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s|ll", &host,
15481546
&host_len, &port, &weight) &&
15491547
NULL != host) {
1550-
instance = nr_php_memcached_create_datastore_instance(host, port);
1551-
instance_metric = nr_formatf("Datastore/instance/Memcached/%s/%s",
1552-
instance->host, instance->port_path_or_id);
1553-
nrm_force_add(NRPRG(txn)->unscoped_metrics, instance_metric, 0);
1554-
nr_datastore_instance_destroy(&instance);
1555-
nr_free(instance_metric);
1548+
nr_php_memcached_create_instance_metric(host, port);
15561549
}
15571550
zcaught = nr_zend_call_old_handler(nr_wrapper->oldhandler,
15581551
INTERNAL_FUNCTION_PARAM_PASSTHRU);
@@ -1565,8 +1558,6 @@ NR_INNER_WRAPPER(memcached_add_server) {
15651558
NR_INNER_WRAPPER(memcached_add_servers) {
15661559
zval* servers = NULL;
15671560
zval* server = NULL;
1568-
nr_datastore_instance_t* instance = NULL;
1569-
char* instance_metric = NULL;
15701561
int zcaught = 0;
15711562

15721563
if (SUCCESS
@@ -1576,14 +1567,9 @@ NR_INNER_WRAPPER(memcached_add_servers) {
15761567
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(servers), server) {
15771568
zval* host = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 0);
15781569
zval* port = nr_php_zend_hash_index_find(Z_ARRVAL_P(server), 1);
1579-
if (NULL != host && NULL != port &&
1580-
Z_TYPE_P(host) == IS_STRING && Z_TYPE_P(port) == IS_LONG) {
1581-
instance = nr_php_memcached_create_datastore_instance(Z_STRVAL_P(host), Z_LVAL_P(port));
1582-
instance_metric = nr_formatf("Datastore/instance/Memcached/%s/%s",
1583-
instance->host, instance->port_path_or_id);
1584-
nrm_force_add(NRPRG(txn)->unscoped_metrics, instance_metric, 0);
1585-
nr_datastore_instance_destroy(&instance);
1586-
nr_free(instance_metric);
1570+
if (nr_php_is_zval_valid_string(host) &&
1571+
nr_php_is_zval_valid_integer(port)) {
1572+
nr_php_memcached_create_instance_metric(Z_STRVAL_P(host), Z_LVAL_P(port));
15871573
}
15881574
}
15891575
ZEND_HASH_FOREACH_END();

agent/php_memcached.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ nr_datastore_instance_t* nr_php_memcached_create_datastore_instance(
2121
return instance;
2222
}
2323

24+
void nr_php_memcached_create_instance_metric(
25+
const char* host_or_socket,
26+
zend_long port) {
27+
nr_datastore_instance_t* instance
28+
= nr_php_memcached_create_datastore_instance(host_or_socket, port);
29+
char* instance_metric = nr_formatf("Datastore/instance/Memcached/%s/%s",
30+
instance->host, instance->port_path_or_id);
31+
nrm_force_add(NRPRG(txn)->unscoped_metrics, instance_metric, 0);
32+
nr_datastore_instance_destroy(&instance);
33+
nr_free(instance_metric);
34+
}

agent/php_memcached.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ extern nr_datastore_instance_t* nr_php_memcached_create_datastore_instance(
2121
const char* host_or_socket,
2222
zend_long port);
2323

24+
/*
25+
* Purpose : Create a memcached instance metric
26+
*
27+
* Params : 1. The memcached host or socket name as given to Memcached::addServer().
28+
* Must be non-null.
29+
* 2. The memcached port as given as given to Memcached::addServer().
30+
* Must be non-null.
31+
*/
32+
extern void nr_php_memcached_create_instance_metric(
33+
const char* host_or_socket,
34+
zend_long port);
35+
36+
2437
#endif

0 commit comments

Comments
 (0)