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