Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bcd7852

Browse files
committedMar 20, 2025··
[chore] Make internal Batcher interface generic
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
1 parent 00886cb commit bcd7852

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed
 

‎exporter/exporterhelper/internal/batcher/batcher.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ import (
1414
)
1515

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

22-
func NewBatcher(batchCfg exporterbatcher.Config,
23-
exportFunc sender.SendFunc[request.Request],
24-
maxWorkers int,
25-
) (Batcher, error) {
22+
func NewBatcher(batchCfg exporterbatcher.Config, exportFunc sender.SendFunc[request.Request], maxWorkers int) (Batcher[request.Request], error) {
2623
if !batchCfg.Enabled {
27-
return newDisabledBatcher(exportFunc), nil
24+
return newDisabledBatcher[request.Request](exportFunc), nil
2825
}
2926
return newDefaultBatcher(batchCfg, exportFunc, maxWorkers), nil
3027
}

‎exporter/exporterhelper/internal/batcher/disabled_batcher.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"go.opentelemetry.io/collector/component"
1010
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
11-
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
1211
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender"
1312
)
1413

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

27-
func newDisabledBatcher(consumeFunc sender.SendFunc[request.Request]) Batcher {
28-
return &disabledBatcher[request.Request]{consumeFunc: consumeFunc}
26+
func newDisabledBatcher[K any](consumeFunc sender.SendFunc[K]) Batcher[K] {
27+
return &disabledBatcher[K]{consumeFunc: consumeFunc}
2928
}

‎exporter/exporterhelper/internal/queue_sender.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var _ = featuregate.GlobalRegistry().MustRegister(
2929

3030
type QueueSender struct {
3131
queue queuebatch.Queue[request.Request]
32-
batcher component.Component
32+
batcher batcher.Batcher[request.Request]
3333
}
3434

3535
func NewQueueSender(

0 commit comments

Comments
 (0)
Please sign in to comment.