Skip to content

Commit

Permalink
Remove dependency on metrics packages (#1988)
Browse files Browse the repository at this point in the history
* Declare internal/metric module to version it separately

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Remove dependency on metrics module from soon-to-be-stable modules

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Add PR ID to CHANGELOG

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* rename metric/oteltest to metric/metrictest

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Fix metrictest package name in CHANGELOG

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
  • Loading branch information
Aneurysm9 authored Jun 10, 2021
1 parent 135ac4b commit 7728a52
Show file tree
Hide file tree
Showing 45 changed files with 362 additions and 129 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ updates:
schedule:
day: sunday
interval: weekly
-
package-ecosystem: gomod
directory: /internal/metric
labels:
- dependencies
- go
- "Skip Changelog"
schedule:
day: sunday
interval: weekly
-
package-ecosystem: gomod
directory: /internal/tools
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Rename `NewExporter` to `New` in the `go.opentelemetry.io/otel/exporters/otlp` package. (#1985)
- Rename `NewUnstartedExporter` to `NewUnstarted` in the `go.opentelemetry.io/otel/exporters/otlp` package. (#1985)
- The `go.opentelemetry.io/otel/semconv` package has been moved to `go.opentelemetry.io/otel/semconv/v1.4.0` to allow for multiple [telemetry schema](https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md) versions to be used concurrently. (#1987)
- Metrics test helpers in `go.opentelemetry.io/otel/oteltest` have been moved to `go.opentelemetry.io/otel/metric/metrictest`. (#1988)

### Deprecated

Expand Down
2 changes: 2 additions & 0 deletions bridge/opencensus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions bridge/opentracing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/jaeger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/namedtracer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/opencensus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/otel-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/passthrough/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/prom-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions example/zipkin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otl
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../exporters/otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../exporters/otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions exporters/metric/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrac
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ./otl
replace go.opentelemetry.io/otel/example/passthrough => ../../example/passthrough

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ./otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ replace go.opentelemetry.io/otel/sdk/metric => ../../../sdk/metric
replace go.opentelemetry.io/otel/example/passthrough => ../../../example/passthrough

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ./otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/otlptracegrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ replace go.opentelemetry.io/otel/sdk/metric => ../../../../sdk/metric
replace go.opentelemetry.io/otel/example/passthrough => ../../../../example/passthrough

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/otlptracehttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ replace go.opentelemetry.io/otel/sdk/export/metric => ../../../../sdk/export/met
replace go.opentelemetry.io/otel/sdk/metric => ../../../../sdk/metric

replace go.opentelemetry.io/otel/trace => ../../../../trace

replace go.opentelemetry.io/otel/internal/metric => ../../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/stdout/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../otlp/otlptrace
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../internal/metric
2 changes: 2 additions & 0 deletions exporters/trace/jaeger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrac
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
2 changes: 2 additions & 0 deletions exporters/trace/zipkin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../otlp/otlptrac
replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc => ../../otlp/otlptrace/otlptracegrpc

replace go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp => ../../otlp/otlptrace/otlptracehttp

replace go.opentelemetry.io/otel/internal/metric => ../../../internal/metric
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.15
require (
github.com/google/go-cmp v0.5.6
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel/metric v0.20.0
go.opentelemetry.io/otel/oteltest v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
)
Expand Down Expand Up @@ -44,6 +43,8 @@ replace go.opentelemetry.io/otel/internal/tools => ./internal/tools

replace go.opentelemetry.io/otel/sdk => ./sdk

replace go.opentelemetry.io/otel/internal/metric => ./internal/metric

replace go.opentelemetry.io/otel/metric => ./metric

replace go.opentelemetry.io/otel/oteltest => ./oteltest
Expand Down
19 changes: 0 additions & 19 deletions internal/global/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,9 @@ import (
"testing"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/global"
metricglobal "go.opentelemetry.io/otel/metric/global"
)

func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
// Compare with BenchmarkGlobalInt64CounterAddWithSDK() in
// ../../sdk/metric/benchmark_test.go to see the overhead of the
// global no-op system against a registered SDK.
global.ResetForTest()
ctx := context.Background()
sdk := metricglobal.Meter("test")
labs := []attribute.KeyValue{attribute.String("A", "B")}
cnt := Must(sdk).NewInt64Counter("int64.counter")

b.ResetTimer()

for i := 0; i < b.N; i++ {
cnt.Add(ctx, 1, labs...)
}
}

func BenchmarkStartEndSpanNoSDK(b *testing.B) {
// Compare with BenchmarkStartEndSpan() in
// ../../sdk/trace/benchmark_test.go.
Expand Down
37 changes: 0 additions & 37 deletions internal/global/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"sync"
"sync/atomic"

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
Expand All @@ -28,21 +27,15 @@ type (
tp trace.TracerProvider
}

meterProviderHolder struct {
mp metric.MeterProvider
}

propagatorsHolder struct {
tm propagation.TextMapPropagator
}
)

var (
globalTracer = defaultTracerValue()
globalMeter = defaultMeterValue()
globalPropagators = defaultPropagatorsValue()

delegateMeterOnce sync.Once
delegateTraceOnce sync.Once
delegateTextMapPropagatorOnce sync.Once
)
Expand All @@ -69,28 +62,6 @@ func SetTracerProvider(tp trace.TracerProvider) {
globalTracer.Store(tracerProviderHolder{tp: tp})
}

// MeterProvider is the internal implementation for global.MeterProvider.
func MeterProvider() metric.MeterProvider {
return globalMeter.Load().(meterProviderHolder).mp
}

// SetMeterProvider is the internal implementation for global.SetMeterProvider.
func SetMeterProvider(mp metric.MeterProvider) {
delegateMeterOnce.Do(func() {
current := MeterProvider()

if current == mp {
// Setting the provider to the prior default is nonsense, panic.
// Panic is acceptable because we are likely still early in the
// process lifetime.
panic("invalid MeterProvider, the global instance cannot be reinstalled")
} else if def, ok := current.(*meterProvider); ok {
def.setDelegate(mp)
}
})
globalMeter.Store(meterProviderHolder{mp: mp})
}

// TextMapPropagator is the internal implementation for global.TextMapPropagator.
func TextMapPropagator() propagation.TextMapPropagator {
return globalPropagators.Load().(propagatorsHolder).tm
Expand Down Expand Up @@ -120,12 +91,6 @@ func defaultTracerValue() *atomic.Value {
return v
}

func defaultMeterValue() *atomic.Value {
v := &atomic.Value{}
v.Store(meterProviderHolder{mp: newMeterProvider()})
return v
}

func defaultPropagatorsValue() *atomic.Value {
v := &atomic.Value{}
v.Store(propagatorsHolder{tm: newTextMapPropagator()})
Expand All @@ -135,9 +100,7 @@ func defaultPropagatorsValue() *atomic.Value {
// ResetForTest restores the initial global state, for testing purposes.
func ResetForTest() {
globalTracer = defaultTracerValue()
globalMeter = defaultMeterValue()
globalPropagators = defaultPropagatorsValue()
delegateMeterOnce = sync.Once{}
delegateTraceOnce = sync.Once{}
delegateTextMapPropagatorOnce = sync.Once{}
}
3 changes: 0 additions & 3 deletions internal/global/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ func TestResetsOfGlobalsPanic(t *testing.T) {
"SetTracerProvider": func() {
global.SetTracerProvider(global.TracerProvider())
},
"SetMeterProvider": func() {
global.SetMeterProvider(global.MeterProvider())
},
}

for name, test := range tests {
Expand Down
41 changes: 41 additions & 0 deletions internal/metric/global/benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 global_test

import (
"context"
"testing"

"go.opentelemetry.io/otel/attribute"
internalglobal "go.opentelemetry.io/otel/internal/metric/global"
metricglobal "go.opentelemetry.io/otel/metric/global"
)

func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) {
// Compare with BenchmarkGlobalInt64CounterAddWithSDK() in
// ../../sdk/metric/benchmark_test.go to see the overhead of the
// global no-op system against a registered SDK.
internalglobal.ResetForTest()
ctx := context.Background()
sdk := metricglobal.Meter("test")
labs := []attribute.KeyValue{attribute.String("A", "B")}
cnt := Must(sdk).NewInt64Counter("int64.counter")

b.ResetTimer()

for i := 0; i < b.N; i++ {
cnt.Add(ctx, 1, labs...)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"os"
"testing"

"go.opentelemetry.io/otel/internal/global"
ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/internal/metric/global"
)

// Ensure struct alignment prior to running tests.
Expand Down
File renamed without changes.
Loading

0 comments on commit 7728a52

Please sign in to comment.