1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-26 21:05:00 +02:00
opentelemetry-go/metric/syncfloat64_test.go
Tyler Yahn dafe137bbe
Add the synchronous gauge to the metric API and SDK (#5304)
Resolve #5225 

The specification has [added a synchronous gauge
instrument](https://github.com/open-telemetry/opentelemetry-specification/pull/3540).
That instrument has now been
[stabilized](https://github.com/open-telemetry/opentelemetry-specification/pull/4019),
and that stabilization is included in the [next
release](https://github.com/open-telemetry/opentelemetry-specification/pull/4034).

This adds the new synchronous gauge instrument to the metric API and all
implementation we publish.

This change will be a breaking change for any SDK developer. The
`embedded` package is updated to ensure our compatibility guarantees are
meet.

---------

Co-authored-by: David Ashpole <dashpole@google.com>
2024-05-16 09:56:40 -07:00

53 lines
1.3 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package metric // import "go.opentelemetry.io/otel/metric"
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFloat64Configuration(t *testing.T) {
const (
token float64 = 43
desc = "Instrument description."
uBytes = "By"
)
run := func(got float64Config) func(*testing.T) {
return func(t *testing.T) {
assert.Equal(t, desc, got.Description(), "description")
assert.Equal(t, uBytes, got.Unit(), "unit")
}
}
t.Run("Float64Counter", run(
NewFloat64CounterConfig(WithDescription(desc), WithUnit(uBytes)),
))
t.Run("Float64UpDownCounter", run(
NewFloat64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes)),
))
t.Run("Float64Histogram", run(
NewFloat64HistogramConfig(WithDescription(desc), WithUnit(uBytes)),
))
t.Run("Float64Gauge", run(
NewFloat64GaugeConfig(WithDescription(desc), WithUnit(uBytes)),
))
}
type float64Config interface {
Description() string
Unit() string
}
func TestFloat64ExplicitBucketHistogramConfiguration(t *testing.T) {
bounds := []float64{0.1, 0.5, 1.0}
got := NewFloat64HistogramConfig(WithExplicitBucketBoundaries(bounds...))
assert.Equal(t, bounds, got.ExplicitBucketBoundaries(), "boundaries")
}