Skip to content

Commit 730e7b0

Browse files
milkrageedsiper
authored andcommitted
proxy: go: add context for input methods
The way to add context to input methods is completely identical to the approach used for output methods. Without this, the callback can only perform hardwired tasks, and the configuration values can not be accessed. As a result, the input becomes extremely constrained on what it can do. Signed-off-by: milkrage <hello@milkrage.ru>
1 parent f366284 commit 730e7b0

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/proxy/go/go.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ int proxy_go_input_register(struct flb_plugin_proxy *proxy,
185185
*
186186
* - FLBPluginInit
187187
* - FLBPluginInputCallback
188+
* - FLBPluginInputCallbackCtx
188189
* - FLBPluginExit
189190
*
190191
* note: registration callback FLBPluginRegister() is resolved by the
@@ -199,7 +200,9 @@ int proxy_go_input_register(struct flb_plugin_proxy *proxy,
199200
}
200201

201202
plugin->cb_collect = flb_plugin_proxy_symbol(proxy, "FLBPluginInputCallback");
203+
plugin->cb_collect_ctx = flb_plugin_proxy_symbol(proxy, "FLBPluginInputCallbackCtx");
202204
plugin->cb_cleanup = flb_plugin_proxy_symbol(proxy, "FLBPluginInputCleanupCallback");
205+
plugin->cb_cleanup_ctx = flb_plugin_proxy_symbol(proxy, "FLBPluginInputCleanupCallbackCtx");
203206
plugin->cb_exit = flb_plugin_proxy_symbol(proxy, "FLBPluginExit");
204207
plugin->name = flb_strdup(def->name);
205208

@@ -231,27 +234,35 @@ int proxy_go_input_init(struct flb_plugin_proxy *proxy)
231234
return ret;
232235
}
233236

234-
int proxy_go_input_collect(struct flb_plugin_proxy *ctx,
237+
int proxy_go_input_collect(struct flb_plugin_input_proxy_context *ctx,
235238
void **collected_data, size_t *len)
236239
{
237240
int ret;
238241
void *data = NULL;
239-
struct flbgo_input_plugin *plugin = ctx->data;
242+
struct flbgo_input_plugin *plugin = ctx->proxy->data;
240243

241-
ret = plugin->cb_collect(&data, len);
244+
if (plugin->cb_collect_ctx) {
245+
ret = plugin->cb_collect_ctx(ctx->remote_context, &data, len);
246+
}
247+
else {
248+
ret = plugin->cb_collect(&data, len);
249+
}
242250

243251
*collected_data = data;
244252

245253
return ret;
246254
}
247255

248-
int proxy_go_input_cleanup(struct flb_plugin_proxy *ctx,
256+
int proxy_go_input_cleanup(struct flb_plugin_input_proxy_context *ctx,
249257
void *allocated_data)
250258
{
251259
int ret = 0;
252-
struct flbgo_input_plugin *plugin = ctx->data;
260+
struct flbgo_input_plugin *plugin = ctx->proxy->data;
253261

254-
if (plugin->cb_cleanup) {
262+
if (plugin->cb_cleanup_ctx) {
263+
ret = plugin->cb_cleanup_ctx(ctx->remote_context, allocated_data);
264+
}
265+
else if (plugin->cb_cleanup) {
255266
ret = plugin->cb_cleanup(allocated_data);
256267
}
257268
else {

src/proxy/go/go.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ struct flbgo_input_plugin {
4040
char *name;
4141
void *api;
4242
void *i_ins;
43-
struct flb_plugin_proxy_context *context;
43+
struct flb_plugin_input_proxy_context *context;
4444

4545
int (*cb_init)(struct flbgo_input_plugin *);
4646
int (*cb_collect)(void **, size_t *);
47+
int (*cb_collect_ctx)(void *, void **, size_t *);
4748
int (*cb_cleanup)(void *);
49+
int (*cb_cleanup_ctx)(void *, void *);
4850
int (*cb_exit)();
4951
};
5052

@@ -73,9 +75,9 @@ int proxy_go_input_register(struct flb_plugin_proxy *proxy,
7375
struct flb_plugin_proxy_def *def);
7476

7577
int proxy_go_input_init(struct flb_plugin_proxy *proxy);
76-
int proxy_go_input_collect(struct flb_plugin_proxy *ctx,
78+
int proxy_go_input_collect(struct flb_plugin_input_proxy_context *ctx,
7779
void **collected_data, size_t *len);
78-
int proxy_go_input_cleanup(struct flb_plugin_proxy *ctx,
80+
int proxy_go_input_cleanup(struct flb_plugin_input_proxy_context *ctx,
7981
void *allocated_data);
8082
int proxy_go_input_destroy(struct flb_plugin_input_proxy_context *ctx);
8183
void proxy_go_input_unregister(void *data);

0 commit comments

Comments
 (0)