1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-10 09:50:58 +02:00

Remove the deprecated sdk/metric/aggregation package (#4468)

* Remove the deprecated sdk/metric/aggregation package

* Update PR number
This commit is contained in:
Tyler Yahn 2023-08-29 13:19:33 -07:00 committed by GitHub
parent 537fd53e6e
commit d702e92c2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 319 deletions

View File

@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Remove the deprecated `go.opentelemetry.io/otel/exporters/jaeger` package. (#4467)
- Remove the deprecated `go.opentelemetry.io/otel/example/jaeger` package. (#4467)
- Removed the deprecated `go.opentelemetry.io/otel/sdk/metric/aggregation` package. (#4468)
## [1.17.0/0.40.0/0.0.5] 2023-08-28

View File

@ -1,224 +0,0 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package aggregation contains configuration types that define the
// aggregation operation used to summarizes recorded measurements.
//
// Deprecated: Use the aggregation types in go.opentelemetry.io/otel/sdk/metric
// instead.
package aggregation // import "go.opentelemetry.io/otel/sdk/metric/aggregation"
import (
"errors"
"fmt"
)
// errAgg is wrapped by misconfigured aggregations.
var errAgg = errors.New("aggregation")
// Aggregation is the aggregation used to summarize recorded measurements.
type Aggregation interface {
// private attempts to ensure no user-defined Aggregation are allowed. The
// OTel specification does not allow user-defined Aggregation currently.
private()
// Copy returns a deep copy of the Aggregation.
Copy() Aggregation
// Err returns an error for any misconfigured Aggregation.
Err() error
}
// Drop is an aggregation that drops all recorded data.
type Drop struct{} // Drop has no parameters.
var _ Aggregation = Drop{}
func (Drop) private() {}
// Copy returns a deep copy of d.
func (d Drop) Copy() Aggregation { return d }
// Err returns an error for any misconfiguration. A Drop aggregation has no
// parameters and cannot be misconfigured, therefore this always returns nil.
func (Drop) Err() error { return nil }
// Default is an aggregation that uses the default instrument kind selection
// mapping to select another aggregation. A metric reader can be configured to
// make an aggregation selection based on instrument kind that differs from
// the default. This aggregation ensures the default is used.
//
// See the "go.opentelemetry.io/otel/sdk/metric".DefaultAggregationSelector
// for information about the default instrument kind selection mapping.
type Default struct{} // Default has no parameters.
var _ Aggregation = Default{}
func (Default) private() {}
// Copy returns a deep copy of d.
func (d Default) Copy() Aggregation { return d }
// Err returns an error for any misconfiguration. A Default aggregation has no
// parameters and cannot be misconfigured, therefore this always returns nil.
func (Default) Err() error { return nil }
// Sum is an aggregation that summarizes a set of measurements as their
// arithmetic sum.
type Sum struct{} // Sum has no parameters.
var _ Aggregation = Sum{}
func (Sum) private() {}
// Copy returns a deep copy of s.
func (s Sum) Copy() Aggregation { return s }
// Err returns an error for any misconfiguration. A Sum aggregation has no
// parameters and cannot be misconfigured, therefore this always returns nil.
func (Sum) Err() error { return nil }
// LastValue is an aggregation that summarizes a set of measurements as the
// last one made.
type LastValue struct{} // LastValue has no parameters.
var _ Aggregation = LastValue{}
func (LastValue) private() {}
// Copy returns a deep copy of l.
func (l LastValue) Copy() Aggregation { return l }
// Err returns an error for any misconfiguration. A LastValue aggregation has
// no parameters and cannot be misconfigured, therefore this always returns
// nil.
func (LastValue) Err() error { return nil }
// ExplicitBucketHistogram is an aggregation that summarizes a set of
// measurements as an histogram with explicitly defined buckets.
type ExplicitBucketHistogram struct {
// Boundaries are the increasing bucket boundary values. Boundary values
// define bucket upper bounds. Buckets are exclusive of their lower
// boundary and inclusive of their upper bound (except at positive
// infinity). A measurement is defined to fall into the greatest-numbered
// bucket with a boundary that is greater than or equal to the
// measurement. As an example, boundaries defined as:
//
// []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000}
//
// Will define these buckets:
//
// (-∞, 0], (0, 5.0], (5.0, 10.0], (10.0, 25.0], (25.0, 50.0],
// (50.0, 75.0], (75.0, 100.0], (100.0, 250.0], (250.0, 500.0],
// (500.0, 1000.0], (1000.0, +∞)
Boundaries []float64
// NoMinMax indicates whether to not record the min and max of the
// distribution. By default, these extrema are recorded.
//
// Recording these extrema for cumulative data is expected to have little
// value, they will represent the entire life of the instrument instead of
// just the current collection cycle. It is recommended to set this to true
// for that type of data to avoid computing the low-value extrema.
NoMinMax bool
}
var _ Aggregation = ExplicitBucketHistogram{}
func (ExplicitBucketHistogram) private() {}
// errHist is returned by misconfigured ExplicitBucketHistograms.
var errHist = fmt.Errorf("%w: explicit bucket histogram", errAgg)
// Err returns an error for any misconfiguration.
func (h ExplicitBucketHistogram) Err() error {
if len(h.Boundaries) <= 1 {
return nil
}
// Check boundaries are monotonic.
i := h.Boundaries[0]
for _, j := range h.Boundaries[1:] {
if i >= j {
return fmt.Errorf("%w: non-monotonic boundaries: %v", errHist, h.Boundaries)
}
i = j
}
return nil
}
// Copy returns a deep copy of h.
func (h ExplicitBucketHistogram) Copy() Aggregation {
b := make([]float64, len(h.Boundaries))
copy(b, h.Boundaries)
return ExplicitBucketHistogram{
Boundaries: b,
NoMinMax: h.NoMinMax,
}
}
// Base2ExponentialHistogram is an aggregation that summarizes a set of
// measurements as an histogram with bucket widths that grow exponentially.
type Base2ExponentialHistogram struct {
// MaxSize is the maximum number of buckets to use for the histogram.
MaxSize int32
// MaxScale is the maximum resolution scale to use for the histogram.
//
// MaxScale has a maximum value of 20. Using a value of 20 means the
// maximum number of buckets that can fit within the range of a
// signed 32-bit integer index could be used.
//
// MaxScale has a minimum value of -10. Using a value of -10 means only
// two buckets will be use.
MaxScale int32
// NoMinMax indicates whether to not record the min and max of the
// distribution. By default, these extrema are recorded.
//
// Recording these extrema for cumulative data is expected to have little
// value, they will represent the entire life of the instrument instead of
// just the current collection cycle. It is recommended to set this to true
// for that type of data to avoid computing the low-value extrema.
NoMinMax bool
}
var _ Aggregation = Base2ExponentialHistogram{}
// private attempts to ensure no user-defined Aggregation is allowed. The
// OTel specification does not allow user-defined Aggregation currently.
func (e Base2ExponentialHistogram) private() {}
// Copy returns a deep copy of the Aggregation.
func (e Base2ExponentialHistogram) Copy() Aggregation {
return e
}
const (
expoMaxScale = 20
expoMinScale = -10
)
// errExpoHist is returned by misconfigured Base2ExponentialBucketHistograms.
var errExpoHist = fmt.Errorf("%w: exponential histogram", errAgg)
// Err returns an error for any misconfigured Aggregation.
func (e Base2ExponentialHistogram) Err() error {
if e.MaxScale > expoMaxScale {
return fmt.Errorf("%w: max size %d is greater than maximum scale %d", errExpoHist, e.MaxSize, expoMaxScale)
}
if e.MaxSize <= 0 {
return fmt.Errorf("%w: max size %d is less than or equal to zero", errExpoHist, e.MaxSize)
}
return nil
}

View File

@ -1,95 +0,0 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package aggregation
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAggregationErr(t *testing.T) {
t.Run("DropOperation", func(t *testing.T) {
assert.NoError(t, Drop{}.Err())
})
t.Run("SumOperation", func(t *testing.T) {
assert.NoError(t, Sum{}.Err())
})
t.Run("LastValueOperation", func(t *testing.T) {
assert.NoError(t, LastValue{}.Err())
})
t.Run("ExplicitBucketHistogramOperation", func(t *testing.T) {
assert.NoError(t, ExplicitBucketHistogram{}.Err())
assert.NoError(t, ExplicitBucketHistogram{
Boundaries: []float64{0},
NoMinMax: true,
}.Err())
assert.NoError(t, ExplicitBucketHistogram{
Boundaries: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000},
}.Err())
})
t.Run("NonmonotonicHistogramBoundaries", func(t *testing.T) {
assert.ErrorIs(t, ExplicitBucketHistogram{
Boundaries: []float64{2, 1},
}.Err(), errAgg)
assert.ErrorIs(t, ExplicitBucketHistogram{
Boundaries: []float64{0, 1, 2, 1, 3, 4},
}.Err(), errAgg)
})
t.Run("ExponentialHistogramOperation", func(t *testing.T) {
assert.NoError(t, Base2ExponentialHistogram{
MaxSize: 160,
MaxScale: 20,
}.Err())
assert.NoError(t, Base2ExponentialHistogram{
MaxSize: 1,
NoMinMax: true,
}.Err())
assert.NoError(t, Base2ExponentialHistogram{
MaxSize: 1024,
MaxScale: -3,
}.Err())
})
t.Run("InvalidExponentialHistogramOperation", func(t *testing.T) {
// MazSize must be greater than 0
assert.ErrorIs(t, Base2ExponentialHistogram{}.Err(), errAgg)
// MaxScale Must be <=20
assert.ErrorIs(t, Base2ExponentialHistogram{
MaxSize: 1,
MaxScale: 30,
}.Err(), errAgg)
})
}
func TestExplicitBucketHistogramDeepCopy(t *testing.T) {
const orig = 0.0
b := []float64{orig}
h := ExplicitBucketHistogram{Boundaries: b}
cpH := h.Copy().(ExplicitBucketHistogram)
b[0] = orig + 1
assert.Equal(t, orig, cpH.Boundaries[0], "changing the underlying slice data should not affect the copy")
}