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:
Krasi Georgiev 2018-02-07 12:29:27 +02:00 committed by Brian Brazil
parent 6edc493c95
commit 404b306fb9
3 changed files with 43 additions and 0 deletions

View File

@ -301,6 +301,10 @@ func (sp *scrapePool) sync(targets []*Target) {
sp.loops[hash] = l
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())
}
}

View File

@ -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 {
startFunc func(interval, timeout time.Duration, errc chan<- error)
stopFunc func()

View File

@ -115,6 +115,11 @@ func (t *Target) DiscoveredLabels() labels.Labels {
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.
func (t *Target) URL() *url.URL {
params := url.Values{}