From ab5591279ca74e4bda8af455f74f49f546b37224 Mon Sep 17 00:00:00 2001 From: csuzhang Date: Mon, 3 Jan 2022 02:21:14 +0800 Subject: [PATCH 1/5] change UploadMetrics signature from slice to single Resource --- exporters/otlp/otlpmetric/clients.go | 2 +- exporters/otlp/otlpmetric/exporter_test.go | 4 ++-- exporters/otlp/otlpmetric/otlpmetricgrpc/client.go | 4 ++-- exporters/otlp/otlpmetric/otlpmetrichttp/client.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/exporters/otlp/otlpmetric/clients.go b/exporters/otlp/otlpmetric/clients.go index 540ab614307..6808d464761 100644 --- a/exporters/otlp/otlpmetric/clients.go +++ b/exporters/otlp/otlpmetric/clients.go @@ -39,5 +39,5 @@ type Client interface { // UploadMetrics should transform the passed metrics to the // wire format and send it to the collector. May be called // concurrently. - UploadMetrics(ctx context.Context, protoMetrics []*metricpb.ResourceMetrics) error + UploadMetrics(ctx context.Context, protoMetrics *metricpb.ResourceMetrics) error } diff --git a/exporters/otlp/otlpmetric/exporter_test.go b/exporters/otlp/otlpmetric/exporter_test.go index cc7d4728461..ffb4e6fb15a 100644 --- a/exporters/otlp/otlpmetric/exporter_test.go +++ b/exporters/otlp/otlpmetric/exporter_test.go @@ -63,8 +63,8 @@ func (m *stubClient) Stop(ctx context.Context) error { return nil } -func (m *stubClient) UploadMetrics(ctx context.Context, protoMetrics []*metricpb.ResourceMetrics) error { - m.rm = append(m.rm, protoMetrics...) +func (m *stubClient) UploadMetrics(ctx context.Context, protoMetrics *metricpb.ResourceMetrics) error { + m.rm = append(m.rm, []*metricpb.ResourceMetrics{protoMetrics}...) return nil } diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go index ee08f8a00b2..cb67a4fe812 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/client.go @@ -180,7 +180,7 @@ var errShutdown = errors.New("the client is shutdown") // // Retryable errors from the server will be handled according to any // RetryConfig the client was created with. -func (c *client) UploadMetrics(ctx context.Context, protoMetrics []*metricpb.ResourceMetrics) error { +func (c *client) UploadMetrics(ctx context.Context, protoMetrics *metricpb.ResourceMetrics) error { // Hold a read lock to ensure a shut down initiated after this starts does // not abandon the export. This read lock acquire has less priority than a // write lock acquire (i.e. Stop), meaning if the client is shutting down @@ -197,7 +197,7 @@ func (c *client) UploadMetrics(ctx context.Context, protoMetrics []*metricpb.Res return c.requestFunc(ctx, func(iCtx context.Context) error { _, err := c.msc.Export(iCtx, &colmetricpb.ExportMetricsServiceRequest{ - ResourceMetrics: protoMetrics, + ResourceMetrics: []*metricpb.ResourceMetrics{protoMetrics}, }) // nil is converted to OK. if status.Code(err) == codes.OK { diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go index 55334a221c6..b472611fb40 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go @@ -144,9 +144,9 @@ func (d *client) Stop(ctx context.Context) error { } // UploadMetrics sends a batch of metrics to the collector. -func (d *client) UploadMetrics(ctx context.Context, protoMetrics []*metricpb.ResourceMetrics) error { +func (d *client) UploadMetrics(ctx context.Context, protoMetrics *metricpb.ResourceMetrics) error { pbRequest := &colmetricpb.ExportMetricsServiceRequest{ - ResourceMetrics: protoMetrics, + ResourceMetrics: []*metricpb.ResourceMetrics{protoMetrics}, } rawRequest, err := proto.Marshal(pbRequest) if err != nil { From db85073aa5234655099fd88a6701d518d0d7c5c8 Mon Sep 17 00:00:00 2001 From: csuzhang Date: Mon, 3 Jan 2022 02:27:15 +0800 Subject: [PATCH 2/5] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bc1eef716d..94c725f4d84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - Fixes the instrument kind for noop async instruments. (#2461) +- Change UploadMetrics signature from slice to single Resource. (#2491) ## [1.3.0] - 2021-12-10 From ae92295211e4d0136b6165ada106220dcfde28e2 Mon Sep 17 00:00:00 2001 From: csuzhang Date: Mon, 3 Jan 2022 02:30:25 +0800 Subject: [PATCH 3/5] fix otlp exporter bug. --- exporters/otlp/otlpmetric/exporter.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exporters/otlp/otlpmetric/exporter.go b/exporters/otlp/otlpmetric/exporter.go index d6c9a6f4e76..2cd90ac435a 100644 --- a/exporters/otlp/otlpmetric/exporter.go +++ b/exporters/otlp/otlpmetric/exporter.go @@ -24,7 +24,6 @@ import ( "go.opentelemetry.io/otel/sdk/metric/export" "go.opentelemetry.io/otel/sdk/metric/export/aggregation" "go.opentelemetry.io/otel/sdk/resource" - metricpb "go.opentelemetry.io/proto/otlp/metrics/v1" ) var ( @@ -57,7 +56,7 @@ func (e *Exporter) Export(ctx context.Context, res *resource.Resource, ilr expor // call, as per the specification. We can change the // signature of UploadMetrics correspondingly. Here create a // singleton list to reduce the size of the current PR: - return e.client.UploadMetrics(ctx, []*metricpb.ResourceMetrics{rm}) + return e.client.UploadMetrics(ctx, rm) } // Start establishes a connection to the receiving endpoint. From 070d2b204522b90428e8fe02f6cdc6e1f7404484 Mon Sep 17 00:00:00 2001 From: Chester Cheung Date: Tue, 4 Jan 2022 01:20:46 +0800 Subject: [PATCH 4/5] Update exporters/otlp/otlpmetric/exporter_test.go Co-authored-by: Anthony Mirabella --- exporters/otlp/otlpmetric/exporter_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/otlpmetric/exporter_test.go b/exporters/otlp/otlpmetric/exporter_test.go index ffb4e6fb15a..31e3f3e6848 100644 --- a/exporters/otlp/otlpmetric/exporter_test.go +++ b/exporters/otlp/otlpmetric/exporter_test.go @@ -64,7 +64,7 @@ func (m *stubClient) Stop(ctx context.Context) error { } func (m *stubClient) UploadMetrics(ctx context.Context, protoMetrics *metricpb.ResourceMetrics) error { - m.rm = append(m.rm, []*metricpb.ResourceMetrics{protoMetrics}...) + m.rm = append(m.rm, protoMetrics) return nil } From cc686d524ef6f3d902d0ff7f0c164b00a00fafff Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 4 Jan 2022 10:03:02 -0800 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94c725f4d84..98a40894b8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - Fixes the instrument kind for noop async instruments. (#2461) -- Change UploadMetrics signature from slice to single Resource. (#2491) +- Change the `otlpmetric.Client` interface's `UploadMetrics` method to accept a single `ResourceMetrics` instead of a slice of them. (#2491) ## [1.3.0] - 2021-12-10