Skip to content

Commit

Permalink
return nil for empty metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Dec 15, 2022
1 parent 7e521eb commit 50f9f55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 3 additions & 0 deletions bridge/opencensus/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (p *producer) Produce(_ context.Context) ([]metricdata.ScopeMetrics, error)
data = append(data, ocProducer.Read()...)
}
otelmetrics, err := internal.ConvertMetrics(data)
if len(otelmetrics) == 0 {
return nil, err
}
return []metricdata.ScopeMetrics{{
Scope: instrumentation.Scope{
Name: scopeName,
Expand Down
24 changes: 11 additions & 13 deletions bridge/opencensus/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@ func TestMetricProducer(t *testing.T) {
for _, tc := range []struct {
desc string
input []*ocmetricdata.Metric
expected metricdata.ScopeMetrics
expected []metricdata.ScopeMetrics
expectErr bool
}{
{
desc: "empty",
expected: metricdata.ScopeMetrics{
Scope: instrumentation.Scope{
Name: scopeName,
},
},
desc: "empty",
expected: nil,
},
{
desc: "success",
Expand All @@ -69,7 +65,7 @@ func TestMetricProducer(t *testing.T) {
},
},
},
expected: metricdata.ScopeMetrics{
expected: []metricdata.ScopeMetrics{{
Scope: instrumentation.Scope{
Name: scopeName,
},
Expand All @@ -87,7 +83,7 @@ func TestMetricProducer(t *testing.T) {
},
},
},
},
}},
},
{
desc: "partial success",
Expand Down Expand Up @@ -117,7 +113,7 @@ func TestMetricProducer(t *testing.T) {
},
},
},
expected: metricdata.ScopeMetrics{
expected: []metricdata.ScopeMetrics{{
Scope: instrumentation.Scope{
Name: scopeName,
},
Expand All @@ -135,7 +131,7 @@ func TestMetricProducer(t *testing.T) {
},
},
},
},
}},
expectErr: true,
},
} {
Expand All @@ -149,8 +145,10 @@ func TestMetricProducer(t *testing.T) {
} else {
require.Nil(t, err)
}
require.Equal(t, len(output), 1)
metricdatatest.AssertEqual(t, tc.expected, output[0])
require.Equal(t, len(output), len(tc.expected))
for i := range output {
metricdatatest.AssertEqual(t, tc.expected[i], output[i])
}
})
}
}
Expand Down

0 comments on commit 50f9f55

Please sign in to comment.