mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--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.-->
34 lines
801 B
Go
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,
|
|
}
|
|
}
|