Skip to content

Commit

Permalink
influxdb: allow stripping of tag prefix
Browse files Browse the repository at this point in the history
Removes a configured prefix from measurement names

Signed-off-by: Ueli Graf <ugraf@outlook.com>
  • Loading branch information
ueli-g authored and Ueli Graf committed Sep 26, 2024
1 parent f36c956 commit d6e4d82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 26 additions & 1 deletion plugins/out_influxdb/influxdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ static int influxdb_format(struct flb_config *config,
char *str = NULL;
size_t str_size;
char tmp[128];
int prefix_match = 0;
int prefix_offset = 0;
msgpack_object map;
struct flb_time tm;
struct influxdb_bulk *bulk = NULL;
Expand Down Expand Up @@ -124,8 +126,16 @@ static int influxdb_format(struct flb_config *config,
ctx->seq++;
}

prefix_match = strncmp(tag, ctx->prefix, ctx->prefix_len);
if (prefix_match == 0) {
if (tag_len > ctx->prefix_len) {
prefix_offset = ctx->prefix_len;
}
}

ret = influxdb_bulk_append_header(bulk_head,
tag, tag_len,
tag + prefix_offset,
tag_len - prefix_offset,
seq,
ctx->seq_name, ctx->seq_len);
if (ret == -1) {
Expand Down Expand Up @@ -368,6 +378,15 @@ static int cb_influxdb_init(struct flb_output_instance *ins, struct flb_config *
}
ctx->seq_len = strlen(ctx->seq_name);

/* prefix */
tmp = flb_output_get_property("strip_prefix", ins);
if (!tmp) {
ctx->prefix = flb_strdup("");
} else {
ctx->prefix = flb_strdup(tmp);
}
ctx->prefix_len = strlen(ctx->prefix);

if (ctx->custom_uri) {
/* custom URI endpoint (e.g: Grafana */
if (ctx->custom_uri[0] != '/') {
Expand Down Expand Up @@ -696,6 +715,12 @@ static struct flb_config_map config_map[] = {
"Use influxdb line protocol's integer type suffix."
},

{
FLB_CONFIG_MAP_STR, "strip_prefix", NULL,
0, FLB_FALSE, 0,
"Prefix to be removed from the record tag when writing influx measurements."
},

/* EOF */
{0}
};
Expand Down
4 changes: 4 additions & 0 deletions plugins/out_influxdb/influxdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ struct flb_influxdb {
char *seq_name;
int seq_len;

/* prefix */
char *prefix;
int prefix_len;

/* auto_tags: on/off */
int auto_tags;

Expand Down

0 comments on commit d6e4d82

Please sign in to comment.