@@ -40,15 +40,16 @@ static void to_traceparent(uint8_t *trace_id, char *span_id, char *out)
4040 sprintf (out + size , "-%s-01" , span_id );
4141}
4242
43- static int tag_values_to_json (UT_array * tags , neu_json_read_resp_t * json )
43+ static int tag_values_to_json (UT_array * tags , mqtt_static_vt_t * s_tags ,
44+ size_t n_s_tags , neu_json_read_resp_t * json )
4445{
4546 int index = 0 ;
4647
4748 if (0 == utarray_len (tags )) {
4849 return 0 ;
4950 }
5051
51- json -> n_tag = utarray_len (tags );
52+ json -> n_tag = utarray_len (tags ) + n_s_tags ;
5253 json -> tags = (neu_json_read_resp_tag_t * ) calloc (
5354 json -> n_tag , sizeof (neu_json_read_resp_tag_t ));
5455 if (NULL == json -> tags ) {
@@ -61,6 +62,16 @@ static int tag_values_to_json(UT_array *tags, neu_json_read_resp_t *json)
6162 index += 1 ;
6263 }
6364
65+ if (s_tags != NULL ) {
66+ for (size_t i = 0 ; i < n_s_tags ; i ++ ) {
67+ neu_json_read_resp_tag_t * tag = & json -> tags [index ];
68+ tag -> name = s_tags [i ].name ;
69+ tag -> t = s_tags [i ].jtype ;
70+ tag -> value = s_tags [i ].jvalue ;
71+ index += 1 ;
72+ }
73+ }
74+
6475 return 0 ;
6576}
6677
@@ -86,7 +97,9 @@ void filter_error_tags(neu_reqresp_trans_data_t *data)
8697}
8798
8899char * generate_upload_json (neu_plugin_t * plugin , neu_reqresp_trans_data_t * data ,
89- mqtt_upload_format_e format , bool * skip )
100+ mqtt_upload_format_e format , mqtt_schema_vt_t * vts ,
101+ size_t n_vts , mqtt_static_vt_t * s_tags ,
102+ size_t n_s_tags , bool * skip )
90103{
91104 char * json_str = NULL ;
92105 neu_json_read_periodic_t header = { .group = (char * ) data -> group ,
@@ -103,9 +116,16 @@ char *generate_upload_json(neu_plugin_t *plugin, neu_reqresp_trans_data_t *data,
103116 }
104117 }
105118
106- if (0 != tag_values_to_json (data -> tags , & json )) {
107- plog_error (plugin , "tag_values_to_json fail" );
108- return NULL ;
119+ if (format == MQTT_UPLOAD_FORMAT_CUSTOM ) {
120+ if (0 != tag_values_to_json (data -> tags , NULL , 0 , & json )) {
121+ plog_error (plugin , "tag_values_to_json fail" );
122+ return NULL ;
123+ }
124+ } else {
125+ if (0 != tag_values_to_json (data -> tags , s_tags , n_s_tags , & json )) {
126+ plog_error (plugin , "tag_values_to_json fail" );
127+ return NULL ;
128+ }
109129 }
110130
111131 int ret ;
@@ -131,6 +151,11 @@ char *generate_upload_json(neu_plugin_t *plugin, neu_reqresp_trans_data_t *data,
131151 data -> group );
132152 }
133153 break ;
154+ case MQTT_UPLOAD_FORMAT_CUSTOM : {
155+ ret = mqtt_schema_encode (data -> driver , data -> group , & json , vts , n_vts ,
156+ s_tags , n_s_tags , & json_str );
157+ break ;
158+ }
134159 default :
135160 plog_warn (plugin , "invalid upload format: %d" , format );
136161 break ;
@@ -157,7 +182,7 @@ static char *generate_read_resp_json(neu_plugin_t * plugin,
157182 char * json_str = NULL ;
158183 neu_json_read_resp_t json = { 0 };
159184
160- if (0 != tag_values_to_json (data -> tags , & json )) {
185+ if (0 != tag_values_to_json (data -> tags , NULL , 0 , & json )) {
161186 plog_error (plugin , "tag_values_to_json fail" );
162187 return NULL ;
163188 }
@@ -855,9 +880,22 @@ int handle_trans_data(neu_plugin_t * plugin,
855880 break ;
856881 }
857882
858- bool skip_none = false;
859- char * json_str = generate_upload_json (
860- plugin , trans_data , plugin -> config .format , & skip_none );
883+ bool skip_none = false;
884+ size_t n_satic_tag = 0 ;
885+ mqtt_static_vt_t * static_tags = NULL ;
886+ if (route -> static_tags != NULL && strlen (route -> static_tags ) > 0 ) {
887+ mqtt_static_validate (route -> static_tags , & static_tags ,
888+ & n_satic_tag );
889+ }
890+
891+ char * json_str = generate_upload_json (
892+ plugin , trans_data , plugin -> config .format ,
893+ plugin -> config .schema_vts , plugin -> config .n_schema_vt , static_tags ,
894+ n_satic_tag , & skip_none );
895+ if (n_satic_tag > 0 ) {
896+ mqtt_static_free (static_tags , n_satic_tag );
897+ }
898+
861899 if (skip_none ) {
862900 break ;
863901 }
@@ -919,8 +957,9 @@ int handle_subscribe_group(neu_plugin_t *plugin, neu_req_subscribe_t *sub_info)
919957 goto end ;
920958 }
921959
922- rv = route_tbl_add_new (& plugin -> route_tbl , sub_info -> driver ,
923- sub_info -> group , topic .v .val_str );
960+ rv =
961+ route_tbl_add_new (& plugin -> route_tbl , sub_info -> driver , sub_info -> group ,
962+ topic .v .val_str , sub_info -> static_tags );
924963 // topic.v.val_str ownership moved
925964 if (0 != rv ) {
926965 plog_error (plugin , "route driver:%s group:%s fail, `%s`" ,
@@ -953,7 +992,7 @@ int handle_update_subscribe(neu_plugin_t *plugin, neu_req_subscribe_t *sub_info)
953992 }
954993
955994 rv = route_tbl_update (& plugin -> route_tbl , sub_info -> driver , sub_info -> group ,
956- topic .v .val_str );
995+ topic .v .val_str , sub_info -> static_tags );
957996 // topic.v.val_str ownership moved
958997 if (0 != rv ) {
959998 plog_error (plugin , "route driver:%s group:%s fail, `%s`" ,
0 commit comments