1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Update the metric Export interface to accept a *ResourceMetrics instead of ResourceMetrics (#3853)

* Change the signature of Export method

* Pass tests for otlp exporter

* Pass tests for otlp grpc and http packages

* Update opencensus bridge

* Refactor and pass tests for stdoutmetric package

* Update periodic reader tests

* Update changelog

* Apply suggestions

* Apply suggestions

* Update CHANGELOG.md

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Sinan Ülker
2023-03-16 18:58:43 +01:00
committed by GitHub
parent 3a40e65a38
commit 7fc24d2b14
15 changed files with 41 additions and 52 deletions
@@ -153,7 +153,7 @@ func Example() {
// This is where the sdk would be used to create a Meter and from that
// instruments that would make measurements of your code. To simulate that
// behavior, call export directly with mocked data.
_ = exp.Export(ctx, mockData)
_ = exp.Export(ctx, &mockData)
// Ensure the periodic reader is cleaned up by shutting down the sdk.
_ = sdk.Shutdown(ctx)
@@ -325,6 +325,6 @@ func Example() {
// }
// }
// ],
// "ScopeMetrics": []
// "ScopeMetrics": null
// }
}
+7 -19
View File
@@ -62,7 +62,7 @@ func (e *exporter) Aggregation(k metric.InstrumentKind) aggregation.Aggregation
return e.aggregationSelector(k)
}
func (e *exporter) Export(ctx context.Context, data metricdata.ResourceMetrics) error {
func (e *exporter) Export(ctx context.Context, data *metricdata.ResourceMetrics) error {
select {
case <-ctx.Done():
// Don't do anything if the context has already timed out.
@@ -71,7 +71,7 @@ func (e *exporter) Export(ctx context.Context, data metricdata.ResourceMetrics)
// Context is still valid, continue.
}
if e.redactTimestamps {
data = redactTimestamps(data)
redactTimestamps(data)
}
return e.encVal.Load().(encoderHolder).Encode(data)
}
@@ -90,26 +90,14 @@ func (e *exporter) Shutdown(ctx context.Context) error {
return ctx.Err()
}
func redactTimestamps(orig metricdata.ResourceMetrics) metricdata.ResourceMetrics {
rm := metricdata.ResourceMetrics{
Resource: orig.Resource,
ScopeMetrics: make([]metricdata.ScopeMetrics, len(orig.ScopeMetrics)),
}
func redactTimestamps(orig *metricdata.ResourceMetrics) {
for i, sm := range orig.ScopeMetrics {
rm.ScopeMetrics[i] = metricdata.ScopeMetrics{
Scope: sm.Scope,
Metrics: make([]metricdata.Metrics, len(sm.Metrics)),
}
for j, m := range sm.Metrics {
rm.ScopeMetrics[i].Metrics[j] = metricdata.Metrics{
Name: m.Name,
Description: m.Description,
Unit: m.Unit,
Data: redactAggregationTimestamps(m.Data),
}
metrics := sm.Metrics
for j, m := range metrics {
data := m.Data
orig.ScopeMetrics[i].Metrics[j].Data = redactAggregationTimestamps(data)
}
}
return rm
}
var (
@@ -83,7 +83,7 @@ func TestExporterHonorsContextErrors(t *testing.T) {
exp, err := stdoutmetric.New(testEncoderOption())
require.NoError(t, err)
return func(ctx context.Context) error {
var data metricdata.ResourceMetrics
data := new(metricdata.ResourceMetrics)
return exp.Export(ctx, data)
}
}))
@@ -91,7 +91,7 @@ func TestExporterHonorsContextErrors(t *testing.T) {
func TestShutdownExporterReturnsShutdownErrorOnExport(t *testing.T) {
var (
data metricdata.ResourceMetrics
data = new(metricdata.ResourceMetrics)
ctx = context.Background()
exp, err = stdoutmetric.New(testEncoderOption())
)