Skip to content

Commit f1bdeb3

Browse files
authored
[chore] Make internal Batcher interface generic (#12689)
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 562aedc commit f1bdeb3

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
@@ -20,7 +20,7 @@ import (
2020

2121
type QueueSender struct {
2222
queue queuebatch.Queue[request.Request]
23-
batcher component.Component
23+
batcher batcher.Batcher[request.Request]
2424
}
2525

2626
func NewQueueSender(

0 commit comments

Comments
 (0)