Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.

Commit 7f59cea

Browse files
authored
Merge pull request #29 from ovh/fix/antlr/uptodate
Fix/antlr/uptodate
2 parents cfc2074 + ba24053 commit 7f59cea

File tree

4 files changed

+98
-10
lines changed

4 files changed

+98
-10
lines changed

antlr/tsl.expr

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,42 @@ select('foo').add(1).timemodulo(100, "mod")
197197

198198
mySelect.renameLabelValue("dc", "lg.*", "new-dc")
199199

200-
add(mySelect.add(1), select('foo').add(1).timemodulo(100, "mod"))
200+
add(mySelect.add(1), select('foo').add(1).timemodulo(100, "mod"))
201+
202+
select('foo').abs()
203+
select('foo').resets()
204+
205+
select('foo').finite()
206+
207+
select('foo').keepLastValues()
208+
select('foo').keepLastValues(10)
209+
select('foo').keepFirstValues(10)
210+
select('foo').keepFirstValues()
211+
212+
select('foo').timesplit(now, 42, 'test')
213+
select('foo').timesplit(1h, 4, 'test')
214+
select('foo').timesplit(20000000, 1, 'test')
215+
select('foo').timemodulo(42, "quotient")
216+
select('foo').timeclip(now, 200000)
217+
select('foo').timeclip(1535641320000000, 2m)
218+
select('foo').timeclip("2018-04-22T00:57:00-05:00", "2018-04-22T01:00:00-05:00")
219+
220+
select('foo').quantize("quantile", 0.1)
221+
select('foo').quantize("quantile", 0.1, 2m)
222+
select('foo').quantize("quantile",[ 0, 10 ], 2m)
223+
select('foo').quantize("quantile",[ 0, 10 ])
224+
225+
select('foo').tolong()
226+
select('foo').toboolean()
227+
select('foo').todouble()
228+
select('foo').tostring()
229+
230+
select("sys.cpu.nice")
231+
.from(1346846400000000,1346847000006000)
232+
.sampleBy(span=1m, aggregator="mean", fill=fill(0), relative=false)
233+
234+
235+
create(series("name"), series("name"))
236+
237+
create(series("test").setLabels(["l0=42","l1=42"]).setValues(now, [ -5m, 2], [0, 1]).setValues(now,[ 2m, 3]), series("test2").setLabels(["l0=42","l1=42"]).setValues(now, [-5m, 2], [0, 1]))
238+
.sampleBy(30s, max)

antlr/tsl.g4

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,30 @@ expr: selectExpr
1919
| connectExpr (DOT selectExpr)?
2020
| opExpr
2121
| form
22+
| createExpr
2223
;
2324

25+
// Create a Time series set statement
26+
createExpr: CREATE LPAREN createSeries (COMMA createSeries)* RPAREN (seriesOperations)*
27+
;
28+
29+
// Internal create statement to create a single series
30+
createSeries: SERIES LPAREN (STRING|IDENT) RPAREN (DOT postSeries)*
31+
;
32+
33+
// Internal create statement to fill a single series
34+
postSeries: setLabels | setValues
35+
;
36+
37+
// Internal create statement to set a series labels
38+
setLabels: SETLABELS LPAREN (STRING_LIST | EMPTY_LIST | STRING | IDENT) RPAREN
39+
;
40+
41+
// Internal create statement to set a series values
42+
setValues: SETVALUES LPAREN (NUMBER|IDENT|NOW COMMA)? ('[' WS* (NUMBER|DURATIONVAL|IDENT) (COMMA (NUMBER|DURATIONVAL|IDENT))* WS* ']') (COMMA '[' WS* (NUMBER|DURATIONVAL|IDENT) (COMMA (NUMBER|DURATIONVAL|IDENT))* WS* ']')* RPAREN
43+
;
44+
45+
// Declare a variable statement
2446
form: IDENT '=' expr
2547
| IDENT '=' basic
2648
| IDENT seriesOperations*
@@ -105,7 +127,11 @@ sampleParam: fillSampling | COMMA spanSampling | COMMA countSampling | relativeS
105127
;
106128

