Skip to content

Commit e2fecd3

Browse files
committed
engine: support of tests which require generation of context passed to the test callback based on configuration of Fluent Bit and based on configuration of plugin
Signed-off-by: Marat Abrarov <[email protected]>
1 parent cf14ff5 commit e2fecd3

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

include/fluent-bit/flb_lib.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <fluent-bit/flb_macros.h>
2424
#include <fluent-bit/flb_config.h>
25+
#include <fluent-bit/flb_input.h>
2526

2627
/* Lib engine status */
2728
#define FLB_LIB_ERROR -1
@@ -62,6 +63,16 @@ FLB_EXPORT int flb_output_set_test(flb_ctx_t *ctx, int ffd, char *test_name,
6263
void *, size_t, void *),
6364
void *out_callback_data,
6465
void *test_ctx);
66+
FLB_EXPORT int flb_output_set_test_with_ctx_callback(
67+
flb_ctx_t *ctx, int ffd, char *test_name,
68+
void (*out_callback) (void *, int, int,
69+
void *, size_t, void *),
70+
void *out_callback_data,
71+
void *test_ctx,
72+
void *(*test_ctx_callback) (
73+
struct flb_config *,
74+
struct flb_input_instance *,
75+
void *, void *));
6576
FLB_EXPORT int flb_output_set_callback(flb_ctx_t *ctx, int ffd, char *name,
6677
void (*cb)(char *, void *, void *));
6778

include/fluent-bit/flb_output.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,24 @@ struct flb_test_out_formatter {
136136
*/
137137
void *rt_data;
138138

139-
/* optional context for flush callback */
139+
/* optional context for "flush context callback" */
140140
void *flush_ctx;
141141

142+
/*
143+
* Callback
144+
* =========
145+
* Optional "flush context callback": it references the function that extracts
146+
* optional flush context for "formatter callback".
147+
*/
148+
void *(*flush_ctx_callback) (/* Fluent Bit context */
149+
struct flb_config *,
150+
/* plugin that ingested the records */
151+
struct flb_input_instance *,
152+
/* plugin instance context */
153+
void *plugin_context,
154+
/* context for "flush context callback" */
155+
void *flush_ctx);
156+
142157
/*
143158
* Callback
144159
* =========

src/flb_engine_dispatch.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,23 @@ int flb_engine_dispatch_retry(struct flb_task_retry *retry,
100100
static void test_run_formatter(struct flb_config *config,
101101
struct flb_input_instance *i_ins,
102102
struct flb_output_instance *o_ins,
103-
struct flb_task *task,
104-
void *flush_ctx)
103+
struct flb_task *task)
105104
{
106105
int ret;
107106
void *out_buf = NULL;
108107
size_t out_size = 0;
109108
struct flb_test_out_formatter *otf;
110109
struct flb_event_chunk *evc;
110+
void *flush_ctx;
111111

112112
otf = &o_ins->test_formatter;
113113
evc = task->event_chunk;
114114

115+
flush_ctx = otf->flush_ctx;
116+
if (otf->flush_ctx_callback) {
117+
flush_ctx = otf->flush_ctx_callback(config, i_ins, o_ins->context, flush_ctx);
118+
}
119+
115120
/* Invoke the output plugin formatter test callback */
116121
ret = otf->callback(config,
117122
i_ins,
@@ -175,9 +180,7 @@ static int tasks_start(struct flb_input_instance *in,
175180
out->test_formatter.callback != NULL) {
176181

177182
/* Run the formatter test */
178-
test_run_formatter(config, in, out,
179-
task,
180-
out->test_formatter.flush_ctx);
183+
test_run_formatter(config, in, out, task);
181184

182185
/* Remove the route */
183186
mk_list_del(&route->_head);

src/flb_lib.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,18 @@ int flb_output_set_test(flb_ctx_t *ctx, int ffd, char *test_name,
482482
void (*out_callback) (void *, int, int, void *, size_t, void *),
483483
void *out_callback_data,
484484
void *test_ctx)
485+
{
486+
return flb_output_set_test_with_ctx_callback(ctx, ffd, test_name, out_callback,
487+
out_callback_data, test_ctx, NULL);
488+
}
489+
490+
int flb_output_set_test_with_ctx_callback(flb_ctx_t *ctx, int ffd, char *test_name,
491+
void (*out_callback) (void *, int, int, void *, size_t, void *),
492+
void *out_callback_data,
493+
void *test_ctx,
494+
void *(*test_ctx_callback) (struct flb_config *,
495+
struct flb_input_instance *,
496+
void *, void *))
485497
{
486498
struct flb_output_instance *o_ins;
487499

@@ -503,6 +515,7 @@ int flb_output_set_test(flb_ctx_t *ctx, int ffd, char *test_name,
503515
o_ins->test_formatter.rt_out_callback = out_callback;
504516
o_ins->test_formatter.rt_data = out_callback_data;
505517
o_ins->test_formatter.flush_ctx = test_ctx;
518+
o_ins->test_formatter.flush_ctx_callback = test_ctx_callback;
506519
}
507520
else {
508521
return -1;

0 commit comments

Comments
 (0)