Skip to content

Commit

Permalink
feat: Batcher.Add made variadic to allow passing of multiple points
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastahajek committed Oct 1, 2024
1 parent e115711 commit 5309171
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions influxdb3/batching/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 3 additions & 4 deletions influxdb3/batching/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5309171

Please sign in to comment.