Skip to content

Commit 1dad845

Browse files
committed
Merge branch 'master' of github.com:fluent/fluent-bit
2 parents f2f63c6 + d72d42c commit 1dad845

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

include/fluent-bit/flb_plugin_proxy.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ struct flb_plugin_proxy {
5757
struct mk_list _head; /* link to parent config->proxies */
5858
};
5959

60+
/* This is the context for proxy plugins */
61+
struct flb_plugin_proxy_context {
62+
/* This context is set by the remote init and is passed to remote flush */
63+
void *remote_context;
64+
/* A proxy ptr is needed to detect the proxy type/lang (OUTPUT/GOLANG) */
65+
struct flb_plugin_proxy *proxy;
66+
};
67+
6068
void *flb_plugin_proxy_symbol(struct flb_plugin_proxy *proxy,
6169
const char *symbol);
6270

src/flb_output.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,17 @@ struct flb_output_instance *flb_output_new(struct flb_config *config,
272272
instance->context = NULL;
273273
}
274274
else {
275-
instance->context = plugin->proxy;
275+
struct flb_plugin_proxy_context *ctx;
276+
277+
ctx = flb_calloc(1, sizeof(struct flb_plugin_proxy_context));
278+
if (!ctx) {
279+
perror("calloc");
280+
return NULL;
281+
}
282+
283+
ctx->proxy = plugin->proxy;
284+
285+
instance->context = ctx;
276286
}
277287

278288
instance->alias = NULL;

src/flb_plugin_proxy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ static void flb_proxy_cb_flush(void *data, size_t bytes,
4949
struct flb_config *config)
5050
{
5151
int ret = FLB_ERROR;
52-
struct flb_plugin_proxy *p = out_context;
52+
struct flb_plugin_proxy_context *ctx = out_context;
5353
(void) tag_len;
5454
(void) i_ins;
5555
(void) config;
5656

5757
#ifdef FLB_HAVE_PROXY_GO
58-
if (p->proxy == FLB_PROXY_GOLANG) {
58+
if (ctx->proxy->proxy == FLB_PROXY_GOLANG) {
5959
flb_trace("[GO] entering go_flush()");
60-
ret = proxy_go_flush(p, data, bytes, tag, tag_len);
60+
ret = proxy_go_flush(ctx, data, bytes, tag, tag_len);
6161
}
6262
#else
63-
(void) p;
63+
(void) ctx;
6464
#endif
6565

6666
if (ret != FLB_OK && ret != FLB_RETRY && ret != FLB_ERROR) {

src/proxy/go/go.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* - name: shortname of the plugin.
4343
* - description: plugin description.
4444
* - type: input, output, filter, whatever.
45+
* - proxy: type of proxy e.g. GOLANG
4546
* - flags: optional flags, not used by Go plugins at the moment.
4647
*
4748
* this is done through Go Wrapper:
@@ -55,8 +56,11 @@ struct flbgo_output_plugin {
5556
char *name;
5657
void *api;
5758
void *o_ins;
59+
struct flb_plugin_proxy_context *context;
60+
5861
int (*cb_init)();
5962
int (*cb_flush)(void *, size_t, char *);
63+
int (*cb_flush_ctx)(void *, void *, size_t, char *);
6064
int (*cb_exit)(void *);
6165
};
6266
/*------------------------EOF------------------------------------------------*/
@@ -76,6 +80,7 @@ int proxy_go_register(struct flb_plugin_proxy *proxy,
7680
*
7781
* - FLBPluginInit
7882
* - FLBPluginFlush
83+
* - FLBPluginFlushCtx
7984
* - FLBPluginExit
8085
*
8186
* note: registration callback FLBPluginRegister() is resolved by the
@@ -90,6 +95,7 @@ int proxy_go_register(struct flb_plugin_proxy *proxy,
9095
}
9196

9297
plugin->cb_flush = flb_plugin_proxy_symbol(proxy, "FLBPluginFlush");
98+
plugin->cb_flush_ctx = flb_plugin_proxy_symbol(proxy, "FLBPluginFlushCtx");
9399
plugin->cb_exit = flb_plugin_proxy_symbol(proxy, "FLBPluginExit");
94100
plugin->name = flb_strdup(def->name);
95101

@@ -107,6 +113,9 @@ int proxy_go_init(struct flb_plugin_proxy *proxy)
107113
/* set the API */
108114
plugin->api = proxy->api;
109115
plugin->o_ins = proxy->instance;
116+
// In order to avoid having the whole instance as part of the ABI we
117+
// copy the context pointer into the plugin.
118+
plugin->context = ((struct flb_output_instance *)proxy->instance)->context;
110119

111120
ret = plugin->cb_init(plugin);
112121
if (ret <= 0) {
@@ -119,12 +128,12 @@ int proxy_go_init(struct flb_plugin_proxy *proxy)
119128
return ret;
120129
}
121130

122-
int proxy_go_flush(struct flb_plugin_proxy *proxy, void *data, size_t size,
131+
int proxy_go_flush(struct flb_plugin_proxy_context *ctx, void *data, size_t size,
123132
char *tag, int tag_len)
124133
{
125134
int ret;
126135
char *buf;
127-
struct flbgo_output_plugin *plugin = proxy->data;
136+
struct flbgo_output_plugin *plugin = ctx->proxy->data;
128137

129138
/* temporal buffer for the tag */
130139
buf = flb_malloc(tag_len + 1);
@@ -136,7 +145,12 @@ int proxy_go_flush(struct flb_plugin_proxy *proxy, void *data, size_t size,
136145
memcpy(buf, tag, tag_len);
137146
buf[tag_len] = '\0';
138147

139-
ret = plugin->cb_flush(data, size, buf);
148+
if (plugin->cb_flush_ctx) {
149+
ret = plugin->cb_flush_ctx(ctx->remote_context, data, size, buf);
150+
}
151+
else {
152+
ret = plugin->cb_flush(data, size, buf);
153+
}
140154
flb_free(buf);
141155
return ret;
142156
}

src/proxy/go/go.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int proxy_go_register(struct flb_plugin_proxy *proxy,
2929

3030
int proxy_go_init(struct flb_plugin_proxy *proxy);
3131

32-
int proxy_go_flush(struct flb_plugin_proxy *proxy, void *data, size_t size,
32+
int proxy_go_flush(struct flb_plugin_proxy_context *ctx, void *data, size_t size,
3333
char *tag, int tag_len);
3434

3535
#endif

0 commit comments

Comments
 (0)