@@ -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 ) {
@@ -369,6 +379,15 @@ static int cb_influxdb_init(struct flb_output_instance *ins, struct flb_config *
369379 }
370380 ctx -> seq_len = strlen (ctx -> seq_name );
371381
382+ /* prefix */
383+ tmp = flb_output_get_property ("strip_prefix" , ins );
384+ if (!tmp ) {
385+ ctx -> prefix = flb_strdup ("" );
386+ } else {
387+ ctx -> prefix = flb_strdup (tmp );
388+ }
389+ ctx -> prefix_len = strlen (ctx -> prefix );
390+
372391 if (ctx -> custom_uri ) {
373392 /* custom URI endpoint (e.g: Grafana */
374393 if (ctx -> custom_uri [0 ] != '/' ) {
@@ -697,6 +716,12 @@ static struct flb_config_map config_map[] = {
697716 "Use influxdb line protocol's integer type suffix."
698717 },
699718
719+ {
720+ FLB_CONFIG_MAP_STR , "strip_prefix" , NULL ,
721+ 0 , FLB_FALSE , 0 ,
722+ "Prefix to be removed from the record tag when writing influx measurements."
723+ },
724+
700725 /* EOF */
701726 {0 }
702727};
0 commit comments