Skip to content

Commit 4713f44

Browse files
committed
proxy: send proxy context to go input plugin
This is necessary so that go input plugin can implement methods with context in the same way as it is done in go output plugin. Signed-off-by: milkrage <hello@milkrage.ru>
1 parent db09528 commit 4713f44

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

include/fluent-bit/flb_plugin_proxy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ struct flb_plugin_proxy_context {
6464

6565
struct flb_plugin_input_proxy_context {
6666
int coll_fd;
67+
/* This context is set by the remote init and is passed to remote collect */
68+
void *remote_context;
6769
/* A proxy ptr is needed to store the proxy type/lang (OUTPUT/GOLANG) */
6870
struct flb_plugin_proxy *proxy;
6971
};

src/flb_plugin_proxy.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int flb_proxy_input_cb_collect(struct flb_input_instance *ins,
8181
#ifdef FLB_HAVE_PROXY_GO
8282
if (ctx->proxy->def->proxy == FLB_PROXY_GOLANG) {
8383
flb_trace("[GO] entering go_collect()");
84-
ret = proxy_go_input_collect(ctx->proxy, &data, &len);
84+
ret = proxy_go_input_collect(ctx, &data, &len);
8585

8686
if (len == 0) {
8787
flb_trace("[GO] No logs are ingested");
@@ -95,7 +95,7 @@ static int flb_proxy_input_cb_collect(struct flb_input_instance *ins,
9595

9696
flb_input_log_append(ins, NULL, 0, data, len);
9797

98-
ret = proxy_go_input_cleanup(ctx->proxy, data);
98+
ret = proxy_go_input_cleanup(ctx, data);
9999
if (ret == -1) {
100100
flb_errno();
101101
return -1;
@@ -110,19 +110,10 @@ static int flb_proxy_input_cb_init(struct flb_input_instance *ins,
110110
struct flb_config *config, void *data)
111111
{
112112
int ret = -1;
113-
struct flb_plugin_input_proxy_context *ctx;
114-
struct flb_plugin_proxy_context *pc;
115-
116-
/* Allocate space for the configuration context */
117-
ctx = flb_malloc(sizeof(struct flb_plugin_input_proxy_context));
118-
if (!ctx) {
119-
flb_errno();
120-
return -1;
121-
}
113+
struct flb_plugin_input_proxy_context *pc;
122114

123115
/* Before to initialize for proxy, set the proxy instance reference */
124-
pc = (struct flb_plugin_proxy_context *)(ins->context);
125-
ctx->proxy = pc->proxy;
116+
pc = (struct flb_plugin_input_proxy_context *)(ins->context);
126117

127118
/* Before to initialize, set the instance reference */
128119
pc->proxy->instance = ins;
@@ -147,7 +138,7 @@ static int flb_proxy_input_cb_init(struct flb_input_instance *ins,
147138
}
148139

149140
/* Set the context */
150-
flb_input_set_context(ins, ctx);
141+
flb_input_set_context(ins, pc);
151142

152143
/* Collect upon data available on timer */
153144
ret = flb_input_set_collector_time(ins,
@@ -159,12 +150,12 @@ static int flb_proxy_input_cb_init(struct flb_input_instance *ins,
159150
flb_error("Could not set collector for threaded proxy input plugin");
160151
goto init_error;
161152
}
162-
ctx->coll_fd = ret;
153+
pc->coll_fd = ret;
163154

164155
return ret;
165156

166157
init_error:
167-
flb_free(ctx);
158+
flb_free(pc);
168159

169160
return -1;
170161
}
@@ -311,10 +302,10 @@ static int flb_proxy_input_cb_pre_run(struct flb_input_instance *ins,
311302
struct flb_config *config, void *data)
312303
{
313304
int ret = -1;
314-
struct flb_plugin_proxy_context *pc;
305+
struct flb_plugin_input_proxy_context *pc;
315306
struct flb_plugin_proxy *proxy;
316307

317-
pc = (struct flb_plugin_proxy_context *)(ins->context);
308+
pc = (struct flb_plugin_input_proxy_context *)(ins->context);
318309
proxy = pc->proxy;
319310

320311
/* pre_run */

0 commit comments

Comments
 (0)