From acf5db543e1a56f7aa1046cc1316674f17db743a Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Wed, 9 Feb 2022 23:22:54 +0100 Subject: [PATCH] Fix: Reset counter --- sinks/httpSink.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sinks/httpSink.go b/sinks/httpSink.go index 844de0b..22ecfce 100644 --- a/sinks/httpSink.go +++ b/sinks/httpSink.go @@ -47,6 +47,9 @@ func (s *HttpSink) Init(config json.RawMessage) error { s.config.Timeout = "5s" s.config.BatchSize = 20 + // Reset counter + s.batchCounter = 0 + // Read config if len(config) > 0 { err := json.Unmarshal(config, &s.config) @@ -103,6 +106,14 @@ func (s *HttpSink) Write(m lp.CCMetric) error { } func (s *HttpSink) Flush() error { + // Do not flush empty buffer + if s.batchCounter == 0 { + return nil + } + + // Reset counter + s.batchCounter = 0 + // Create new request to send buffer req, err := http.NewRequest(http.MethodPost, s.url, s.buffer) if err != nil {