Meta labels sd 3693 (#3805)
Always keep the discovered labels up to date. add test that DiscoveredLabels are always updated
This commit is contained in:
parent
6edc493c95
commit
404b306fb9
|
@ -301,6 +301,10 @@ func (sp *scrapePool) sync(targets []*Target) {
|
||||||
sp.loops[hash] = l
|
sp.loops[hash] = l
|
||||||
|
|
||||||
go l.run(interval, timeout, nil)
|
go l.run(interval, timeout, nil)
|
||||||
|
} else {
|
||||||
|
// Need to keep the most updated labels information
|
||||||
|
// for displaying it in the Service Discovery web page.
|
||||||
|
sp.targets[hash].SetDiscoveredLabels(t.DiscoveredLabels())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,40 @@ func TestDroppedTargetsList(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestDiscoveredLabelsUpdate checks that DiscoveredLabels are updated
|
||||||
|
// even when new labels don't affect the target `hash`.
|
||||||
|
func TestDiscoveredLabelsUpdate(t *testing.T) {
|
||||||
|
|
||||||
|
sp := &scrapePool{}
|
||||||
|
// These are used when syncing so need this to avoid a panic.
|
||||||
|
sp.config = &config.ScrapeConfig{
|
||||||
|
ScrapeInterval: model.Duration(1),
|
||||||
|
ScrapeTimeout: model.Duration(1),
|
||||||
|
}
|
||||||
|
sp.targets = make(map[uint64]*Target)
|
||||||
|
t1 := &Target{
|
||||||
|
discoveredLabels: labels.Labels{
|
||||||
|
labels.Label{
|
||||||
|
Name: "label",
|
||||||
|
Value: "name",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
sp.targets[t1.hash()] = t1
|
||||||
|
|
||||||
|
t2 := &Target{
|
||||||
|
discoveredLabels: labels.Labels{
|
||||||
|
labels.Label{
|
||||||
|
Name: "labelNew",
|
||||||
|
Value: "nameNew",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
sp.sync([]*Target{t2})
|
||||||
|
|
||||||
|
testutil.Equals(t, t2.DiscoveredLabels(), sp.targets[t1.hash()].DiscoveredLabels())
|
||||||
|
}
|
||||||
|
|
||||||
type testLoop struct {
|
type testLoop struct {
|
||||||
startFunc func(interval, timeout time.Duration, errc chan<- error)
|
startFunc func(interval, timeout time.Duration, errc chan<- error)
|
||||||
stopFunc func()
|
stopFunc func()
|
||||||
|
|
|
@ -115,6 +115,11 @@ func (t *Target) DiscoveredLabels() labels.Labels {
|
||||||
return lset
|
return lset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetDiscoveredLabels sets new DiscoveredLabels
|
||||||
|
func (t *Target) SetDiscoveredLabels(l labels.Labels) {
|
||||||
|
t.discoveredLabels = l
|
||||||
|
}
|
||||||
|
|
||||||
// URL returns a copy of the target's URL.
|
// URL returns a copy of the target's URL.
|
||||||
func (t *Target) URL() *url.URL {
|
func (t *Target) URL() *url.URL {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
|
|
Loading…
Reference in New Issue