Skip to content

Commit

Permalink
Add latency metrics for logstash async output
Browse files Browse the repository at this point in the history
  • Loading branch information
strawgate committed Jan 31, 2025
1 parent 2b8d554 commit 1a17e8f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libbeat/outputs/logstash/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type msgRef struct {
win *window
batchSize int
deadlockListener *deadlockListener
start time.Time
}

func newAsyncClient(
Expand Down Expand Up @@ -154,6 +155,7 @@ func (c *asyncClient) Publish(_ context.Context, batch publisher.Batch) error {
win: c.win,
err: nil,
deadlockListener: newDeadlockListener(c.log, logstashDeadlockTimeout),
start: time.Time{},
}
ref.count.Store(1)
defer ref.dec()
Expand Down Expand Up @@ -221,6 +223,7 @@ func (c *asyncClient) sendEvents(ref *msgRef, events []publisher.Event) error {
window[i] = &events[i].Content
}
ref.count.Add(1)
ref.start = time.Now()
return client.Send(ref.callback, window)
}

Expand All @@ -246,6 +249,10 @@ func (r *msgRef) callback(n uint32, err error) {
r.win.tryGrowWindow(r.batchSize)
}
}

// Report the latency for the batch of events
r.client.observer.ReportLatency(time.Since(r.start))

r.dec()
}

Expand Down

0 comments on commit 1a17e8f

Please sign in to comment.