Files
Sindy LiandGitHub ba5ec51b36 [exporterhelper][queuebatcher] partitioner as the interface to get partition key (#12803)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This RP implements a type `partitioner` that serves as the interface to
get partition key.

<!-- Issue number if applicable -->
#### Link to tracking issue
https://github.com/open-telemetry/opentelemetry-collector/issues/12795

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->
2025-04-16 05:05:16 +00:00

34 lines
801 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package queuebatch // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
import (
"context"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal/request"
)
// Partitioner is an interface that returns the the partition key of the given element.
type Partitioner[T any] interface {
GetKey(context.Context, T) string
}
type GetKeyFunc[T any] func(context.Context, T) string
func (f GetKeyFunc[T]) GetKey(ctx context.Context, t T) string {
return f(ctx, t)
}
type basePartitioner struct {
GetKeyFunc[request.Request]
}
func NewPartitioner(
getKeyFunc GetKeyFunc[request.Request],
) Partitioner[request.Request] {
return &basePartitioner{
GetKeyFunc: getKeyFunc,
}
}