From f27a884423570d250c79427c4a96df95a6321987 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 10 May 2024 14:27:02 +0900 Subject: [PATCH] processor_metrics_selector: Add test case for delete_label_value operation Signed-off-by: Hiroshi Hatake --- tests/runtime/processor_metrics_selector.c | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/runtime/processor_metrics_selector.c b/tests/runtime/processor_metrics_selector.c index 78f64e83b14..02d7b02d51b 100644 --- a/tests/runtime/processor_metrics_selector.c +++ b/tests/runtime/processor_metrics_selector.c @@ -613,6 +613,82 @@ void flb_test_selector_can_modify_output(void) flb_stop(ctx); flb_destroy(ctx); } + + +void flb_test_selector_context_delete_label_value(void) +{ + int ret; + flb_ctx_t *ctx; + int in_ffd; + int out_ffd; + struct flb_processor *proc; + struct flb_processor_unit *pu; + struct cfl_variant var = { + .type = CFL_VARIANT_STRING, + .data.as_string = "delete_label_value", + }; + struct cfl_variant label_pair = { + .type = CFL_VARIANT_STRING, + .data.as_string = "name lib.0", + }; + int got; + int n_metrics = 20; + int not_used = 0; + struct flb_lib_out_cb cb_data; + + /* Prepare output callback with expected result */ + cb_data.cb = cb_count_metrics_msgpack; + cb_data.data = ¬_used; + + ctx = flb_create(); + flb_service_set(ctx, + "Flush", "0.200000000", + "Grace", "2", + NULL); + + proc = flb_processor_create(ctx->config, "unit_test", NULL, 0); + TEST_CHECK(proc != NULL); + + pu = flb_processor_unit_create(proc, FLB_PROCESSOR_METRICS, "metrics_selector"); + TEST_CHECK(pu != NULL); + ret = flb_processor_unit_set_property(pu, "context", &var); + TEST_CHECK(ret == 0); + ret = flb_processor_unit_set_property(pu, "label", &label_pair); + TEST_CHECK(ret == 0); + + /* Input */ + in_ffd = flb_input(ctx, (char *) "fluentbit_metrics", NULL); + TEST_CHECK(in_ffd >= 0); + ret = flb_input_set(ctx, in_ffd, "tag", "test", NULL); + TEST_CHECK(ret == 0); + ret = flb_input_set(ctx, in_ffd, "scrape_on_start", "true", NULL); + TEST_CHECK(ret == 0); + ret = flb_input_set(ctx, in_ffd, "scrape_interval", "1", NULL); + TEST_CHECK(ret == 0); + + /* set up processor */ + ret = flb_input_set_processor(ctx, in_ffd, proc); + TEST_CHECK(ret == 0); + + out_ffd = flb_output(ctx, (char *) "lib", &cb_data); + TEST_CHECK(out_ffd >= 0); + flb_output_set(ctx, out_ffd, "match", "test", NULL); + + clear_output_num(); + + ret = flb_start(ctx); + TEST_CHECK(ret == 0); + + flb_time_msleep(1500); /* waiting flush */ + + got = get_output_num(); + if (!TEST_CHECK(got >= n_metrics)) { + TEST_MSG("expect: %d >= %d, got: %d < %d", got, n_metrics, got, n_metrics); + } + + flb_stop(ctx); + flb_destroy(ctx); +} #endif /* Test list */ @@ -625,6 +701,7 @@ TEST_LIST = { {"substring_include", flb_test_selector_substring_include}, {"substring_exclude", flb_test_selector_substring_exclude}, {"can_modify_output", flb_test_selector_can_modify_output}, + {"context_delete_label_value", flb_test_selector_context_delete_label_value}, #endif {NULL, NULL} };