diff --git a/plugins/in_dummy/in_dummy.c b/plugins/in_dummy/in_dummy.c index 8cb58e18824..6d008b4cb2c 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 0b98511e1a1..a75aa89cb69 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 fb9c119635f..5eb8a836603 100644 --- a/tests/runtime/in_simple_systems.c +++ b/tests/runtime/in_simple_systems.c @@ -569,6 +569,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); @@ -610,6 +615,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()