Skip to content

Commit fef9cb6

Browse files
cosmo0920edsiper
authored andcommitted
output: Add a capability to inject HTTP response testing environment
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent ce2d371 commit fef9cb6

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

include/fluent-bit/flb_output.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,66 @@ struct flb_test_out_formatter {
168168
size_t *); /* output buffer size */
169169
};
170170

171+
struct flb_test_out_response {
172+
/*
173+
* Runtime Library Mode
174+
* ====================
175+
* When the runtime library enable the test formatter mode, it needs to
176+
* keep a reference of the context and other information:
177+
*
178+
* - rt_ctx : context created by flb_create()
179+
*
180+
* - rt_ffd : this plugin assigned 'integer' created by flb_output()
181+
*
182+
* - rt_step_calback: intermediary function to receive the results of
183+
* the formatter plugin test function.
184+
*
185+
* - rt_data: opaque data type for rt_step_callback()
186+
*/
187+
188+
/* runtime library context */
189+
void *rt_ctx;
190+
191+
/* runtime library: assigned plugin integer */
192+
int rt_ffd;
193+
194+
/*
195+
* "runtime step callback": this function pointer is used by Fluent Bit
196+
* library mode to reference a test function that must retrieve the
197+
* results of 'callback'. Consider this an intermediary function to
198+
* transfer the results to the runtime test.
199+
*
200+
* This function is private and should not be set manually in the plugin
201+
* code, it's set on src/flb_lib.c .
202+
*/
203+
void (*rt_out_response) (void *, int, int, void *, size_t, void *);
204+
205+
/*
206+
* opaque data type passed by the runtime library to be used on
207+
* rt_step_test().
208+
*/
209+
void *rt_data;
210+
211+
/* optional context for flush callback */
212+
void *flush_ctx;
213+
214+
/*
215+
* Callback
216+
* =========
217+
* "Formatter callback": it references the plugin function that performs
218+
* data formatting (msgpack -> local data). This entry is mostly to
219+
* expose the plugin local function.
220+
*/
221+
int (*callback) (/* Fluent Bit context */
222+
struct flb_config *,
223+
void *, /* plugin instance context */
224+
int status, /* HTTP status code */
225+
const void *, /* respond msgpack data */
226+
size_t, /* respond msgpack size */
227+
void **, /* output buffer */
228+
size_t *); /* output buffer size */
229+
};
230+
171231
struct flb_output_plugin {
172232
/*
173233
* a 'mask' to define what kind of data the plugin can manage:
@@ -241,6 +301,7 @@ struct flb_output_plugin {
241301

242302
/* Tests */
243303
struct flb_test_out_formatter test_formatter;
304+
struct flb_test_out_response test_response;
244305

245306
/* Link to global list from flb_config->outputs */
246307
struct mk_list _head;
@@ -391,6 +452,7 @@ struct flb_output_instance {
391452

392453
/* Tests */
393454
struct flb_test_out_formatter test_formatter;
455+
struct flb_test_out_response test_response;
394456

395457
/*
396458
* Buffer counter: it counts the total of disk space (filesystem) used by buffers

src/flb_output.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ struct flb_output_instance *flb_output_new(struct flb_config *config,
729729

730730
/* Tests */
731731
instance->test_formatter.callback = plugin->test_formatter.callback;
732+
instance->test_response.callback = plugin->test_response.callback;
732733

733734

734735
return instance;

0 commit comments

Comments
 (0)