107129
// Sampling fill param
108-
fillSampling: COMMA ('fill' '=')? fill=(STRING|STRING_LIST|EMPTY_LIST|IDENT)
130+
fillSampling: COMMA (('fill' '=')? fillvalue=(STRING|STRING_LIST|EMPTY_LIST|IDENT) | ('fill' '=')? fillMethod)
131+
;
132+
133+
// Internal fill method (to fill data by a value)
134+
fillMethod:FILL LPAREN (NUMBER | DURATIONVAL | STRING | TRUE | FALSE | IDENT ) RPAREN
109135
;
110136

111137
// Sampling relative param
@@ -141,7 +167,6 @@ windowAggregators: DELTA | STDDEV | STDVAR
141167
| aggregators
142168
;
143169

144-
145170
// Aggregators available for operations like sampling, grouping
146171
aggregators: MIN | MAX | MEAN | FIRST | LAST | SUM | (STRING | IDENT) COMMA JOIN | MEDIAN | COUNT | ANDL | ORL | NUMBER COMMA PERCENTILE | STRING | IDENT
147172
;
@@ -152,23 +177,26 @@ arithmeticOperationWithParam: DOT arithmeticOperatorWithParam LPAREN value=(NUMB
152177

153178
// Arithmetic operator with a single number parameter
154179
arithmeticOperatorWithParam: (ADDSERIES | SUBSERIES | MULSERIES | DIVSERIES | LOGN | EQUAL | NOTEQUAL | GREATERTHAN | GREATEROREQUAL | LESSTHAN
155-
| LESSOREQUAL | MAXWITH | MINWITH | TOPN | BOTTOMN | SHRINK | TIMESCALE)
180+
| LESSOREQUAL | MAXWITH | MINWITH | TOPN | BOTTOMN | SHRINK | TIMESCALE | KEEPFIRSTVALUES | KEEPLASTVALUES )
156181
;
157182

158183
// Simple operations
159184
simpleOperation: DOT simpleOperator LPAREN RPAREN
160185
;
161186

162187
// Operator that does not require a parameter
163-
simpleOperator: ABS CEIL CUMULATIVESUM FLOOR RESETS ROUND LN LOG2 LOG10 SQRT DAY WEEKDAY HOUR MINUTE MONTH YEAR TIMESTAMP SORT SORTDESC
188+
simpleOperator: ABS | CEIL | CUMULATIVESUM | FLOOR | FINITE | RESETS | ROUND | LN | LOG2 | LOG10 | SQRT | DAY | WEEKDAY | HOUR | MINUTE
189+
| MONTH | YEAR | TIMESTAMP | SORT | SORTDESC | KEEPFIRSTVALUES | KEEPLASTVALUES | TOLONG | TOBOOLEAN | TODOUBLE | TOSTRING
164190
;
165191

166192
// Operation with a single string parameter
167193
stringOperation: DOT stringOperator LPAREN value=(STRING|IDENT) RPAREN
168194
;
169195

