@@ -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};
0 commit comments