runsc metric-server: Fix printing labels with only external labels specified

Prior to this CL, attempting to write data for a data point with no labels
other than `d.ExternalLabels` set would not actually print these labels.

This CL adds `d.ExternalLabels` to the check that checks whether there are any
labels to write, and simplifies it to not check for nil-ness (as the `len` of
a `nil` map is 0).

PiperOrigin-RevId: 526715338
This commit is contained in:
Etienne Perot
2023-04-24 12:05:02 -07:00
committed by gVisor bot
parent 70d8b97c89
commit 779cd96de5
+1 -1
View File
@@ -660,7 +660,7 @@ func OrderedLabels(labels ...map[string]string) <-chan LabelOrError {
// writeLabelsTo writes a set of metric labels.
func (d *Data) writeLabelsTo(w io.Writer, extraLabels map[string]string, leLabel *Number) error {
if (d.Labels != nil && len(d.Labels) != 0) || (extraLabels != nil && len(extraLabels) != 0) || leLabel != nil {
if len(d.Labels)+len(d.ExternalLabels)+len(extraLabels) != 0 || leLabel != nil {
if _, err := io.WriteString(w, "{"); err != nil {
return err
}