Skip to content

Commit e858af6

Browse files
nokute78edsiper
authored andcommitted
in_forward: support config map
Signed-off-by: Takahiro Yamashita <[email protected]>
1 parent 0a27990 commit e858af6

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

plugins/in_forward/fw.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ static int in_fw_exit(void *data, struct flb_config *config)
206206
return 0;
207207
}
208208

209+
/* Configuration properties map */
210+
static struct flb_config_map config_map[] = {
211+
{
212+
FLB_CONFIG_MAP_STR, "unix_path", NULL,
213+
0, FLB_TRUE, offsetof(struct flb_in_fw_config, unix_path),
214+
"The path to unix socket to receive a Forward message."
215+
},
216+
{
217+
FLB_CONFIG_MAP_SIZE, "buffer_chunk_size", FLB_IN_FW_CHUNK_SIZE,
218+
0, FLB_TRUE, offsetof(struct flb_in_fw_config, buffer_chunk_size),
219+
"The buffer memory size used to receive a Forward message."
220+
},
221+
{
222+
FLB_CONFIG_MAP_SIZE, "buffer_max_size", FLB_IN_FW_CHUNK_MAX_SIZE,
223+
0, FLB_TRUE, offsetof(struct flb_in_fw_config, buffer_max_size),
224+
"The maximum buffer memory size used to receive a Forward message."
225+
},
226+
{0}
227+
};
228+
209229
/* Plugin reference */
210230
struct flb_input_plugin in_forward_plugin = {
211231
.name = "forward",
@@ -216,5 +236,6 @@ struct flb_input_plugin in_forward_plugin = {
216236
.cb_flush_buf = NULL,
217237
.cb_pause = in_fw_pause,
218238
.cb_exit = in_fw_exit,
239+
.config_map = config_map,
219240
.flags = FLB_INPUT_NET
220241
};

plugins/in_forward/fw_config.c

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <stdlib.h>
2222
#include <fluent-bit/flb_utils.h>
23+
#include <fluent-bit/flb_input_plugin.h>
2324

2425
#include "fw.h"
2526
#include "fw_conn.h"
@@ -28,8 +29,7 @@
2829
struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins)
2930
{
3031
char tmp[16];
31-
const char *buffer_size;
32-
const char *chunk_size;
32+
int ret = -1;
3333
const char *p;
3434
struct flb_in_fw_config *config;
3535

@@ -39,38 +39,22 @@ struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins)
3939
return NULL;
4040
}
4141

42-
p = flb_input_get_property("unix_path", i_ins);
43-
if (p) {
44-
config->unix_path = flb_strdup(p);
42+
ret = flb_input_config_map_set(i_ins, (void *)config);
43+
if (ret == -1) {
44+
flb_plg_error(i_ins, "config map set error");
45+
flb_free(config);
46+
return NULL;
4547
}
46-
else {
48+
49+
p = flb_input_get_property("unix_path", i_ins);
50+
if (p == NULL) {
4751
/* Listen interface (if not set, defaults to 0.0.0.0:24224) */
4852
flb_input_net_default_listener("0.0.0.0", 24224, i_ins);
4953
config->listen = i_ins->host.listen;
5054
snprintf(tmp, sizeof(tmp) - 1, "%d", i_ins->host.port);
5155
config->tcp_port = flb_strdup(tmp);
5256
}
5357

54-
/* Chunk size */
55-
chunk_size = flb_input_get_property("buffer_chunk_size", i_ins);
56-
if (!chunk_size) {
57-
config->buffer_chunk_size = FLB_IN_FW_CHUNK_SIZE; /* 1MB */
58-
}
59-
else {
60-
/* Convert KB unit to Bytes */
61-
config->buffer_chunk_size = flb_utils_size_to_bytes(chunk_size);
62-
}
63-
64-
/* Buffer size */
65-
buffer_size = flb_input_get_property("buffer_max_size", i_ins);
66-
if (!buffer_size) {
67-
config->buffer_max_size = FLB_IN_FW_CHUNK_MAX_SIZE; /* 6MB */
68-
}
69-
else {
70-
/* Convert unit to bytes */
71-
config->buffer_max_size = flb_utils_size_to_bytes(buffer_size);
72-
}
73-
7458
if (!config->unix_path) {
7559
flb_debug("[in_fw] Listen='%s' TCP_Port=%s",
7660
config->listen, config->tcp_port);
@@ -82,7 +66,6 @@ int fw_config_destroy(struct flb_in_fw_config *config)
8266
{
8367
if (config->unix_path) {
8468
unlink(config->unix_path);
85-
flb_free(config->unix_path);
8669
}
8770
else {
8871
flb_free(config->tcp_port);

plugins/in_forward/fw_conn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#ifndef FLB_IN_FW_CONN_H
2222
#define FLB_IN_FW_CONN_H
2323

24-
#define FLB_IN_FW_CHUNK_SIZE 1024000 /* 1MB */
25-
#define FLB_IN_FW_CHUNK_MAX_SIZE FLB_IN_FW_CHUNK_SIZE * 6 /* 6M */
24+
#define FLB_IN_FW_CHUNK_SIZE "1024000" /* 1MB */
25+
#define FLB_IN_FW_CHUNK_MAX_SIZE "6144000" /* =FLB_IN_FW_CHUNK_SIZE * 6. 6MB */
2626

2727
enum {
2828
FW_NEW = 1, /* it's a new connection */

0 commit comments

Comments
 (0)