Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter][chore] Change queue batcher to use exportFunc instead of request.export() #11636

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions exporter/internal/queue/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ type BaseBatcher struct {
queue Queue[internal.Request]
maxWorkers int
workerPool chan bool
exportFunc func(ctx context.Context, req internal.Request) error
stopWG sync.WaitGroup
}

func NewBatcher(batchCfg exporterbatcher.Config, queue Queue[internal.Request], maxWorkers int) (Batcher, error) {
func NewBatcher(batchCfg exporterbatcher.Config,
queue Queue[internal.Request],
exportFunc func(ctx context.Context, req internal.Request) error,
maxWorkers int) (Batcher, error) {
if !batchCfg.Enabled {
return &DisabledBatcher{
BaseBatcher{
batchCfg: batchCfg,
queue: queue,
maxWorkers: maxWorkers,
exportFunc: exportFunc,
stopWG: sync.WaitGroup{},
},
}, nil
Expand All @@ -48,6 +53,7 @@ func NewBatcher(batchCfg exporterbatcher.Config, queue Queue[internal.Request],
batchCfg: batchCfg,
queue: queue,
maxWorkers: maxWorkers,
exportFunc: exportFunc,
stopWG: sync.WaitGroup{},
},
}, nil
Expand All @@ -65,7 +71,7 @@ func (qb *BaseBatcher) startWorkerPool() {

// flush exports the incoming batch synchronously.
func (qb *BaseBatcher) flush(batchToFlush batch) {
err := batchToFlush.req.Export(batchToFlush.ctx)
err := qb.exportFunc(batchToFlush.ctx, batchToFlush.req)
for _, idx := range batchToFlush.idxList {
qb.queue.OnProcessingFinished(idx, err)
}
Expand Down
16 changes: 12 additions & 4 deletions exporter/internal/queue/default_batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func TestDefaultBatcher_NoSplit_MinThresholdZero_TimeoutDisabled(t *testing.T) {
Capacity: 10,
})

ba, err := NewBatcher(cfg, q, tt.maxWorkers)
ba, err := NewBatcher(cfg, q,
func(ctx context.Context, req internal.Request) error { return req.Export(ctx) },
tt.maxWorkers)
require.NoError(t, err)

require.NoError(t, q.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -108,7 +110,9 @@ func TestDefaultBatcher_NoSplit_TimeoutDisabled(t *testing.T) {
Capacity: 10,
})

ba, err := NewBatcher(cfg, q, tt.maxWorkers)
ba, err := NewBatcher(cfg, q,
func(ctx context.Context, req internal.Request) error { return req.Export(ctx) },
tt.maxWorkers)
require.NoError(t, err)

require.NoError(t, q.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -172,7 +176,9 @@ func TestDefaultBatcher_NoSplit_WithTimeout(t *testing.T) {
Capacity: 10,
})

ba, err := NewBatcher(cfg, q, tt.maxWorkers)
ba, err := NewBatcher(cfg, q,
func(ctx context.Context, req internal.Request) error { return req.Export(ctx) },
tt.maxWorkers)
require.NoError(t, err)

require.NoError(t, q.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -236,7 +242,9 @@ func TestDefaultBatcher_Split_TimeoutDisabled(t *testing.T) {
Capacity: 10,
})

ba, err := NewBatcher(cfg, q, tt.maxWorkers)
ba, err := NewBatcher(cfg, q,
func(ctx context.Context, req internal.Request) error { return req.Export(ctx) },
tt.maxWorkers)
require.NoError(t, err)

require.NoError(t, q.Start(context.Background(), componenttest.NewNopHost()))
Expand Down
4 changes: 3 additions & 1 deletion exporter/internal/queue/disabled_batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func TestDisabledBatcher_Basic(t *testing.T) {
Capacity: 10,
})

ba, err := NewBatcher(cfg, q, tt.maxWorkers)
ba, err := NewBatcher(cfg, q,
func(ctx context.Context, req internal.Request) error { return req.Export(ctx) },
tt.maxWorkers)
require.NoError(t, err)

require.NoError(t, q.Start(context.Background(), componenttest.NewNopHost()))
Expand Down
Loading