mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix remote read labelset corruption (#3456)
The labelsets returned from remote read are mutated in higher levels (like seriesFilter.Labels()) and since the concreteSeriesSet didn't return a copy, the external mutation affected the labelset in the concreteSeries itself. This resulted in bizarre bugs where local and remote series would show with identical label sets in the UI, but not be deduplicated, since internally, a series might come to look like: {__name__="node_load5", instance="192.168.1.202:12090", job="node_exporter", node="odroid", node="odroid"} (note the repetition of the last label)
This commit is contained in:
parent
c8a735ceb6
commit
9f10c63cff
|
@ -201,7 +201,7 @@ type concreteSeries struct {
|
|||
}
|
||||
|
||||
func (c *concreteSeries) Labels() labels.Labels {
|
||||
return c.labels
|
||||
return labels.New(c.labels...)
|
||||
}
|
||||
|
||||
func (c *concreteSeries) Iterator() storage.SeriesIterator {
|
||||
|
|
|
@ -16,6 +16,8 @@ package remote
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/prometheus/prometheus/pkg/labels"
|
||||
"github.com/prometheus/prometheus/prompb"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
|
@ -124,3 +126,22 @@ func TestConcreteSeriesSet(t *testing.T) {
|
|||
t.Fatalf("Expected Next() to be false.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcreteSeriesClonesLabels(t *testing.T) {
|
||||
lbls := labels.Labels{
|
||||
labels.Label{Name: "a", Value: "b"},
|
||||
labels.Label{Name: "c", Value: "d"},
|
||||
}
|
||||
cs := concreteSeries{
|
||||
labels: labels.New(lbls...),
|
||||
}
|
||||
|
||||
gotLabels := cs.Labels()
|
||||
require.Equal(t, lbls, gotLabels)
|
||||
|
||||
gotLabels[0].Value = "foo"
|
||||
gotLabels[1].Value = "bar"
|
||||
|
||||
gotLabels = cs.Labels()
|
||||
require.Equal(t, lbls, gotLabels)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue