2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-11-15 23:01:20 +02:00
|
|
|
//
|
|
|
|
// 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 simple_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-03-19 21:02:46 +02:00
|
|
|
"go.opentelemetry.io/otel/api/metric"
|
2020-06-13 09:55:01 +02:00
|
|
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
2019-11-15 23:01:20 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch"
|
2020-04-01 23:36:37 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
2019-11-27 00:07:58 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
|
2020-03-12 05:21:34 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
|
2019-11-15 23:01:20 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-05-16 07:11:12 +02:00
|
|
|
testCounterDesc = metric.NewDescriptor("counter", metric.CounterKind, metric.Int64NumberKind)
|
|
|
|
testValueRecorderDesc = metric.NewDescriptor("valuerecorder", metric.ValueRecorderKind, metric.Int64NumberKind)
|
2020-05-18 20:03:43 +02:00
|
|
|
testValueObserverDesc = metric.NewDescriptor("valueobserver", metric.ValueObserverKind, metric.Int64NumberKind)
|
2019-11-15 23:01:20 +02:00
|
|
|
)
|
|
|
|
|
2020-06-23 19:51:15 +02:00
|
|
|
func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator {
|
2020-06-13 09:55:01 +02:00
|
|
|
var agg export.Aggregator
|
|
|
|
sel.AggregatorFor(desc, &agg)
|
|
|
|
return agg
|
|
|
|
}
|
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
func TestInexpensiveDistribution(t *testing.T) {
|
|
|
|
inex := simple.NewWithInexpensiveDistribution()
|
2020-06-13 09:55:01 +02:00
|
|
|
require.NotPanics(t, func() { _ = oneAgg(inex, &testCounterDesc).(*sum.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(inex, &testValueRecorderDesc).(*minmaxsumcount.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(inex, &testValueObserverDesc).(*minmaxsumcount.Aggregator) })
|
2019-11-15 23:01:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
func TestSketchDistribution(t *testing.T) {
|
|
|
|
sk := simple.NewWithSketchDistribution(ddsketch.NewDefaultConfig())
|
2020-06-13 09:55:01 +02:00
|
|
|
require.NotPanics(t, func() { _ = oneAgg(sk, &testCounterDesc).(*sum.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(sk, &testValueRecorderDesc).(*ddsketch.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(sk, &testValueObserverDesc).(*ddsketch.Aggregator) })
|
2019-11-15 23:01:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
func TestExactDistribution(t *testing.T) {
|
|
|
|
ex := simple.NewWithExactDistribution()
|
2020-06-13 09:55:01 +02:00
|
|
|
require.NotPanics(t, func() { _ = oneAgg(ex, &testCounterDesc).(*sum.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(ex, &testValueRecorderDesc).(*array.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(ex, &testValueObserverDesc).(*array.Aggregator) })
|
2019-11-15 23:01:20 +02:00
|
|
|
}
|
2020-04-01 23:36:37 +02:00
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
func TestHistogramDistribution(t *testing.T) {
|
2020-05-21 19:29:03 +02:00
|
|
|
ex := simple.NewWithHistogramDistribution(nil)
|
2020-06-13 09:55:01 +02:00
|
|
|
require.NotPanics(t, func() { _ = oneAgg(ex, &testCounterDesc).(*sum.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(ex, &testValueRecorderDesc).(*histogram.Aggregator) })
|
|
|
|
require.NotPanics(t, func() { _ = oneAgg(ex, &testValueObserverDesc).(*histogram.Aggregator) })
|
2020-04-01 23:36:37 +02:00
|
|
|
}
|