mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promscrape/discovery/kubernetes: fix a deadlock introduced in eddba29664
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1240 Thanks to @f41gh7 for providing the initial idea for deadlock fix at https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1248
This commit is contained in:
parent
cba2d13456
commit
b3da457629
1 changed files with 9 additions and 4 deletions
|
@ -74,6 +74,11 @@ func newAPIWatcher(apiServer string, ac *promauth.Config, sdc *SDConfig, swcFunc
|
|||
|
||||
func (aw *apiWatcher) mustStart() {
|
||||
aw.gw.startWatchersForRole(aw.role, aw)
|
||||
if aw.role == "endpoints" || aw.role == "endpointslices" {
|
||||
// endpoints and endpointslices watchers query pod and service objects. So start watchers for these roles as well.
|
||||
aw.gw.startWatchersForRole("pod", nil)
|
||||
aw.gw.startWatchersForRole("service", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (aw *apiWatcher) mustStop() {
|
||||
|
@ -280,7 +285,6 @@ func (gw *groupWatcher) getObjectByRole(role, namespace, name string) object {
|
|||
|
||||
func (gw *groupWatcher) getCachedObjectByRole(role, namespace, name string) object {
|
||||
key := namespace + "/" + name
|
||||
gw.startWatchersForRole(role, nil)
|
||||
uws := gw.getURLWatchers()
|
||||
for _, uw := range uws {
|
||||
if uw.role != role {
|
||||
|
@ -309,9 +313,6 @@ func (gw *groupWatcher) refreshEndpointsLabels(namespace, key string) {
|
|||
}
|
||||
|
||||
func (gw *groupWatcher) refreshObjectLabels(role, namespace, key string) {
|
||||
// There is no need in starting url watcher for the given role,
|
||||
// since there is no (namespace, key) object yet for this role.
|
||||
// gw.startWatchersForRole(role, nil)
|
||||
uws := gw.getURLWatchers()
|
||||
for _, uw := range uws {
|
||||
if uw.role != role {
|
||||
|
@ -470,6 +471,10 @@ func (uw *urlWatcher) subscribeAPIWatcher(aw *apiWatcher) {
|
|||
|
||||
func (uw *urlWatcher) registerPendingAPIWatchers() {
|
||||
uw.mu.Lock()
|
||||
if len(uw.awsPending) == 0 {
|
||||
uw.mu.Unlock()
|
||||
return
|
||||
}
|
||||
awsPending := make([]*apiWatcher, 0, len(uw.awsPending))
|
||||
for aw := range uw.awsPending {
|
||||
awsPending = append(awsPending, aw)
|
||||
|
|
Loading…
Reference in a new issue