Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit e62cccf

Browse files
committed
Discard tags with empty fields
Labels with empty key or value are not allowed by the remote write spec, so if any seen tag contains them then they are not mapped to the related label.
1 parent 7aba207 commit e62cccf

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pkg/remotewrite/prometheus.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ func MapTagSet(t *metrics.TagSet) []*prompb.Label {
2121
labels := make([]*prompb.Label, 0, n.Len())
2222
for !n.IsRoot() {
2323
prev, key, value := n.Data()
24-
labels = append(labels, &prompb.Label{Name: key, Value: value})
2524
n = prev
25+
if key == "" || value == "" {
26+
continue
27+
}
28+
labels = append(labels, &prompb.Label{Name: key, Value: value})
2629
}
2730
return labels
2831
}

pkg/remotewrite/prometheus_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ func TestMapSeries(t *testing.T) {
1717
t.Parallel()
1818

1919
r := metrics.NewRegistry()
20+
tags := r.RootTagSet().
21+
With("tagk1", "tagv1").With("b1", "v1").
22+
// labels with empty key or value are not allowed
23+
// so they will be not added as labels
24+
With("tagEmptyValue", "").
25+
With("", "tagEmptyKey")
26+
2027
series := metrics.TimeSeries{
2128
Metric: &metrics.Metric{
2229
Name: "test",
2330
Type: metrics.Counter,
2431
},
25-
Tags: r.RootTagSet().With("tagk1", "tagv1").With("b1", "v1"),
32+
Tags: tags,
2633
}
2734

2835
lbls := MapSeries(series, "")

0 commit comments

Comments
 (0)