Browse Source

promqltest: add support for setting counter reset hint on histogram samples (#14537)

* promqltest: add support for setting counter reset hint on histogram samples

Signed-off-by: Charles Korn <charles.korn@grafana.com>
pull/14538/head
Charles Korn 4 months ago committed by GitHub
parent
commit
7fab72a280
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      docs/configuration/unit_testing_rules.md
  2. 17
      promql/parser/generated_parser.y
  3. 779
      promql/parser/generated_parser.y.go
  4. 33
      promql/parser/lex.go
  5. 22
      promql/parser/parse.go
  6. 75
      promql/parser/parse_test.go

4
docs/configuration/unit_testing_rules.md

@ -92,7 +92,7 @@ series: <string>
#
# Native histogram notation:
# Native histograms can be used instead of floating point numbers using the following notation:
# {{schema:1 sum:-0.3 count:3.1 z_bucket:7.1 z_bucket_w:0.05 buckets:[5.1 10 7] offset:-3 n_buckets:[4.1 5] n_offset:-5}}
# {{schema:1 sum:-0.3 count:3.1 z_bucket:7.1 z_bucket_w:0.05 buckets:[5.1 10 7] offset:-3 n_buckets:[4.1 5] n_offset:-5 counter_reset_hint:gauge}}
# Native histograms support the same expanding notation as floating point numbers, i.e. 'axn', 'a+bxn' and 'a-bxn'.
# All properties are optional and default to 0. The order is not important. The following properties are supported:
# - schema (int):
@ -119,6 +119,8 @@ series: <string>
# Observation counts in negative buckets. Each represents an absolute count.
# - n_offset (int):
# The starting index of the first entry in the negative buckets.
# - counter_reset_hint (one of 'unknown', 'reset', 'not_reset' or 'gauge')
# The counter reset hint associated with this histogram. Defaults to 'unknown' if not set.
values: <string>
```

17
promql/parser/generated_parser.y

@ -84,6 +84,7 @@ NEGATIVE_BUCKETS_DESC
ZERO_BUCKET_DESC
ZERO_BUCKET_WIDTH_DESC
CUSTOM_VALUES_DESC
COUNTER_RESET_HINT_DESC
%token histogramDescEnd
// Operators.
@ -149,6 +150,14 @@ START
END
%token preprocessorEnd
// Counter reset hints.
%token counterResetHintsStart
%token <item>
UNKNOWN_COUNTER_RESET
COUNTER_RESET
NOT_COUNTER_RESET
GAUGE_TYPE
%token counterResetHintsEnd
// Start symbols for the generated parser.
%token startSymbolsStart
@ -163,7 +172,7 @@ START_METRIC_SELECTOR
// Type definitions for grammar rules.
%type <matchers> label_match_list
%type <matcher> label_matcher
%type <item> aggregate_op grouping_label match_op maybe_label metric_identifier unary_op at_modifier_preprocessors string_identifier
%type <item> aggregate_op grouping_label match_op maybe_label metric_identifier unary_op at_modifier_preprocessors string_identifier counter_reset_hint
%type <labels> label_set metric
%type <lblList> label_set_list
%type <label> label_set_item
@ -839,6 +848,11 @@ histogram_desc_item
$$ = yylex.(*parser).newMap()
$$["n_offset"] = $3
}
| COUNTER_RESET_HINT_DESC COLON counter_reset_hint
{
$$ = yylex.(*parser).newMap()
$$["counter_reset_hint"] = $3
}
;
bucket_set : LEFT_BRACKET bucket_set_list SPACE RIGHT_BRACKET
@ -862,6 +876,7 @@ bucket_set_list : bucket_set_list SPACE number
| bucket_set_list error
;
counter_reset_hint : UNKNOWN_COUNTER_RESET | COUNTER_RESET | NOT_COUNTER_RESET | GAUGE_TYPE;
/*
* Keyword lists.

779
promql/parser/generated_parser.y.go

@ -67,64 +67,71 @@ const NEGATIVE_BUCKETS_DESC = 57376
const ZERO_BUCKET_DESC = 57377
const ZERO_BUCKET_WIDTH_DESC = 57378
const CUSTOM_VALUES_DESC = 57379
const histogramDescEnd = 57380
const operatorsStart = 57381
const ADD = 57382
const DIV = 57383
const EQLC = 57384
const EQL_REGEX = 57385
const GTE = 57386
const GTR = 57387
const LAND = 57388
const LOR = 57389
const LSS = 57390
const LTE = 57391
const LUNLESS = 57392
const MOD = 57393
const MUL = 57394
const NEQ = 57395
const NEQ_REGEX = 57396
const POW = 57397
const SUB = 57398
const AT = 57399
const ATAN2 = 57400
const operatorsEnd = 57401
const aggregatorsStart = 57402
const AVG = 57403
const BOTTOMK = 57404
const COUNT = 57405
const COUNT_VALUES = 57406
const GROUP = 57407
const MAX = 57408
const MIN = 57409
const QUANTILE = 57410
const STDDEV = 57411
const STDVAR = 57412
const SUM = 57413
const TOPK = 57414
const LIMITK = 57415
const LIMIT_RATIO = 57416
const aggregatorsEnd = 57417
const keywordsStart = 57418
const BOOL = 57419
const BY = 57420
const GROUP_LEFT = 57421
const GROUP_RIGHT = 57422
const IGNORING = 57423
const OFFSET = 57424
const ON = 57425
const WITHOUT = 57426
const keywordsEnd = 57427
const preprocessorStart = 57428
const START = 57429
const END = 57430
const preprocessorEnd = 57431
const startSymbolsStart = 57432
const START_METRIC = 57433
const START_SERIES_DESCRIPTION = 57434
const START_EXPRESSION = 57435
const START_METRIC_SELECTOR = 57436
const startSymbolsEnd = 57437
const COUNTER_RESET_HINT_DESC = 57380
const histogramDescEnd = 57381
const operatorsStart = 57382
const ADD = 57383
const DIV = 57384
const EQLC = 57385
const EQL_REGEX = 57386
const GTE = 57387
const GTR = 57388
const LAND = 57389
const LOR = 57390
const LSS = 57391
const LTE = 57392
const LUNLESS = 57393
const MOD = 57394
const MUL = 57395
const NEQ = 57396
const NEQ_REGEX = 57397
const POW = 57398
const SUB = 57399
const AT = 57400
const ATAN2 = 57401
const operatorsEnd = 57402
const aggregatorsStart = 57403
const AVG = 57404
const BOTTOMK = 57405
const COUNT = 57406
const COUNT_VALUES = 57407
const GROUP = 57408
const MAX = 57409
const MIN = 57410
const QUANTILE = 57411
const STDDEV = 57412
const STDVAR = 57413
const SUM = 57414
const TOPK = 57415
const LIMITK = 57416
const LIMIT_RATIO = 57417
const aggregatorsEnd = 57418
const keywordsStart = 57419
const BOOL = 57420
const BY = 57421
const GROUP_LEFT = 57422
const GROUP_RIGHT = 57423
const IGNORING = 57424
const OFFSET = 57425
const ON = 57426
const WITHOUT = 57427
const keywordsEnd = 57428
const preprocessorStart = 57429
const START = 57430
const END = 57431
const preprocessorEnd = 57432
const counterResetHintsStart = 57433
const UNKNOWN_COUNTER_RESET = 57434
const COUNTER_RESET = 57435
const NOT_COUNTER_RESET = 57436
const GAUGE_TYPE = 57437
const counterResetHintsEnd = 57438
const startSymbolsStart = 57439
const START_METRIC = 57440
const START_SERIES_DESCRIPTION = 57441
const START_EXPRESSION = 57442
const START_METRIC_SELECTOR = 57443
const startSymbolsEnd = 57444
var yyToknames = [...]string{
"$end",
@ -164,6 +171,7 @@ var yyToknames = [...]string{
"ZERO_BUCKET_DESC",
"ZERO_BUCKET_WIDTH_DESC",
"CUSTOM_VALUES_DESC",
"COUNTER_RESET_HINT_DESC",
"histogramDescEnd",
"operatorsStart",
"ADD",
@ -216,6 +224,12 @@ var yyToknames = [...]string{
"START",
"END",
"preprocessorEnd",
"counterResetHintsStart",
"UNKNOWN_COUNTER_RESET",
"COUNTER_RESET",
"NOT_COUNTER_RESET",
"GAUGE_TYPE",
"counterResetHintsEnd",
"startSymbolsStart",
"START_METRIC",
"START_SERIES_DESCRIPTION",
@ -240,308 +254,313 @@ var yyExca = [...]int16{
24, 137,
-2, 0,
-1, 61,
2, 175,
15, 175,
78, 175,
84, 175,
2, 180,
15, 180,
79, 180,
85, 180,
-2, 101,
-1, 62,
2, 176,
15, 176,
78, 176,
84, 176,
2, 181,
15, 181,
79, 181,
85, 181,
-2, 102,
-1, 63,
2, 177,
15, 177,
78, 177,
84, 177,
2, 182,
15, 182,
79, 182,
85, 182,
-2, 104,
-1, 64,
2, 178,
15, 178,
78, 178,
84, 178,
2, 183,
15, 183,
79, 183,
85, 183,
-2, 105,
-1, 65,
2, 179,
15, 179,
78, 179,
84, 179,
2, 184,
15, 184,
79, 184,
85, 184,
-2, 106,
-1, 66,
2, 180,
15, 180,
78, 180,
84, 180,
2, 185,
15, 185,
79, 185,
85, 185,
-2, 111,
-1, 67,
2, 181,
15, 181,
78, 181,
84, 181,
2, 186,
15, 186,
79, 186,
85, 186,
-2, 113,
-1, 68,
2, 182,
15, 182,
78, 182,
84, 182,
2, 187,
15, 187,
79, 187,
85, 187,
-2, 115,
-1, 69,
2, 183,
15, 183,
78, 183,
84, 183,
2, 188,
15, 188,
79, 188,
85, 188,
-2, 116,
-1, 70,
2, 184,
15, 184,
78, 184,
84, 184,
2, 189,
15, 189,
79, 189,
85, 189,
-2, 117,
-1, 71,
2, 185,
15, 185,
78, 185,
84, 185,
2, 190,
15, 190,
79, 190,
85, 190,
-2, 118,
-1, 72,
2, 186,
15, 186,
78, 186,
84, 186,
2, 191,
15, 191,
79, 191,
85, 191,
-2, 119,
-1, 73,
2, 187,
15, 187,
78, 187,
84, 187,
2, 192,
15, 192,
79, 192,
85, 192,
-2, 123,
-1, 74,
2, 188,
15, 188,
78, 188,
84, 188,
2, 193,
15, 193,
79, 193,
85, 193,
-2, 124,
-1, 200,
9, 237,
12, 237,
13, 237,
18, 237,
19, 237,
25, 237,
40, 237,
46, 237,
47, 237,
50, 237,
56, 237,
61, 237,
62, 237,
63, 237,
64, 237,
65, 237,
66, 237,
67, 237,
68, 237,
69, 237,
70, 237,
71, 237,
72, 237,
73, 237,
74, 237,
78, 237,
82, 237,
84, 237,
87, 237,
88, 237,
9, 242,
12, 242,
13, 242,
18, 242,
19, 242,
25, 242,
41, 242,
47, 242,
48, 242,
51, 242,
57, 242,
62, 242,
63, 242,
64, 242,
65, 242,
66, 242,
67, 242,
68, 242,
69, 242,
70, 242,
71, 242,
72, 242,
73, 242,
74, 242,
75, 242,
79, 242,
83, 242,
85, 242,
88, 242,
89, 242,
-2, 0,
-1, 201,
9, 237,
12, 237,
13, 237,
18, 237,
19, 237,
25, 237,
40, 237,
46, 237,
47, 237,
50, 237,
56, 237,
61, 237,
62, 237,
63, 237,
64, 237,
65, 237,
66, 237,
67, 237,
68, 237,
69, 237,
70, 237,
71, 237,
72, 237,
73, 237,
74, 237,
78, 237,
82, 237,
84, 237,
87, 237,
88, 237,
9, 242,
12, 242,
13, 242,
18, 242,
19, 242,
25, 242,
41, 242,
47, 242,
48, 242,
51, 242,
57, 242,
62, 242,
63, 242,
64, 242,
65, 242,
66, 242,
67, 242,
68, 242,
69, 242,
70, 242,
71, 242,
72, 242,
73, 242,
74, 242,
75, 242,
79, 242,
83, 242,
85, 242,
88, 242,
89, 242,
-2, 0,
}
const yyPrivate = 57344
const yyLast = 728
const yyLast = 763
var yyAct = [...]int16{
155, 331, 329, 275, 336, 152, 226, 39, 192, 44,
289, 288, 156, 118, 82, 178, 55, 106, 6, 53,
77, 109, 56, 133, 108, 22, 54, 110, 107, 172,
300, 198, 57, 199, 200, 201, 60, 111, 326, 151,
325, 302, 321, 308, 266, 154, 55, 75, 128, 105,
291, 300, 160, 18, 19, 309, 54, 20, 307, 218,
105, 320, 159, 76, 113, 306, 114, 330, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 112, 161, 180, 13, 87, 89, 265, 24,
101, 30, 104, 150, 31, 32, 115, 98, 99, 162,
109, 101, 102, 104, 88, 349, 110, 2, 3, 4,
5, 264, 196, 149, 111, 163, 160, 103, 337, 173,
167, 170, 84, 182, 348, 166, 159, 347, 103, 194,
157, 158, 83, 181, 183, 165, 184, 197, 77, 186,
185, 195, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 129, 269, 263,
217, 160, 219, 220, 55, 38, 35, 53, 77, 267,
56, 159, 270, 22, 54, 121, 297, 188, 7, 259,
57, 296, 262, 161, 319, 119, 318, 317, 271, 179,
261, 180, 161, 260, 258, 75, 295, 84, 122, 162,
187, 18, 19, 316, 268, 20, 315, 83, 162, 286,
287, 76, 314, 290, 313, 81, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
182, 86, 292, 13, 55, 10, 312, 24, 311, 30,
181, 183, 31, 32, 54, 79, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 310, 127, 36, 126, 1, 121, 298, 299, 301,
164, 303, 49, 48, 190, 294, 119, 55, 160, 304,
305, 193, 55, 160, 117, 196, 223, 54, 159, 122,
222, 228, 54, 159, 293, 350, 50, 47, 46, 169,
132, 238, 78, 323, 324, 221, 45, 244, 43, 161,
328, 322, 168, 333, 334, 335, 130, 332, 171, 177,
339, 338, 341, 340, 176, 162, 125, 342, 343, 42,
59, 124, 344, 9, 9, 240, 241, 175, 346, 242,
131, 8, 41, 40, 123, 37, 51, 255, 351, 191,
229, 231, 233, 234, 235, 243, 245, 248, 249, 250,
251, 252, 256, 257, 345, 272, 230, 232, 236, 237,
239, 246, 247, 85, 189, 55, 253, 254, 53, 77,
224, 56, 80, 120, 22, 54, 153, 58, 227, 52,
116, 57, 0, 0, 0, 0, 0, 0, 0, 0,
0, 228, 0, 0, 0, 0, 75, 0, 0, 0,
0, 238, 18, 19, 0, 0, 20, 244, 0, 0,
0, 225, 76, 0, 0, 0, 0, 61, 62, 63,
155, 333, 331, 275, 338, 152, 226, 39, 192, 44,
290, 289, 156, 118, 82, 178, 106, 55, 109, 105,
53, 77, 133, 56, 110, 108, 22, 54, 356, 6,
172, 107, 60, 57, 345, 346, 347, 348, 111, 198,
328, 199, 200, 201, 327, 154, 303, 355, 266, 75,
354, 151, 160, 128, 259, 18, 19, 160, 55, 20,
301, 101, 159, 104, 113, 76, 114, 159, 54, 258,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 161, 112, 269, 13, 103, 161,
292, 24, 115, 30, 309, 265, 31, 32, 332, 267,
162, 270, 109, 223, 323, 162, 150, 222, 110, 308,
301, 263, 310, 149, 161, 163, 307, 271, 264, 173,
167, 170, 221, 322, 166, 2, 3, 4, 5, 194,
162, 157, 158, 179, 262, 180, 184, 197, 165, 186,
196, 195, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 129, 188, 121,
217, 121, 219, 220, 55, 38, 218, 53, 77, 119,
56, 119, 339, 22, 54, 182, 169, 260, 298, 117,
57, 187, 122, 297, 122, 181, 183, 160, 295, 168,
261, 180, 111, 77, 164, 55, 75, 159, 296, 357,
7, 55, 18, 19, 268, 54, 20, 294, 35, 287,
288, 54, 76, 291, 321, 320, 319, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 0, 0, 0, 13, 240, 241, 0, 24, 242,
30, 0, 0, 31, 32, 0, 0, 255, 105, 0,
229, 231, 233, 234, 235, 243, 245, 248, 249, 250,
251, 252, 256, 257, 0, 0, 230, 232, 236, 237,
239, 246, 247, 17, 77, 89, 253, 254, 0, 22,
0, 0, 327, 0, 0, 98, 99, 0, 0, 101,
0, 104, 88, 277, 278, 276, 283, 285, 282, 284,
279, 280, 281, 17, 35, 0, 0, 18, 19, 22,
0, 20, 0, 0, 0, 0, 103, 0, 0, 0,
0, 0, 11, 12, 14, 15, 16, 21, 23, 25,
26, 27, 28, 29, 33, 34, 0, 18, 19, 13,
0, 20, 0, 24, 0, 30, 0, 0, 31, 32,
0, 0, 11, 12, 14, 15, 16, 21, 23, 25,
26, 27, 28, 29, 33, 34, 105, 0, 0, 13,
0, 0, 0, 24, 174, 30, 0, 0, 31, 32,
0, 0, 0, 0, 0, 105, 0, 0, 0, 0,
0, 0, 87, 89, 90, 0, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 0, 101, 102, 104,
88, 87, 89, 90, 0, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 274, 101, 102, 104, 88,
105, 0, 273, 0, 103, 0, 277, 278, 276, 283,
285, 282, 284, 279, 280, 281, 0, 0, 0, 105,
0, 0, 0, 103, 0, 0, 87, 89, 90, 0,
91, 92, 93, 0, 95, 96, 97, 98, 99, 100,
74, 182, 293, 318, 13, 160, 317, 316, 24, 315,
30, 181, 183, 31, 32, 159, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
148, 314, 313, 55, 105, 84, 84, 299, 300, 302,
86, 304, 177, 54, 190, 83, 83, 176, 160, 305,
306, 193, 125, 185, 81, 196, 10, 124, 159, 312,
175, 311, 89, 50, 8, 36, 79, 228, 37, 78,
123, 1, 98, 99, 325, 326, 101, 238, 104, 88,
161, 330, 49, 244, 335, 336, 337, 324, 334, 48,
47, 341, 340, 343, 342, 127, 162, 126, 59, 349,
350, 9, 9, 103, 351, 46, 132, 45, 43, 130,
353, 171, 240, 241, 42, 131, 242, 41, 40, 51,
191, 352, 272, 85, 255, 358, 189, 229, 231, 233,
234, 235, 243, 245, 248, 249, 250, 251, 252, 256,
257, 224, 80, 230, 232, 236, 237, 239, 246, 247,
344, 120, 55, 253, 254, 53, 77, 153, 56, 274,
58, 22, 54, 227, 52, 116, 273, 0, 57, 0,
277, 278, 276, 283, 285, 282, 284, 279, 280, 281,
286, 0, 0, 0, 75, 0, 0, 0, 0, 0,
18, 19, 0, 0, 20, 0, 0, 0, 0, 0,
76, 0, 0, 0, 0, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 228,
0, 0, 13, 0, 0, 0, 24, 0, 30, 238,
329, 31, 32, 0, 0, 244, 0, 0, 0, 225,
0, 277, 278, 276, 283, 285, 282, 284, 279, 280,
281, 286, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 240, 241, 0, 0, 242, 0,
0, 0, 17, 77, 0, 105, 255, 0, 22, 229,
231, 233, 234, 235, 243, 245, 248, 249, 250, 251,
252, 256, 257, 0, 0, 230, 232, 236, 237, 239,
246, 247, 87, 89, 0, 253, 254, 18, 19, 0,
0, 20, 0, 98, 99, 17, 35, 101, 102, 104,
88, 22, 11, 12, 14, 15, 16, 21, 23, 25,
26, 27, 28, 29, 33, 34, 0, 0, 0, 13,
0, 0, 0, 24, 103, 30, 0, 0, 31, 32,
18, 19, 0, 0, 20, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 11, 12, 14, 15, 16,
21, 23, 25, 26, 27, 28, 29, 33, 34, 105,
0, 0, 13, 0, 0, 0, 24, 174, 30, 0,
0, 31, 32, 0, 0, 0, 0, 0, 105, 0,
0, 0, 0, 0, 0, 0, 87, 89, 90, 0,
91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
0, 101, 102, 104, 88, 87, 89, 90, 0, 91,
92, 0, 0, 95, 96, 0, 98, 99, 100, 0,
101, 102, 104, 88, 0, 0, 0, 0, 103, 0,
92, 93, 94, 95, 96, 97, 98, 99, 100, 0,
101, 102, 104, 88, 105, 0, 0, 0, 103, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 103,
0, 0, 0, 105, 0, 0, 0, 103, 0, 0,
0, 87, 89, 90, 0, 91, 92, 93, 0, 95,
96, 97, 98, 99, 100, 0, 101, 102, 104, 88,
87, 89, 90, 0, 91, 92, 0, 0, 95, 96,
0, 98, 99, 100, 0, 101, 102, 104, 88, 0,
0, 0, 0, 103, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 103,
}
var yyPact = [...]int16{
16, 168, 501, 501, 155, 471, -1000, -1000, -1000, 153,
27, 190, 533, 533, 155, 490, -1000, -1000, -1000, 195,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, 264, -1000, 268, -1000, 614,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, 195, -1000, 229, -1000, 581,
-1000, -1000, 23, 177, -1000, -1000, 373, -1000, 373, 180,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, 22, 99, -1000, -1000, 366, -1000, 366, 125,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, 159, -1000, -1000,
280, -1000, -1000, 323, -1000, 29, -1000, -56, -56, -56,
-56, -56, -56, -56, -56, -56, -56, -56, -56, -56,
-56, -56, -56, 49, 43, 192, 177, -61, -1000, 174,
174, 8, -1000, 595, 5, -1000, 270, -1000, -1000, 131,
187, -1000, -1000, -1000, 263, -1000, 156, -1000, 269, 373,
-1000, -43, -38, -1000, 373, 373, 373, 373, 373, 373,
373, 373, 373, 373, 373, 373, 373, 373, 373, -1000,
254, -1000, -1000, 151, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, 226, 226, 101, -1000, -1000, -1000, -1000, 447, -1000,
-1000, 47, -1000, 614, -1000, -1000, 157, -1000, 109, -1000,
-1000, -1000, -1000, -1000, 93, -1000, -1000, -1000, -1000, -1000,
22, 73, 60, -1000, -1000, -1000, 372, 250, 174, 174,
174, 174, 5, 5, 491, 491, 491, 679, 660, 491,
491, 679, 5, 5, 491, 5, 250, -1000, 68, -1000,
-1000, -1000, 186, -1000, 176, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, 264, -1000, -1000,
324, -1000, -1000, 260, -1000, 24, -1000, -54, -54, -54,
-54, -54, -54, -54, -54, -54, -54, -54, -54, -54,
-54, -54, -54, 37, 43, 268, 99, -57, -1000, 297,
297, 7, -1000, 562, 35, -1000, 317, -1000, -1000, 187,
80, -1000, -1000, -1000, 120, -1000, 175, -1000, 269, 366,
-1000, -50, -45, -1000, 366, 366, 366, 366, 366, 366,
366, 366, 366, 366, 366, 366, 366, 366, 366, -1000,
225, -1000, -1000, 44, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, 107, 107, 284, -1000, -1000, -1000, -1000, 399, -1000,
-1000, 172, -1000, 581, -1000, -1000, 173, -1000, 157, -1000,
-1000, -1000, -1000, -1000, 86, -1000, -1000, -1000, -1000, -1000,
18, 143, 132, -1000, -1000, -1000, 618, 444, 297, 297,
297, 297, 35, 35, 46, 46, 46, 645, 626, 46,
46, 645, 35, 35, 46, 35, 444, -1000, 28, -1000,
-1000, -1000, 273, -1000, 174, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 373,
-1000, -1000, -1000, -1000, -1000, -1000, 91, 91, 20, 91,
124, 124, 92, 95, -1000, -1000, 285, 283, 256, 255,
233, 231, 230, 227, 210, 209, 208, -1000, -1000, -1000,
-1000, -1000, -1000, 102, -1000, -1000, -1000, 295, -1000, 614,
-1000, -1000, -1000, 91, -1000, 18, 14, 443, -1000, -1000,
-1000, 41, 48, 226, 226, 226, 158, 158, 41, 158,
41, -58, -1000, -1000, -1000, -1000, -1000, 91, 91, -1000,
-1000, -1000, 91, -1000, -1000, -1000, -1000, -1000, -1000, 226,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 366,
-1000, -1000, -1000, -1000, -1000, -1000, 32, 32, 15, 32,
96, 96, 41, 38, -1000, -1000, 255, 232, 230, 208,
206, 200, 197, 181, 180, 178, -1000, -1000, -1000, -1000,
-1000, -1000, 40, -1000, -1000, -1000, 289, -1000, 581, -1000,
-1000, -1000, 32, -1000, 14, 12, 475, -1000, -1000, -1000,
11, 152, 107, 107, 107, 104, 104, 11, 104, 11,
-1000, -1000, -1000, -1000, -1000, 32, 32, -1000, -1000, -1000,
32, -1000, -1000, -1000, -1000, -1000, -1000, 107, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, 103, -1000, 274, -1000, -1000,
-1000, -1000,
-1000, -1000, 26, -1000, 178, -1000, -1000, -1000, -1000,
}
var yyPgo = [...]int16{
0, 390, 13, 389, 6, 15, 388, 330, 387, 386,
383, 235, 341, 382, 14, 380, 10, 11, 374, 373,
8, 365, 3, 4, 364, 2, 1, 0, 349, 12,
5, 346, 343, 17, 157, 342, 340, 7, 329, 318,
28, 316, 36, 308, 9, 306, 300, 298, 297, 273,
272, 296, 265, 263,
0, 395, 13, 394, 6, 15, 393, 328, 390, 387,
381, 380, 286, 294, 372, 14, 371, 10, 11, 356,
353, 8, 352, 3, 4, 351, 2, 1, 0, 350,
12, 5, 349, 348, 16, 157, 347, 345, 7, 344,
341, 31, 339, 32, 338, 9, 337, 336, 335, 320,
319, 312, 293, 301, 295,
}
var yyR1 = [...]int8{
0, 52, 52, 52, 52, 52, 52, 52, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
32, 32, 32, 32, 33, 33, 35, 35, 35, 35,
35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
35, 35, 34, 36, 36, 46, 46, 41, 41, 41,
41, 16, 16, 16, 16, 15, 15, 15, 4, 4,
38, 40, 40, 39, 39, 39, 47, 45, 45, 45,
31, 31, 31, 9, 9, 43, 49, 49, 49, 49,
49, 49, 50, 51, 51, 51, 42, 42, 42, 1,
1, 1, 2, 2, 2, 2, 2, 2, 2, 12,
12, 7, 7, 7, 7, 7, 7, 7, 7, 7,
0, 53, 53, 53, 53, 53, 53, 53, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
33, 33, 33, 33, 34, 34, 36, 36, 36, 36,
36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
36, 36, 35, 37, 37, 47, 47, 42, 42, 42,
42, 17, 17, 17, 17, 16, 16, 16, 4, 4,
39, 41, 41, 40, 40, 40, 48, 46, 46, 46,
32, 32, 32, 9, 9, 44, 50, 50, 50, 50,
50, 50, 51, 52, 52, 52, 43, 43, 43, 1,
1, 1, 2, 2, 2, 2, 2, 2, 2, 13,
13, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 11, 11, 11, 11, 13,
13, 13, 14, 14, 14, 14, 53, 19, 19, 19,
19, 18, 18, 18, 18, 18, 18, 18, 18, 18,
28, 28, 28, 20, 20, 20, 20, 21, 21, 21,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
23, 23, 24, 24, 24, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 6,
7, 7, 7, 7, 7, 12, 12, 12, 12, 14,
14, 14, 15, 15, 15, 15, 54, 20, 20, 20,
20, 19, 19, 19, 19, 19, 19, 19, 19, 19,
29, 29, 29, 21, 21, 21, 21, 22, 22, 22,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 24, 24, 25, 25, 25, 11, 11, 11, 11,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 8, 8,
5, 5, 5, 5, 44, 44, 27, 27, 29, 29,
30, 30, 26, 25, 25, 48, 10, 17, 17,
6, 6, 6, 8, 8, 5, 5, 5, 5, 45,
45, 28, 28, 30, 30, 31, 31, 27, 26, 26,
49, 10, 18, 18,
}
var yyR2 = [...]int8{
@ -562,52 +581,53 @@ var yyR2 = [...]int8{
1, 1, 3, 1, 3, 4, 1, 3, 5, 5,
1, 1, 1, 4, 3, 3, 2, 3, 1, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 3, 3, 1, 2, 1, 1, 1, 1, 1,
3, 4, 3, 3, 1, 2, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
1, 1, 1, 2, 1, 1, 1, 0, 1,
1, 1, 1, 2, 2, 1, 1, 1, 2, 1,
1, 1, 0, 1,
}
var yyChk = [...]int16{
-1000, -52, 91, 92, 93, 94, 2, 10, -12, -7,
-11, 61, 62, 78, 63, 64, 65, 12, 46, 47,
50, 66, 18, 67, 82, 68, 69, 70, 71, 72,
84, 87, 88, 73, 74, 13, -53, -12, 10, -37,
-32, -35, -38, -43, -44, -45, -47, -48, -49, -50,
-51, -31, -3, 12, 19, 9, 15, 25, -8, -7,
-42, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 40, 56, 13, -51, -11,
-13, 20, -14, 12, 2, -19, 2, 40, 58, 41,
42, 44, 45, 46, 47, 48, 49, 50, 51, 52,
53, 55, 56, 82, 57, 14, -33, -40, 2, 78,
84, 15, -40, -37, -37, -42, -1, 20, -2, 12,
-10, 2, 25, 20, 7, 2, 4, 2, 24, -34,
-41, -36, -46, 77, -34, -34, -34, -34, -34, -34,
-34, -34, -34, -34, -34, -34, -34, -34, -34, -44,
56, 2, -30, -9, 2, -27, -29, 87, 88, 19,
9, 40, 56, -44, 2, -40, -33, -16, 15, 2,
-16, -39, 22, -37, 22, 20, 7, 2, -5, 2,
4, 53, 43, 54, -5, 20, -14, 25, 2, -18,
5, -28, -20, 12, -27, -29, 16, -37, 81, 83,
79, 80, -37, -37, -37, -37, -37, -37, -37, -37,
-37, -37, -37, -37, -37, -37, -37, -44, 15, -27,
-27, 21, 6, 2, -15, 22, -4, -6, 2, 61,
77, 62, 78, 63, 64, 65, 79, 80, 12, 81,
46, 47, 50, 66, 18, 67, 82, 83, 68, 69,
70, 71, 72, 87, 88, 58, 73, 74, 22, 7,
20, -2, 25, 2, 25, 2, 26, 26, -29, 26,
40, 56, -21, 24, 17, -22, 30, 28, 29, 35,
36, 37, 33, 31, 34, 32, -16, -16, -17, -16,
-17, 22, -44, 21, 2, 22, 7, 2, -37, -26,
19, -26, 26, -26, -20, -20, 24, 17, 2, 17,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
21, 2, 22, -4, -26, 26, 26, 17, -22, -25,
56, -26, -30, -27, -27, -27, -23, 14, -23, -25,
-23, -25, -26, -26, -26, -24, -27, 24, 21, 2,
21, -27,
-1000, -53, 98, 99, 100, 101, 2, 10, -13, -7,
-12, 62, 63, 79, 64, 65, 66, 12, 47, 48,
51, 67, 18, 68, 83, 69, 70, 71, 72, 73,
85, 88, 89, 74, 75, 13, -54, -13, 10, -38,
-33, -36, -39, -44, -45, -46, -48, -49, -50, -51,
-52, -32, -3, 12, 19, 9, 15, 25, -8, -7,
-43, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 41, 57, 13, -52, -12,
-14, 20, -15, 12, 2, -20, 2, 41, 59, 42,
43, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 56, 57, 83, 58, 14, -34, -41, 2, 79,
85, 15, -41, -38, -38, -43, -1, 20, -2, 12,
-10, 2, 25, 20, 7, 2, 4, 2, 24, -35,
-42, -37, -47, 78, -35, -35, -35, -35, -35, -35,
-35, -35, -35, -35, -35, -35, -35, -35, -35, -45,
57, 2, -31, -9, 2, -28, -30, 88, 89, 19,
9, 41, 57, -45, 2, -41, -34, -17, 15, 2,
-17, -40, 22, -38, 22, 20, 7, 2, -5, 2,
4, 54, 44, 55, -5, 20, -15, 25, 2, -19,
5, -29, -21, 12, -28, -30, 16, -38, 82, 84,
80, 81, -38, -38, -38, -38, -38, -38, -38, -38,
-38, -38, -38, -38, -38, -38, -38, -45, 15, -28,
-28, 21, 6, 2, -16, 22, -4, -6, 2, 62,
78, 63, 79, 64, 65, 66, 80, 81, 12, 82,
47, 48, 51, 67, 18, 68, 83, 84, 69, 70,
71, 72, 73, 88, 89, 59, 74, 75, 22, 7,
20, -2, 25, 2, 25, 2, 26, 26, -30, 26,
41, 57, -22, 24, 17, -23, 30, 28, 29, 35,
36, 37, 33, 31, 34, 32, 38, -17, -17, -18,
-17, -18, 22, -45, 21, 2, 22, 7, 2, -38,
-27, 19, -27, 26, -27, -21, -21, 24, 17, 2,
17, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 21, 2, 22, -4, -27, 26, 26, 17,
-23, -26, 57, -27, -31, -28, -28, -28, -24, 14,
-24, -26, -24, -26, -11, 92, 93, 94, 95, -27,
-27, -27, -25, -28, 24, 21, 2, 21, -28,
}
var yyDef = [...]int16{
@ -616,37 +636,37 @@ var yyDef = [...]int16{
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 0, 2, -2, 3, 4,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 0, 107, 224, 225, 0, 235, 0, 84,
18, 19, 0, 107, 229, 230, 0, 240, 0, 84,
85, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, 218, 219, 0, 5, 99,
-2, -2, -2, -2, -2, 223, 224, 0, 5, 99,
0, 127, 130, 0, 135, 136, 140, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 0, 0, 0, 0, 22, 23, 0,
0, 0, 60, 0, 82, 83, 0, 88, 90, 0,
94, 98, 236, 125, 0, 131, 0, 134, 139, 0,
94, 98, 241, 125, 0, 131, 0, 134, 139, 0,
42, 47, 48, 44, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 67,
0, 69, 70, 0, 72, 230, 231, 73, 74, 226,
227, 0, 0, 0, 81, 20, 21, 24, 0, 54,
0, 69, 70, 0, 72, 235, 236, 73, 74, 231,
232, 0, 0, 0, 81, 20, 21, 24, 0, 54,
25, 0, 62, 64, 66, 86, 0, 91, 0, 97,
220, 221, 222, 223, 0, 126, 129, 132, 133, 138,
225, 226, 227, 228, 0, 126, 129, 132, 133, 138,
141, 143, 146, 150, 151, 152, 0, 26, 0, 0,
-2, -2, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 68, 0, 228,
229, 75, 0, 80, 0, 53, 56, 58, 59, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 61, 65,
35, 36, 37, 38, 39, 40, 41, 68, 0, 233,
234, 75, 0, 80, 0, 53, 56, 58, 59, 194,
195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
215, 216, 217, 218, 219, 220, 221, 222, 61, 65,
87, 89, 92, 96, 93, 95, 0, 0, 0, 0,
0, 0, 0, 0, 156, 158, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 45, 46, 49, 238,
50, 71, 0, 77, 79, 51, 0, 57, 63, 142,
232, 144, 0, 147, 0, 0, 0, 154, 159, 155,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
76, 78, 52, 55, 145, 0, 0, 153, 157, 160,
0, 234, 161, 162, 163, 164, 165, 0, 166, 167,
168, 169, 148, 149, 233, 0, 173, 0, 171, 174,
170, 172,
0, 0, 0, 0, 0, 0, 0, 45, 46, 49,
243, 50, 71, 0, 77, 79, 51, 0, 57, 63,
142, 237, 144, 0, 147, 0, 0, 0, 154, 159,
155, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 76, 78, 52, 55, 145, 0, 0, 153,
157, 160, 0, 239, 161, 162, 163, 164, 165, 0,
166, 167, 168, 169, 170, 176, 177, 178, 179, 148,
149, 238, 0, 174, 0, 172, 175, 171, 173,
}
var yyTok1 = [...]int8{
@ -663,7 +683,8 @@ var yyTok2 = [...]int8{
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102,
}
var yyTok3 = [...]int8{
@ -1800,26 +1821,32 @@ yydefault:
yyVAL.descriptors["n_offset"] = yyDollar[3].int
}
case 170:
yyDollar = yyS[yypt-3 : yypt+1]
{
yyVAL.descriptors = yylex.(*parser).newMap()
yyVAL.descriptors["counter_reset_hint"] = yyDollar[3].item
}
case 171:
yyDollar = yyS[yypt-4 : yypt+1]
{
yyVAL.bucket_set = yyDollar[2].bucket_set
}
case 171:
case 172:
yyDollar = yyS[yypt-3 : yypt+1]
{
yyVAL.bucket_set = yyDollar[2].bucket_set
}
case 172:
case 173:
yyDollar = yyS[yypt-3 : yypt+1]
{
yyVAL.bucket_set = append(yyDollar[1].bucket_set, yyDollar[3].float)
}
case 173:
case 174:
yyDollar = yyS[yypt-1 : yypt+1]
{
yyVAL.bucket_set = []float64{yyDollar[1].float}
}
case 224:
case 229:
yyDollar = yyS[yypt-1 : yypt+1]
{
yyVAL.node = &NumberLiteral{
@ -1827,7 +1854,7 @@ yydefault:
PosRange: yyDollar[1].item.PositionRange(),
}
}
case 225:
case 230:
yyDollar = yyS[yypt-1 : yypt+1]
{
var err error
@ -1841,12 +1868,12 @@ yydefault:
PosRange: yyDollar[1].item.PositionRange(),
}
}
case 226:
case 231:
yyDollar = yyS[yypt-1 : yypt+1]
{
yyVAL.float = yylex.(*parser).number(yyDollar[1].item.Val)
}
case 227:
case 232:
yyDollar = yyS[yypt-1 : yypt+1]
{
var err error
@ -1857,17 +1884,17 @@ yydefault:
}
yyVAL.float = dur.Seconds()
}
case 228:
case 233:
yyDollar = yyS[yypt-2 : yypt+1]
{
yyVAL.float = yyDollar[2].float
}
case 229:
case 234:
yyDollar = yyS[yypt-2 : yypt+1]
{
yyVAL.float = -yyDollar[2].float
}
case 232:
case 237:
yyDollar = yyS[yypt-1 : yypt+1]
{
var err error
@ -1876,17 +1903,17 @@ yydefault:
yylex.(*parser).addParseErrf(yyDollar[1].item.PositionRange(), "invalid repetition in series values: %s", err)
}
}
case 233:
case 238:
yyDollar = yyS[yypt-2 : yypt+1]
{
yyVAL.int = -int64(yyDollar[2].uint)
}
case 234:
case 239:
yyDollar = yyS[yypt-1 : yypt+1]
{
yyVAL.int = int64(yyDollar[1].uint)
}
case 235:
case 240:
yyDollar = yyS[yypt-1 : yypt+1]
{
yyVAL.node = &StringLiteral{
@ -1894,7 +1921,7 @@ yydefault:
PosRange: yyDollar[1].item.PositionRange(),
}
}
case 236:
case 241:
yyDollar = yyS[yypt-1 : yypt+1]
{
yyVAL.item = Item{
@ -1903,7 +1930,7 @@ yydefault:
Val: yylex.(*parser).unquoteString(yyDollar[1].item.Val),
}
}
case 237:
case 242:
yyDollar = yyS[yypt-0 : yypt+1]
{
yyVAL.strings = nil

33
promql/parser/lex.go

@ -137,16 +137,24 @@ var key = map[string]ItemType{
}
var histogramDesc = map[string]ItemType{
"sum": SUM_DESC,
"count": COUNT_DESC,
"schema": SCHEMA_DESC,
"offset": OFFSET_DESC,
"n_offset": NEGATIVE_OFFSET_DESC,
"buckets": BUCKETS_DESC,
"n_buckets": NEGATIVE_BUCKETS_DESC,
"z_bucket": ZERO_BUCKET_DESC,
"z_bucket_w": ZERO_BUCKET_WIDTH_DESC,
"custom_values": CUSTOM_VALUES_DESC,
"sum": SUM_DESC,
"count": COUNT_DESC,
"schema": SCHEMA_DESC,
"offset": OFFSET_DESC,
"n_offset": NEGATIVE_OFFSET_DESC,
"buckets": BUCKETS_DESC,
"n_buckets": NEGATIVE_BUCKETS_DESC,
"z_bucket": ZERO_BUCKET_DESC,
"z_bucket_w": ZERO_BUCKET_WIDTH_DESC,
"custom_values": CUSTOM_VALUES_DESC,
"counter_reset_hint": COUNTER_RESET_HINT_DESC,
}
var counterResetHints = map[string]ItemType{
"unknown": UNKNOWN_COUNTER_RESET,
"reset": COUNTER_RESET,
"not_reset": NOT_COUNTER_RESET,
"gauge": GAUGE_TYPE,
}
// ItemTypeStr is the default string representations for common Items. It does not
@ -585,6 +593,11 @@ Loop:
return lexHistogram
}
}
if desc, ok := counterResetHints[strings.ToLower(word)]; ok {
l.emit(desc)
return lexHistogram
}
l.errorf("bad histogram descriptor found: %q", word)
break Loop
}

22
promql/parser/parse.go

@ -580,6 +580,28 @@ func (p *parser) buildHistogramFromMap(desc *map[string]interface{}) *histogram.
}
}
val, ok = (*desc)["counter_reset_hint"]
if ok {
resetHint, ok := val.(Item)
if ok {
switch resetHint.Typ {
case UNKNOWN_COUNTER_RESET:
output.CounterResetHint = histogram.UnknownCounterReset
case COUNTER_RESET:
output.CounterResetHint = histogram.CounterReset
case NOT_COUNTER_RESET:
output.CounterResetHint = histogram.NotCounterReset
case GAUGE_TYPE:
output.CounterResetHint = histogram.GaugeType
default:
p.addParseErrf(p.yyParser.lval.item.PositionRange(), "error parsing counter_reset_hint: unknown value %v", resetHint.Typ)
}
} else {
p.addParseErrf(p.yyParser.lval.item.PositionRange(), "error parsing counter_reset_hint: %v", val)
}
}
buckets, spans := p.buildHistogramBucketsAndSpans(desc, "buckets", "offset")
output.PositiveBuckets = buckets
output.PositiveSpans = spans

75
promql/parser/parse_test.go

@ -4038,32 +4038,34 @@ func TestParseHistogramSeries(t *testing.T) {
},
{
name: "all properties used",
input: `{} {{schema:1 sum:-0.3 count:3.1 z_bucket:7.1 z_bucket_w:0.05 buckets:[5.1 10 7] offset:-3 n_buckets:[4.1 5] n_offset:-5}}`,
input: `{} {{schema:1 sum:-0.3 count:3.1 z_bucket:7.1 z_bucket_w:0.05 buckets:[5.1 10 7] offset:-3 n_buckets:[4.1 5] n_offset:-5 counter_reset_hint:gauge}}`,
expected: []histogram.FloatHistogram{{
Schema: 1,
Sum: -0.3,
Count: 3.1,
ZeroCount: 7.1,
ZeroThreshold: 0.05,
PositiveBuckets: []float64{5.1, 10, 7},
PositiveSpans: []histogram.Span{{Offset: -3, Length: 3}},
NegativeBuckets: []float64{4.1, 5},
NegativeSpans: []histogram.Span{{Offset: -5, Length: 2}},
Schema: 1,
Sum: -0.3,
Count: 3.1,
ZeroCount: 7.1,
ZeroThreshold: 0.05,
PositiveBuckets: []float64{5.1, 10, 7},
PositiveSpans: []histogram.Span{{Offset: -3, Length: 3}},
NegativeBuckets: []float64{4.1, 5},
NegativeSpans: []histogram.Span{{Offset: -5, Length: 2}},
CounterResetHint: histogram.GaugeType,
}},
},
{
name: "all properties used - with spaces",
input: `{} {{schema:1 sum:0.3 count:3 z_bucket:7 z_bucket_w:5 buckets:[5 10 7 ] offset:-3 n_buckets:[4 5] n_offset:5 }}`,
input: `{} {{schema:1 sum:0.3 count:3 z_bucket:7 z_bucket_w:5 buckets:[5 10 7 ] offset:-3 n_buckets:[4 5] n_offset:5 counter_reset_hint:gauge }}`,
expected: []histogram.FloatHistogram{{
Schema: 1,
Sum: 0.3,
Count: 3,
ZeroCount: 7,
ZeroThreshold: 5,
PositiveBuckets: []float64{5, 10, 7},
PositiveSpans: []histogram.Span{{Offset: -3, Length: 3}},
NegativeBuckets: []float64{4, 5},
NegativeSpans: []histogram.Span{{Offset: 5, Length: 2}},
Schema: 1,
Sum: 0.3,
Count: 3,
ZeroCount: 7,
ZeroThreshold: 5,
PositiveBuckets: []float64{5, 10, 7},
PositiveSpans: []histogram.Span{{Offset: -3, Length: 3}},
NegativeBuckets: []float64{4, 5},
NegativeSpans: []histogram.Span{{Offset: 5, Length: 2}},
CounterResetHint: histogram.GaugeType,
}},
},
{
@ -4250,6 +4252,39 @@ func TestParseHistogramSeries(t *testing.T) {
input: `{} {{ schema:1}}`,
expectedError: `1:7: parse error: unexpected "<Item 57372>" "schema" in series values`,
},
{
name: "invalid counter reset hint value",
input: `{} {{counter_reset_hint:foo}}`,
expectedError: `1:25: parse error: bad histogram descriptor found: "foo"`,
},
{
name: "'unknown' counter reset hint value",
input: `{} {{counter_reset_hint:unknown}}`,
expected: []histogram.FloatHistogram{{
CounterResetHint: histogram.UnknownCounterReset,
}},
},
{
name: "'reset' counter reset hint value",
input: `{} {{counter_reset_hint:reset}}`,
expected: []histogram.FloatHistogram{{
CounterResetHint: histogram.CounterReset,
}},
},
{
name: "'not_reset' counter reset hint value",
input: `{} {{counter_reset_hint:not_reset}}`,
expected: []histogram.FloatHistogram{{
CounterResetHint: histogram.NotCounterReset,
}},
},
{
name: "'gauge' counter reset hint value",
input: `{} {{counter_reset_hint:gauge}}`,
expected: []histogram.FloatHistogram{{
CounterResetHint: histogram.GaugeType,
}},
},
} {
t.Run(test.name, func(t *testing.T) {
_, vals, err := ParseSeriesDesc(test.input)

Loading…
Cancel
Save