Skip to content

Commit

Permalink
processor_metrics_selector: Add test case for delete_label_value oper…
Browse files Browse the repository at this point in the history
…ation

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
  • Loading branch information
cosmo0920 committed May 10, 2024
1 parent 2fca359 commit e73334c
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/runtime/processor_metrics_selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,82 @@ void flb_test_selector_substring_exclude(void)
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 = &not_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 */
Expand All @@ -560,6 +636,7 @@ TEST_LIST = {
{"prefix_exclude", flb_test_selector_prefix_exclude},
{"substring_include", flb_test_selector_substring_include},
{"substring_exclude", flb_test_selector_substring_exclude},
{"context_delete_label_value", flb_test_selector_context_delete_label_value},
#endif
{NULL, NULL}
};

0 comments on commit e73334c

Please sign in to comment.