-
Notifications
You must be signed in to change notification settings - Fork 70
feat(agent): Memcached instance metrics with host name #958
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
Changes from 49 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
275f841
create named datastore metrics for memcached
ZNeumann a462c20
restrict metrics
ZNeumann b5cef15
fixup
ZNeumann 6530778
integration tests
ZNeumann 4c46e86
fix expecteds
ZNeumann ca82d09
refactor
ZNeumann b777c76
PR feedback
ZNeumann 31186d8
add memcached instance socket test
ZNeumann 9fb7bd3
doc string
ZNeumann 55af999
Update agent/php_memcached.c
ZNeumann eb038da
host_or_socket name
ZNeumann f7878e0
Update agent/php_internal_instrument.c
ZNeumann db755da
Update agent/php_internal_instrument.c
ZNeumann ee6ad5f
Update agent/php_internal_instrument.c
ZNeumann 330e976
doc string
ZNeumann c60dacd
move datastore op call
ZNeumann b38b9ca
return status
ZNeumann 1b8a849
add empty addservers test
ZNeumann 5d165f2
fixups
ZNeumann 92ac8d5
unit test
ZNeumann 007c774
more unit tests
ZNeumann 1e97b44
refactor lines
ZNeumann 6db55f6
NULL unit test
ZNeumann f447a56
rename add_server
ZNeumann ae2a70b
NULL check
ZNeumann cf1f772
fix
ZNeumann 330b5c6
more tests
ZNeumann c8b0880
simplify everything
ZNeumann 8c07bd8
test comment
ZNeumann 5ca4df6
remove old code
ZNeumann 3869a62
split tests
ZNeumann 9fae58d
unscoped metrics
ZNeumann a78bcf4
modify socket test
ZNeumann 2125e6f
remove accident
ZNeumann 368a2ba
remove ZTS block
ZNeumann 06cf165
fix regex
ZNeumann 18fff7a
free better
ZNeumann c40cbd4
fix function name
ZNeumann 68843dc
update makefile
ZNeumann 63beced
PR comments
ZNeumann 5597d7f
concise unit tests
ZNeumann 7cbf7f4
more integration tests
ZNeumann 65424c6
environment variables in expecteds
ZNeumann 8ec0268
socket path
ZNeumann a40b011
remove extern
ZNeumann 0453459
revert port
ZNeumann 62b8889
remove comment
ZNeumann 1b227d3
reword
ZNeumann 90f1151
Update agent/php_internal_instrument.c
ZNeumann 3364eb0
fix comment
ZNeumann c8bdfb7
remove incorrect comment
ZNeumann 6e720c9
more tests
ZNeumann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "php_memcached.h" | ||
ZNeumann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "nr_datastore_instance.h" | ||
#include "php_agent.h" | ||
|
||
nr_datastore_instance_t* nr_php_memcached_create_datastore_instance( | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const char* host_or_socket, | ||
zend_long port) { | ||
nr_datastore_instance_t* instance = NULL; | ||
if (port == 0) { // local socket | ||
instance = nr_datastore_instance_create("localhost", host_or_socket, NULL); | ||
} else { | ||
char* port_str = nr_formatf("%ld", (long)port); | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
instance = nr_datastore_instance_create(host_or_socket, port_str, NULL); | ||
nr_free(port_str); | ||
} | ||
return instance; | ||
} | ||
|
||
void nr_php_memcached_create_instance_metric( | ||
const char* host_or_socket, | ||
zend_long port) { | ||
nr_datastore_instance_t* instance | ||
= nr_php_memcached_create_datastore_instance(host_or_socket, port); | ||
char* instance_metric = nr_formatf("Datastore/instance/Memcached/%s/%s", | ||
instance->host, instance->port_path_or_id); | ||
nrm_force_add(NRPRG(txn)->unscoped_metrics, instance_metric, 0); | ||
nr_datastore_instance_destroy(&instance); | ||
nr_free(instance_metric); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef PHP_MEMCACHED_HDR | ||
#define PHP_MEMCACHED_HDR | ||
|
||
#include "nr_datastore_instance.h" | ||
#include "php_includes.h" | ||
|
||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* | ||
* Purpose : Create a datastore instance metadata for a Memcached server. | ||
* | ||
* Params : 1. The memcached host or socket name as given to Memcached::addServer(). | ||
* 2. The memcached port as given as given to Memcached::addServer(). | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Returns: nr_datastore_instance_t* that the caller is responsible for freeing | ||
*/ | ||
nr_datastore_instance_t* nr_php_memcached_create_datastore_instance( | ||
const char* host_or_socket, | ||
zend_long port); | ||
|
||
/* | ||
* Purpose : Create a memcached instance metric | ||
* | ||
* Params : 1. The memcached host or socket name as given to Memcached::addServer(). | ||
* Must be non-null. | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 2. The memcached port as given as given to Memcached::addServer(). | ||
* Must be non-null. | ||
*/ | ||
extern void nr_php_memcached_create_instance_metric( | ||
const char* host_or_socket, | ||
zend_long port); | ||
|
||
|
||
#endif |
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include "tlib_php.h" | ||
#include "tlib_datastore.h" | ||
|
||
#include "php_agent.h" | ||
#include "php_memcached.h" | ||
#include "util_system.h" | ||
|
||
tlib_parallel_info_t parallel_info | ||
= {.suggested_nthreads = -1, .state_size = 0}; | ||
|
||
static char* system_host_name; | ||
|
||
static void test_create_datastore_instance(void) { | ||
assert_datastore_instance_equals_destroy( | ||
"named socket", | ||
&((nr_datastore_instance_t){ | ||
.host = system_host_name, | ||
.database_name = "unknown", | ||
.port_path_or_id = "/tmp/memcached.sock", | ||
}), | ||
nr_php_memcached_create_datastore_instance("/tmp/memcached.sock", 0)); | ||
|
||
assert_datastore_instance_equals_destroy( | ||
"empty socket", | ||
&((nr_datastore_instance_t){ | ||
.host = system_host_name, | ||
.database_name = "unknown", | ||
.port_path_or_id = "unknown", | ||
}), | ||
nr_php_memcached_create_datastore_instance("", 0)); | ||
|
||
assert_datastore_instance_equals_destroy( | ||
"empty host", | ||
&((nr_datastore_instance_t){ | ||
.host = system_host_name, | ||
.database_name = "unknown", | ||
.port_path_or_id = "unknown", | ||
}), | ||
nr_php_memcached_create_datastore_instance(NULL, 0)); | ||
|
||
assert_datastore_instance_equals_destroy( | ||
"host.name socket", | ||
&((nr_datastore_instance_t){ | ||
.host = "host.name", | ||
.database_name = "unknown", | ||
.port_path_or_id = "11211", | ||
}), | ||
nr_php_memcached_create_datastore_instance("host.name", 11211)); | ||
|
||
assert_datastore_instance_equals_destroy( | ||
"host and port", | ||
&((nr_datastore_instance_t){ | ||
.host = "unknown", | ||
.database_name = "unknown", | ||
.port_path_or_id = "6379", | ||
}), | ||
nr_php_memcached_create_datastore_instance("", 6379)); | ||
|
||
assert_datastore_instance_equals_destroy( | ||
"NULL socket", | ||
&((nr_datastore_instance_t){ | ||
.host = "unknown", | ||
.database_name = "unknown", | ||
.port_path_or_id = "11211", | ||
}), | ||
nr_php_memcached_create_datastore_instance(NULL, 11211)); | ||
} | ||
|
||
void test_main(void* p NRUNUSED) { | ||
system_host_name = nr_system_get_hostname(); | ||
|
||
test_create_datastore_instance(); | ||
|
||
nr_free(system_host_name); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should report instance metrics when multiple servers are | ||
added at once via Memcached::addServers() | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php require('skipif.inc'); ?> | ||
*/ | ||
|
||
/*INI | ||
*/ | ||
|
||
/*EXPECT_METRICS_EXIST | ||
Datastore/instance/Memcached/host1/1, 1 | ||
Datastore/instance/Memcached/host2/2, 1 | ||
Datastore/instance/Memcached/host3/11211, 1 | ||
Datastore/instance/Memcached/host4/1, 1 | ||
*/ | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/helpers.php'); | ||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/tap.php'); | ||
require_once(realpath (dirname ( __FILE__ )) . '/memcache.inc'); | ||
|
||
$memcached = new Memcached(); | ||
$memcached->addServers(array( | ||
bduranleau-nr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
array("host1", 1), | ||
array("host2", 2), | ||
array("host3", 11211))); | ||
$memcached->addServers(array()); | ||
lavarou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$memcached->addServers(array(array("host4", 1, "test field"))); | ||
$memcached->quit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should gracefully handle when malformed server entries | ||
are added via Memcached::addServers() | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php require('skipif.inc'); ?> | ||
*/ | ||
|
||
/*INI | ||
*/ | ||
|
||
/*EXPECT_REGEX | ||
|
||
.*(PHP )?Warning:.*could not add entry.* | ||
|
||
.*(PHP )?Warning:.*could not add entry.* | ||
|
||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": "??", | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"type": "TransactionError", | ||
"timestamp": "??", | ||
"error.class": "E_WARNING", | ||
"error.message": "Memcached::addServers(): could not add entry #2 to the server list", | ||
"transactionName": "OtherTransaction\/php__FILE__", | ||
"duration": "??", | ||
"nr.transactionGuid": "??", | ||
"guid": "??", | ||
"sampled": true, | ||
"priority": "??", | ||
"traceId": "??", | ||
"spanId": "??" | ||
}, | ||
{}, | ||
{} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/helpers.php'); | ||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/tap.php'); | ||
require_once(realpath (dirname ( __FILE__ )) . '/memcache.inc'); | ||
|
||
$memcached = new Memcached(); | ||
$memcached->addServer(5, 5); | ||
//$memcached->addServer("host", string); crashes PHP | ||
$memcached->addServers(array(array(1))); | ||
$memcached->addServers(array(array("host1"))); | ||
$memcached->addServers(array(array(1, "host1"))); | ||
//$memcahed->addServers("string"); crashes PHP | ||
$memcached->quit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.