mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 09:47:54 +00:00
Fix asynchronous calls to map
This commit is contained in:
parent
c89994104d
commit
44d755ae38
1 changed files with 8 additions and 1 deletions
|
|
@ -19,9 +19,11 @@ package provider
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/golang/glog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
|
||||
pmodel "github.com/prometheus/common/model"
|
||||
apierr "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
|
@ -287,6 +289,7 @@ func (l *cachingMetricsLister) updateMetrics() error {
|
|||
|
||||
// don't do duplicate queries when it's just the matchers that change
|
||||
seriesCacheByQuery := make(map[prom.Selector][]prom.Series)
|
||||
seriesCacheByQueryLock := sync.RWMutex{}
|
||||
|
||||
// these can take a while on large clusters, so launch in parallel
|
||||
// and don't duplicate
|
||||
|
|
@ -298,7 +301,9 @@ func (l *cachingMetricsLister) updateMetrics() error {
|
|||
errs <- nil
|
||||
continue
|
||||
}
|
||||
seriesCacheByQueryLock.Lock()
|
||||
selectors[sel] = struct{}{}
|
||||
seriesCacheByQueryLock.Unlock()
|
||||
go func() {
|
||||
series, err := l.promClient.Series(context.TODO(), pmodel.Interval{startTime, 0}, sel)
|
||||
if err != nil {
|
||||
|
|
@ -306,7 +311,9 @@ func (l *cachingMetricsLister) updateMetrics() error {
|
|||
return
|
||||
}
|
||||
errs <- nil
|
||||
seriesCacheByQueryLock.Lock()
|
||||
seriesCacheByQuery[sel] = series
|
||||
seriesCacheByQueryLock.Unlock()
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue