@@ -293,6 +293,35 @@ func (h *HTTPListenerV2) serveWrite(res http.ResponseWriter, req *http.Request)
293
293
})
294
294
}
295
295
296
+ switch acc := h .acc .(type ) {
297
+ case telegraf.HighPriorityAccumulator :
298
+ h .writeToHighPriorityAccumulator (req , res , acc , metrics )
299
+ default :
300
+ for _ , m := range metrics {
301
+ for headerName , measurementName := range h .HTTPHeaderTags {
302
+ headerValues := req .Header .Get (headerName )
303
+ if len (headerValues ) > 0 {
304
+ m .AddTag (measurementName , headerValues )
305
+ }
306
+ }
307
+
308
+ if h .PathTag {
309
+ m .AddTag (pathTag , req .URL .Path )
310
+ }
311
+
312
+ h .acc .AddMetric (m )
313
+ }
314
+ }
315
+
316
+ res .WriteHeader (h .SuccessCode )
317
+ }
318
+
319
+ func (h * HTTPListenerV2 ) writeToHighPriorityAccumulator (
320
+ req * http.Request ,
321
+ res http.ResponseWriter ,
322
+ acc telegraf.HighPriorityAccumulator ,
323
+ metrics []telegraf.Metric ,
324
+ ) {
296
325
for _ , m := range metrics {
297
326
for headerName , measurementName := range h .HTTPHeaderTags {
298
327
headerValues := req .Header .Get (headerName )
@@ -305,10 +334,19 @@ func (h *HTTPListenerV2) serveWrite(res http.ResponseWriter, req *http.Request)
305
334
m .AddTag (pathTag , req .URL .Path )
306
335
}
307
336
308
- h .acc .AddMetric (m )
309
- }
337
+ if err := acc .AddMetricHighPriority (m ); err != nil {
338
+ acc .AddError (fmt .Errorf ("writing data to output failed: %w" , err ))
339
+ h .Log .Debugf ("got error from high-priority-IO" )
310
340
311
- res .WriteHeader (h .SuccessCode )
341
+ res .WriteHeader (http .StatusInternalServerError )
342
+ _ , err = res .Write ([]byte (fmt .Sprintf (`{"error":"%v"}` , err )))
343
+ if err != nil {
344
+ acc .AddError (fmt .Errorf ("send htp response failed: %w" , err ))
345
+ h .Log .Tracef ("send http response failed: %v" , err )
346
+ }
347
+ return
348
+ }
349
+ }
312
350
}
313
351
314
352
func (h * HTTPListenerV2 ) collectBody (res http.ResponseWriter , req * http.Request ) ([]byte , bool ) {
@@ -419,6 +457,10 @@ func (h *HTTPListenerV2) authenticateIfSet(handler http.HandlerFunc, res http.Re
419
457
}
420
458
}
421
459
460
+ func (h * HTTPListenerV2 ) MarkHighPriority () {
461
+ // Do nothing
462
+ }
463
+
422
464
func init () {
423
465
inputs .Add ("http_listener_v2" , func () telegraf.Input {
424
466
return & HTTPListenerV2 {
0 commit comments