Skip to content

Commit 67df784

Browse files
authored
out_tcp: register config_map (#1971)
Signed-off-by: Atibhi Agrawal <[email protected]>
1 parent 92df2d9 commit 67df784

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

plugins/out_tcp/tcp.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <fluent-bit/flb_utils.h>
2626
#include <fluent-bit/flb_pack.h>
2727
#include <fluent-bit/flb_sds.h>
28+
#include <fluent-bit/flb_config_map.h>
2829
#include <msgpack.h>
2930

3031
#include <stdio.h>
@@ -109,12 +110,34 @@ static int cb_tcp_exit(void *data, struct flb_config *config)
109110
return 0;
110111
}
111112

113+
/* Configuration properties map */
114+
static struct flb_config_map config_map[] = {
115+
{
116+
FLB_CONFIG_MAP_STR, "format", NULL,
117+
0, FLB_FALSE, 0,
118+
NULL
119+
},
120+
{
121+
FLB_CONFIG_MAP_STR, "json_date_format", NULL,
122+
0, FLB_FALSE, 0,
123+
NULL
124+
},
125+
{
126+
FLB_CONFIG_MAP_STR, "json_date_key", "date",
127+
0, FLB_TRUE, offsetof(struct flb_out_tcp, json_date_key),
128+
NULL
129+
},
130+
/* EOF */
131+
{0}
132+
};
133+
112134
/* Plugin reference */
113135
struct flb_output_plugin out_tcp_plugin = {
114136
.name = "tcp",
115137
.description = "TCP Output",
116138
.cb_init = cb_tcp_init,
117139
.cb_flush = cb_tcp_flush,
118140
.cb_exit = cb_tcp_exit,
141+
.config_map = config_map,
119142
.flags = FLB_OUTPUT_NET | FLB_IO_OPT_TLS,
120143
};

plugins/out_tcp/tcp_conf.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ struct flb_out_tcp *flb_tcp_conf_create(struct flb_output_instance *ins,
4242
return NULL;
4343
}
4444
ctx->ins = ins;
45+
46+
ret = flb_output_config_map_set(ins, (void *) ctx);
47+
if (ret == -1) {
48+
return -1;
49+
}
4550

4651
/* Set default network configuration if not set */
4752
flb_output_net_default("127.0.0.1", 5170, ins);
@@ -101,14 +106,6 @@ struct flb_out_tcp *flb_tcp_conf_create(struct flb_output_instance *ins,
101106
}
102107
}
103108

104-
/* Date key for JSON output */
105-
tmp = flb_output_get_property("json_date_key", ins);
106-
if (tmp) {
107-
ctx->json_date_key = flb_sds_create(tmp);
108-
}
109-
else {
110-
ctx->json_date_key = flb_sds_create("date");
111-
}
112109
ctx->u = upstream;
113110
ctx->host = ins->host.name;
114111
ctx->port = ins->host.port;
@@ -126,9 +123,6 @@ void flb_tcp_conf_destroy(struct flb_out_tcp *ctx)
126123
flb_upstream_destroy(ctx->u);
127124
}
128125

129-
if (ctx->json_date_key) {
130-
flb_sds_destroy(ctx->json_date_key);
131-
}
132126
flb_free(ctx);
133127
ctx = NULL;
134128
}

0 commit comments

Comments
 (0)