mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
vmalert: use rule's evaluationInterval
as step
param by default (#1258)
User still can override param by specifying `datasource.queryStep` flag.
This commit is contained in:
parent
daf2778025
commit
6fbedd62b8
3 changed files with 13 additions and 6 deletions
|
@ -23,7 +23,8 @@ var (
|
||||||
|
|
||||||
lookBack = flag.Duration("datasource.lookback", 0, `Lookback defines how far into the past to look when evaluating queries. For example, if the datasource.lookback=5m then param "time" with value now()-5m will be added to every query.`)
|
lookBack = flag.Duration("datasource.lookback", 0, `Lookback defines how far into the past to look when evaluating queries. For example, if the datasource.lookback=5m then param "time" with value now()-5m will be added to every query.`)
|
||||||
queryStep = flag.Duration("datasource.queryStep", 0, "queryStep defines how far a value can fallback to when evaluating queries. "+
|
queryStep = flag.Duration("datasource.queryStep", 0, "queryStep defines how far a value can fallback to when evaluating queries. "+
|
||||||
"For example, if datasource.queryStep=15s then param \"step\" with value \"15s\" will be added to every query.")
|
"For example, if datasource.queryStep=15s then param \"step\" with value \"15s\" will be added to every query."+
|
||||||
|
"If queryStep isn't specified, rule's evaluationInterval will be used instead.")
|
||||||
maxIdleConnections = flag.Int("datasource.maxIdleConnections", 100, `Defines the number of idle (keep-alive connections) to each configured datasource. Consider setting this value equal to the value: groups_total * group.concurrency. Too low a value may result in a high number of sockets in TIME_WAIT state.`)
|
maxIdleConnections = flag.Int("datasource.maxIdleConnections", 100, `Defines the number of idle (keep-alive connections) to each configured datasource. Consider setting this value equal to the value: groups_total * group.concurrency. Too low a value may result in a high number of sockets in TIME_WAIT state.`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -209,9 +209,13 @@ func (s *VMStorage) setPrometheusReqParams(r *http.Request, query string, timest
|
||||||
if s.evaluationInterval > 0 {
|
if s.evaluationInterval > 0 {
|
||||||
// see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1232
|
// see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1232
|
||||||
timestamp = timestamp.Truncate(s.evaluationInterval)
|
timestamp = timestamp.Truncate(s.evaluationInterval)
|
||||||
|
// set step as evaluationInterval by default
|
||||||
|
q.Set("step", s.evaluationInterval.String())
|
||||||
}
|
}
|
||||||
q.Set("time", fmt.Sprintf("%d", timestamp.Unix()))
|
q.Set("time", fmt.Sprintf("%d", timestamp.Unix()))
|
||||||
|
|
||||||
if s.queryStep > 0 {
|
if s.queryStep > 0 {
|
||||||
|
// override step with user-specified value
|
||||||
q.Set("step", s.queryStep.String())
|
q.Set("step", s.queryStep.String())
|
||||||
}
|
}
|
||||||
r.URL.RawQuery = q.Encode()
|
r.URL.RawQuery = q.Encode()
|
||||||
|
|
|
@ -213,8 +213,9 @@ func TestPrepareReq(t *testing.T) {
|
||||||
evaluationInterval: 15 * time.Second,
|
evaluationInterval: 15 * time.Second,
|
||||||
},
|
},
|
||||||
func(t *testing.T, r *http.Request) {
|
func(t *testing.T, r *http.Request) {
|
||||||
tt := timestamp.Truncate(15 * time.Second)
|
evalInterval := 15 * time.Second
|
||||||
exp := fmt.Sprintf("query=%s&time=%d", query, tt.Unix())
|
tt := timestamp.Truncate(evalInterval)
|
||||||
|
exp := fmt.Sprintf("query=%s&step=%v&time=%d", query, evalInterval, tt.Unix())
|
||||||
checkEqualString(t, exp, r.URL.RawQuery)
|
checkEqualString(t, exp, r.URL.RawQuery)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -225,14 +226,15 @@ func TestPrepareReq(t *testing.T) {
|
||||||
evaluationInterval: 15 * time.Second,
|
evaluationInterval: 15 * time.Second,
|
||||||
},
|
},
|
||||||
func(t *testing.T, r *http.Request) {
|
func(t *testing.T, r *http.Request) {
|
||||||
|
evalInterval := 15 * time.Second
|
||||||
tt := timestamp.Add(-time.Minute)
|
tt := timestamp.Add(-time.Minute)
|
||||||
tt = tt.Truncate(15 * time.Second)
|
tt = tt.Truncate(evalInterval)
|
||||||
exp := fmt.Sprintf("query=%s&time=%d", query, tt.Unix())
|
exp := fmt.Sprintf("query=%s&step=%v&time=%d", query, evalInterval, tt.Unix())
|
||||||
checkEqualString(t, exp, r.URL.RawQuery)
|
checkEqualString(t, exp, r.URL.RawQuery)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"step",
|
"step override",
|
||||||
&VMStorage{
|
&VMStorage{
|
||||||
queryStep: time.Minute,
|
queryStep: time.Minute,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue