1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-09-16 09:26:25 +02:00

Remove unneeded allocation on empty labels (#597)

Co-authored-by: Liz Fong-Jones <lizf@honeycomb.io>
This commit is contained in:
Tyler Yahn
2020-03-25 20:17:43 -07:00
committed by GitHub
parent e458809c41
commit e7a9ba1e2e
2 changed files with 8 additions and 7 deletions

View File

@@ -135,10 +135,7 @@ func minMaxSumCount(desc *metric.Descriptor, labels export.Labels, a aggregator.
func stringKeyValues(iter export.LabelIterator) []*commonpb.StringKeyValue { func stringKeyValues(iter export.LabelIterator) []*commonpb.StringKeyValue {
l := iter.Len() l := iter.Len()
if l == 0 { if l == 0 {
// TODO: That looks like a pointless allocation in case of return nil
// no labels, but returning nil from this function makes
// the test fail.
return []*commonpb.StringKeyValue{}
} }
result := make([]*commonpb.StringKeyValue, 0, l) result := make([]*commonpb.StringKeyValue, 0, l)
for iter.Next() { for iter.Next() {

View File

@@ -36,9 +36,13 @@ func TestStringKeyValues(t *testing.T) {
kvs []core.KeyValue kvs []core.KeyValue
expected []*commonpb.StringKeyValue expected []*commonpb.StringKeyValue
}{ }{
{
nil,
nil,
},
{ {
[]core.KeyValue{}, []core.KeyValue{},
[]*commonpb.StringKeyValue{}, nil,
}, },
{ {
[]core.KeyValue{ []core.KeyValue{
@@ -118,7 +122,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
Description: "test-a-description", Description: "test-a-description",
Unit: "1", Unit: "1",
Type: metricpb.MetricDescriptor_SUMMARY, Type: metricpb.MetricDescriptor_SUMMARY,
Labels: []*commonpb.StringKeyValue{}, Labels: nil,
}, },
}, },
{ {
@@ -224,7 +228,7 @@ func TestSumMetricDescriptor(t *testing.T) {
Description: "test-a-description", Description: "test-a-description",
Unit: "1", Unit: "1",
Type: metricpb.MetricDescriptor_COUNTER_INT64, Type: metricpb.MetricDescriptor_COUNTER_INT64,
Labels: []*commonpb.StringKeyValue{}, Labels: nil,
}, },
}, },
{ {