Skip to content

Commit

Permalink
fix failing fw_support integration tests
Browse files Browse the repository at this point in the history
Don't create package major version metric when package version is unknown.
  • Loading branch information
lavarou committed Sep 19, 2024
1 parent 9514a6f commit 0654d0a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
7 changes: 5 additions & 2 deletions agent/fw_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ void nr_fw_support_add_package_supportability_metric(
// override provided package_version only if:
// - php_package is provided
// - its version is not NULL
if (NULL != p && NULL != p->package_version) {
// - its version is not PHP_PACKAGE_VERSION_UNKNOWN
if (NULL != p && NULL != p->package_version
&& 0 == nr_strcmp(version, PHP_PACKAGE_VERSION_UNKNOWN)) {
version = p->package_version;
}

if (NULL == version) {
// only generate metric if version is known
if (NULL == version || 0 == nr_strcmp(version, PHP_PACKAGE_VERSION_UNKNOWN)) {
return;
}

Expand Down
29 changes: 28 additions & 1 deletion agent/tests/test_fw_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ static void test_fw_supportability_metrics_with_vm_disabled(void) {
#define LIBRARY_MAJOR_VERSION_7 "0.4.5"
#define LIBRARY_METRIC "Supportability/library/" LIBRARY_NAME "/detected"
#define LOGGING_LIBRARY_METRIC "Supportability/Logging/PHP/" LIBRARY_NAME
#define PACKAGE_METRIC "Supportability/PHP/package/" LIBRARY_NAME
#define PACKAGE_METRIC_PREFIX "Supportability/PHP/package/"
#define PACKAGE_METRIC PACKAGE_METRIC_PREFIX LIBRARY_NAME
nrtxn_t t;
nrtxn_t* txn = &t;
nr_php_package_t* php_package = NULL;
Expand Down Expand Up @@ -150,9 +151,35 @@ static void test_fw_supportability_metrics_with_vm_enabled(void) {
= {.package_name = LIBRARY_NAME,
.package_version = NULL,
.source_priority = NR_PHP_PACKAGE_SOURCE_COMPOSER};
nr_php_package_t php_package_unknown_version
= {.package_name = LIBRARY_NAME,
.package_version = PHP_PACKAGE_VERSION_UNKNOWN,
.source_priority = NR_PHP_PACKAGE_SOURCE_COMPOSER};
txn->unscoped_metrics = nrm_table_create(10);

NRINI(force_framework) = false;
nr_fw_support_add_package_supportability_metric(txn, LIBRARY_NAME, NULL,
&php_package_null_version);
tlib_pass_if_null(
"library major version metric not created when version is unknown - "
"version is NULL and package version is NULL",
nrm_get_metric(txn->unscoped_metrics, 0));

nr_fw_support_add_package_supportability_metric(txn, LIBRARY_NAME,
PHP_PACKAGE_VERSION_UNKNOWN,
&php_package_null_version);
tlib_pass_if_null(
"library major version metric not created when version is unknown - "
"version is PHP_PACKAGE_VERSION_UNKNOWN and package version is NULL",
nrm_get_metric(txn->unscoped_metrics, 0));

nr_fw_support_add_package_supportability_metric(txn, LIBRARY_NAME, NULL,
&php_package_unknown_version);
tlib_pass_if_null(
"library major version metric not created when version is unknown - "
"version is NULL and package version is PHP_PACKAGE_VERSION_UNKNOWN",
nrm_get_metric(txn->unscoped_metrics, 0));

nr_fw_support_add_package_supportability_metric(
txn, LIBRARY_NAME, LIBRARY_MAJOR_VERSION, &php_package);
tlib_pass_if_not_null(
Expand Down

0 comments on commit 0654d0a

Please sign in to comment.