From f52b4296c8cbf7224fd1d933077be02a56d6e408 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 28 Jul 2023 12:11:31 -0700 Subject: [PATCH 1/2] Document the Reader and Exporter concurrent safe requirements The aggregation and temporality methods may be called concurrently. Both with themselves and with other methods of the Reader or Exporter. Implementations need to provide concurrent safe methods. This change adds documentation about this requirement. Part of #3925 --- CHANGELOG.md | 1 + sdk/metric/exporter.go | 6 ++++++ sdk/metric/reader.go | 6 ++++++ sdk/metric/reader_test.go | 12 ++++++++++++ 4 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e07b19348af..dc1cb99d63f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add info and debug logging to the metric SDK. (#4315) - The `go.opentelemetry.io/otel/semconv/v1.21.0` package. The package contains semantic conventions from the `v1.21.0` version of the OpenTelemetry Semantic Conventions. (#4362) +- Document the `Temporality` and `Aggregation` methods of the `"go.opentelemetry.io/otel/sdk/metric".Exporter"` need to be concurrent safe. (#TBD) ### Changed diff --git a/sdk/metric/exporter.go b/sdk/metric/exporter.go index b4f7c7b72f9..7efb8bf2fbe 100644 --- a/sdk/metric/exporter.go +++ b/sdk/metric/exporter.go @@ -30,9 +30,15 @@ var ErrExporterShutdown = fmt.Errorf("exporter is shutdown") // the final component in the metric push pipeline. type Exporter interface { // Temporality returns the Temporality to use for an instrument kind. + // + // This method needs to be concurrent safe with itself and all the other + // Exporter methods. Temporality(InstrumentKind) metricdata.Temporality // Aggregation returns the Aggregation to use for an instrument kind. + // + // This method needs to be concurrent safe with itself and all the other + // Exporter methods. Aggregation(InstrumentKind) aggregation.Aggregation // Export serializes and transmits metric data to a receiver. diff --git a/sdk/metric/reader.go b/sdk/metric/reader.go index a281104bd08..da68ef33686 100644 --- a/sdk/metric/reader.go +++ b/sdk/metric/reader.go @@ -65,9 +65,15 @@ type Reader interface { RegisterProducer(Producer) // temporality reports the Temporality for the instrument kind provided. + // + // This method needs to be concurrent safe with itself and all the other + // Reader methods. temporality(InstrumentKind) metricdata.Temporality // aggregation returns what Aggregation to use for an instrument kind. + // + // This method needs to be concurrent safe with itself and all the other + // Reader methods. aggregation(InstrumentKind) aggregation.Aggregation // nolint:revive // import-shadow for method scoped by type. // Collect gathers and returns all metric data related to the Reader from diff --git a/sdk/metric/reader_test.go b/sdk/metric/reader_test.go index d375a1b4f6c..8904d68ee40 100644 --- a/sdk/metric/reader_test.go +++ b/sdk/metric/reader_test.go @@ -168,6 +168,18 @@ func (ts *readerTestSuite) TestMethodConcurrentSafe() { var wg sync.WaitGroup const threads = 2 for i := 0; i < threads; i++ { + wg.Add(1) + go func() { + defer wg.Done() + _ = ts.Reader.temporality(InstrumentKindCounter) + }() + + wg.Add(1) + go func() { + defer wg.Done() + _ = ts.Reader.aggregation(InstrumentKindCounter) + }() + wg.Add(1) go func() { defer wg.Done() From 90e2d59505678c449a35ca4bad9dc0a69f2fb3c5 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 28 Jul 2023 12:15:23 -0700 Subject: [PATCH 2/2] Fix PR number in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1cb99d63f..e892b88c91e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add info and debug logging to the metric SDK. (#4315) - The `go.opentelemetry.io/otel/semconv/v1.21.0` package. The package contains semantic conventions from the `v1.21.0` version of the OpenTelemetry Semantic Conventions. (#4362) -- Document the `Temporality` and `Aggregation` methods of the `"go.opentelemetry.io/otel/sdk/metric".Exporter"` need to be concurrent safe. (#TBD) +- Document the `Temporality` and `Aggregation` methods of the `"go.opentelemetry.io/otel/sdk/metric".Exporter"` need to be concurrent safe. (#4381) ### Changed