You've already forked opentelemetry-go
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:
@@ -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() {
|
||||
|
@@ -36,9 +36,13 @@ func TestStringKeyValues(t *testing.T) {
|
||||
kvs []core.KeyValue
|
||||
expected []*commonpb.StringKeyValue
|
||||
}{
|
||||
{
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
[]core.KeyValue{},
|
||||
[]*commonpb.StringKeyValue{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
[]core.KeyValue{
|
||||
@@ -118,7 +122,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
||||
Description: "test-a-description",
|
||||
Unit: "1",
|
||||
Type: metricpb.MetricDescriptor_SUMMARY,
|
||||
Labels: []*commonpb.StringKeyValue{},
|
||||
Labels: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user