Skip to content

Commit ebafd0b

Browse files
cosmo0920nourdouf
authored andcommitted
input: Add callback member for testing input format
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 9c8a910 commit ebafd0b

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

include/fluent-bit/flb_input.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,71 @@
7575

7676
struct flb_input_instance;
7777

78+
/*
79+
* Tests callbacks
80+
* ===============
81+
*/
82+
struct flb_test_in_formatter {
83+
/*
84+
* Runtime Library Mode
85+
* ====================
86+
* When the runtime library enable the test formatter mode, it needs to
87+
* keep a reference of the context and other information:
88+
*
89+
* - rt_ctx : context created by flb_create()
90+
*
91+
* - rt_ffd : this plugin assigned 'integer' created by flb_output()
92+
*
93+
* - rt_in_calback: intermediary function to receive the results of
94+
* the formatter plugin test function.
95+
*
96+
* - rt_data: opaque data type for rt_step_callback()
97+
*/
98+
99+
/* runtime library context */
100+
void *rt_ctx;
101+
102+
/* runtime library: assigned plugin integer */
103+
int rt_ffd;
104+
105+
/* optional format context */
106+
void *format_ctx;
107+
108+
/*
109+
* "runtime step callback": this function pointer is used by Fluent Bit
110+
* library mode to reference a test function that must retrieve the
111+
* results of 'callback'. Consider this an intermediary function to
112+
* transfer the results to the runtime test.
113+
*
114+
* This function is private and should not be set manually in the plugin
115+
* code, it's set on src/flb_lib.c .
116+
*/
117+
void (*rt_in_callback) (void *, int, int, void *, size_t, void *);
118+
119+
/*
120+
* opaque data type passed by the runtime library to be used on
121+
* rt_step_test().
122+
*/
123+
void *rt_data;
124+
125+
/*
126+
* Callback
127+
* =========
128+
* "Formatter callback": it references the plugin function that performs
129+
* data formatting (msgpack -> local data). This entry is mostly to
130+
* expose the plugin local function.
131+
*/
132+
int (*callback) (/* Fluent Bit context */
133+
struct flb_config *,
134+
/* plugin that ingested the records */
135+
struct flb_input_instance *,
136+
void *, /* plugin instance context */
137+
const void *, /* incoming unformatted data */
138+
size_t, /* incoming unformatted size */
139+
void **, /* output buffer */
140+
size_t *); /* output buffer size */
141+
};
142+
78143
struct flb_input_plugin {
79144
/*
80145
* The type defines if this is a core-based plugin or it's handled by
@@ -138,6 +203,9 @@ struct flb_input_plugin {
138203
/* Destroy */
139204
void (*cb_destroy) (struct flb_input_plugin *);
140205

206+
/* Tests */
207+
struct flb_test_in_formatter test_formatter;
208+
141209
void *instance;
142210

143211
struct mk_list _head;
@@ -177,6 +245,7 @@ struct flb_input_instance {
177245
int runs_in_coroutine; /* instance runs in coroutine ? */
178246
char name[32]; /* numbered name (cpu -> cpu.0) */
179247
char *alias; /* alias name for the instance */
248+
int test_mode; /* running tests? (default:off) */
180249
void *context; /* plugin configuration context */
181250
flb_pipefd_t ch_events[2]; /* channel for events */
182251
struct flb_input_plugin *p; /* original plugin */
@@ -294,6 +363,8 @@ struct flb_input_instance {
294363
struct flb_metrics *metrics; /* metrics */
295364
#endif
296365

366+
/* Tests */
367+
struct flb_test_in_formatter test_formatter;
297368

298369
/* is the plugin running in a separate thread ? */
299370
int is_threaded;

src/flb_input.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ struct flb_input_instance *flb_input_new(struct flb_config *config,
242242
instance->alias = NULL;
243243
instance->id = id;
244244
instance->flags = plugin->flags;
245+
instance->test_mode = FLB_FALSE;
245246
instance->p = plugin;
246247
instance->tag = NULL;
247248
instance->tag_len = 0;
@@ -345,6 +346,9 @@ struct flb_input_instance *flb_input_new(struct flb_config *config,
345346

346347
/* processor instance */
347348
instance->processor = flb_processor_create(config, instance->name, instance, FLB_PLUGIN_INPUT);
349+
350+
/* Tests */
351+
instance->test_formatter.callback = plugin->test_formatter.callback;
348352
}
349353

350354
return instance;

0 commit comments

Comments
 (0)