1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-12 10:04:29 +02:00
opentelemetry-go/sdk/metric/selector/simple/simple_test.go
Joshua MacDonald a7b9d02167
Rename metric instruments to match feature-freeze API specification (#2202)
* s/ValueRecorder/Histogram/g

* s/ValueObserver/GaugeObserver/g

* s/UpDownSumObserver/UpDownCounterObserver/g

* s/SumObserver/CounterObserver/g

* changelog

* pr num

* unstable->experimental

* Apply suggestions from code review

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Apply suggestions from code review

* apply feedback from @evantorrie by hand

* Apply suggestions from code review

Thanks

Co-authored-by: ET <evantorrie@users.noreply.github.com>

* Update sdk/export/metric/metric.go

* Apply suggestions from code review

Thank you @evantorrie !

Co-authored-by: ET <evantorrie@users.noreply.github.com>

* revert getting-started fix let tyler's update remove this text

* more variable name fixes

* test repair

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: ET <evantorrie@users.noreply.github.com>
Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
2021-09-01 16:38:37 -04:00

74 lines
3.1 KiB
Go

// 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 simple_test
import (
"testing"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/exact"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
)
var (
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)
)
func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator {
var agg export.Aggregator
sel.AggregatorFor(desc, &agg)
return agg
}
func testFixedSelectors(t *testing.T, sel export.AggregatorSelector) {
require.IsType(t, (*lastvalue.Aggregator)(nil), oneAgg(sel, &testGaugeObserverDesc))
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, &testCounterObserverDesc))
require.IsType(t, (*sum.Aggregator)(nil), oneAgg(sel, &testUpDownCounterObserverDesc))
}
func TestInexpensiveDistribution(t *testing.T) {
inex := simple.NewWithInexpensiveDistribution()
require.IsType(t, (*minmaxsumcount.Aggregator)(nil), oneAgg(inex, &testHistogramDesc))
testFixedSelectors(t, inex)
}
func TestExactDistribution(t *testing.T) {
ex := simple.NewWithExactDistribution()
require.IsType(t, (*exact.Aggregator)(nil), oneAgg(ex, &testHistogramDesc))
testFixedSelectors(t, ex)
}
func TestHistogramDistribution(t *testing.T) {
hist := simple.NewWithHistogramDistribution()
require.IsType(t, (*histogram.Aggregator)(nil), oneAgg(hist, &testHistogramDesc))
testFixedSelectors(t, hist)
}