|
57 | 57 | /* Test functions */
|
58 | 58 | void flb_test_log_to_metrics_counter_k8s(void);
|
59 | 59 | void flb_test_log_to_metrics_counter(void);
|
| 60 | +void flb_test_log_to_metrics_counter_value_field(void); |
60 | 61 | void flb_test_log_to_metrics_counter_k8s_two_tuples(void);
|
61 | 62 | void flb_test_log_to_metrics_gauge(void);
|
62 | 63 | void flb_test_log_to_metrics_histogram(void);
|
@@ -118,6 +119,7 @@ void flb_test_log_to_metrics_label(void);
|
118 | 119 | TEST_LIST = {
|
119 | 120 | {"counter_k8s", flb_test_log_to_metrics_counter_k8s },
|
120 | 121 | {"counter", flb_test_log_to_metrics_counter },
|
| 122 | + {"counter_value_field", flb_test_log_to_metrics_counter_value_field }, |
121 | 123 | {"counter_k8s_two_tuples", flb_test_log_to_metrics_counter_k8s_two_tuples },
|
122 | 124 | {"gauge", flb_test_log_to_metrics_gauge },
|
123 | 125 | {"histogram", flb_test_log_to_metrics_histogram },
|
@@ -321,6 +323,74 @@ void flb_test_log_to_metrics_counter(void)
|
321 | 323 |
|
322 | 324 | }
|
323 | 325 |
|
| 326 | +void flb_test_log_to_metrics_counter_value_field(void) |
| 327 | +{ |
| 328 | + int ret; |
| 329 | + int i; |
| 330 | + flb_ctx_t *ctx; |
| 331 | + int in_ffd; |
| 332 | + int filter_ffd; |
| 333 | + int out_ffd; |
| 334 | + char *result = NULL; |
| 335 | + struct flb_lib_out_cb cb_data; |
| 336 | + char *input = JSON_MSG1; |
| 337 | + char finalString[32768] = ""; |
| 338 | + const char *expected = "\"value\":100.0,\"labels\":[\"red\",\"right\"]"; |
| 339 | + const char *expected2 = "{\"ns\":\"myns\",\"ss\":\"subsystem\"," |
| 340 | + "\"name\":\"test\",\"desc\":\"Counts durations\"}"; |
| 341 | + |
| 342 | + ctx = flb_create(); |
| 343 | + flb_service_set(ctx, "Flush", "0.200000000", "Grace", "1", "Log_Level", |
| 344 | + "error", NULL); |
| 345 | + |
| 346 | + cb_data.cb = callback_test; |
| 347 | + cb_data.data = NULL; |
| 348 | + |
| 349 | + in_ffd = flb_input(ctx, (char *) "lib", NULL); |
| 350 | + TEST_CHECK(in_ffd >= 0); |
| 351 | + flb_input_set(ctx, in_ffd, "tag", "test", NULL); |
| 352 | + |
| 353 | + filter_ffd = flb_filter(ctx, (char *) "log_to_metrics", NULL); |
| 354 | + TEST_CHECK(filter_ffd >= 0); |
| 355 | + ret = flb_filter_set(ctx, filter_ffd, |
| 356 | + "Match", "*", |
| 357 | + "Tag", "test_metric", |
| 358 | + "metric_mode", "counter", |
| 359 | + "metric_name", "test", |
| 360 | + "metric_description", "Counts durations", |
| 361 | + "metric_subsystem", "subsystem", |
| 362 | + "metric_namespace", "myns", |
| 363 | + "kubernetes_mode", "off", |
| 364 | + "label_field", "color", |
| 365 | + "label_field", "direction", |
| 366 | + "value_field", "duration", |
| 367 | + NULL); |
| 368 | + |
| 369 | + out_ffd = flb_output(ctx, (char *) "lib", (void *)&cb_data); |
| 370 | + TEST_CHECK(out_ffd >= 0); |
| 371 | + flb_output_set(ctx, out_ffd, |
| 372 | + "match", "*", |
| 373 | + "format", "json", |
| 374 | + NULL); |
| 375 | + ret = flb_start(ctx); |
| 376 | + TEST_CHECK(ret == 0); |
| 377 | + |
| 378 | + for (i = 0; i < 5; i++){ |
| 379 | + flb_lib_push(ctx, in_ffd, input, strlen(input)); |
| 380 | + } |
| 381 | + wait_with_timeout(2000, finalString); |
| 382 | + result = strstr(finalString, expected); |
| 383 | + if (!TEST_CHECK(result != NULL)) { |
| 384 | + TEST_MSG("expected substring:\n%s\ngot:\n%s\n", expected, finalString); |
| 385 | + } |
| 386 | + result = strstr(finalString, expected2); |
| 387 | + if (!TEST_CHECK(result != NULL)) { |
| 388 | + TEST_MSG("expected substring:\n%s\ngot:\n%s\n", expected, finalString); |
| 389 | + } |
| 390 | + filter_test_destroy(ctx); |
| 391 | + |
| 392 | +} |
| 393 | + |
324 | 394 | void flb_test_log_to_metrics_counter_k8s_two_tuples(void)
|
325 | 395 | {
|
326 | 396 | int ret;
|
|
0 commit comments