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}
0 commit comments