mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
lib/promscrape/k8s_sd: set resourceVersion to 0 by default for watch … (#4901)
* lib/promscrape/k8s_sd: set resourceVersion to 0 by default for watch requests it must reduce load for kubernetes ETCD servers. Since requests without resourceVersion performs force cache sync at kubernetes API server with ETCD more info at https://kubernetes.io/docs/reference/using-api/api-concepts/\#semantics-for-watch https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4855 * wip --------- Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
This commit is contained in:
parent
ad39838c34
commit
dd9d64680a
1 changed files with 15 additions and 5 deletions
|
@ -580,7 +580,13 @@ func (uw *urlWatcher) reloadObjects() string {
|
|||
}
|
||||
|
||||
startTime := time.Now()
|
||||
requestURL := uw.apiURL
|
||||
apiURL := uw.apiURL
|
||||
|
||||
// Set resourceVersion to 0 in order to reduce load on Kubernetes control plane.
|
||||
// See https://kubernetes.io/docs/reference/using-api/api-concepts/#semantics-for-get-and-list
|
||||
// and https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4855 .
|
||||
delimiter := getQueryArgsDelimiter(apiURL)
|
||||
requestURL := apiURL + delimiter + "resourceVersion=0&resourceVersionMatch=NotOlderThan"
|
||||
resp, err := uw.gw.doRequest(requestURL)
|
||||
if err != nil {
|
||||
logger.Errorf("cannot perform request to %q: %s", requestURL, err)
|
||||
|
@ -657,10 +663,7 @@ func (uw *urlWatcher) watchForUpdates() {
|
|||
}
|
||||
}
|
||||
apiURL := uw.apiURL
|
||||
delimiter := "?"
|
||||
if strings.Contains(apiURL, "?") {
|
||||
delimiter = "&"
|
||||
}
|
||||
delimiter := getQueryArgsDelimiter(apiURL)
|
||||
timeoutSeconds := time.Duration(0.9 * float64(uw.gw.client.Timeout)).Seconds()
|
||||
apiURL += delimiter + "watch=1&allowWatchBookmarks=true&timeoutSeconds=" + strconv.Itoa(int(timeoutSeconds))
|
||||
for {
|
||||
|
@ -943,3 +946,10 @@ func getObjectParsersForRole(role string) (parseObjectFunc, parseObjectListFunc)
|
|||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func getQueryArgsDelimiter(apiURL string) string {
|
||||
if strings.Contains(apiURL, "?") {
|
||||
return "&"
|
||||
}
|
||||
return "?"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue