Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Move metric No-Op to metric/noop (#3893)" #3921

Merged
merged 2 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Both the `Histogram` and `HistogramDataPoint` are redefined with a generic argument of `[N int64 | float64]` in `go.opentelemetry.io/otel/sdk/metric/metricdata`. (#3849)
- The metric `Export` interface from `go.opentelemetry.io/otel/sdk/metric` accepts a `*ResourceMetrics` instead of `ResourceMetrics`. (#3853)
- Rename `Asynchronous` to `Observable` in `go.opentelemetry.io/otel/metric/instrument`. (#3892)
- Move No-Op implementation from `go.opentelemetry.io/otel/metric` into its own package `go.opentelemetry.io/otel/metric/noop`. (#3893)
- `NewNoopMeterProvider` is replaced with `noop.NewMeterProvider`
- `NewNoopMeter` is replaced with `noop.NewMeterProvider().Meter("")`
- Rename `Int64ObserverOption` to `Int64ObservableOption` in `go.opentelemetry.io/otel/metric/instrument`. (#3895)
- Rename `Float64ObserverOption` to `Float64ObservableOption` in `go.opentelemetry.io/otel/metric/instrument`. (#3895)
- The internal logging changes the verbosity level of info to `V(4)`, the verbosity level of debug to `V(8)`. (#3900)
Expand All @@ -45,6 +42,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
Use the added `float64` instrument configuration instead. (#3895)
- The `Int64ObserverConfig` and `NewInt64ObserverConfig` in `go.opentelemetry.io/otel/sdk/metric/instrument`.
Use the added `int64` instrument configuration instead. (#3895)
- Remove `NewNoopMeter` from `go.opentelemetry.io/otel/metric`, use `NewMeterProvider.Meter("")` instead. (#3893)

## [1.15.0-rc.1/0.38.0-rc.1] 2023-03-01

Expand Down
5 changes: 2 additions & 3 deletions internal/global/instruments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/noop"
)

func testFloat64Race(interact func(context.Context, float64, ...attribute.KeyValue), setDelegate func(metric.Meter)) {
Expand All @@ -37,7 +36,7 @@ func testFloat64Race(interact func(context.Context, float64, ...attribute.KeyVal
}
}()

setDelegate(noop.NewMeterProvider().Meter(""))
setDelegate(metric.NewNoopMeterProvider().Meter(""))
close(finish)
}

Expand All @@ -54,7 +53,7 @@ func testInt64Race(interact func(context.Context, int64, ...attribute.KeyValue),
}
}()

setDelegate(noop.NewMeterProvider().Meter(""))
setDelegate(metric.NewNoopMeterProvider().Meter(""))
close(finish)
}

Expand Down
7 changes: 3 additions & 4 deletions internal/global/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/noop"
)

func TestMeterProviderRace(t *testing.T) {
Expand All @@ -42,7 +41,7 @@ func TestMeterProviderRace(t *testing.T) {
}
}()

mp.setDelegate(noop.NewMeterProvider())
mp.setDelegate(metric.NewNoopMeterProvider())
close(finish)
}

Expand Down Expand Up @@ -85,7 +84,7 @@ func TestMeterRace(t *testing.T) {
}()

wg.Wait()
mtr.setDelegate(noop.NewMeterProvider())
mtr.setDelegate(metric.NewNoopMeterProvider())
close(finish)
}

Expand Down Expand Up @@ -114,7 +113,7 @@ func TestUnregisterRace(t *testing.T) {
_ = reg.Unregister()

wg.Wait()
mtr.setDelegate(noop.NewMeterProvider())
mtr.setDelegate(metric.NewNoopMeterProvider())
close(finish)
}

Expand Down
5 changes: 2 additions & 3 deletions internal/global/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestSetMeterProvider(t *testing.T) {
t.Run("First Set() should replace the delegate", func(t *testing.T) {
ResetForTest(t)

SetMeterProvider(noop.NewMeterProvider())
SetMeterProvider(metric.NewNoopMeterProvider())

_, ok := MeterProvider().(*meterProvider)
if ok {
Expand All @@ -166,7 +165,7 @@ func TestSetMeterProvider(t *testing.T) {

mp := MeterProvider()

SetMeterProvider(noop.NewMeterProvider())
SetMeterProvider(metric.NewNoopMeterProvider())

dmp := mp.(*meterProvider)

Expand Down
9 changes: 4 additions & 5 deletions metric/noop/example_test.go → metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package noop_test
package metric_test

import (
"context"
Expand All @@ -23,13 +23,12 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/noop"
)

//nolint:govet // Meter doesn't register for go vet
func ExampleMeter_synchronous() {
// In a library or program this would be provided by otel.GetMeterProvider().
meterProvider := noop.NewMeterProvider()
meterProvider := metric.NewNoopMeterProvider()

workDuration, err := meterProvider.Meter("go.opentelemetry.io/otel/metric#SyncExample").Int64Histogram(
"workDuration",
Expand All @@ -49,7 +48,7 @@ func ExampleMeter_synchronous() {
//nolint:govet // Meter doesn't register for go vet
func ExampleMeter_asynchronous_single() {
// In a library or program this would be provided by otel.GetMeterProvider().
meterProvider := noop.NewMeterProvider()
meterProvider := metric.NewNoopMeterProvider()
meter := meterProvider.Meter("go.opentelemetry.io/otel/metric#AsyncExample")

_, err := meter.Int64ObservableGauge(
Expand Down Expand Up @@ -81,7 +80,7 @@ func ExampleMeter_asynchronous_single() {

//nolint:govet // Meter doesn't register for go vet
func ExampleMeter_asynchronous_multiple() {
meterProvider := noop.NewMeterProvider()
meterProvider := metric.NewNoopMeterProvider()
meter := meterProvider.Meter("go.opentelemetry.io/otel/metric#MultiAsyncExample")

// This is just a sample of memory stats to record from the Memstats
Expand Down
134 changes: 134 additions & 0 deletions metric/noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// 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 metric // import "go.opentelemetry.io/otel/metric"

import (
"context"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/instrument"
)

// NewNoopMeterProvider creates a MeterProvider that does not record any metrics.
func NewNoopMeterProvider() MeterProvider {
return noopMeterProvider{}
}

type noopMeterProvider struct{}

func (noopMeterProvider) Meter(string, ...MeterOption) Meter {
return noopMeter{}
}

type noopMeter struct{}

func (noopMeter) Int64Counter(string, ...instrument.Int64CounterOption) (instrument.Int64Counter, error) {
return nonrecordingSyncInt64Instrument{}, nil
}

func (noopMeter) Int64UpDownCounter(string, ...instrument.Int64UpDownCounterOption) (instrument.Int64UpDownCounter, error) {
return nonrecordingSyncInt64Instrument{}, nil
}

func (noopMeter) Int64Histogram(string, ...instrument.Int64HistogramOption) (instrument.Int64Histogram, error) {
return nonrecordingSyncInt64Instrument{}, nil
}

func (noopMeter) Int64ObservableCounter(string, ...instrument.Int64ObservableCounterOption) (instrument.Int64ObservableCounter, error) {
return nonrecordingAsyncInt64Instrument{}, nil
}

func (noopMeter) Int64ObservableUpDownCounter(string, ...instrument.Int64ObservableUpDownCounterOption) (instrument.Int64ObservableUpDownCounter, error) {
return nonrecordingAsyncInt64Instrument{}, nil
}

func (noopMeter) Int64ObservableGauge(string, ...instrument.Int64ObservableGaugeOption) (instrument.Int64ObservableGauge, error) {
return nonrecordingAsyncInt64Instrument{}, nil
}

func (noopMeter) Float64Counter(string, ...instrument.Float64CounterOption) (instrument.Float64Counter, error) {
return nonrecordingSyncFloat64Instrument{}, nil
}

func (noopMeter) Float64UpDownCounter(string, ...instrument.Float64UpDownCounterOption) (instrument.Float64UpDownCounter, error) {
return nonrecordingSyncFloat64Instrument{}, nil
}

func (noopMeter) Float64Histogram(string, ...instrument.Float64HistogramOption) (instrument.Float64Histogram, error) {
return nonrecordingSyncFloat64Instrument{}, nil
}

func (noopMeter) Float64ObservableCounter(string, ...instrument.Float64ObservableCounterOption) (instrument.Float64ObservableCounter, error) {
return nonrecordingAsyncFloat64Instrument{}, nil
}

func (noopMeter) Float64ObservableUpDownCounter(string, ...instrument.Float64ObservableUpDownCounterOption) (instrument.Float64ObservableUpDownCounter, error) {
return nonrecordingAsyncFloat64Instrument{}, nil
}

func (noopMeter) Float64ObservableGauge(string, ...instrument.Float64ObservableGaugeOption) (instrument.Float64ObservableGauge, error) {
return nonrecordingAsyncFloat64Instrument{}, nil
}

// RegisterCallback creates a register callback that does not record any metrics.
func (noopMeter) RegisterCallback(Callback, ...instrument.Observable) (Registration, error) {
return noopReg{}, nil
}

type noopReg struct{}

func (noopReg) Unregister() error { return nil }

type nonrecordingAsyncFloat64Instrument struct {
instrument.Float64Observable
}

var (
_ instrument.Float64ObservableCounter = nonrecordingAsyncFloat64Instrument{}
_ instrument.Float64ObservableUpDownCounter = nonrecordingAsyncFloat64Instrument{}
_ instrument.Float64ObservableGauge = nonrecordingAsyncFloat64Instrument{}
)

type nonrecordingAsyncInt64Instrument struct {
instrument.Int64Observable
}

var (
_ instrument.Int64ObservableCounter = nonrecordingAsyncInt64Instrument{}
_ instrument.Int64ObservableUpDownCounter = nonrecordingAsyncInt64Instrument{}
_ instrument.Int64ObservableGauge = nonrecordingAsyncInt64Instrument{}
)

type nonrecordingSyncFloat64Instrument struct{}

var (
_ instrument.Float64Counter = nonrecordingSyncFloat64Instrument{}
_ instrument.Float64UpDownCounter = nonrecordingSyncFloat64Instrument{}
_ instrument.Float64Histogram = nonrecordingSyncFloat64Instrument{}
)

func (nonrecordingSyncFloat64Instrument) Add(context.Context, float64, ...attribute.KeyValue) {}
func (nonrecordingSyncFloat64Instrument) Record(context.Context, float64, ...attribute.KeyValue) {}

type nonrecordingSyncInt64Instrument struct{}

var (
_ instrument.Int64Counter = nonrecordingSyncInt64Instrument{}
_ instrument.Int64UpDownCounter = nonrecordingSyncInt64Instrument{}
_ instrument.Int64Histogram = nonrecordingSyncInt64Instrument{}
)

func (nonrecordingSyncInt64Instrument) Add(context.Context, int64, ...attribute.KeyValue) {}
func (nonrecordingSyncInt64Instrument) Record(context.Context, int64, ...attribute.KeyValue) {}
Loading