-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move drop and filtered reservoir types to internal/aggregate
- Loading branch information
Showing
12 changed files
with
96 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
sdk/metric/exemplar/drop.go → sdk/metric/internal/aggregate/drop.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" | ||
package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/sdk/metric/exemplar" | ||
) | ||
|
||
// Drop returns a [FilteredReservoir] that drops all measurements it is offered. | ||
func Drop[N int64 | float64]() FilteredReservoir[N] { return &dropRes[N]{} } | ||
// DropReservoir returns a [FilteredReservoir] that drops all measurements it is offered. | ||
func DropReservoir[N int64 | float64]() FilteredExemplarReservoir[N] { return &dropRes[N]{} } | ||
|
||
type dropRes[N int64 | float64] struct{} | ||
|
||
// Offer does nothing, all measurements offered will be dropped. | ||
func (r *dropRes[N]) Offer(context.Context, N, []attribute.KeyValue) {} | ||
|
||
// Collect resets dest. No exemplars will ever be returned. | ||
func (r *dropRes[N]) Collect(dest *[]Exemplar) { | ||
func (r *dropRes[N]) Collect(dest *[]exemplar.Exemplar) { | ||
*dest = (*dest)[:0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package aggregate // import "go.opentelemetry.io/otel/sdk/metric/internal/aggregate" | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/sdk/metric/exemplar" | ||
) | ||
|
||
// FilteredExemplarReservoir wraps a [exemplar.Reservoir] with a filter. | ||
type FilteredExemplarReservoir[N int64 | float64] interface { | ||
// Offer accepts the parameters associated with a measurement. The | ||
// parameters will be stored as an exemplar if the filter decides to | ||
// sample the measurement. | ||
// | ||
// The passed ctx needs to contain any baggage or span that were active | ||
// when the measurement was made. This information may be used by the | ||
// Reservoir in making a sampling decision. | ||
Offer(ctx context.Context, val N, attr []attribute.KeyValue) | ||
// Collect returns all the held exemplars in the reservoir. | ||
Collect(dest *[]exemplar.Exemplar) | ||
} | ||
|
||
// filteredExemplarReservoir handles the pre-sampled exemplar of measurements made. | ||
type filteredExemplarReservoir[N int64 | float64] struct { | ||
filter exemplar.Filter | ||
reservoir exemplar.Reservoir | ||
} | ||
|
||
// NewFilteredExemplarReservoir creates a [FilteredExemplarReservoir] which only offers values | ||
// that are allowed by the filter. | ||
func NewFilteredExemplarReservoir[N int64 | float64](f exemplar.Filter, r exemplar.Reservoir) FilteredExemplarReservoir[N] { | ||
return &filteredExemplarReservoir[N]{ | ||
filter: f, | ||
reservoir: r, | ||
} | ||
} | ||
|
||
func (f *filteredExemplarReservoir[N]) Offer(ctx context.Context, val N, attr []attribute.KeyValue) { | ||
if f.filter(ctx) { | ||
// only record the current time if we are sampling this measurment. | ||
f.reservoir.Offer(ctx, time.Now(), exemplar.NewValue(val), attr) | ||
} | ||
} | ||
|
||
func (f *filteredExemplarReservoir[N]) Collect(dest *[]exemplar.Exemplar) { f.reservoir.Collect(dest) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.