mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 06:07:11 +02:00
Merge pull request #16478 from KofClubs/range-vector-1001ms
promql: function selector sometimes misses a sample on dense samples
This commit is contained in:
commit
59874fd89c
@ -452,7 +452,7 @@ positive_duration_expr : duration_expr
|
||||
offset_expr: expr OFFSET duration_expr
|
||||
{
|
||||
if numLit, ok := $3.(*NumberLiteral); ok {
|
||||
yylex.(*parser).addOffset($1, time.Duration(numLit.Val*1000)*time.Millisecond)
|
||||
yylex.(*parser).addOffset($1, time.Duration(math.Round(numLit.Val*float64(time.Second))))
|
||||
$$ = $1
|
||||
break
|
||||
}
|
||||
@ -506,7 +506,7 @@ matrix_selector : expr LEFT_BRACKET positive_duration_expr RIGHT_BRACKET
|
||||
|
||||
var rangeNl time.Duration
|
||||
if numLit, ok := $3.(*NumberLiteral); ok {
|
||||
rangeNl = time.Duration(numLit.Val*1000)*time.Millisecond
|
||||
rangeNl = time.Duration(math.Round(numLit.Val*float64(time.Second)))
|
||||
}
|
||||
rangeExpr, _ := $3.(*DurationExpr)
|
||||
$$ = &MatrixSelector{
|
||||
@ -523,11 +523,11 @@ subquery_expr : expr LEFT_BRACKET positive_duration_expr COLON positive_durati
|
||||
var rangeNl time.Duration
|
||||
var stepNl time.Duration
|
||||
if numLit, ok := $3.(*NumberLiteral); ok {
|
||||
rangeNl = time.Duration(numLit.Val*1000)*time.Millisecond
|
||||
rangeNl = time.Duration(math.Round(numLit.Val*float64(time.Second)))
|
||||
}
|
||||
rangeExpr, _ := $3.(*DurationExpr)
|
||||
if numLit, ok := $5.(*NumberLiteral); ok {
|
||||
stepNl = time.Duration(numLit.Val*1000)*time.Millisecond
|
||||
stepNl = time.Duration(math.Round(numLit.Val*float64(time.Second)))
|
||||
}
|
||||
stepExpr, _ := $5.(*DurationExpr)
|
||||
$$ = &SubqueryExpr{
|
||||
@ -543,7 +543,7 @@ subquery_expr : expr LEFT_BRACKET positive_duration_expr COLON positive_durati
|
||||
{
|
||||
var rangeNl time.Duration
|
||||
if numLit, ok := $3.(*NumberLiteral); ok {
|
||||
rangeNl = time.Duration(numLit.Val*1000)*time.Millisecond
|
||||
rangeNl = time.Duration(math.Round(numLit.Val*float64(time.Second)))
|
||||
}
|
||||
rangeExpr, _ := $3.(*DurationExpr)
|
||||
$$ = &SubqueryExpr{
|
||||
|
@ -1372,7 +1372,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
{
|
||||
if numLit, ok := yyDollar[3].node.(*NumberLiteral); ok {
|
||||
yylex.(*parser).addOffset(yyDollar[1].node, time.Duration(numLit.Val*1000)*time.Millisecond)
|
||||
yylex.(*parser).addOffset(yyDollar[1].node, time.Duration(math.Round(numLit.Val*float64(time.Second))))
|
||||
yyVAL.node = yyDollar[1].node
|
||||
break
|
||||
}
|
||||
@ -1423,7 +1423,7 @@ yydefault:
|
||||
|
||||
var rangeNl time.Duration
|
||||
if numLit, ok := yyDollar[3].node.(*NumberLiteral); ok {
|
||||
rangeNl = time.Duration(numLit.Val*1000) * time.Millisecond
|
||||
rangeNl = time.Duration(math.Round(numLit.Val * float64(time.Second)))
|
||||
}
|
||||
rangeExpr, _ := yyDollar[3].node.(*DurationExpr)
|
||||
yyVAL.node = &MatrixSelector{
|
||||
@ -1439,11 +1439,11 @@ yydefault:
|
||||
var rangeNl time.Duration
|
||||
var stepNl time.Duration
|
||||
if numLit, ok := yyDollar[3].node.(*NumberLiteral); ok {
|
||||
rangeNl = time.Duration(numLit.Val*1000) * time.Millisecond
|
||||
rangeNl = time.Duration(math.Round(numLit.Val * float64(time.Second)))
|
||||
}
|
||||
rangeExpr, _ := yyDollar[3].node.(*DurationExpr)
|
||||
if numLit, ok := yyDollar[5].node.(*NumberLiteral); ok {
|
||||
stepNl = time.Duration(numLit.Val*1000) * time.Millisecond
|
||||
stepNl = time.Duration(math.Round(numLit.Val * float64(time.Second)))
|
||||
}
|
||||
stepExpr, _ := yyDollar[5].node.(*DurationExpr)
|
||||
yyVAL.node = &SubqueryExpr{
|
||||
@ -1460,7 +1460,7 @@ yydefault:
|
||||
{
|
||||
var rangeNl time.Duration
|
||||
if numLit, ok := yyDollar[3].node.(*NumberLiteral); ok {
|
||||
rangeNl = time.Duration(numLit.Val*1000) * time.Millisecond
|
||||
rangeNl = time.Duration(math.Round(numLit.Val * float64(time.Second)))
|
||||
}
|
||||
rangeExpr, _ := yyDollar[3].node.(*DurationExpr)
|
||||
yyVAL.node = &SubqueryExpr{
|
||||
|
@ -2008,6 +2008,57 @@ var testExpr = []struct {
|
||||
errMsg: `unexpected "}" in label matching, expected string`,
|
||||
},
|
||||
// Test matrix selector.
|
||||
{
|
||||
input: "test[1000ms]",
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "test",
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "test"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 4,
|
||||
},
|
||||
},
|
||||
Range: 1000 * time.Millisecond,
|
||||
EndPos: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "test[1001ms]",
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "test",
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "test"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 4,
|
||||
},
|
||||
},
|
||||
Range: 1001 * time.Millisecond,
|
||||
EndPos: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "test[1002ms]",
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "test",
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "test"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 4,
|
||||
},
|
||||
},
|
||||
Range: 1002 * time.Millisecond,
|
||||
EndPos: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "test[5s]",
|
||||
expected: &MatrixSelector{
|
||||
|
41
promql/promqltest/testdata/functions.test
vendored
41
promql/promqltest/testdata/functions.test
vendored
@ -1019,6 +1019,47 @@ eval instant at 1m sum_over_time(metric[2m])
|
||||
eval instant at 1m avg_over_time(metric[2m])
|
||||
{} 0.5
|
||||
|
||||
# Test per-series aggregation on dense samples.
|
||||
clear
|
||||
load 1ms
|
||||
metric 1+0x4000
|
||||
|
||||
eval instant at 4s sum_over_time(metric[1000ms])
|
||||
{} 1000
|
||||
|
||||
eval instant at 4s sum_over_time(metric[1001ms])
|
||||
{} 1001
|
||||
|
||||
eval instant at 4s sum_over_time(metric[1002ms])
|
||||
{} 1002
|
||||
|
||||
eval instant at 4s sum_over_time(metric[1003ms])
|
||||
{} 1003
|
||||
|
||||
eval instant at 4s sum_over_time(metric[2000ms])
|
||||
{} 2000
|
||||
|
||||
eval instant at 4s sum_over_time(metric[2001ms])
|
||||
{} 2001
|
||||
|
||||
eval instant at 4s sum_over_time(metric[2002ms])
|
||||
{} 2002
|
||||
|
||||
eval instant at 4s sum_over_time(metric[2003ms])
|
||||
{} 2003
|
||||
|
||||
eval instant at 4s sum_over_time(metric[3000ms])
|
||||
{} 3000
|
||||
|
||||
eval instant at 4s sum_over_time(metric[3001ms])
|
||||
{} 3001
|
||||
|
||||
eval instant at 4s sum_over_time(metric[3002ms])
|
||||
{} 3002
|
||||
|
||||
eval instant at 4s sum_over_time(metric[3003ms])
|
||||
{} 3003
|
||||
|
||||
# Tests for stddev_over_time and stdvar_over_time.
|
||||
clear
|
||||
load 10s
|
||||
|
Loading…
Reference in New Issue
Block a user