From ceab855829ea16b87d89f6710e704af5319fafe1 Mon Sep 17 00:00:00 2001 From: Anthony J Mirabella Date: Wed, 9 Jun 2021 16:42:21 -0400 Subject: [PATCH 1/5] Declare internal/metric module to version it separately Signed-off-by: Anthony J Mirabella --- bridge/opencensus/go.mod | 2 + bridge/opentracing/go.mod | 2 + example/jaeger/go.mod | 2 + example/namedtracer/go.mod | 2 + example/opencensus/go.mod | 2 + example/otel-collector/go.mod | 2 + example/passthrough/go.mod | 2 + example/prom-collector/go.mod | 2 + example/prometheus/go.mod | 2 + example/zipkin/go.mod | 2 + exporters/metric/prometheus/go.mod | 2 + exporters/otlp/go.mod | 2 + exporters/otlp/otlptrace/go.mod | 2 + exporters/otlp/otlptrace/otlptracegrpc/go.mod | 2 + exporters/otlp/otlptrace/otlptracehttp/go.mod | 2 + exporters/stdout/go.mod | 2 + exporters/trace/jaeger/go.mod | 2 + exporters/trace/zipkin/go.mod | 2 + go.mod | 2 + internal/metric/go.mod | 62 +++++++++++++++++++ internal/tools/go.mod | 2 + metric/go.mod | 2 + oteltest/go.mod | 3 + sdk/export/metric/go.mod | 2 + sdk/go.mod | 2 + sdk/metric/go.mod | 3 + trace/go.mod | 2 + 27 files changed, 116 insertions(+) create mode 100644 internal/metric/go.mod diff --git a/bridge/opencensus/go.mod b/bridge/opencensus/go.mod index a788bbfa996..5852214116f 100644 --- a/bridge/opencensus/go.mod +++ b/bridge/opencensus/go.mod @@ -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 diff --git a/bridge/opentracing/go.mod b/bridge/opentracing/go.mod index 70304940630..1e3e825a70c 100644 --- a/bridge/opentracing/go.mod +++ b/bridge/opentracing/go.mod @@ -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 diff --git a/example/jaeger/go.mod b/example/jaeger/go.mod index 51b95ae2927..ff9d694e0f5 100644 --- a/example/jaeger/go.mod +++ b/example/jaeger/go.mod @@ -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 diff --git a/example/namedtracer/go.mod b/example/namedtracer/go.mod index 9de96a9e08f..35245f151de 100644 --- a/example/namedtracer/go.mod +++ b/example/namedtracer/go.mod @@ -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 diff --git a/example/opencensus/go.mod b/example/opencensus/go.mod index 6d24147ac63..c3193709d52 100644 --- a/example/opencensus/go.mod +++ b/example/opencensus/go.mod @@ -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 diff --git a/example/otel-collector/go.mod b/example/otel-collector/go.mod index c992f277231..f8f54302e9e 100644 --- a/example/otel-collector/go.mod +++ b/example/otel-collector/go.mod @@ -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 diff --git a/example/passthrough/go.mod b/example/passthrough/go.mod index af55e50a41f..7c6da39c3b3 100644 --- a/example/passthrough/go.mod +++ b/example/passthrough/go.mod @@ -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 diff --git a/example/prom-collector/go.mod b/example/prom-collector/go.mod index bf47db5d4bb..717c031a877 100644 --- a/example/prom-collector/go.mod +++ b/example/prom-collector/go.mod @@ -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 diff --git a/example/prometheus/go.mod b/example/prometheus/go.mod index 7fcf5ccc33d..8c8809dbd91 100644 --- a/example/prometheus/go.mod +++ b/example/prometheus/go.mod @@ -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 diff --git a/example/zipkin/go.mod b/example/zipkin/go.mod index bb8f45d8062..c57da075adf 100644 --- a/example/zipkin/go.mod +++ b/example/zipkin/go.mod @@ -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 diff --git a/exporters/metric/prometheus/go.mod b/exporters/metric/prometheus/go.mod index 99fbb49e5ae..78802ce873f 100644 --- a/exporters/metric/prometheus/go.mod +++ b/exporters/metric/prometheus/go.mod @@ -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 diff --git a/exporters/otlp/go.mod b/exporters/otlp/go.mod index d60ec7d7eba..acdf29f12d1 100644 --- a/exporters/otlp/go.mod +++ b/exporters/otlp/go.mod @@ -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 diff --git a/exporters/otlp/otlptrace/go.mod b/exporters/otlp/otlptrace/go.mod index 5a0e2db6f0a..64c4366c853 100644 --- a/exporters/otlp/otlptrace/go.mod +++ b/exporters/otlp/otlptrace/go.mod @@ -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 diff --git a/exporters/otlp/otlptrace/otlptracegrpc/go.mod b/exporters/otlp/otlptrace/otlptracegrpc/go.mod index 2fd6143b7c7..9a3b5cd8c08 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/go.mod +++ b/exporters/otlp/otlptrace/otlptracegrpc/go.mod @@ -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 diff --git a/exporters/otlp/otlptrace/otlptracehttp/go.mod b/exporters/otlp/otlptrace/otlptracehttp/go.mod index c5a1c4a5e30..0d89b189d98 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/go.mod +++ b/exporters/otlp/otlptrace/otlptracehttp/go.mod @@ -62,3 +62,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 diff --git a/exporters/stdout/go.mod b/exporters/stdout/go.mod index 5b927d14c82..94fef1a7567 100644 --- a/exporters/stdout/go.mod +++ b/exporters/stdout/go.mod @@ -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 diff --git a/exporters/trace/jaeger/go.mod b/exporters/trace/jaeger/go.mod index 8fd0f8bc634..045826d53eb 100644 --- a/exporters/trace/jaeger/go.mod +++ b/exporters/trace/jaeger/go.mod @@ -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 diff --git a/exporters/trace/zipkin/go.mod b/exporters/trace/zipkin/go.mod index 7d084e68546..921db6c4947 100644 --- a/exporters/trace/zipkin/go.mod +++ b/exporters/trace/zipkin/go.mod @@ -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 diff --git a/go.mod b/go.mod index 3b37117fb3e..ad2b220295b 100644 --- a/go.mod +++ b/go.mod @@ -44,6 +44,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 diff --git a/internal/metric/go.mod b/internal/metric/go.mod new file mode 100644 index 00000000000..5ce45465fd0 --- /dev/null +++ b/internal/metric/go.mod @@ -0,0 +1,62 @@ +module go.opentelemetry.io/otel/internal/metric + +go 1.15 + +require ( + go.opentelemetry.io/otel v0.20.0 + go.opentelemetry.io/otel/metric v0.20.0 +) + +replace go.opentelemetry.io/otel => ../.. + +replace go.opentelemetry.io/otel/metric => ../../metric + +replace go.opentelemetry.io/otel/internal/metric => ./ + +replace go.opentelemetry.io/otel/bridge/opencensus => ../../bridge/opencensus + +replace go.opentelemetry.io/otel/bridge/opentracing => ../../bridge/opentracing + +replace go.opentelemetry.io/otel/example/jaeger => ../../example/jaeger + +replace go.opentelemetry.io/otel/example/namedtracer => ../../example/namedtracer + +replace go.opentelemetry.io/otel/example/opencensus => ../../example/opencensus + +replace go.opentelemetry.io/otel/example/otel-collector => ../../example/otel-collector + +replace go.opentelemetry.io/otel/example/passthrough => ../../example/passthrough + +replace go.opentelemetry.io/otel/example/prom-collector => ../../example/prom-collector + +replace go.opentelemetry.io/otel/example/prometheus => ../../example/prometheus + +replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin + +replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../../exporters/metric/prometheus + +replace go.opentelemetry.io/otel/exporters/otlp => ../../exporters/otlp + +replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../exporters/otlp/otlptrace + +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/exporters/stdout => ../../exporters/stdout + +replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../exporters/trace/jaeger + +replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace/zipkin + +replace go.opentelemetry.io/otel/internal/tools => ../tools + +replace go.opentelemetry.io/otel/oteltest => ../../oteltest + +replace go.opentelemetry.io/otel/sdk => ../../sdk + +replace go.opentelemetry.io/otel/sdk/export/metric => ../../sdk/export/metric + +replace go.opentelemetry.io/otel/sdk/metric => ../../sdk/metric + +replace go.opentelemetry.io/otel/trace => ../../trace diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 5e30ea68162..a2850a14b8c 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -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 => ../metric diff --git a/metric/go.mod b/metric/go.mod index 82ac8852048..d8c6a40a939 100644 --- a/metric/go.mod +++ b/metric/go.mod @@ -60,3 +60,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../exporters/otlp/o 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 diff --git a/oteltest/go.mod b/oteltest/go.mod index f3ac5942a18..65f1ffe1c3c 100644 --- a/oteltest/go.mod +++ b/oteltest/go.mod @@ -36,6 +36,8 @@ replace go.opentelemetry.io/otel/internal/tools => ../internal/tools replace go.opentelemetry.io/otel/metric => ../metric +replace go.opentelemetry.io/otel/internal/metric => ../internal/metric + replace go.opentelemetry.io/otel/oteltest => ./ replace go.opentelemetry.io/otel/sdk => ../sdk @@ -49,6 +51,7 @@ replace go.opentelemetry.io/otel/trace => ../trace require ( github.com/stretchr/testify v1.7.0 go.opentelemetry.io/otel v0.20.0 + go.opentelemetry.io/otel/internal/metric v0.20.0 go.opentelemetry.io/otel/metric v0.20.0 go.opentelemetry.io/otel/trace v0.20.0 ) diff --git a/sdk/export/metric/go.mod b/sdk/export/metric/go.mod index f1b6b0ec10b..422805c7af7 100644 --- a/sdk/export/metric/go.mod +++ b/sdk/export/metric/go.mod @@ -60,3 +60,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../../../exporters/ 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 diff --git a/sdk/go.mod b/sdk/go.mod index 79cbbf0f08d..42c0abfcbf1 100644 --- a/sdk/go.mod +++ b/sdk/go.mod @@ -61,3 +61,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../exporters/otlp/o 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 diff --git a/sdk/metric/go.mod b/sdk/metric/go.mod index 488eb2bdb5c..e2e908ccf2a 100644 --- a/sdk/metric/go.mod +++ b/sdk/metric/go.mod @@ -50,6 +50,7 @@ require ( github.com/benbjohnson/clock v1.1.0 // do not upgrade to v1.1.x because it would require Go >= 1.15 github.com/stretchr/testify v1.7.0 go.opentelemetry.io/otel v0.20.0 + go.opentelemetry.io/otel/internal/metric v0.20.0 go.opentelemetry.io/otel/metric v0.20.0 go.opentelemetry.io/otel/sdk v0.20.0 go.opentelemetry.io/otel/sdk/export/metric v0.20.0 @@ -62,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 diff --git a/trace/go.mod b/trace/go.mod index ced132c7b14..01069d8ca8a 100644 --- a/trace/go.mod +++ b/trace/go.mod @@ -59,3 +59,5 @@ replace go.opentelemetry.io/otel/exporters/otlp/otlptrace => ../exporters/otlp/o 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 From b3edfd5b58a9ec015c9a68812aef65d53c107ca4 Mon Sep 17 00:00:00 2001 From: Anthony J Mirabella Date: Wed, 9 Jun 2021 17:27:19 -0400 Subject: [PATCH 2/5] Remove dependency on metrics module from soon-to-be-stable modules Signed-off-by: Anthony J Mirabella --- .github/dependabot.yml | 10 +++ CHANGELOG.md | 1 + go.mod | 1 - internal/global/benchmark_test.go | 19 ------ internal/global/state.go | 37 ----------- internal/global/state_test.go | 3 - internal/metric/global/benchmark_test.go | 41 ++++++++++++ internal/{ => metric}/global/internal_test.go | 2 +- internal/{ => metric}/global/meter.go | 0 internal/{ => metric}/global/meter_test.go | 4 +- internal/metric/global/metric.go | 66 +++++++++++++++++++ internal/{ => metric}/global/registry_test.go | 0 internal/metric/global/state_test.go | 45 +++++++++++++ internal/metric/go.mod | 1 + internal/metric/go.sum | 15 +++++ metric/global/metric.go | 2 +- metric/go.mod | 2 +- metric/metric_test.go | 2 +- .../oteltest}/alignment_test.go | 0 {oteltest => metric/oteltest}/meter.go | 2 +- metric/registry/registry_test.go | 2 +- oteltest/go.mod | 2 - 22 files changed, 187 insertions(+), 70 deletions(-) create mode 100644 internal/metric/global/benchmark_test.go rename internal/{ => metric}/global/internal_test.go (95%) rename internal/{ => metric}/global/meter.go (100%) rename internal/{ => metric}/global/meter_test.go (98%) create mode 100644 internal/metric/global/metric.go rename internal/{ => metric}/global/registry_test.go (100%) create mode 100644 internal/metric/global/state_test.go create mode 100644 internal/metric/go.sum rename {oteltest => metric/oteltest}/alignment_test.go (100%) rename {oteltest => metric/oteltest}/meter.go (98%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 95816ded71c..de7125cd5bf 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index ae0eccd125e..329abac7865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The `Get` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931) - The `Insert` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a pair of `string`s instead of an `attribute.KeyValue` type. (#1931) - The `Delete` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931) +- Metrics test helpers in `go.opentelemetry.io/otel/oteltest` have been moved to `go.opentelemetry.io/otel/metric/oteltest`. (#TBD) ### Deprecated diff --git a/go.mod b/go.mod index ad2b220295b..9dad82a25a4 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/internal/global/benchmark_test.go b/internal/global/benchmark_test.go index ea06b7dd87e..ef37194f4c6 100644 --- a/internal/global/benchmark_test.go +++ b/internal/global/benchmark_test.go @@ -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. diff --git a/internal/global/state.go b/internal/global/state.go index f3bf0035100..c553455761a 100644 --- a/internal/global/state.go +++ b/internal/global/state.go @@ -18,7 +18,6 @@ import ( "sync" "sync/atomic" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" ) @@ -28,10 +27,6 @@ type ( tp trace.TracerProvider } - meterProviderHolder struct { - mp metric.MeterProvider - } - propagatorsHolder struct { tm propagation.TextMapPropagator } @@ -39,10 +34,8 @@ type ( var ( globalTracer = defaultTracerValue() - globalMeter = defaultMeterValue() globalPropagators = defaultPropagatorsValue() - delegateMeterOnce sync.Once delegateTraceOnce sync.Once delegateTextMapPropagatorOnce sync.Once ) @@ -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 @@ -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()}) @@ -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{} } diff --git a/internal/global/state_test.go b/internal/global/state_test.go index cf5ce254370..9e812083a13 100644 --- a/internal/global/state_test.go +++ b/internal/global/state_test.go @@ -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 { diff --git a/internal/metric/global/benchmark_test.go b/internal/metric/global/benchmark_test.go new file mode 100644 index 00000000000..05cab62d2dc --- /dev/null +++ b/internal/metric/global/benchmark_test.go @@ -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...) + } +} diff --git a/internal/global/internal_test.go b/internal/metric/global/internal_test.go similarity index 95% rename from internal/global/internal_test.go rename to internal/metric/global/internal_test.go index ff332feae02..44e1904aefe 100644 --- a/internal/global/internal_test.go +++ b/internal/metric/global/internal_test.go @@ -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. diff --git a/internal/global/meter.go b/internal/metric/global/meter.go similarity index 100% rename from internal/global/meter.go rename to internal/metric/global/meter.go diff --git a/internal/global/meter_test.go b/internal/metric/global/meter_test.go similarity index 98% rename from internal/global/meter_test.go rename to internal/metric/global/meter_test.go index 830ef074c8a..9ff458a2682 100644 --- a/internal/global/meter_test.go +++ b/internal/metric/global/meter_test.go @@ -22,11 +22,11 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/internal/global" + "go.opentelemetry.io/otel/internal/metric/global" "go.opentelemetry.io/otel/metric" metricglobal "go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/number" - "go.opentelemetry.io/otel/oteltest" + "go.opentelemetry.io/otel/metric/oteltest" ) var Must = metric.Must diff --git a/internal/metric/global/metric.go b/internal/metric/global/metric.go new file mode 100644 index 00000000000..be95ff61449 --- /dev/null +++ b/internal/metric/global/metric.go @@ -0,0 +1,66 @@ +// 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 + +import ( + "sync" + "sync/atomic" + + "go.opentelemetry.io/otel/metric" +) + +type meterProviderHolder struct { + mp metric.MeterProvider +} + +var ( + globalMeter = defaultMeterValue() + + delegateMeterOnce sync.Once +) + +// 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}) +} + +func defaultMeterValue() *atomic.Value { + v := &atomic.Value{} + v.Store(meterProviderHolder{mp: newMeterProvider()}) + return v +} + +// ResetForTest restores the initial global state, for testing purposes. +func ResetForTest() { + globalMeter = defaultMeterValue() + delegateMeterOnce = sync.Once{} +} diff --git a/internal/global/registry_test.go b/internal/metric/global/registry_test.go similarity index 100% rename from internal/global/registry_test.go rename to internal/metric/global/registry_test.go diff --git a/internal/metric/global/state_test.go b/internal/metric/global/state_test.go new file mode 100644 index 00000000000..526eac7fa69 --- /dev/null +++ b/internal/metric/global/state_test.go @@ -0,0 +1,45 @@ +// 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 ( + "testing" + + internalglobal "go.opentelemetry.io/otel/internal/metric/global" + metricglobal "go.opentelemetry.io/otel/metric/global" +) + +func TestResetsOfGlobalsPanic(t *testing.T) { + internalglobal.ResetForTest() + tests := map[string]func(){ + "SetMeterProvider": func() { + metricglobal.SetMeterProvider(metricglobal.GetMeterProvider()) + }, + } + + for name, test := range tests { + shouldPanic(t, name, test) + } +} + +func shouldPanic(t *testing.T, name string, f func()) { + defer func() { + if r := recover(); r == nil { + t.Errorf("calling %s with default global did not panic", name) + } + }() + + f() +} diff --git a/internal/metric/go.mod b/internal/metric/go.mod index 5ce45465fd0..a605bfe85ab 100644 --- a/internal/metric/go.mod +++ b/internal/metric/go.mod @@ -3,6 +3,7 @@ module go.opentelemetry.io/otel/internal/metric go 1.15 require ( + github.com/stretchr/testify v1.7.0 go.opentelemetry.io/otel v0.20.0 go.opentelemetry.io/otel/metric v0.20.0 ) diff --git a/internal/metric/go.sum b/internal/metric/go.sum new file mode 100644 index 00000000000..f212493d586 --- /dev/null +++ b/internal/metric/go.sum @@ -0,0 +1,15 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/metric/global/metric.go b/metric/global/metric.go index 8d16d34d486..14ba862002a 100644 --- a/metric/global/metric.go +++ b/metric/global/metric.go @@ -15,7 +15,7 @@ package global // import "go.opentelemetry.io/otel/metric/global" import ( - "go.opentelemetry.io/otel/internal/global" + "go.opentelemetry.io/otel/internal/metric/global" "go.opentelemetry.io/otel/metric" ) diff --git a/metric/go.mod b/metric/go.mod index d8c6a40a939..096fd460914 100644 --- a/metric/go.mod +++ b/metric/go.mod @@ -50,7 +50,7 @@ require ( github.com/google/go-cmp v0.5.6 github.com/stretchr/testify v1.7.0 go.opentelemetry.io/otel v0.20.0 - go.opentelemetry.io/otel/oteltest v0.20.0 + go.opentelemetry.io/otel/internal/metric v0.20.0 ) replace go.opentelemetry.io/otel/example/passthrough => ../example/passthrough diff --git a/metric/metric_test.go b/metric/metric_test.go index 899cc273714..b7e528e669d 100644 --- a/metric/metric_test.go +++ b/metric/metric_test.go @@ -22,8 +22,8 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/oteltest" "go.opentelemetry.io/otel/metric/unit" - "go.opentelemetry.io/otel/oteltest" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" diff --git a/oteltest/alignment_test.go b/metric/oteltest/alignment_test.go similarity index 100% rename from oteltest/alignment_test.go rename to metric/oteltest/alignment_test.go diff --git a/oteltest/meter.go b/metric/oteltest/meter.go similarity index 98% rename from oteltest/meter.go rename to metric/oteltest/meter.go index bef72d23791..9026e3d1221 100644 --- a/oteltest/meter.go +++ b/metric/oteltest/meter.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package oteltest // import "go.opentelemetry.io/otel/oteltest" +package oteltest // import "go.opentelemetry.io/otel/metric/oteltest" import ( "context" diff --git a/metric/registry/registry_test.go b/metric/registry/registry_test.go index ed86ba739d0..2711f56999d 100644 --- a/metric/registry/registry_test.go +++ b/metric/registry/registry_test.go @@ -22,8 +22,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/oteltest" "go.opentelemetry.io/otel/metric/registry" - "go.opentelemetry.io/otel/oteltest" ) type ( diff --git a/oteltest/go.mod b/oteltest/go.mod index 65f1ffe1c3c..c6e2342f678 100644 --- a/oteltest/go.mod +++ b/oteltest/go.mod @@ -51,8 +51,6 @@ replace go.opentelemetry.io/otel/trace => ../trace require ( github.com/stretchr/testify v1.7.0 go.opentelemetry.io/otel v0.20.0 - go.opentelemetry.io/otel/internal/metric v0.20.0 - go.opentelemetry.io/otel/metric v0.20.0 go.opentelemetry.io/otel/trace v0.20.0 ) From 79f8dbb675f08311a9ec566ebf86cc60ac10cc12 Mon Sep 17 00:00:00 2001 From: Anthony J Mirabella Date: Thu, 10 Jun 2021 11:33:52 -0400 Subject: [PATCH 3/5] Add PR ID to CHANGELOG Signed-off-by: Anthony J Mirabella --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 329abac7865..8afefa53418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The `Get` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931) - The `Insert` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a pair of `string`s instead of an `attribute.KeyValue` type. (#1931) - The `Delete` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931) -- Metrics test helpers in `go.opentelemetry.io/otel/oteltest` have been moved to `go.opentelemetry.io/otel/metric/oteltest`. (#TBD) +- Metrics test helpers in `go.opentelemetry.io/otel/oteltest` have been moved to `go.opentelemetry.io/otel/metric/oteltest`. (#1988) ### Deprecated From 48a75246c5771ec45f408cea3dab1abd64f18c31 Mon Sep 17 00:00:00 2001 From: Anthony J Mirabella Date: Thu, 10 Jun 2021 11:56:32 -0400 Subject: [PATCH 4/5] rename metric/oteltest to metric/metrictest Signed-off-by: Anthony J Mirabella --- internal/metric/global/meter_test.go | 54 ++++++++--------- metric/metric_test.go | 60 +++++++++---------- .../alignment_test.go | 2 +- metric/{oteltest => metrictest}/meter.go | 2 +- metric/registry/registry_test.go | 10 ++-- 5 files changed, 64 insertions(+), 64 deletions(-) rename metric/{oteltest => metrictest}/alignment_test.go (98%) rename metric/{oteltest => metrictest}/meter.go (98%) diff --git a/internal/metric/global/meter_test.go b/internal/metric/global/meter_test.go index 9ff458a2682..be3d63b717a 100644 --- a/internal/metric/global/meter_test.go +++ b/internal/metric/global/meter_test.go @@ -25,8 +25,8 @@ import ( "go.opentelemetry.io/otel/internal/metric/global" "go.opentelemetry.io/otel/metric" metricglobal "go.opentelemetry.io/otel/metric/global" + "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/number" - "go.opentelemetry.io/otel/metric/oteltest" ) var Must = metric.Must @@ -66,7 +66,7 @@ func TestDirect(t *testing.T) { second.Record(ctx, 1, labels3...) second.Record(ctx, 2, labels3...) - mock, provider := oteltest.NewMeterProvider() + mock, provider := metrictest.NewMeterProvider() metricglobal.SetMeterProvider(provider) counter.Add(ctx, 1, labels1...) @@ -75,56 +75,56 @@ func TestDirect(t *testing.T) { mock.RunAsyncInstruments() - measurements := oteltest.AsStructs(mock.MeasurementBatches) + measurements := metrictest.AsStructs(mock.MeasurementBatches) require.EqualValues(t, - []oteltest.Measured{ + []metrictest.Measured{ { Name: "test.counter", InstrumentationName: "test1", InstrumentationVersion: "semver:v1.0.0", - Labels: oteltest.LabelsToMap(labels1...), + Labels: metrictest.LabelsToMap(labels1...), Number: asInt(1), }, { Name: "test.valuerecorder", InstrumentationName: "test1", InstrumentationVersion: "semver:v1.0.0", - Labels: oteltest.LabelsToMap(labels1...), + Labels: metrictest.LabelsToMap(labels1...), Number: asFloat(3), }, { Name: "test.second", InstrumentationName: "test2", - Labels: oteltest.LabelsToMap(labels3...), + Labels: metrictest.LabelsToMap(labels3...), Number: asFloat(3), }, { Name: "test.valueobserver.float", InstrumentationName: "test1", InstrumentationVersion: "semver:v1.0.0", - Labels: oteltest.LabelsToMap(labels1...), + Labels: metrictest.LabelsToMap(labels1...), Number: asFloat(1), }, { Name: "test.valueobserver.float", InstrumentationName: "test1", InstrumentationVersion: "semver:v1.0.0", - Labels: oteltest.LabelsToMap(labels2...), + Labels: metrictest.LabelsToMap(labels2...), Number: asFloat(2), }, { Name: "test.valueobserver.int", InstrumentationName: "test1", InstrumentationVersion: "semver:v1.0.0", - Labels: oteltest.LabelsToMap(labels1...), + Labels: metrictest.LabelsToMap(labels1...), Number: asInt(1), }, { Name: "test.valueobserver.int", InstrumentationName: "test1", InstrumentationVersion: "semver:v1.0.0", - Labels: oteltest.LabelsToMap(labels2...), + Labels: metrictest.LabelsToMap(labels2...), Number: asInt(2), }, }, @@ -151,28 +151,28 @@ func TestBound(t *testing.T) { boundM.Record(ctx, 1) boundM.Record(ctx, 2) - mock, provider := oteltest.NewMeterProvider() + mock, provider := metrictest.NewMeterProvider() metricglobal.SetMeterProvider(provider) boundC.Add(ctx, 1) boundM.Record(ctx, 3) require.EqualValues(t, - []oteltest.Measured{ + []metrictest.Measured{ { Name: "test.counter", InstrumentationName: "test", - Labels: oteltest.LabelsToMap(labels1...), + Labels: metrictest.LabelsToMap(labels1...), Number: asFloat(1), }, { Name: "test.valuerecorder", InstrumentationName: "test", - Labels: oteltest.LabelsToMap(labels1...), + Labels: metrictest.LabelsToMap(labels1...), Number: asInt(3), }, }, - oteltest.AsStructs(mock.MeasurementBatches)) + metrictest.AsStructs(mock.MeasurementBatches)) boundC.Unbind() boundM.Unbind() @@ -199,7 +199,7 @@ func TestUnbindThenRecordOne(t *testing.T) { global.ResetForTest() ctx := context.Background() - mock, provider := oteltest.NewMeterProvider() + mock, provider := metrictest.NewMeterProvider() meter := metricglobal.Meter("test") counter := Must(meter).NewInt64Counter("test.counter") @@ -238,7 +238,7 @@ func TestErrorInDeferredConstructor(t *testing.T) { c1 := Must(meter).NewInt64Counter("test") c2 := Must(meter).NewInt64Counter("test") - _, provider := oteltest.NewMeterProvider() + _, provider := metrictest.NewMeterProvider() sdk := &meterProviderWithConstructorError{provider} require.Panics(t, func() { @@ -264,7 +264,7 @@ func TestImplementationIndirection(t *testing.T) { ival := counter.Measurement(1).SyncImpl().Implementation() require.NotNil(t, ival) - _, ok := ival.(*oteltest.Sync) + _, ok := ival.(*metrictest.Sync) require.False(t, ok) // Async: no SDK yet @@ -276,11 +276,11 @@ func TestImplementationIndirection(t *testing.T) { ival = valueobserver.AsyncImpl().Implementation() require.NotNil(t, ival) - _, ok = ival.(*oteltest.Async) + _, ok = ival.(*metrictest.Async) require.False(t, ok) // Register the SDK - _, provider := oteltest.NewMeterProvider() + _, provider := metrictest.NewMeterProvider() metricglobal.SetMeterProvider(provider) // Repeat the above tests @@ -289,14 +289,14 @@ func TestImplementationIndirection(t *testing.T) { ival = counter.Measurement(1).SyncImpl().Implementation() require.NotNil(t, ival) - _, ok = ival.(*oteltest.Sync) + _, ok = ival.(*metrictest.Sync) require.True(t, ok) // Async ival = valueobserver.AsyncImpl().Implementation() require.NotNil(t, ival) - _, ok = ival.(*oteltest.Async) + _, ok = ival.(*metrictest.Async) require.True(t, ok) } @@ -309,19 +309,19 @@ func TestRecordBatchMock(t *testing.T) { meter.RecordBatch(context.Background(), nil, counter.Measurement(1)) - mock, provider := oteltest.NewMeterProvider() + mock, provider := metrictest.NewMeterProvider() metricglobal.SetMeterProvider(provider) meter.RecordBatch(context.Background(), nil, counter.Measurement(1)) require.EqualValues(t, - []oteltest.Measured{ + []metrictest.Measured{ { Name: "test.counter", InstrumentationName: "builtin", - Labels: oteltest.LabelsToMap(), + Labels: metrictest.LabelsToMap(), Number: asInt(1), }, }, - oteltest.AsStructs(mock.MeasurementBatches)) + metrictest.AsStructs(mock.MeasurementBatches)) } diff --git a/metric/metric_test.go b/metric/metric_test.go index b7e528e669d..45566a29043 100644 --- a/metric/metric_test.go +++ b/metric/metric_test.go @@ -21,8 +21,8 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/number" - "go.opentelemetry.io/otel/metric/oteltest" "go.opentelemetry.io/otel/metric/unit" "github.com/google/go-cmp/cmp" @@ -119,14 +119,14 @@ func TestPrecomputedSum(t *testing.T) { } } -func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { +func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { t.Helper() batchesCount := len(mock.MeasurementBatches) if len(mock.MeasurementBatches) != len(expected) { t.Errorf("Expected %d recorded measurement batches, got %d", batchesCount, len(mock.MeasurementBatches)) } - recorded := oteltest.AsStructs(mock.MeasurementBatches) + recorded := metrictest.AsStructs(mock.MeasurementBatches) for i, batch := range mock.MeasurementBatches { if len(batch.Measurements) != 1 { @@ -136,11 +136,11 @@ func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyV measurement := batch.Measurements[0] descriptor := measurement.Instrument.Descriptor() - expected := oteltest.Measured{ + expected := metrictest.Measured{ Name: descriptor.Name(), InstrumentationName: descriptor.InstrumentationName(), - Labels: oteltest.LabelsToMap(labels...), - Number: oteltest.ResolveNumberByKind(t, nkind, expected[i]), + Labels: metrictest.LabelsToMap(labels...), + Number: metrictest.ResolveNumberByKind(t, nkind, expected[i]), } require.Equal(t, expected, recorded[i]) } @@ -308,7 +308,7 @@ func TestCounter(t *testing.T) { // N.B. the API does not check for negative // values, that's the SDK's responsibility. t.Run("float64 counter", func(t *testing.T) { - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() c := Must(meter).NewFloat64Counter("test.counter.float") ctx := context.Background() labels := []attribute.KeyValue{attribute.String("A", "B")} @@ -321,7 +321,7 @@ func TestCounter(t *testing.T) { ) }) t.Run("int64 counter", func(t *testing.T) { - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() c := Must(meter).NewInt64Counter("test.counter.int") ctx := context.Background() labels := []attribute.KeyValue{attribute.String("A", "B"), attribute.String("C", "D")} @@ -335,7 +335,7 @@ func TestCounter(t *testing.T) { }) t.Run("int64 updowncounter", func(t *testing.T) { - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() c := Must(meter).NewInt64UpDownCounter("test.updowncounter.int") ctx := context.Background() labels := []attribute.KeyValue{attribute.String("A", "B"), attribute.String("C", "D")} @@ -348,7 +348,7 @@ func TestCounter(t *testing.T) { ) }) t.Run("float64 updowncounter", func(t *testing.T) { - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() c := Must(meter).NewFloat64UpDownCounter("test.updowncounter.float") ctx := context.Background() labels := []attribute.KeyValue{attribute.String("A", "B"), attribute.String("C", "D")} @@ -364,7 +364,7 @@ func TestCounter(t *testing.T) { func TestValueRecorder(t *testing.T) { t.Run("float64 valuerecorder", func(t *testing.T) { - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() m := Must(meter).NewFloat64ValueRecorder("test.valuerecorder.float") ctx := context.Background() labels := []attribute.KeyValue{} @@ -377,7 +377,7 @@ func TestValueRecorder(t *testing.T) { ) }) t.Run("int64 valuerecorder", func(t *testing.T) { - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() m := Must(meter).NewInt64ValueRecorder("test.valuerecorder.int") ctx := context.Background() labels := []attribute.KeyValue{attribute.Int("I", 1)} @@ -394,7 +394,7 @@ func TestValueRecorder(t *testing.T) { func TestObserverInstruments(t *testing.T) { t.Run("float valueobserver", func(t *testing.T) { labels := []attribute.KeyValue{attribute.String("O", "P")} - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) }) @@ -405,7 +405,7 @@ func TestObserverInstruments(t *testing.T) { }) t.Run("int valueobserver", func(t *testing.T) { labels := []attribute.KeyValue{} - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) }) @@ -416,7 +416,7 @@ func TestObserverInstruments(t *testing.T) { }) t.Run("float sumobserver", func(t *testing.T) { labels := []attribute.KeyValue{attribute.String("O", "P")} - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) }) @@ -427,7 +427,7 @@ func TestObserverInstruments(t *testing.T) { }) t.Run("int sumobserver", func(t *testing.T) { labels := []attribute.KeyValue{} - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) }) @@ -438,7 +438,7 @@ func TestObserverInstruments(t *testing.T) { }) t.Run("float updownsumobserver", func(t *testing.T) { labels := []attribute.KeyValue{attribute.String("O", "P")} - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(42.1, labels...) }) @@ -449,7 +449,7 @@ func TestObserverInstruments(t *testing.T) { }) t.Run("int updownsumobserver", func(t *testing.T) { labels := []attribute.KeyValue{} - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) { result.Observe(-142, labels...) }) @@ -461,7 +461,7 @@ func TestObserverInstruments(t *testing.T) { } func TestBatchObserverInstruments(t *testing.T) { - mockSDK, meter := oteltest.NewMeter() + mockSDK, meter := metrictest.NewMeter() var obs1 metric.Int64ValueObserver var obs2 metric.Float64ValueObserver @@ -486,8 +486,8 @@ func TestBatchObserverInstruments(t *testing.T) { require.Len(t, mockSDK.MeasurementBatches, 1) - impl1 := obs1.AsyncImpl().Implementation().(*oteltest.Async) - impl2 := obs2.AsyncImpl().Implementation().(*oteltest.Async) + impl1 := obs1.AsyncImpl().Implementation().(*metrictest.Async) + impl2 := obs2.AsyncImpl().Implementation().(*metrictest.Async) require.NotNil(t, impl1) require.NotNil(t, impl2) @@ -497,21 +497,21 @@ func TestBatchObserverInstruments(t *testing.T) { require.Len(t, got.Measurements, 2) m1 := got.Measurements[0] - require.Equal(t, impl1, m1.Instrument.Implementation().(*oteltest.Async)) - require.Equal(t, 0, m1.Number.CompareNumber(number.Int64Kind, oteltest.ResolveNumberByKind(t, number.Int64Kind, 42))) + require.Equal(t, impl1, m1.Instrument.Implementation().(*metrictest.Async)) + require.Equal(t, 0, m1.Number.CompareNumber(number.Int64Kind, metrictest.ResolveNumberByKind(t, number.Int64Kind, 42))) m2 := got.Measurements[1] - require.Equal(t, impl2, m2.Instrument.Implementation().(*oteltest.Async)) - require.Equal(t, 0, m2.Number.CompareNumber(number.Float64Kind, oteltest.ResolveNumberByKind(t, number.Float64Kind, 42))) + require.Equal(t, impl2, m2.Instrument.Implementation().(*metrictest.Async)) + require.Equal(t, 0, m2.Number.CompareNumber(number.Float64Kind, metrictest.ResolveNumberByKind(t, number.Float64Kind, 42))) } -func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) { +func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) { t.Helper() assert.Len(t, mock.MeasurementBatches, 1) if len(mock.MeasurementBatches) < 1 { return } - o := observer.Implementation().(*oteltest.Async) + o := observer.Implementation().(*metrictest.Async) if !assert.NotNil(t, o) { return } @@ -523,8 +523,8 @@ func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *oteltes } measurement := got.Measurements[0] require.Equal(t, mkind, measurement.Instrument.Descriptor().InstrumentKind()) - assert.Equal(t, o, measurement.Instrument.Implementation().(*oteltest.Async)) - ft := oteltest.ResolveNumberByKind(t, nkind, expected) + assert.Equal(t, o, measurement.Instrument.Implementation().(*metrictest.Async)) + ft := metrictest.ResolveNumberByKind(t, nkind, expected) assert.Equal(t, 0, measurement.Number.CompareNumber(nkind, ft)) } @@ -561,7 +561,7 @@ func TestWrappedInstrumentError(t *testing.T) { func TestNilCallbackObserverNoop(t *testing.T) { // Tests that a nil callback yields a no-op observer without error. - _, meter := oteltest.NewMeter() + _, meter := metrictest.NewMeter() observer := Must(meter).NewInt64ValueObserver("test.observer", nil) diff --git a/metric/oteltest/alignment_test.go b/metric/metrictest/alignment_test.go similarity index 98% rename from metric/oteltest/alignment_test.go rename to metric/metrictest/alignment_test.go index 816ea311691..183d46bda82 100644 --- a/metric/oteltest/alignment_test.go +++ b/metric/metrictest/alignment_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package oteltest +package metrictest import ( "os" diff --git a/metric/oteltest/meter.go b/metric/metrictest/meter.go similarity index 98% rename from metric/oteltest/meter.go rename to metric/metrictest/meter.go index 9026e3d1221..a70d12b0de8 100644 --- a/metric/oteltest/meter.go +++ b/metric/metrictest/meter.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package oteltest // import "go.opentelemetry.io/otel/metric/oteltest" +package metrictest // import "go.opentelemetry.io/otel/metric/metrictest" import ( "context" diff --git a/metric/registry/registry_test.go b/metric/registry/registry_test.go index 2711f56999d..3e021f13cd3 100644 --- a/metric/registry/registry_test.go +++ b/metric/registry/registry_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/oteltest" + "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/registry" ) @@ -72,7 +72,7 @@ func unwrap(impl interface{}, err error) (metric.InstrumentImpl, error) { func TestRegistrySameInstruments(t *testing.T) { for _, nf := range allNew { - _, provider := oteltest.NewMeterProvider() + _, provider := metrictest.NewMeterProvider() meter := provider.Meter("meter") inst1, err1 := nf(meter, "this") @@ -86,7 +86,7 @@ func TestRegistrySameInstruments(t *testing.T) { func TestRegistryDifferentNamespace(t *testing.T) { for _, nf := range allNew { - _, provider := oteltest.NewMeterProvider() + _, provider := metrictest.NewMeterProvider() meter1 := provider.Meter("meter1") meter2 := provider.Meter("meter2") @@ -101,7 +101,7 @@ func TestRegistryDifferentNamespace(t *testing.T) { func TestRegistryDiffInstruments(t *testing.T) { for origName, origf := range allNew { - _, provider := oteltest.NewMeterProvider() + _, provider := metrictest.NewMeterProvider() meter := provider.Meter("meter") _, err := origf(meter, "this") @@ -121,7 +121,7 @@ func TestRegistryDiffInstruments(t *testing.T) { } func TestMeterProvider(t *testing.T) { - impl, _ := oteltest.NewMeter() + impl, _ := metrictest.NewMeter() p := registry.NewMeterProvider(impl) m1 := p.Meter("m1") m1p := p.Meter("m1") From cb4ac65fb804727092ca578c564a46cd6e8ae3ab Mon Sep 17 00:00:00 2001 From: Anthony J Mirabella Date: Thu, 10 Jun 2021 12:58:36 -0400 Subject: [PATCH 5/5] Fix metrictest package name in CHANGELOG Signed-off-by: Anthony J Mirabella --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8afefa53418..0a0ee8b4cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The `Get` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931) - The `Insert` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a pair of `string`s instead of an `attribute.KeyValue` type. (#1931) - The `Delete` method of the `TraceState` type from the `go.opentelemetry.io/otel/trace` package has been updated to accept a `string` instead of an `attribute.Key` type. (#1931) -- Metrics test helpers in `go.opentelemetry.io/otel/oteltest` have been moved to `go.opentelemetry.io/otel/metric/oteltest`. (#1988) +- Metrics test helpers in `go.opentelemetry.io/otel/oteltest` have been moved to `go.opentelemetry.io/otel/metric/metrictest`. (#1988) ### Deprecated