Skip to content
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

feat(agent): Add supportability metrics for packages that provide major version #868

Merged
merged 21 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
879b332
feat(agent): create new function that sends up supportability metrics…
hahuja2 Mar 25, 2024
2a83042
feat(agent): add supportability metrics for packages that provide ver…
hahuja2 Mar 25, 2024
08dbf01
feat(agent): add if statement to check if major version is more than …
hahuja2 Mar 26, 2024
cfa5e7f
feat(agent): set major version to first digit only in else statement
hahuja2 Mar 27, 2024
9ff6234
feat(agent): improve how the major version is found
hahuja2 Mar 27, 2024
3d36800
chore(agent): add check to ensure major version is not null
hahuja2 Mar 27, 2024
2b4836a
chore(agent): set predis to specific version instead of latest
hahuja2 Mar 27, 2024
67eaae4
chore(agent): add new supportability metric to guzzle and predis tests
hahuja2 Mar 27, 2024
e32440d
chore(agent): add if statement to not run predis tests on PHP 7.0/7.1
hahuja2 Mar 28, 2024
5248b97
chore(agent): add supportability metrics for guzzle and monolog by ma…
hahuja2 Mar 29, 2024
1fb5879
chore(agent): add macro to remove duplication
hahuja2 Mar 29, 2024
e94e897
chore(agent): fix error
hahuja2 Mar 29, 2024
4b61257
chore(agent): simplify how we look for major version
hahuja2 Apr 8, 2024
c8f52a4
chore(agent): add unit tests for package detection supportability metric
hahuja2 Apr 9, 2024
4231922
chore(agent): increase size to account for null terminator
hahuja2 Apr 9, 2024
5eedee9
chore(agent): change where version is defined
hahuja2 Apr 9, 2024
15c0422
chore(agent): define version at the top
hahuja2 Apr 9, 2024
97c639e
chore(agent): add additional tests
hahuja2 Apr 10, 2024
647d424
chore(agent): add supportability metric even when VM is disabled
hahuja2 Apr 10, 2024
0fc0bde
chore(agent): update description
hahuja2 Apr 10, 2024
55c1e1e
chore(agent): define major version length
hahuja2 Apr 15, 2024
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
2 changes: 2 additions & 0 deletions agent/fw_drupal8.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ void nr_drupal_version() {
if (nr_php_is_zval_valid_string(zval_version)) {
char* version = Z_STRVAL_P(zval_version);
nr_txn_add_php_package(NRPRG(txn), "drupal/core", version);
nr_fw_support_add_package_supportability_metric(NRPRG(txn), "drupal/core",
mfulb marked this conversation as resolved.
Show resolved Hide resolved
version);
}

nr_php_zval_free(&zval_version);
Expand Down
2 changes: 2 additions & 0 deletions agent/fw_laravel.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,8 @@ NR_PHP_WRAPPER(nr_laravel_application_construct) {
if (NRINI(vulnerability_management_package_detection_enabled)) {
// Add php package to transaction
nr_txn_add_php_package(NRPRG(txn), "laravel/framework", version);
nr_fw_support_add_package_supportability_metric(
NRPRG(txn), "laravel/framework", version);
}

if (version) {
Expand Down
3 changes: 3 additions & 0 deletions agent/fw_slim.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ NR_PHP_WRAPPER(nr_slim_application_construct) {
// Add php package to transaction
nr_txn_add_php_package(NRPRG(txn), "slim/slim", version);

nr_fw_support_add_package_supportability_metric(NRPRG(txn), "slim/slim",
version);

nr_free(version);
nr_php_scope_release(&this_var);
}
Expand Down
38 changes: 38 additions & 0 deletions agent/fw_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,41 @@ void nr_fw_support_add_logging_supportability_metric(nrtxn_t* txn,
nrm_force_add(txn->unscoped_metrics, metname, 0);
nr_free(metname);
}

void nr_fw_support_add_package_supportability_metric(
nrtxn_t* txn,
const char* package_name,
const char* package_version) {
if (NULL == txn || NULL == package_name || NULL == package_version) {
return;
}

char* metname = NULL;
char major_version[4] = {0};

/* The below for loop checks if the major version of the package is more than
* one digit and keeps looping until a '.' is encountered or one of the
* conditions is met.
*/
for (int i = 0; package_version[i] && i < 4; i++) {
if ('.' == package_version[i]) {
strncpy(major_version, package_version, i);
major_version[i] = '\0';
break;
}
}

if ('\0' == major_version[0]) {
return;
}

if (NR_FW_UNSET == NRINI(force_framework)) {
metname = nr_formatf("Supportability/PHP/package/%s/%s/detected",
package_name, major_version);
} else {
metname = nr_formatf("Supportability/PHP/package/%s/%s/forced",
package_name, major_version);
}
nrm_force_add(txn->unscoped_metrics, metname, 0);
nr_free(metname);
}
13 changes: 13 additions & 0 deletions agent/fw_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ extern void nr_fw_support_add_logging_supportability_metric(
const char* library_name,
const bool is_enabled);

/*
* Purpose: Add 'Supportability/PHP/package/{package}/{version}/detected' metric
*
* Params : 1. Transaction object
* 2. Package name
* 3. Package version
*
*/
extern void nr_fw_support_add_package_supportability_metric(
nrtxn_t* txn,
const char* package_name,
const char* package_version);

#endif /* FW_SUPPORT_HDR */
2 changes: 2 additions & 0 deletions agent/fw_wordpress.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ void nr_wordpress_version() {
if (nr_php_is_zval_valid_string(&retval)) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "wordpress", version);
nr_fw_support_add_package_supportability_metric(NRPRG(txn), "wordpress",
version);
}
zval_dtor(&retval);
}
Expand Down
2 changes: 2 additions & 0 deletions agent/lib_guzzle6.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ NR_PHP_WRAPPER_START(nr_guzzle6_client_construct) {
char* version = nr_php_get_object_constant(this_var, "VERSION");
// Add php package to transaction
nr_txn_add_php_package(NRPRG(txn), "guzzlehttp/guzzle", version);
nr_fw_support_add_package_supportability_metric(
NRPRG(txn), "guzzlehttp/guzzle", version);
nr_free(version);
}

Expand Down
2 changes: 2 additions & 0 deletions agent/lib_predis.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ NR_PHP_WRAPPER(nr_predis_client_construct) {
char* version = nr_php_get_object_constant(scope, "VERSION");
// Add php package to transaction
nr_txn_add_php_package(NRPRG(txn), "predis/predis", version);
nr_fw_support_add_package_supportability_metric(
NRPRG(txn), "predis/predis", version);
nr_free(version);
}

Expand Down
2 changes: 1 addition & 1 deletion files/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ RUN \
# install predis
# installation will be in /usr/src/vendor/predis/predis
# which is value which should be used for PREDIS_HOME
RUN php composer.phar require "predis/predis"
RUN php composer.phar require "predis/predis:2.2.2"
RUN php composer.phar update

#
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle6/test_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle6/test_dt.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle6/test_dt_synthetics.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
[{"name":"WebTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"WebTransactionTotalTime/Uri__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
[{"name":"WebTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"WebTransactionTotalTime/Uri__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"HttpDispatcher"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, [3, 0, 0, 0, 0, 0]],
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/external/guzzle6/test_no_cat_no_dt.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/guzzlehttp/guzzle/6/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/predis/test_basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/predis/predis/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Predis/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/predis/test_basic_logging_off.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/predis/predis/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Predis/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Forwarding/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/predis/test_basic_reporting_disabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/predis/predis/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Predis/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/predis/test_pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/predis/predis/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Predis/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/predis/test_pipeline_atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/predis/predis/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Predis/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
1 change: 1 addition & 0 deletions tests/integration/predis/test_pipeline_fire_and_forget.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/predis/predis/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Predis/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/PHP/package/predis/predis/2/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/library/Predis/detected"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Forwarding/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/Logging/Metrics/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
Expand Down
Loading