2020-03-23 22:41:10 -07:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-11-15 13:01:20 -08: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-11-12 16:28:32 +01:00
|
|
|
"go.opentelemetry.io/otel/metric"
|
2020-11-11 16:24:12 +01:00
|
|
|
"go.opentelemetry.io/otel/metric/number"
|
2020-06-13 00:55:01 -07:00
|
|
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
2021-01-12 10:19:13 -08:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/exact"
|
2020-04-01 23:36:37 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
2020-09-24 15:30:55 -07:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
|
2019-11-26 14:07:58 -08:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
|
2020-03-11 20:21:34 -07:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
|
2019-11-15 13:01:20 -08:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-11-12 16:28:32 +01:00
|
|
|
testCounterDesc = metric.NewDescriptor("counter", metric.CounterInstrumentKind, number.Int64Kind)
|
|
|
|
testUpDownCounterDesc = metric.NewDescriptor("updowncounter", metric.UpDownCounterInstrumentKind, number.Int64Kind)
|
|
|
|
testSumObserverDesc = metric.NewDescriptor("sumobserver", metric.SumObserverInstrumentKind, number.Int64Kind)
|
|
|
|
testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", metric.UpDownSumObserverInstrumentKind, number.Int64Kind)
|
|
|
|
testValueRecorderDesc = metric.NewDescriptor("valuerecorder", metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
|
|
|
testValueObserverDesc = metric.NewDescriptor("valueobserver", metric.ValueObserverInstrumentKind, number.Int64Kind)
|
2019-11-15 13:01:20 -08:00
|
|
|
)
|
|
|
|
|
2020-11-12 16:28:32 +01:00
|
|
|
func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator {
|
2020-06-13 00:55:01 -07:00
|
|
|
var agg export.Aggregator
|
|
|
|
sel.AggregatorFor(desc, &agg)
|
|
|
|
return agg
|
|
|
|
}
|
|
|
|
|
2020-09-24 15:30:55 -07:00
|
|
|
func testFixedSelectors(t *testing.T, sel export.AggregatorSelector) {
|
|
|
|
require.IsType(t, (*lastvalue.Aggregator)(nil), oneAgg(sel, &testValueObserverDesc))
|
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testCounterDesc))
|
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testUpDownCounterDesc))
|
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testSumObserverDesc))
|
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testUpDownSumObserverDesc))
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:11:12 -07:00
|
|
|
func TestInexpensiveDistribution(t *testing.T) {
|
|
|
|
inex := simple.NewWithInexpensiveDistribution()
|
2020-09-24 15:30:55 -07:00
|
|
|
require.IsType(t, (*minmaxsumcount.Aggregator)(nil), oneAgg(inex, &testValueRecorderDesc))
|
|
|
|
testFixedSelectors(t, inex)
|
2019-11-15 13:01:20 -08:00
|
|
|
}
|
|
|
|
|
2020-05-15 22:11:12 -07:00
|
|
|
func TestExactDistribution(t *testing.T) {
|
|
|
|
ex := simple.NewWithExactDistribution()
|
2021-01-12 10:19:13 -08:00
|
|
|
require.IsType(t, (*exact.Aggregator)(nil), oneAgg(ex, &testValueRecorderDesc))
|
2020-09-24 15:30:55 -07:00
|
|
|
testFixedSelectors(t, ex)
|
2019-11-15 13:01:20 -08:00
|
|
|
}
|
2020-04-01 23:36:37 +02:00
|
|
|
|
2020-05-15 22:11:12 -07:00
|
|
|
func TestHistogramDistribution(t *testing.T) {
|
2020-09-24 15:30:55 -07:00
|
|
|
hist := simple.NewWithHistogramDistribution(nil)
|
|
|
|
require.IsType(t, (*histogram.Aggregator)(nil), oneAgg(hist, &testValueRecorderDesc))
|
|
|
|
testFixedSelectors(t, hist)
|
2020-04-01 23:36:37 +02:00
|
|
|
}
|