@@ -161,6 +161,133 @@ static void test_max_segments_config_values(TSRMLS_D) {
161
161
tlib_php_request_end ();
162
162
}
163
163
164
+ #define PHP_VERSION_METRIC_BASE "Supportability/PHP/Version"
165
+ #define AGENT_VERSION_METRIC_BASE "Supportability/PHP/AgentVersion"
166
+
167
+ static void test_create_php_version_metric () {
168
+ nrtxn_t * txn ;
169
+ int count ;
170
+
171
+ tlib_php_request_start ();
172
+ txn = NRPRG (txn );
173
+
174
+ count = nrm_table_size (txn -> unscoped_metrics );
175
+
176
+ /* Test invalid values are properly handled */
177
+ nr_php_txn_create_php_version_metric (NULL , NULL );
178
+ tlib_pass_if_int_equal ("PHP version metric shouldnt be created 1" , count ,
179
+ nrm_table_size (txn -> unscoped_metrics ));
180
+
181
+ nr_php_txn_create_php_version_metric (txn , NULL );
182
+ tlib_pass_if_int_equal ("PHP version metric shouldnt be created 2" , count ,
183
+ nrm_table_size (txn -> unscoped_metrics ));
184
+
185
+ nr_php_txn_create_php_version_metric (NULL , "7.4.0" );
186
+ tlib_pass_if_int_equal ("PHP version metric shouldnt be created 3" , count ,
187
+ nrm_table_size (txn -> unscoped_metrics ));
188
+
189
+ nr_php_txn_create_php_version_metric (txn , "" );
190
+ tlib_pass_if_int_equal ("PHP version metric shouldnt be created 4" , count ,
191
+ nrm_table_size (txn -> unscoped_metrics ));
192
+
193
+ /* test valid values */
194
+ nr_php_txn_create_php_version_metric (txn , "7.4.0" );
195
+ tlib_pass_if_int_equal ("PHP version metric should be create" , count + 1 ,
196
+ nrm_table_size (txn -> unscoped_metrics ));
197
+
198
+ const nrmetric_t * metric
199
+ = nrm_find (txn -> unscoped_metrics , PHP_VERSION_METRIC_BASE "/7.4.0" );
200
+ const char * metric_name = nrm_get_name (txn -> unscoped_metrics , metric );
201
+
202
+ tlib_pass_if_not_null ("PHP version metric found" , metric );
203
+ tlib_pass_if_str_equal ("PHP version metric name check" , metric_name ,
204
+ PHP_VERSION_METRIC_BASE "/7.4.0" );
205
+
206
+ tlib_php_request_end ();
207
+ }
208
+
209
+ static void test_create_agent_version_metric () {
210
+ nrtxn_t * txn ;
211
+ int count ;
212
+
213
+ tlib_php_request_start ();
214
+ txn = NRPRG (txn );
215
+
216
+ count = nrm_table_size (txn -> unscoped_metrics );
217
+
218
+ /* Test invalid values are properly handled */
219
+ nr_php_txn_create_agent_version_metric (NULL );
220
+ tlib_pass_if_int_equal ("Agent version metric shouldnt be created - txn is NULL" , count ,
221
+ nrm_table_size (txn -> unscoped_metrics ));
222
+
223
+ /* Test valid values */
224
+ nr_php_txn_create_agent_version_metric (txn );
225
+ tlib_pass_if_int_equal ("Agent version metric should be created - txn is not NULL" , count + 1 ,
226
+ nrm_table_size (txn -> unscoped_metrics ));
227
+
228
+ const nrmetric_t * metric
229
+ = nrm_find (txn -> unscoped_metrics , AGENT_VERSION_METRIC_BASE "/" NR_VERSION );
230
+ const char * metric_name = nrm_get_name (txn -> unscoped_metrics , metric );
231
+
232
+ tlib_pass_if_not_null ("Agent version metric found" , metric );
233
+ tlib_pass_if_str_equal ("Agent version metric name check" , metric_name ,
234
+ AGENT_VERSION_METRIC_BASE "/" NR_VERSION );
235
+
236
+ tlib_php_request_end ();
237
+ }
238
+
239
+ static void test_create_agent_php_version_metrics () {
240
+ nrtxn_t * txn ;
241
+
242
+ /*
243
+ * Test : Create agent PHP version metrics.
244
+ */
245
+ tlib_php_request_start ();
246
+ txn = NRPRG (txn );
247
+
248
+ zval * expected_php_zval = tlib_php_request_eval_expr ("phpversion();" );
249
+
250
+ char * php_version_name = nr_formatf (PHP_VERSION_METRIC_BASE "/%s" ,
251
+ Z_STRVAL_P (expected_php_zval ));
252
+
253
+ nr_php_zval_free (& expected_php_zval );
254
+
255
+ char * agent_version_name
256
+ = nr_formatf (AGENT_VERSION_METRIC_BASE "/%s" , NR_VERSION );
257
+
258
+ nr_php_txn_create_agent_php_version_metrics (txn );
259
+
260
+ /* Test the PHP version metric creation */
261
+ const nrmetric_t * metric = nrm_find (txn -> unscoped_metrics , php_version_name );
262
+ const char * metric_name = nrm_get_name (txn -> unscoped_metrics , metric );
263
+
264
+ tlib_pass_if_not_null ("happy path: PHP version metric created" , metric );
265
+ tlib_pass_if_not_null ("happy path: PHP version metric name created" ,
266
+ metric_name );
267
+
268
+ tlib_pass_if_str_equal ("happy path: PHP version metric name check" ,
269
+ metric_name , php_version_name );
270
+
271
+ /* Test the agent version metric creation*/
272
+ metric = nrm_find (txn -> unscoped_metrics , agent_version_name );
273
+ metric_name = nrm_get_name (txn -> unscoped_metrics , metric );
274
+
275
+ tlib_pass_if_not_null ("happy path: Agent version metric created" , metric );
276
+ tlib_pass_if_not_null ("happy path: Agent version metric name created" ,
277
+ metric_name );
278
+
279
+ tlib_pass_if_str_equal ("happy path: Agent version metric name check" ,
280
+ metric_name , agent_version_name );
281
+
282
+ nr_free (agent_version_name );
283
+ nr_free (php_version_name );
284
+
285
+ tlib_php_request_end ();
286
+ }
287
+
288
+ #undef PHP_VERSION_METRIC_BASE
289
+ #undef AGENT_VERSION_METRIC_BASE
290
+
164
291
tlib_parallel_info_t parallel_info = {.suggested_nthreads = 1 , .state_size = 0 };
165
292
166
293
void test_main (void * p NRUNUSED ) {
@@ -175,8 +302,11 @@ void test_main(void* p NRUNUSED) {
175
302
tlib_php_engine_create (
176
303
"newrelic.transaction_events.attributes.include=request.uri" PTSRMLS_CC );
177
304
178
- test_handle_fpm_error (TSRMLS_C );
179
- test_max_segments_config_values (TSRMLS_C );
305
+ test_handle_fpm_error ();
306
+ test_max_segments_config_values ();
307
+ test_create_php_version_metric ();
308
+ test_create_agent_version_metric ();
309
+ test_create_agent_php_version_metrics ();
180
310
181
- tlib_php_engine_destroy (TSRMLS_C );
311
+ tlib_php_engine_destroy ();
182
312
}
0 commit comments