mirror of
https://github.com/prometheus/prometheus
synced 2024-12-23 23:13:11 +00:00
Deprecate duration token
Signed-off-by: darshanime <deathbullet@gmail.com>
This commit is contained in:
parent
8c8860d2d6
commit
cfad8ff3b2
@ -43,7 +43,6 @@ import (
|
||||
int int64
|
||||
uint uint64
|
||||
float float64
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
|
||||
@ -176,8 +175,7 @@ START_METRIC_SELECTOR
|
||||
%type <int> int
|
||||
%type <uint> uint
|
||||
%type <float> number series_value signed_number signed_or_unsigned_number
|
||||
%type <node> step_invariant_expr aggregate_expr aggregate_modifier bin_modifier binary_expr bool_modifier expr function_call function_call_args function_call_body group_modifiers label_matchers matrix_selector number_literal offset_expr on_or_ignoring paren_expr string_literal subquery_expr unary_expr vector_selector
|
||||
%type <duration> duration maybe_duration
|
||||
%type <node> step_invariant_expr aggregate_expr aggregate_modifier bin_modifier binary_expr bool_modifier expr function_call function_call_args function_call_body group_modifiers label_matchers matrix_selector number_duration_literal offset_expr on_or_ignoring paren_expr string_literal subquery_expr unary_expr vector_selector
|
||||
|
||||
%start start
|
||||
|
||||
@ -218,7 +216,7 @@ expr :
|
||||
| binary_expr
|
||||
| function_call
|
||||
| matrix_selector
|
||||
| number_literal
|
||||
| number_duration_literal
|
||||
| offset_expr
|
||||
| paren_expr
|
||||
| string_literal
|
||||
@ -415,18 +413,22 @@ paren_expr : LEFT_PAREN expr RIGHT_PAREN
|
||||
* Offset modifiers.
|
||||
*/
|
||||
|
||||
offset_expr: expr OFFSET duration
|
||||
offset_expr: expr OFFSET number_duration_literal
|
||||
{
|
||||
yylex.(*parser).addOffset($1, $3)
|
||||
$$ = $1
|
||||
numLit, _ := $3.(*NumberLiteral)
|
||||
dur := time.Duration(numLit.Val * 1000) * time.Millisecond
|
||||
yylex.(*parser).addOffset($1, dur)
|
||||
$$ = $1
|
||||
}
|
||||
| expr OFFSET SUB duration
|
||||
| expr OFFSET SUB number_duration_literal
|
||||
{
|
||||
yylex.(*parser).addOffset($1, -$4)
|
||||
$$ = $1
|
||||
numLit, _ := $4.(*NumberLiteral)
|
||||
dur := time.Duration(numLit.Val * 1000) * time.Millisecond
|
||||
yylex.(*parser).addOffset($1, -dur)
|
||||
$$ = $1
|
||||
}
|
||||
| expr OFFSET error
|
||||
{ yylex.(*parser).unexpected("offset", "duration"); $$ = $1 }
|
||||
{ yylex.(*parser).unexpected("offset", "integer or duration"); $$ = $1 }
|
||||
;
|
||||
/*
|
||||
* @ modifiers.
|
||||
@ -452,7 +454,7 @@ at_modifier_preprocessors: START | END;
|
||||
* Subquery and range selectors.
|
||||
*/
|
||||
|
||||
matrix_selector : expr LEFT_BRACKET duration RIGHT_BRACKET
|
||||
matrix_selector : expr LEFT_BRACKET number_duration_literal RIGHT_BRACKET
|
||||
{
|
||||
var errMsg string
|
||||
vs, ok := $1.(*VectorSelector)
|
||||
@ -469,32 +471,44 @@ matrix_selector : expr LEFT_BRACKET duration RIGHT_BRACKET
|
||||
yylex.(*parser).addParseErrf(errRange, errMsg)
|
||||
}
|
||||
|
||||
numLit, _ := $3.(*NumberLiteral)
|
||||
$$ = &MatrixSelector{
|
||||
VectorSelector: $1.(Expr),
|
||||
Range: $3,
|
||||
Range: time.Duration(numLit.Val * 1000) * time.Millisecond,
|
||||
EndPos: yylex.(*parser).lastClosing,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
subquery_expr : expr LEFT_BRACKET duration COLON maybe_duration RIGHT_BRACKET
|
||||
subquery_expr : expr LEFT_BRACKET number_duration_literal COLON number_duration_literal RIGHT_BRACKET
|
||||
{
|
||||
numLitRange, _ := $3.(*NumberLiteral)
|
||||
numLitStep, _ := $5.(*NumberLiteral)
|
||||
$$ = &SubqueryExpr{
|
||||
Expr: $1.(Expr),
|
||||
Range: $3,
|
||||
Step: $5,
|
||||
|
||||
Range: time.Duration(numLitRange.Val * 1000) * time.Millisecond,
|
||||
Step: time.Duration(numLitStep.Val * 1000) * time.Millisecond,
|
||||
EndPos: $6.Pos + 1,
|
||||
}
|
||||
}
|
||||
| expr LEFT_BRACKET duration COLON duration error
|
||||
| expr LEFT_BRACKET number_duration_literal COLON RIGHT_BRACKET
|
||||
{
|
||||
numLitRange, _ := $3.(*NumberLiteral)
|
||||
$$ = &SubqueryExpr{
|
||||
Expr: $1.(Expr),
|
||||
Range: time.Duration(numLitRange.Val * 1000) * time.Millisecond,
|
||||
Step: 0,
|
||||
EndPos: $5.Pos + 1,
|
||||
}
|
||||
}
|
||||
| expr LEFT_BRACKET number_duration_literal COLON number_duration_literal error
|
||||
{ yylex.(*parser).unexpected("subquery selector", "\"]\""); $$ = $1 }
|
||||
| expr LEFT_BRACKET duration COLON error
|
||||
{ yylex.(*parser).unexpected("subquery selector", "duration or \"]\""); $$ = $1 }
|
||||
| expr LEFT_BRACKET duration error
|
||||
| expr LEFT_BRACKET number_duration_literal COLON error
|
||||
{ yylex.(*parser).unexpected("subquery selector", "number/duration or \"]\""); $$ = $1 }
|
||||
| expr LEFT_BRACKET number_duration_literal error
|
||||
{ yylex.(*parser).unexpected("subquery or range", "\":\" or \"]\""); $$ = $1 }
|
||||
| expr LEFT_BRACKET error
|
||||
{ yylex.(*parser).unexpected("subquery selector", "duration"); $$ = $1 }
|
||||
{ yylex.(*parser).unexpected("subquery selector", "number/duration"); $$ = $1 }
|
||||
;
|
||||
|
||||
/*
|
||||
@ -866,12 +880,25 @@ match_op : EQL | NEQ | EQL_REGEX | NEQ_REGEX ;
|
||||
* Literals.
|
||||
*/
|
||||
|
||||
number_literal : NUMBER
|
||||
number_duration_literal : NUMBER
|
||||
{
|
||||
$$ = &NumberLiteral{
|
||||
$$ = &NumberLiteral{
|
||||
Val: yylex.(*parser).number($1.Val),
|
||||
PosRange: $1.PositionRange(),
|
||||
}
|
||||
}
|
||||
| DURATION
|
||||
{
|
||||
var err error
|
||||
var dur time.Duration
|
||||
dur, err = parseDuration($1.Val)
|
||||
if err != nil {
|
||||
yylex.(*parser).addParseErr($1.PositionRange(), err)
|
||||
}
|
||||
$$ = &NumberLiteral{
|
||||
Val: dur.Seconds(),
|
||||
PosRange: $1.PositionRange(),
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@ -897,21 +924,6 @@ int : SUB uint { $$ = -int64($2) }
|
||||
| uint { $$ = int64($1) }
|
||||
;
|
||||
|
||||
duration : DURATION
|
||||
{
|
||||
var err error
|
||||
$$, err = parseDuration($1.Val)
|
||||
if err != nil {
|
||||
yylex.(*parser).addParseErr($1.PositionRange(), err)
|
||||
}
|
||||
}
|
||||
| number
|
||||
{
|
||||
$$ = yylex.(*parser).parseNumberLiteral($1);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
string_literal : STRING
|
||||
{
|
||||
$$ = &StringLiteral{
|
||||
@ -935,11 +947,6 @@ string_identifier : STRING
|
||||
* Wrappers for optional arguments.
|
||||
*/
|
||||
|
||||
maybe_duration : /* empty */
|
||||
{$$ = 0}
|
||||
| duration
|
||||
;
|
||||
|
||||
maybe_grouping_labels: /* empty */ { $$ = nil }
|
||||
| grouping_labels
|
||||
;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -849,10 +849,6 @@ func parseDuration(ds string) (time.Duration, error) {
|
||||
return time.Duration(dur), nil
|
||||
}
|
||||
|
||||
func (p *parser) parseNumberLiteral(ts float64) time.Duration {
|
||||
return time.Duration(ts * float64(time.Second))
|
||||
}
|
||||
|
||||
// parseGenerated invokes the yacc generated parser.
|
||||
// The generated parser gets the provided startSymbol injected into
|
||||
// the lexer stream, based on which grammar will be used.
|
||||
|
@ -2152,6 +2152,96 @@ var testExpr = []struct {
|
||||
EndPos: 27,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `foo[3ms] @ 2.345`,
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "foo",
|
||||
Timestamp: makeInt64Pointer(2345),
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "foo"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 3,
|
||||
},
|
||||
},
|
||||
Range: 3 * time.Millisecond,
|
||||
EndPos: 16,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `foo[4s180ms] @ 2.345`,
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "foo",
|
||||
Timestamp: makeInt64Pointer(2345),
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "foo"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 3,
|
||||
},
|
||||
},
|
||||
Range: 4*time.Second + 180*time.Millisecond,
|
||||
EndPos: 20,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `foo[4.18] @ 2.345`,
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "foo",
|
||||
Timestamp: makeInt64Pointer(2345),
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "foo"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 3,
|
||||
},
|
||||
},
|
||||
Range: 4*time.Second + 180*time.Millisecond,
|
||||
EndPos: 17,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `foo[4s18ms] @ 2.345`,
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "foo",
|
||||
Timestamp: makeInt64Pointer(2345),
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "foo"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 3,
|
||||
},
|
||||
},
|
||||
Range: 4*time.Second + 18*time.Millisecond,
|
||||
EndPos: 19,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `foo[4.018] @ 2.345`,
|
||||
expected: &MatrixSelector{
|
||||
VectorSelector: &VectorSelector{
|
||||
Name: "foo",
|
||||
Timestamp: makeInt64Pointer(2345),
|
||||
LabelMatchers: []*labels.Matcher{
|
||||
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "foo"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 3,
|
||||
},
|
||||
},
|
||||
Range: 4*time.Second + 18*time.Millisecond,
|
||||
EndPos: 18,
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `test{a="b"}[5y] @ 1603774699`,
|
||||
expected: &MatrixSelector{
|
||||
@ -2245,7 +2335,7 @@ var testExpr = []struct {
|
||||
{
|
||||
input: `some_metric[5m] OFFSET`,
|
||||
fail: true,
|
||||
errMsg: "unexpected end of input in offset, expected duration",
|
||||
errMsg: "unexpected end of input in offset, expected integer or duration",
|
||||
},
|
||||
{
|
||||
input: `some_metric OFFSET 1m[5m]`,
|
||||
|
6
promql/promqltest/testdata/functions.test
vendored
6
promql/promqltest/testdata/functions.test
vendored
@ -244,10 +244,16 @@ eval instant at 50m deriv(testcounter_reset_middle[100m])
|
||||
eval instant at 50m predict_linear(testcounter_reset_middle[50m], 3600)
|
||||
{} 76.81818181818181
|
||||
|
||||
eval instant at 50m predict_linear(testcounter_reset_middle[50m], 1h)
|
||||
{} 76.81818181818181
|
||||
|
||||
# intercept at t = 3000+3600 = 6600
|
||||
eval instant at 50m predict_linear(testcounter_reset_middle[50m] @ 3000, 3600)
|
||||
{} 76.81818181818181
|
||||
|
||||
eval instant at 50m predict_linear(testcounter_reset_middle[50m] @ 3000, 1h)
|
||||
{} 76.81818181818181
|
||||
|
||||
# intercept at t = 600+3600 = 4200
|
||||
eval instant at 10m predict_linear(testcounter_reset_middle[50m] @ 3000, 3600)
|
||||
{} 51.36363636363637
|
||||
|
Loading…
Reference in New Issue
Block a user