196+
// Time series set operator expecting a string parameter
170197
stringOperator: ADDNAMEPREFIX | ADDNAMESUFFIX | RENAME | RENAMEBY | STORE | FILTERBYNAME | FILTERBYLASTVALUE
171198
;
199+
172200
// Complex operation fix the grammar rule for unique TSL functions as
173201
// - rate
174202
// - shift
@@ -185,9 +213,10 @@ complexOperation: DOT RATE LPAREN (DURATIONVAL|IDENT)? RPAREN
185213
| DOT (REMOVELABELS|FILTERBYLABELS) LPAREN (STRING|IDENT) (COMMA (STRING|IDENT))* RPAREN
186214
| DOT RENAMELABELKEY LPAREN (STRING|IDENT) COMMA (STRING|IDENT) RPAREN
187215
| DOT RENAMELABELVALUE LPAREN (STRING|IDENT) COMMA (STRING|IDENT) (COMMA (STRING|IDENT))? RPAREN
188-
| DOT TIMECLIP LPAREN (NUMBER|IDENT) COMMA (NUMBER|IDENT) RPAREN
216+
| DOT TIMECLIP LPAREN (NUMBER|IDENT|NOW|STRING) COMMA (NUMBER|IDENT|DURATIONVAL|STRING) RPAREN
189217
| DOT TIMEMODULO LPAREN (NUMBER|IDENT) COMMA (STRING|IDENT) RPAREN
190-
| DOT TIMESPLIT LPAREN (NUMBER|DURATIONVAL) COMMA (NUMBER|IDENT) COMMA (STRING|IDENT) RPAREN
218+
| DOT TIMESPLIT LPAREN (NUMBER|DURATIONVAL|NOW|IDENT) COMMA (NUMBER|IDENT) COMMA (STRING|IDENT) RPAREN
219+
| DOT QUANTIZE LPAREN (STRING|IDENT) COMMA (('[' WS* (NUMBER|IDENT) (COMMA (NUMBER|IDENT))* WS* ']')|EMPTY_LIST|NUMBER|IDENT|) (COMMA (DURATIONVAL|IDENT))? RPAREN
191220
;
192221

193222
// Apply a multiple operations between several statements results

antlr/tslTokens.g4

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ lexer grammar tslTokens; // note "TSL tokens"
22

33
// TSL native types and tokens
44
DURATIONVAL: INT_LIT ([wdhms]|'ms'|'us'|'ns'|'ps')
5+
| '-' INT_LIT ([wdhms]|'ms'|'us'|'ns'|'ps')
56
;
67

8+
9+
710
NUMBER: INT_LIT
811
| FLOAT_LIT
12+
| '-' INT_LIT
13+
| '-' FLOAT_LIT
914
;
1015

1116
STRING: RAW_STRING_LIT
@@ -38,15 +43,18 @@ BOTTOMNBY: 'bottomNBy';
3843
CEIL: 'ceil';
3944
CONNECT: 'connect';
4045
COUNT: 'count';
46+
CREATE: 'create';
4147
CUMULATIVE: 'cumulative';
4248
CUMULATIVESUM: 'cumulativeSum';
4349
DAY: 'day';
4450
DELTA: 'delta';
4551
DIVSERIES: 'div';
4652
EQUAL: 'equal';
53+
FILL: 'fill';
4754
FILTERBYLABELS: 'filterByLabels';
4855
FILTERBYNAME: 'filterByName';
4956
FILTERBYLASTVALUE: 'filterByLastValue';
57+
FINITE: 'finite';
5058
FIRST: 'first';
5159
FLOOR: 'floor';
5260
FROM: 'from';
@@ -60,6 +68,8 @@ GROUPWITHOUT: 'groupWithout';
6068
HOUR: 'hour';
6169
IGNORING: 'ignoring';
6270
JOIN: 'join';
71+
KEEPFIRSTVALUES: 'keepFirstValues';
72+
KEEPLASTVALUES: 'keepLastValues';
6373
LAST: 'last';
6474
LABELS: 'labels';
6575
LESSOREQUAL: 'lessOrEqual';
@@ -80,12 +90,14 @@ MONTH: 'month';
8090
MULSERIES: 'mul';
8191
NEGMASK: 'negmask';
8292
NOTEQUAL: 'notEqual';
93+
NOW: 'now';
8394
NAMES: 'names';
8495
ON: 'on';
8596
ORL: 'or';
8697
PERCENTILE: 'percentile';
8798
PROM: 'prom';
8899
PROMETHEUS: 'prometheus';
100+
QUANTIZE: 'quantize';
89101
RATE: 'rate';
90102
REMOVELABELS: 'removeLabels';
91103
REMOVE: 'remove';
@@ -99,6 +111,9 @@ SAMPLE: 'sample';
99111
SAMPLEBY: 'sampleBy';
100112
SELECT: 'select';
101113
SELECTORS: 'selectors';
114+
SERIES: 'series';
115+
SETLABELS: 'setLabels';
116+
SETVALUES: 'setValues';
102117
SHIFT: 'shift';
103118
SHRINK: 'shrink';
104119
SORT: 'sort';
@@ -111,8 +126,12 @@ STDVAR: 'stdvar';
111126
STORE: 'store';
112127
SUBSERIES: 'sub';
113128
SUM: 'sum';
129+
TOBOOLEAN: 'toboolean';
130+
TODOUBLE: 'todouble';
131+
TOLONG: 'tolong';
114132
TOPN: 'topN';
115133
TOPNBY: 'topNBy';
134+
TOSTRING: 'tostring';
116135
TIMECLIP: 'timeclip';
117136
TIMEMODULO: 'timemodulo';
118137
TIMESTAMP: 'timestamp';

