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

[chore] Make internal Batcher interface generic #12689

Merged
merged 1 commit into from
Mar 21, 2025
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
11 changes: 4 additions & 7 deletions exporter/exporterhelper/internal/batcher/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import (
)

// Batcher is in charge of reading items from the queue and send them out asynchronously.
type Batcher interface {
type Batcher[K any] interface {
component.Component
Consume(context.Context, request.Request, queuebatch.Done)
Consume(context.Context, K, queuebatch.Done)
}

func NewBatcher(batchCfg exporterbatcher.Config,
exportFunc sender.SendFunc[request.Request],
maxWorkers int,
) (Batcher, error) {
func NewBatcher(batchCfg exporterbatcher.Config, exportFunc sender.SendFunc[request.Request], maxWorkers int) (Batcher[request.Request], error) {
if !batchCfg.Enabled {
return newDisabledBatcher(exportFunc), nil
return newDisabledBatcher[request.Request](exportFunc), nil
}
return newDefaultBatcher(batchCfg, exportFunc, maxWorkers), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender"
)

Expand All @@ -24,6 +23,6 @@ func (db *disabledBatcher[T]) Consume(ctx context.Context, req T, done queuebatc
done.OnDone(db.consumeFunc(ctx, req))
}

func newDisabledBatcher(consumeFunc sender.SendFunc[request.Request]) Batcher {
return &disabledBatcher[request.Request]{consumeFunc: consumeFunc}
func newDisabledBatcher[K any](consumeFunc sender.SendFunc[K]) Batcher[K] {
return &disabledBatcher[K]{consumeFunc: consumeFunc}
}
2 changes: 1 addition & 1 deletion exporter/exporterhelper/internal/queue_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

type QueueSender struct {
queue queuebatch.Queue[request.Request]
batcher component.Component
batcher batcher.Batcher[request.Request]
}

func NewQueueSender(
Expand Down
Loading