@@ -78,12 +78,27 @@ static int http_put(struct flb_out_doris *ctx,
78
78
struct flb_upstream * u ;
79
79
struct flb_connection * u_conn ;
80
80
struct flb_http_client * c ;
81
+ struct mk_list * head ;
82
+ struct flb_config_map_val * mv ;
83
+ struct flb_slist_entry * key = NULL ;
84
+ struct flb_slist_entry * val = NULL ;
85
+
86
+ int i ;
87
+ int root_type ;
88
+ char * out_buf ;
89
+ size_t off = 0 ;
90
+ size_t out_size ;
91
+ msgpack_unpacked result ;
92
+ msgpack_object root ;
93
+ msgpack_object msg_key ;
94
+ msgpack_object msg_val ;
81
95
82
96
/* Get upstream context and connection */
83
97
if (strcmp (host , ctx -> host ) == 0 && port == ctx -> port ) {
84
98
u = ctx -> u ;
85
99
}
86
100
else {
101
+ // TODO cache
87
102
u = flb_upstream_create (ctx -> u -> base .config ,
88
103
host ,
89
104
port ,
@@ -117,22 +132,32 @@ static int http_put(struct flb_out_doris *ctx,
117
132
flb_http_add_header (c , "format" , 6 , "json" , 4 );
118
133
flb_http_add_header (c , "Expect" , 6 , "100-continue" , 12 );
119
134
flb_http_add_header (c , "strip_outer_array" , 17 , "true" , 4 );
120
- flb_http_add_header (c , "columns" , 7 , ctx -> columns , strlen (ctx -> columns ));
121
135
flb_http_add_header (c , "User-Agent" , 10 , "Fluent-Bit" , 10 );
122
- if (ctx -> timeout_second > 0 ) {
123
- char timeout [256 ];
124
- snprintf (timeout , sizeof (timeout ) - 1 , "%d" , ctx -> timeout_second );
125
- flb_http_add_header (c , "timeout" , 7 , timeout , strlen (timeout ));
136
+
137
+ flb_config_map_foreach (head , mv , ctx -> headers ) {
138
+ key = mk_list_entry_first (mv -> val .list , struct flb_slist_entry , _head );
139
+ val = mk_list_entry_last (mv -> val .list , struct flb_slist_entry , _head );
140
+
141
+ flb_http_add_header (c ,
142
+ key -> str , flb_sds_len (key -> str ),
143
+ val -> str , flb_sds_len (val -> str ));
126
144
}
127
145
128
146
/* Basic Auth headers */
129
147
flb_http_basic_auth (c , ctx -> user , ctx -> password );
130
148
131
149
ret = flb_http_do (c , & b_sent );
132
150
if (ret == 0 ) {
133
- flb_plg_debug (ctx -> ins , "%s:%i, HTTP status=%i\n%s\n" ,
134
- host , port ,
135
- c -> resp .status , c -> resp .payload );
151
+ if (ctx -> log_request ) {
152
+ flb_plg_info (ctx -> ins , "%s:%i, HTTP status=%i\n%s\n" ,
153
+ host , port ,
154
+ c -> resp .status , c -> resp .payload );
155
+ } else {
156
+ flb_plg_debug (ctx -> ins , "%s:%i, HTTP status=%i\n%s\n" ,
157
+ host , port ,
158
+ c -> resp .status , c -> resp .payload );
159
+ }
160
+
136
161
if (c -> resp .status == 307 ) { // redict
137
162
// example: Location: http://admin:[email protected] :8040/api/d_fb/t_fb/_stream_load?
138
163
char * location = strstr (c -> resp .data , "Location:" );
@@ -147,15 +172,53 @@ static int http_put(struct flb_out_doris *ctx,
147
172
out_ret = http_put (ctx , redict_host , atoi (redict_port ),
148
173
body , body_len , tag , tag_len );
149
174
}
150
- else if (c -> resp .status == 200 ) {
151
- if (c -> resp .payload_size > 0 &&
152
- (strstr (c -> resp .payload , "\"Status\": \"Success\"" ) != NULL ||
153
- strstr (c -> resp .payload , "\"Status\": \"Publish Timeout\"" ) != NULL )) {
154
- // continue
175
+ else if (c -> resp .status == 200 && c -> resp .payload_size > 0 ) {
176
+ ret = flb_pack_json (c -> resp .payload , c -> resp .payload_size ,
177
+ & out_buf , & out_size , & root_type , NULL );
178
+
179
+ if (ret == -1 ) {
180
+ out_ret = FLB_RETRY ;
181
+ }
182
+
183
+ msgpack_unpacked_init (& result );
184
+ ret = msgpack_unpack_next (& result , out_buf , out_size , & off );
185
+ if (ret != MSGPACK_UNPACK_SUCCESS ) {
186
+ out_ret = FLB_RETRY ;
155
187
}
156
- else {
188
+
189
+ root = result .data ;
190
+ if (root .type != MSGPACK_OBJECT_MAP ) {
157
191
out_ret = FLB_RETRY ;
158
192
}
193
+
194
+ for (i = 0 ; i < root .via .map .size ; i ++ ) {
195
+ msg_key = root .via .map .ptr [i ].key ;
196
+ if (msg_key .type != MSGPACK_OBJECT_STR ) {
197
+ out_ret = FLB_RETRY ;
198
+ break ;
199
+ }
200
+
201
+ if (msg_key .via .str .size == 6 && strncmp (msg_key .via .str .ptr , "Status" , 6 ) == 0 ) {
202
+ msg_val = root .via .map .ptr [i ].val ;
203
+ if (msg_val .type != MSGPACK_OBJECT_STR ) {
204
+ out_ret = FLB_RETRY ;
205
+ break ;
206
+ }
207
+
208
+ if (msg_val .via .str .size == 7 && strncmp (msg_val .via .str .ptr , "Success" , 7 ) == 0 ) {
209
+ out_ret = FLB_OK ;
210
+ break ;
211
+ }
212
+
213
+ if (msg_val .via .str .size == 15 && strncmp (msg_val .via .str .ptr , "Publish Timeout" , 15 ) == 0 ) {
214
+ out_ret = FLB_OK ;
215
+ break ;
216
+ }
217
+
218
+ out_ret = FLB_RETRY ;
219
+ break ;
220
+ }
221
+ }
159
222
}
160
223
else {
161
224
out_ret = FLB_RETRY ;
@@ -204,15 +267,19 @@ static int compose_payload(struct flb_out_doris *ctx,
204
267
in_size ,
205
268
FLB_PACK_JSON_FORMAT_JSON ,
206
269
FLB_PACK_JSON_DATE_EPOCH ,
207
- ctx -> time_key );
270
+ ctx -> date_key );
208
271
if (encoded == NULL ) {
209
272
flb_plg_error (ctx -> ins , "failed to convert json" );
210
273
return FLB_ERROR ;
211
274
}
212
275
* out_body = (void * )encoded ;
213
276
* out_size = flb_sds_len (encoded );
214
277
215
- flb_plg_debug (ctx -> ins , "http body: %s" , (char * ) * out_body );
278
+ if (ctx -> log_request ) {
279
+ flb_plg_info (ctx -> ins , "http body: %s" , (char * ) * out_body );
280
+ } else {
281
+ flb_plg_debug (ctx -> ins , "http body: %s" , (char * ) * out_body );
282
+ }
216
283
217
284
return FLB_OK ;
218
285
}
@@ -233,13 +300,22 @@ static void cb_doris_flush(struct flb_event_chunk *event_chunk,
233
300
& out_body , & out_size );
234
301
235
302
if (ret != FLB_OK ) {
303
+ if (ret == FLB_ERROR ) {
304
+ __sync_fetch_and_add (& ctx -> reporter -> failed_rows , event_chunk -> total_events );
305
+ }
236
306
FLB_OUTPUT_RETURN (ret );
237
307
}
238
308
239
309
ret = http_put (ctx , ctx -> host , ctx -> port , out_body , out_size ,
240
310
event_chunk -> tag , flb_sds_len (event_chunk -> tag ));
241
311
flb_sds_destroy (out_body );
242
312
313
+ if (ret == FLB_OK ) {
314
+ __sync_fetch_and_add (& ctx -> reporter -> total_bytes , out_size );
315
+ __sync_fetch_and_add (& ctx -> reporter -> total_rows , event_chunk -> total_events );
316
+ } else if (ret == FLB_ERROR ) {
317
+ __sync_fetch_and_add (& ctx -> reporter -> failed_rows , event_chunk -> total_events );
318
+ }
243
319
FLB_OUTPUT_RETURN (ret );
244
320
}
245
321
@@ -283,17 +359,23 @@ static struct flb_config_map config_map[] = {
283
359
0 , FLB_TRUE , offsetof(struct flb_out_doris , time_key ),
284
360
"Specify the name of the date field in output"
285
361
},
286
- // columns
362
+ // header
363
+ {
364
+ FLB_CONFIG_MAP_SLIST_1 , "header" , NULL ,
365
+ FLB_CONFIG_MAP_MULT , FLB_TRUE , offsetof(struct flb_out_doris , headers ),
366
+ "Add a doris stream load header key/value pair. Multiple headers can be set"
367
+ },
368
+ // log_request
287
369
{
288
- FLB_CONFIG_MAP_STR , "columns " , "date,log " ,
289
- 0 , FLB_TRUE , offsetof(struct flb_out_doris , columns ),
290
- "Set columns "
370
+ FLB_CONFIG_MAP_BOOL , "log_request " , "true " ,
371
+ 0 , FLB_TRUE , offsetof(struct flb_out_doris , log_request ),
372
+ "Specify if the doris stream load request and response should be logged or not "
291
373
},
292
- // timeout
374
+ // log_progress_interval
293
375
{
294
- FLB_CONFIG_MAP_INT , "timeout_second " , "60 " ,
295
- 0 , FLB_TRUE , offsetof(struct flb_out_doris , timeout_second ),
296
- "Set timeout in second "
376
+ FLB_CONFIG_MAP_INT , "log_progress_interval " , "10 " ,
377
+ 0 , FLB_TRUE , offsetof(struct flb_out_doris , log_progress_interval ),
378
+ "Specify the interval in seconds to log the progress of the doris stream load "
297
379
},
298
380
299
381
/* EOF */
0 commit comments