From 5309171a168348f52238cc3b660227121b56a46b Mon Sep 17 00:00:00 2001 From: vlastahajek <29980246+vlastahajek@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:45:21 +0200 Subject: [PATCH] feat: Batcher.Add made variadic to allow passing of multiple points --- influxdb3/batching/batcher.go | 6 +++--- influxdb3/batching/batcher_test.go | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/influxdb3/batching/batcher.go b/influxdb3/batching/batcher.go index 02d91e1..8e01f2a 100644 --- a/influxdb3/batching/batcher.go +++ b/influxdb3/batching/batcher.go @@ -103,13 +103,13 @@ func NewBatcher(options ...Option) *Batcher { return b } -// Add a metric to the batcher and call the given callbacks if any -func (b *Batcher) Add(p *influxdb3.Point) { +// Add metric(s) to the batcher and call the given callbacks if any +func (b *Batcher) Add(p ...*influxdb3.Point) { b.Lock() defer b.Unlock() // Add the point - b.points = append(b.points, p) + b.points = append(b.points, p...) // Call callbacks if a new batch is ready if b.isReady() { diff --git a/influxdb3/batching/batcher_test.go b/influxdb3/batching/batcher_test.go index a2e82a7..8403005 100644 --- a/influxdb3/batching/batcher_test.go +++ b/influxdb3/batching/batcher_test.go @@ -79,9 +79,8 @@ func TestReady(t *testing.T) { WithSize(batchSize), ) - for range batchSize { - b.Add(&influxdb3.Point{}) - } + points := []*influxdb3.Point{{}, {}, {}, {}, {}} + b.Add(points...) assert.True(t, b.Ready(), "Batcher should be ready when the batch size is reached") } @@ -115,7 +114,7 @@ func TestPartialEmit(t *testing.T) { }), ) - b.Add(&influxdb3.Point{}) + b.Add(&influxdb3.Point{}, &influxdb3.Point{}) b.Add(&influxdb3.Point{}) points := b.Emit()