-
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 exemplar types to non-internal package (#5747)
Part of #5249 This makes all existing types designed to implement the public Exemplar API public by moving most of `internal/exemplar` to `exemplar`. The only types that are not being made public are `exemplar.Drop`, and `exemplar.FilteredReservoir`. Those types are moved to `internal/aggregate`, and are renamed to `DropReservoir` and `FilteredExemplarReservoir`. The following types are made public: * `exemplar.Exemplar` * `exemplar.Filter` * `exemplar.SampledFilter` * `exemplar.AlwaysOnFilter` * `exemplar.HistogramReservoir` * `exemplar.FixedSizeReservoir` * `exemplar.Reservoir` * `exemplar.Value` * `exemplar.ValueType`
- Loading branch information
Showing
29 changed files
with
214 additions
and
172 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 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,3 @@ | ||
# Metric SDK Exemplars | ||
|
||
[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel/sdk/metric/exemplar)](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric/exemplar) |
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
2 changes: 1 addition & 1 deletion
2
sdk/metric/internal/exemplar/exemplar.go → sdk/metric/exemplar/exemplar.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
2 changes: 1 addition & 1 deletion
2
sdk/metric/internal/exemplar/filter.go → sdk/metric/exemplar/filter.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
2 changes: 1 addition & 1 deletion
2
sdk/metric/internal/exemplar/filter_test.go → sdk/metric/exemplar/filter_test.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
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,62 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" | ||
|
||
import ( | ||
"context" | ||
"slices" | ||
"sort" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
// NewHistogramReservoir returns a [HistogramReservoir] that samples the last | ||
// measurement that falls within a histogram bucket. The histogram bucket | ||
// upper-boundaries are define by bounds. | ||
// | ||
// The passed bounds will be sorted by this function. | ||
func NewHistogramReservoir(bounds []float64) *HistogramReservoir { | ||
slices.Sort(bounds) | ||
return &HistogramReservoir{ | ||
bounds: bounds, | ||
storage: newStorage(len(bounds) + 1), | ||
} | ||
} | ||
|
||
var _ Reservoir = &HistogramReservoir{} | ||
|
||
// HistogramReservoir is a [Reservoir] that samples the last measurement that | ||
// falls within a histogram bucket. The histogram bucket upper-boundaries are | ||
// define by bounds. | ||
type HistogramReservoir struct { | ||
*storage | ||
|
||
// bounds are bucket bounds in ascending order. | ||
bounds []float64 | ||
} | ||
|
||
// Offer accepts the parameters associated with a measurement. The | ||
// parameters will be stored as an exemplar if the Reservoir 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. | ||
// | ||
// The time t is the time when the measurement was made. The v and a | ||
// parameters are the value and dropped (filtered) attributes of the | ||
// measurement respectively. | ||
func (r *HistogramReservoir) Offer(ctx context.Context, t time.Time, v Value, a []attribute.KeyValue) { | ||
var x float64 | ||
switch v.Type() { | ||
case Int64ValueType: | ||
x = float64(v.Int64()) | ||
case Float64ValueType: | ||
x = v.Float64() | ||
default: | ||
panic("unknown value type") | ||
} | ||
r.store[sort.SearchFloat64s(r.bounds, x)] = newMeasurement(ctx, t, v, a) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
sdk/metric/internal/exemplar/reservoir.go → sdk/metric/exemplar/reservoir.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
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
sdk/metric/internal/exemplar/value.go → sdk/metric/exemplar/value.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
File renamed without changes.
Oops, something went wrong.