From c70822db505fa236513205964379d6b6d16b8da3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 21 Feb 2020 13:53:18 +0200 Subject: [PATCH] app/vmselect: add `/internl/resetRollupResultCache` handler for resetting response cache Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/312 --- app/vmselect/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/vmselect/main.go b/app/vmselect/main.go index de4674b83b..c6a9b3108f 100644 --- a/app/vmselect/main.go +++ b/app/vmselect/main.go @@ -33,7 +33,8 @@ var ( minScrapeInterval = flag.Duration("dedup.minScrapeInterval", 0, "Remove superflouos samples from time series if they are located closer to each other than this duration. "+ "This may be useful for reducing overhead when multiple identically configured Prometheus instances write data to the same VictoriaMetrics. "+ "Deduplication is disabled if the -dedup.minScrapeInterval is 0") - storageNodes = flagutil.NewArray("storageNode", "Addresses of vmstorage nodes; usage: -storageNode=vmstorage-host1:8401 -storageNode=vmstorage-host2:8401") + resetCacheAuthKey = flag.String("search.resetCacheAuthKey", "", "Optional authKey for resetting rollup cache via /internal/resetCache call") + storageNodes = flagutil.NewArray("storageNode", "Addresses of vmstorage nodes; usage: -storageNode=vmstorage-host1:8401 -storageNode=vmstorage-host2:8401") ) func getDefaultMaxConcurrentRequests() int { @@ -144,8 +145,12 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool { } } - path := r.URL.Path + path := strings.Replace(r.URL.Path, "//", "/", -1) if path == "/internal/resetRollupResultCache" { + if len(*resetCacheAuthKey) > 0 && r.FormValue("authKey") != *resetCacheAuthKey { + sendPrometheusError(w, r, fmt.Errorf("invalid authKey=%q for %q", r.FormValue("authKey"), path)) + return true + } promql.ResetRollupResultCache() return true }