From b82c1795d5f3b53027b756f828c5ea67432f2dda Mon Sep 17 00:00:00 2001 From: Francisco Valente <1435136+franciscovalentecastro@users.noreply.github.com> Date: Mon, 27 Nov 2023 21:06:49 +0000 Subject: [PATCH] in_dummy: Add flush_on_startup config. Signed-off-by: Francisco Valente <1435136+franciscovalentecastro@users.noreply.github.com> --- plugins/in_dummy/in_dummy.c | 9 +++++++++ plugins/in_dummy/in_dummy.h | 1 + tests/runtime/in_simple_systems.c | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/plugins/in_dummy/in_dummy.c b/plugins/in_dummy/in_dummy.c index 3894a410773..fd90e9f9253 100644 --- a/plugins/in_dummy/in_dummy.c +++ b/plugins/in_dummy/in_dummy.c @@ -351,6 +351,10 @@ static int in_dummy_init(struct flb_input_instance *in, flb_input_set_context(in, ctx); + if (ctx->flush_on_startup) { + in_dummy_collect(in, config, ctx); + } + ret = flb_input_set_collector_time(in, in_dummy_collect, tm.tv_sec, @@ -444,6 +448,11 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_dummy, fixed_timestamp), "used a fixed timestamp, allows the message to pre-generated once." }, + { + FLB_CONFIG_MAP_BOOL, "flush_on_startup", "false", + 0, FLB_TRUE, offsetof(struct flb_dummy, flush_on_startup), + "generate the first event on startup" + }, {0} }; diff --git a/plugins/in_dummy/in_dummy.h b/plugins/in_dummy/in_dummy.h index da6c578e743..51f9840f686 100644 --- a/plugins/in_dummy/in_dummy.h +++ b/plugins/in_dummy/in_dummy.h @@ -48,6 +48,7 @@ struct flb_dummy { int start_time_nsec; bool fixed_timestamp; + bool flush_on_startup; char *ref_metadata_msgpack; size_t ref_metadata_msgpack_size; diff --git a/tests/runtime/in_simple_systems.c b/tests/runtime/in_simple_systems.c index 9f1a9d2e49f..5e7b0a1e8bd 100644 --- a/tests/runtime/in_simple_systems.c +++ b/tests/runtime/in_simple_systems.c @@ -548,6 +548,11 @@ void flb_test_dummy_records_message_interval_nsec(struct callback_records *recor TEST_CHECK(records->num_records >= 1); } +void flb_test_dummy_records_message_flush_on_startup(struct callback_records *records) +{ + TEST_CHECK(records->num_records >= 2); +} + void flb_test_in_dummy_flush() { do_test("dummy", NULL); @@ -589,6 +594,11 @@ void flb_test_in_dummy_flush() "interval_sec", "0", "interval_nsec", "700000000", NULL); + do_test_records_wait_time("dummy", 5, flb_test_dummy_records_message_flush_on_startup, + "interval_sec", "5", + "interval_nsec", "0", + "flush_on_startup", "true", + NULL); } void flb_test_in_dummy_thread_flush()