Skip to content

Commit

Permalink
Remove unneeded allocation on empty labels (#597)
Browse files Browse the repository at this point in the history
Co-authored-by: Liz Fong-Jones <lizf@honeycomb.io>
  • Loading branch information
MrAlias and lizthegrey committed Mar 26, 2020
1 parent e458809 commit e7a9ba1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 1 addition & 4 deletions exporters/otlp/internal/transform/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ func minMaxSumCount(desc *metric.Descriptor, labels export.Labels, a aggregator.
func stringKeyValues(iter export.LabelIterator) []*commonpb.StringKeyValue {
l := iter.Len()
if l == 0 {
// TODO: That looks like a pointless allocation in case of
// no labels, but returning nil from this function makes
// the test fail.
return []*commonpb.StringKeyValue{}
return nil
}
result := make([]*commonpb.StringKeyValue, 0, l)
for iter.Next() {
Expand Down
10 changes: 7 additions & 3 deletions exporters/otlp/internal/transform/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ func TestStringKeyValues(t *testing.T) {
kvs []core.KeyValue
expected []*commonpb.StringKeyValue
}{
{
nil,
nil,
},
{
[]core.KeyValue{},
[]*commonpb.StringKeyValue{},
nil,
},
{
[]core.KeyValue{
Expand Down Expand Up @@ -118,7 +122,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
Description: "test-a-description",
Unit: "1",
Type: metricpb.MetricDescriptor_SUMMARY,
Labels: []*commonpb.StringKeyValue{},
Labels: nil,
},
},
{
Expand Down Expand Up @@ -224,7 +228,7 @@ func TestSumMetricDescriptor(t *testing.T) {
Description: "test-a-description",
Unit: "1",
Type: metricpb.MetricDescriptor_COUNTER_INT64,
Labels: []*commonpb.StringKeyValue{},
Labels: nil,
},
},
{
Expand Down

0 comments on commit e7a9ba1

Please sign in to comment.