mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Merge pull request #5752 from brancz/cherry-pick-5749
Cherry pick 5749 & Release v2.11.1
This commit is contained in:
commit
e5b2249485
|
@ -1,3 +1,7 @@
|
|||
## 2.11.1 / 2019-07-10
|
||||
|
||||
* [BUGFIX] Fix potential panic when prometheus is watching multiple zookeeper paths. #5749
|
||||
|
||||
## 2.11.0 / 2019-07-09
|
||||
|
||||
* [CHANGE] Remove `max_retries` from queue_config (it has been unused since rewriting remote-write to utilize the write-ahead-log). #5649
|
||||
|
|
|
@ -109,6 +109,7 @@ type Discovery struct {
|
|||
sources map[string]*targetgroup.Group
|
||||
|
||||
updates chan treecache.ZookeeperTreeCacheEvent
|
||||
pathUpdates []chan treecache.ZookeeperTreeCacheEvent
|
||||
treeCaches []*treecache.ZookeeperTreeCache
|
||||
|
||||
parse func(data []byte, path string) (model.LabelSet, error)
|
||||
|
@ -155,7 +156,9 @@ func NewDiscovery(
|
|||
logger: logger,
|
||||
}
|
||||
for _, path := range paths {
|
||||
sd.treeCaches = append(sd.treeCaches, treecache.NewZookeeperTreeCache(conn, path, updates, logger))
|
||||
pathUpdate := make(chan treecache.ZookeeperTreeCacheEvent)
|
||||
sd.pathUpdates = append(sd.pathUpdates, pathUpdate)
|
||||
sd.treeCaches = append(sd.treeCaches, treecache.NewZookeeperTreeCache(conn, path, pathUpdate, logger))
|
||||
}
|
||||
return sd, nil
|
||||
}
|
||||
|
@ -166,12 +169,26 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
|
|||
for _, tc := range d.treeCaches {
|
||||
tc.Stop()
|
||||
}
|
||||
for _, pathUpdate := range d.pathUpdates {
|
||||
// Drain event channel in case the treecache leaks goroutines otherwise.
|
||||
for range d.updates {
|
||||
for range pathUpdate {
|
||||
}
|
||||
}
|
||||
d.conn.Close()
|
||||
}()
|
||||
|
||||
for _, pathUpdate := range d.pathUpdates {
|
||||
go func(update chan treecache.ZookeeperTreeCacheEvent) {
|
||||
for event := range update {
|
||||
select {
|
||||
case d.updates <- event:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}(pathUpdate)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
|
Loading…
Reference in a new issue