Include scrape labels in the hash (#9551)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
77f411b2ec
commit
b0c98e01c8
|
@ -144,17 +144,8 @@ func (t *Target) SetMetadataStore(s MetricMetadataStore) {
|
|||
func (t *Target) hash() uint64 {
|
||||
h := fnv.New64a()
|
||||
|
||||
// We must build a label set without the scrape interval and timeout
|
||||
// labels because those aren't defining attributes of a target
|
||||
// and can be changed without qualifying its parent as a new target,
|
||||
// therefore they should not effect its unique hash.
|
||||
l := t.labels.Map()
|
||||
delete(l, model.ScrapeIntervalLabel)
|
||||
delete(l, model.ScrapeTimeoutLabel)
|
||||
lset := labels.FromMap(l)
|
||||
|
||||
//nolint: errcheck
|
||||
h.Write([]byte(fmt.Sprintf("%016d", lset.Hash())))
|
||||
h.Write([]byte(fmt.Sprintf("%016d", t.labels.Hash())))
|
||||
//nolint: errcheck
|
||||
h.Write([]byte(t.URL().String()))
|
||||
|
||||
|
|
|
@ -382,29 +382,3 @@ func TestTargetsFromGroup(t *testing.T) {
|
|||
t.Fatalf("Expected error %s, got %s", expectedError, failures[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetHash(t *testing.T) {
|
||||
target1 := &Target{
|
||||
labels: labels.Labels{
|
||||
{Name: model.AddressLabel, Value: "localhost"},
|
||||
{Name: model.SchemeLabel, Value: "http"},
|
||||
{Name: model.MetricsPathLabel, Value: "/metrics"},
|
||||
{Name: model.ScrapeIntervalLabel, Value: "15s"},
|
||||
{Name: model.ScrapeTimeoutLabel, Value: "500ms"},
|
||||
},
|
||||
}
|
||||
hash1 := target1.hash()
|
||||
|
||||
target2 := &Target{
|
||||
labels: labels.Labels{
|
||||
{Name: model.AddressLabel, Value: "localhost"},
|
||||
{Name: model.SchemeLabel, Value: "http"},
|
||||
{Name: model.MetricsPathLabel, Value: "/metrics"},
|
||||
{Name: model.ScrapeIntervalLabel, Value: "14s"},
|
||||
{Name: model.ScrapeTimeoutLabel, Value: "600ms"},
|
||||
},
|
||||
}
|
||||
hash2 := target2.hash()
|
||||
|
||||
require.Equal(t, hash1, hash2, "Scrape interval and duration labels should not effect hash.")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue