@@ -74,6 +74,8 @@ static int influxdb_format(struct flb_config *config,
74
74
char * str = NULL ;
75
75
size_t str_size ;
76
76
char tmp [128 ];
77
+ int prefix_match = 0 ;
78
+ int prefix_offset = 0 ;
77
79
msgpack_object map ;
78
80
struct flb_time tm ;
79
81
struct influxdb_bulk * bulk = NULL ;
@@ -124,8 +126,16 @@ static int influxdb_format(struct flb_config *config,
124
126
ctx -> seq ++ ;
125
127
}
126
128
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
+
127
136
ret = influxdb_bulk_append_header (bulk_head ,
128
- tag , tag_len ,
137
+ tag + prefix_offset ,
138
+ tag_len - prefix_offset ,
129
139
seq ,
130
140
ctx -> seq_name , ctx -> seq_len );
131
141
if (ret == -1 ) {
@@ -368,6 +378,15 @@ static int cb_influxdb_init(struct flb_output_instance *ins, struct flb_config *
368
378
}
369
379
ctx -> seq_len = strlen (ctx -> seq_name );
370
380
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
+
371
390
if (ctx -> custom_uri ) {
372
391
/* custom URI endpoint (e.g: Grafana */
373
392
if (ctx -> custom_uri [0 ] != '/' ) {
@@ -696,6 +715,12 @@ static struct flb_config_map config_map[] = {
696
715
"Use influxdb line protocol's integer type suffix."
697
716
},
698
717
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
+
699
724
/* EOF */
700
725
{0 }
701
726
};
0 commit comments