Skip to content

Commit ff6ef07

Browse files
committed
fix failing fw_support integration tests
Don't create package major version metric when package version is unknown.
1 parent 9514a6f commit ff6ef07

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

agent/fw_support.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ void nr_fw_support_add_package_supportability_metric(
7171
// override provided package_version only if:
7272
// - php_package is provided
7373
// - its version is not NULL
74-
if (NULL != p && NULL != p->package_version) {
74+
// - its version is not PHP_PACKAGE_VERSION_UNKNOWN
75+
if (NULL != p && NULL != p->package_version
76+
&& 0 != nr_strcmp(p->package_version, PHP_PACKAGE_VERSION_UNKNOWN)) {
7577
version = p->package_version;
7678
}
7779

78-
if (NULL == version) {
80+
// only generate metric if version is known
81+
if (NULL == version || 0 == nr_strcmp(version, PHP_PACKAGE_VERSION_UNKNOWN)) {
7982
return;
8083
}
8184

agent/tests/test_fw_support.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ static void test_fw_supportability_metrics_with_vm_disabled(void) {
2727
#define LIBRARY_MAJOR_VERSION_7 "0.4.5"
2828
#define LIBRARY_METRIC "Supportability/library/" LIBRARY_NAME "/detected"
2929
#define LOGGING_LIBRARY_METRIC "Supportability/Logging/PHP/" LIBRARY_NAME
30-
#define PACKAGE_METRIC "Supportability/PHP/package/" LIBRARY_NAME
30+
#define PACKAGE_METRIC_PREFIX "Supportability/PHP/package/"
31+
#define PACKAGE_METRIC PACKAGE_METRIC_PREFIX LIBRARY_NAME
3132
nrtxn_t t;
3233
nrtxn_t* txn = &t;
3334
nr_php_package_t* php_package = NULL;
@@ -150,9 +151,35 @@ static void test_fw_supportability_metrics_with_vm_enabled(void) {
150151
= {.package_name = LIBRARY_NAME,
151152
.package_version = NULL,
152153
.source_priority = NR_PHP_PACKAGE_SOURCE_COMPOSER};
154+
nr_php_package_t php_package_unknown_version
155+
= {.package_name = LIBRARY_NAME,
156+
.package_version = PHP_PACKAGE_VERSION_UNKNOWN,
157+
.source_priority = NR_PHP_PACKAGE_SOURCE_COMPOSER};
153158
txn->unscoped_metrics = nrm_table_create(10);
154159

155160
NRINI(force_framework) = false;
161+
nr_fw_support_add_package_supportability_metric(txn, LIBRARY_NAME, NULL,
162+
&php_package_null_version);
163+
tlib_pass_if_null(
164+
"library major version metric not created when version is unknown - "
165+
"version is NULL and package version is NULL",
166+
nrm_get_metric(txn->unscoped_metrics, 0));
167+
168+
nr_fw_support_add_package_supportability_metric(txn, LIBRARY_NAME,
169+
PHP_PACKAGE_VERSION_UNKNOWN,
170+
&php_package_null_version);
171+
tlib_pass_if_null(
172+
"library major version metric not created when version is unknown - "
173+
"version is PHP_PACKAGE_VERSION_UNKNOWN and package version is NULL",
174+
nrm_get_metric(txn->unscoped_metrics, 0));
175+
176+
nr_fw_support_add_package_supportability_metric(txn, LIBRARY_NAME, NULL,
177+
&php_package_unknown_version);
178+
tlib_pass_if_null(
179+
"library major version metric not created when version is unknown - "
180+
"version is NULL and package version is PHP_PACKAGE_VERSION_UNKNOWN",
181+
nrm_get_metric(txn->unscoped_metrics, 0));
182+
156183
nr_fw_support_add_package_supportability_metric(
157184
txn, LIBRARY_NAME, LIBRARY_MAJOR_VERSION, &php_package);
158185
tlib_pass_if_not_null(

0 commit comments

Comments
 (0)