spec/doc.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ The following TSL methods can be used to apply arithmetic operators on metrics:
429429
* The **logN** operator. Compute values logN of the **number parameter**, example: _.logN(2)_
430430
* The **rate** operator. Compute a **rate** (by default per second when no parameter are sets) or on a specify duration, example: _.rate()_, _.rate(1m)_
431431
* The **sqrt** operator. Compute values **square root**, example: _.sqrt()_
432-
* The **quantize** operator. Compute the amount of **values** inside a **step** on the complete query range or per parameter duration. This generate a single metric per step, based on the label key specified as first parameter. The second parameter corresponds to the step value: it can be a single number or integer value, or a fix step set modelised as a number or integer list. The last optional parameter for the quantize method is the quantize duration. This method can be useful to compute histograms, use example: _.quantize("quantile", [ 0, 10 ], 2m))_, _.quantize("quantile", 0.1))_
432+
* The **quantize** operator. Compute the amount of **values** inside a **step** on the complete query range or per parameter duration. This generate a single metric per step, based on the label key specified as first parameter. The second parameter corresponds to the step value: it can be a single number or integer value, or a fix step set modelised as a number or integer list. The last optional parameter for the quantize method is the quantize duration. This method can be useful to compute histograms, use example: _.quantize("quantile", [ 0, 10 ], 2m)_, _.quantize("quantile", 0.1)_
433433

434434
> The **logN** operator is not available on **Prometheus**.
435435
@@ -735,12 +735,14 @@ The **series** method is used to create a Time Series, only in Warp 10 for now,
735735

736736
The **setValues** takes n parameter, the first one (optional) is the base Timestamp of the values (by default zero). Then the other are a two elements array composed of a timestamp (that would be add to the base one) and the value to set. Use example: _.setValues([0, 1], [100, 2])._
737737

738-
At the end of the create statement, all other Time Series method can be apply on.
738+
The **setLabels** takes a single parameter: a labels string list where the key and values are split per the equals symbol.
739+
740+
At the end of the create statement, all other Time Series set methods can be apply on.
739741

740742
A more complex but valid tsl statement to create 2 Time Series would be:
741743

742744
```tsl
743-
create(series("test").setLabels(["l0=42","l1=42"]).setValues("now", [-5m, 2], [0, 1]).setValues("now",[2m, 3]),series("test2").setLabels(["l0=42","l1=42"]).setValues("now", [-5m, 2], [0, 1]))
745+
create(series("test").setLabels(["l0=42","l1=42"]).setValues("now", [-5m, 2], [0, 1]).setValues("now",[2m, 3]),series("test2").setLabels(["l0=42","l1=42"]).setValues(now, [-5m, 2], [0, 1]))
744746
.sampleBy(30s, max)
745747
```
746748

0 commit comments

Comments
 (0)