Skip to content

Commit cb44828

Browse files
ueli-gUeli Graf
authored andcommitted
out_influxdb: allow stripping of tag prefix
Removes a configured prefix from measurement names Signed-off-by: Ueli Graf <[email protected]>
1 parent f36c956 commit cb44828

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

plugins/out_influxdb/influxdb.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static int influxdb_format(struct flb_config *config,
7474
char *str = NULL;
7575
size_t str_size;
7676
char tmp[128];
77+
int prefix_match = 0;
78+
int prefix_offset = 0;
7779
msgpack_object map;
7880
struct flb_time tm;
7981
struct influxdb_bulk *bulk = NULL;
@@ -124,8 +126,16 @@ static int influxdb_format(struct flb_config *config,
124126
ctx->seq++;
125127
}
126128

129+
prefix_match = strncmp(tag, ctx->prefix, ctx->prefix_len);
130+
if (prefix_match == 0) {
131+
if (tag_len > ctx->prefix_len) {
132+
prefix_offset = ctx->prefix_len;
133+
}
134+
}
135+
127136
ret = influxdb_bulk_append_header(bulk_head,
128-
tag, tag_len,
137+
tag + prefix_offset,
138+
tag_len - prefix_offset,
129139
seq,
130140
ctx->seq_name, ctx->seq_len);
131141
if (ret == -1) {
@@ -368,6 +378,15 @@ static int cb_influxdb_init(struct flb_output_instance *ins, struct flb_config *
368378
}
369379
ctx->seq_len = strlen(ctx->seq_name);
370380

381+
/* prefix */
382+
tmp = flb_output_get_property("strip_prefix", ins);
383+
if (!tmp) {
384+
ctx->prefix = flb_strdup("");
385+
} else {
386+
ctx->prefix = flb_strdup(tmp);
387+
}
388+
ctx->prefix_len = strlen(ctx->prefix);
389+
371390
if (ctx->custom_uri) {
372391
/* custom URI endpoint (e.g: Grafana */
373392
if (ctx->custom_uri[0] != '/') {
@@ -696,6 +715,12 @@ static struct flb_config_map config_map[] = {
696715
"Use influxdb line protocol's integer type suffix."
697716
},
698717

718+
{
719+
FLB_CONFIG_MAP_STR, "strip_prefix", NULL,
720+
0, FLB_FALSE, 0,
721+
"Prefix to be removed from the record tag when writing influx measurements."
722+
},
723+
699724
/* EOF */
700725
{0}
701726
};

plugins/out_influxdb/influxdb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ struct flb_influxdb {
5656
char *seq_name;
5757
int seq_len;
5858

59+
/* prefix */
60+
char *prefix;
61+
int prefix_len;
62+
5963
/* auto_tags: on/off */
6064
int auto_tags;
6165

0 commit comments

Comments
 (0)