Parse numeric labels with a zero-value if units are specified. (#619)
By default, a numeric label with a value of zero is interpreted as an
empty label which will be ignored during parsing. However, a zero value
can be a valid label value. Instead of ignoring it altogether, parse it
as a zero-valued numeric label if num_unit is set.
diff --git a/profile/encode.go b/profile/encode.go
index 1e84c72..ab7f03a 100644
--- a/profile/encode.go
+++ b/profile/encode.go
@@ -308,7 +308,7 @@
if l.strX != 0 {
value, err = getString(p.stringTable, &l.strX, err)
labels[key] = append(labels[key], value)
- } else if l.numX != 0 {
+ } else if l.numX != 0 || l.unitX != 0 {
numValues := numLabels[key]
units := numUnits[key]
if l.unitX != 0 {
diff --git a/profile/proto_test.go b/profile/proto_test.go
index 38b58c5..e030bb2 100644
--- a/profile/proto_test.go
+++ b/profile/proto_test.go
@@ -142,6 +142,16 @@
"alignment": {"kilobytes", "kilobytes"},
},
},
+ {
+ Location: []*Location{testL[1], testL[2], testL[0], testL[1]},
+ Value: []int64{30, 40},
+ NumLabel: map[string][]int64{
+ "size": {0},
+ },
+ NumUnit: map[string][]string{
+ "size": {"bytes"},
+ },
+ },
},
Function: testF,
Mapping: testM,