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

Move metric no-op implementation to metric package #2866

Merged
merged 5 commits into from Apr 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -32,6 +32,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
The method included in the renamed interface also changed from `LabelFilterFor` to `AttributeFilterFor`. (#2790)
- The `Metadata.Labels` method from the `go.opentelemetry.io/otel/sdk/metric/export` package is renamed to `Metadata.Attributes`.
Consequentially, the `Record` type from the same package also has had the embedded method renamed. (#2790)
- Move metric no-op implementation form `nonrecording` to `metric` package. (#2866)

### Deprecated

Expand Down
8 changes: 4 additions & 4 deletions metric/example_test.go
Expand Up @@ -20,16 +20,16 @@ import (
"runtime"
"time"

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/nonrecording"
"go.opentelemetry.io/otel/metric/unit"
)

//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 := nonrecording.NewNoopMeterProvider()
meterProvider := metric.NewNoopMeterProvider()

workDuration, err := meterProvider.Meter("go.opentelemetry.io/otel/metric#SyncExample").SyncInt64().Histogram(
"workDuration",
Expand All @@ -50,7 +50,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 := nonrecording.NewNoopMeterProvider()
meterProvider := metric.NewNoopMeterProvider()
meter := meterProvider.Meter("go.opentelemetry.io/otel/metric#AsyncExample")

memoryUsage, err := meter.AsyncInt64().Gauge(
Expand Down Expand Up @@ -79,7 +79,7 @@ func ExampleMeter_asynchronous_single() {

//nolint:govet // Meter doesn't register for go vet
func ExampleMeter_asynchronous_multiple() {
meterProvider := nonrecording.NewNoopMeterProvider()
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
5 changes: 2 additions & 3 deletions metric/internal/global/instruments_test.go
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/nonrecording"
)

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(nonrecording.NewNoopMeter())
setDelegate(metric.NewNoopMeter())
close(finish)
}

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

setDelegate(nonrecording.NewNoopMeter())
setDelegate(metric.NewNoopMeter())
close(finish)
}

Expand Down
5 changes: 2 additions & 3 deletions metric/internal/global/meter_test.go
Expand Up @@ -27,7 +27,6 @@ import (
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/asyncfloat64"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/nonrecording"
)

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

mp.setDelegate(nonrecording.NewNoopMeterProvider())
mp.setDelegate(metric.NewNoopMeterProvider())
close(finish)

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

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

Expand Down
5 changes: 2 additions & 3 deletions metric/internal/global/state_test.go
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/nonrecording"
)

func resetGlobalMeterProvider() {
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestSetMeterProvider(t *testing.T) {
t.Run("First Set() should replace the delegate", func(t *testing.T) {
resetGlobalMeterProvider()

SetMeterProvider(nonrecording.NewNoopMeterProvider())
SetMeterProvider(metric.NewNoopMeterProvider())

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

mp := MeterProvider()

SetMeterProvider(nonrecording.NewNoopMeterProvider())
SetMeterProvider(metric.NewNoopMeterProvider())

dmp := mp.(*meterProvider)

Expand Down
64 changes: 0 additions & 64 deletions metric/nonrecording/meter.go

This file was deleted.

69 changes: 56 additions & 13 deletions metric/nonrecording/instruments.go → metric/noop.go
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package nonrecording // import "go.opentelemetry.io/otel/metric/nonrecording"
package metric // import "go.opentelemetry.io/otel/metric"

import (
"context"
Expand All @@ -25,6 +25,49 @@ import (
"go.opentelemetry.io/otel/metric/instrument/syncint64"
)

// 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{}
}

// NewNoopMeter creates a Meter that does not record any metrics.
func NewNoopMeter() Meter {
return noopMeter{}
}

type noopMeter struct{}

// AsyncInt64 creates a instrument that does not record any metrics.
func (noopMeter) AsyncInt64() asyncint64.InstrumentProvider {
return nonrecordingAsyncInt64Instrument{}
}

// AsyncFloat64 creates a instrument that does not record any metrics.
func (noopMeter) AsyncFloat64() asyncfloat64.InstrumentProvider {
return nonrecordingAsyncFloat64Instrument{}
}

// SyncInt64 creates a instrument that does not record any metrics.
func (noopMeter) SyncInt64() syncint64.InstrumentProvider {
return nonrecordingSyncInt64Instrument{}
}

// SyncFloat64 creates a instrument that does not record any metrics.
func (noopMeter) SyncFloat64() syncfloat64.InstrumentProvider {
return nonrecordingSyncFloat64Instrument{}
}

// RegisterCallback creates a register callback that does not record any metrics.
func (noopMeter) RegisterCallback([]instrument.Asynchronous, func(context.Context)) error {
return nil
}

type nonrecordingAsyncFloat64Instrument struct {
instrument.Asynchronous
}
Expand All @@ -36,15 +79,15 @@ var (
_ asyncfloat64.Gauge = nonrecordingAsyncFloat64Instrument{}
)

func (n nonrecordingAsyncFloat64Instrument) Counter(name string, opts ...instrument.Option) (asyncfloat64.Counter, error) {
func (n nonrecordingAsyncFloat64Instrument) Counter(string, ...instrument.Option) (asyncfloat64.Counter, error) {
return n, nil
}

func (n nonrecordingAsyncFloat64Instrument) UpDownCounter(name string, opts ...instrument.Option) (asyncfloat64.UpDownCounter, error) {
func (n nonrecordingAsyncFloat64Instrument) UpDownCounter(string, ...instrument.Option) (asyncfloat64.UpDownCounter, error) {
return n, nil
}

func (n nonrecordingAsyncFloat64Instrument) Gauge(name string, opts ...instrument.Option) (asyncfloat64.Gauge, error) {
func (n nonrecordingAsyncFloat64Instrument) Gauge(string, ...instrument.Option) (asyncfloat64.Gauge, error) {
return n, nil
}

Expand All @@ -63,15 +106,15 @@ var (
_ asyncint64.Gauge = nonrecordingAsyncInt64Instrument{}
)

func (n nonrecordingAsyncInt64Instrument) Counter(name string, opts ...instrument.Option) (asyncint64.Counter, error) {
func (n nonrecordingAsyncInt64Instrument) Counter(string, ...instrument.Option) (asyncint64.Counter, error) {
return n, nil
}

func (n nonrecordingAsyncInt64Instrument) UpDownCounter(name string, opts ...instrument.Option) (asyncint64.UpDownCounter, error) {
func (n nonrecordingAsyncInt64Instrument) UpDownCounter(string, ...instrument.Option) (asyncint64.UpDownCounter, error) {
return n, nil
}

func (n nonrecordingAsyncInt64Instrument) Gauge(name string, opts ...instrument.Option) (asyncint64.Gauge, error) {
func (n nonrecordingAsyncInt64Instrument) Gauge(string, ...instrument.Option) (asyncint64.Gauge, error) {
return n, nil
}

Expand All @@ -89,15 +132,15 @@ var (
_ syncfloat64.Histogram = nonrecordingSyncFloat64Instrument{}
)

func (n nonrecordingSyncFloat64Instrument) Counter(name string, opts ...instrument.Option) (syncfloat64.Counter, error) {
func (n nonrecordingSyncFloat64Instrument) Counter(string, ...instrument.Option) (syncfloat64.Counter, error) {
return n, nil
}

func (n nonrecordingSyncFloat64Instrument) UpDownCounter(name string, opts ...instrument.Option) (syncfloat64.UpDownCounter, error) {
func (n nonrecordingSyncFloat64Instrument) UpDownCounter(string, ...instrument.Option) (syncfloat64.UpDownCounter, error) {
return n, nil
}

func (n nonrecordingSyncFloat64Instrument) Histogram(name string, opts ...instrument.Option) (syncfloat64.Histogram, error) {
func (n nonrecordingSyncFloat64Instrument) Histogram(string, ...instrument.Option) (syncfloat64.Histogram, error) {
return n, nil
}

Expand All @@ -120,15 +163,15 @@ var (
_ syncint64.Histogram = nonrecordingSyncInt64Instrument{}
)

func (n nonrecordingSyncInt64Instrument) Counter(name string, opts ...instrument.Option) (syncint64.Counter, error) {
func (n nonrecordingSyncInt64Instrument) Counter(string, ...instrument.Option) (syncint64.Counter, error) {
return n, nil
}

func (n nonrecordingSyncInt64Instrument) UpDownCounter(name string, opts ...instrument.Option) (syncint64.UpDownCounter, error) {
func (n nonrecordingSyncInt64Instrument) UpDownCounter(string, ...instrument.Option) (syncint64.UpDownCounter, error) {
return n, nil
}

func (n nonrecordingSyncInt64Instrument) Histogram(name string, opts ...instrument.Option) (syncint64.Histogram, error) {
func (n nonrecordingSyncInt64Instrument) Histogram(string, ...instrument.Option) (syncint64.Histogram, error) {
return n, nil
}

Expand Down