From d5c2a0ce643c678cb552f88f6eb700869a083631 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 21 Feb 2020 13:54:10 +0200 Subject: [PATCH] app/vmselect: add `-search.cacheTimestampOffset` command-line flag This flag can be used for removing gaps on graphs if the difference between the current time and the timestamps from the ingested data exceeds 5 minutes. This is the case when the time between data sources and VictoriaMetrics is improperly synchronized. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/312 --- app/vmselect/promql/rollup_result_cache.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/vmselect/promql/rollup_result_cache.go b/app/vmselect/promql/rollup_result_cache.go index 7ef34aeb5b..72b1e98f7d 100644 --- a/app/vmselect/promql/rollup_result_cache.go +++ b/app/vmselect/promql/rollup_result_cache.go @@ -19,7 +19,12 @@ import ( "github.com/VictoriaMetrics/metrics" ) -var disableCache = flag.Bool("search.disableCache", false, "Whether to disable response caching. This may be useful during data backfilling") +var ( + disableCache = flag.Bool("search.disableCache", false, "Whether to disable response caching. This may be useful during data backfilling") + cacheTimestampOffset = flag.Duration("search.cacheTimestampOffset", 5*time.Minute, "The maximum duration since the current time for response data, "+ + "which is always queried from the original raw data, without using the response cache. Increase this value if you see gaps in responses "+ + "due to time synchronization issues between VictoriaMetrics and data sources") +) var rollupResultCacheV = &rollupResultCache{ c: workingsetcache.New(1024*1024, time.Hour), // This is a cache for testing. @@ -220,10 +225,10 @@ func (rrc *rollupResultCache) Put(ec *EvalConfig, expr metricsql.Expr, window in return } - // Remove values up to currentTime - step - maxSilenceInterval, + // Remove values up to currentTime - step - cacheTimestampOffset, // since these values may be added later. timestamps := tss[0].Timestamps - deadline := (time.Now().UnixNano() / 1e6) - ec.Step - maxSilenceInterval + deadline := (time.Now().UnixNano() / 1e6) - ec.Step - cacheTimestampOffset.Milliseconds() i := len(timestamps) - 1 for i >= 0 && timestamps[i] > deadline { i--