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-11-12 17:28:32 +02:00
|
|
|
"go.opentelemetry.io/otel/metric"
|
2020-11-11 17:24:12 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/number"
|
2021-08-12 01:02:28 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/sdkapi"
|
2020-06-13 09:55:01 +02:00
|
|
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
2021-01-12 20:19:13 +02: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-25 00:30:55 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
|
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 (
|
2021-09-01 22:38:37 +02:00
|
|
|
testCounterDesc = metric.NewDescriptor("counter", sdkapi.CounterInstrumentKind, number.Int64Kind)
|
|
|
|
testUpDownCounterDesc = metric.NewDescriptor("updowncounter", sdkapi.UpDownCounterInstrumentKind, number.Int64Kind)
|
|
|
|
testCounterObserverDesc = metric.NewDescriptor("counterobserver", sdkapi.CounterObserverInstrumentKind, number.Int64Kind)
|
|
|
|
testUpDownCounterObserverDesc = metric.NewDescriptor("updowncounterobserver", sdkapi.UpDownCounterObserverInstrumentKind, number.Int64Kind)
|
|
|
|
testHistogramDesc = metric.NewDescriptor("histogram", sdkapi.HistogramInstrumentKind, number.Int64Kind)
|
|
|
|
testGaugeObserverDesc = metric.NewDescriptor("gauge", sdkapi.GaugeObserverInstrumentKind, number.Int64Kind)
|
2019-11-15 23:01:20 +02:00
|
|
|
)
|
|
|
|
|
2020-11-12 17:28:32 +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-09-25 00:30:55 +02:00
|
|
|
func testFixedSelectors(t *testing.T, sel export.AggregatorSelector) {
|
2021-09-01 22:38:37 +02:00
|
|
|
require.IsType(t, (*lastvalue.Aggregator)(nil), oneAgg(sel, &testGaugeObserverDesc))
|
2020-09-25 00:30:55 +02:00
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testCounterDesc))
|
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testUpDownCounterDesc))
|
2021-09-01 22:38:37 +02:00
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testCounterObserverDesc))
|
|
|
|
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testUpDownCounterObserverDesc))
|
2020-09-25 00:30:55 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
func TestInexpensiveDistribution(t *testing.T) {
|
|
|
|
inex := simple.NewWithInexpensiveDistribution()
|
2021-09-01 22:38:37 +02:00
|
|
|
require.IsType(t, (*minmaxsumcount.Aggregator)(nil), oneAgg(inex, &testHistogramDesc))
|
2020-09-25 00:30:55 +02:00
|
|
|
testFixedSelectors(t, inex)
|
2019-11-15 23:01:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
func TestExactDistribution(t *testing.T) {
|
|
|
|
ex := simple.NewWithExactDistribution()
|
2021-09-01 22:38:37 +02:00
|
|
|
require.IsType(t, (*exact.Aggregator)(nil), oneAgg(ex, &testHistogramDesc))
|
2020-09-25 00:30:55 +02:00
|
|
|
testFixedSelectors(t, ex)
|
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) {
|
2021-01-16 01:29:02 +02:00
|
|
|
hist := simple.NewWithHistogramDistribution()
|
2021-09-01 22:38:37 +02:00
|
|
|
require.IsType(t, (*histogram.Aggregator)(nil), oneAgg(hist, &testHistogramDesc))
|
2020-09-25 00:30:55 +02:00
|
|
|
testFixedSelectors(t, hist)
|
2020-04-01 23:36:37 +02:00
|
|
|
}
|