diff --git a/model/histogram/float_histogram.go b/model/histogram/float_histogram.go index 58f13c8cf3..5431892dd1 100644 --- a/model/histogram/float_histogram.go +++ b/model/histogram/float_histogram.go @@ -225,6 +225,9 @@ func (h *FloatHistogram) TestExpression() string { if m.ZeroThreshold != 0 { res = append(res, fmt.Sprintf("z_bucket_w:%g", m.ZeroThreshold)) } + if m.UsesCustomBuckets() { + res = append(res, fmt.Sprintf("custom_values:%g", m.CustomValues)) + } addBuckets := func(kind, bucketsKey, offsetKey string, buckets []float64, spans []Span) []string { if len(spans) > 1 { diff --git a/promql/parser/generated_parser.y b/promql/parser/generated_parser.y index 841bd31c19..b39c1150a5 100644 --- a/promql/parser/generated_parser.y +++ b/promql/parser/generated_parser.y @@ -84,6 +84,7 @@ BUCKETS_DESC NEGATIVE_BUCKETS_DESC ZERO_BUCKET_DESC ZERO_BUCKET_WIDTH_DESC +CUSTOM_VALUES_DESC %token histogramDescEnd // Operators. @@ -797,6 +798,11 @@ histogram_desc_item $$ = yylex.(*parser).newMap() $$["z_bucket_w"] = $3 } + | CUSTOM_VALUES_DESC COLON bucket_set + { + $$ = yylex.(*parser).newMap() + $$["custom_values"] = $3 + } | BUCKETS_DESC COLON bucket_set { $$ = yylex.(*parser).newMap() diff --git a/promql/parser/generated_parser.y.go b/promql/parser/generated_parser.y.go index 3075b9b1b1..d9a312a137 100644 --- a/promql/parser/generated_parser.y.go +++ b/promql/parser/generated_parser.y.go @@ -67,62 +67,63 @@ const BUCKETS_DESC = 57375 const NEGATIVE_BUCKETS_DESC = 57376 const ZERO_BUCKET_DESC = 57377 const ZERO_BUCKET_WIDTH_DESC = 57378 -const histogramDescEnd = 57379 -const operatorsStart = 57380 -const ADD = 57381 -const DIV = 57382 -const EQLC = 57383 -const EQL_REGEX = 57384 -const GTE = 57385 -const GTR = 57386 -const LAND = 57387 -const LOR = 57388 -const LSS = 57389 -const LTE = 57390 -const LUNLESS = 57391 -const MOD = 57392 -const MUL = 57393 -const NEQ = 57394 -const NEQ_REGEX = 57395 -const POW = 57396 -const SUB = 57397 -const AT = 57398 -const ATAN2 = 57399 -const operatorsEnd = 57400 -const aggregatorsStart = 57401 -const AVG = 57402 -const BOTTOMK = 57403 -const COUNT = 57404 -const COUNT_VALUES = 57405 -const GROUP = 57406 -const MAX = 57407 -const MIN = 57408 -const QUANTILE = 57409 -const STDDEV = 57410 -const STDVAR = 57411 -const SUM = 57412 -const TOPK = 57413 -const aggregatorsEnd = 57414 -const keywordsStart = 57415 -const BOOL = 57416 -const BY = 57417 -const GROUP_LEFT = 57418 -const GROUP_RIGHT = 57419 -const IGNORING = 57420 -const OFFSET = 57421 -const ON = 57422 -const WITHOUT = 57423 -const keywordsEnd = 57424 -const preprocessorStart = 57425 -const START = 57426 -const END = 57427 -const preprocessorEnd = 57428 -const startSymbolsStart = 57429 -const START_METRIC = 57430 -const START_SERIES_DESCRIPTION = 57431 -const START_EXPRESSION = 57432 -const START_METRIC_SELECTOR = 57433 -const startSymbolsEnd = 57434 +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 aggregatorsEnd = 57415 +const keywordsStart = 57416 +const BOOL = 57417 +const BY = 57418 +const GROUP_LEFT = 57419 +const GROUP_RIGHT = 57420 +const IGNORING = 57421 +const OFFSET = 57422 +const ON = 57423 +const WITHOUT = 57424 +const keywordsEnd = 57425 +const preprocessorStart = 57426 +const START = 57427 +const END = 57428 +const preprocessorEnd = 57429 +const startSymbolsStart = 57430 +const START_METRIC = 57431 +const START_SERIES_DESCRIPTION = 57432 +const START_EXPRESSION = 57433 +const START_METRIC_SELECTOR = 57434 +const startSymbolsEnd = 57435 var yyToknames = [...]string{ "$end", @@ -161,6 +162,7 @@ var yyToknames = [...]string{ "NEGATIVE_BUCKETS_DESC", "ZERO_BUCKET_DESC", "ZERO_BUCKET_WIDTH_DESC", + "CUSTOM_VALUES_DESC", "histogramDescEnd", "operatorsStart", "ADD", @@ -235,270 +237,273 @@ var yyExca = [...]int16{ 24, 134, -2, 0, -1, 58, - 2, 171, - 15, 171, - 75, 171, - 81, 171, - -2, 100, - -1, 59, 2, 172, 15, 172, - 75, 172, - 81, 172, - -2, 101, - -1, 60, + 76, 172, + 82, 172, + -2, 100, + -1, 59, 2, 173, 15, 173, - 75, 173, - 81, 173, - -2, 103, - -1, 61, + 76, 173, + 82, 173, + -2, 101, + -1, 60, 2, 174, 15, 174, - 75, 174, - 81, 174, - -2, 104, - -1, 62, + 76, 174, + 82, 174, + -2, 103, + -1, 61, 2, 175, 15, 175, - 75, 175, - 81, 175, - -2, 105, - -1, 63, + 76, 175, + 82, 175, + -2, 104, + -1, 62, 2, 176, 15, 176, - 75, 176, - 81, 176, - -2, 110, - -1, 64, + 76, 176, + 82, 176, + -2, 105, + -1, 63, 2, 177, 15, 177, - 75, 177, - 81, 177, - -2, 112, - -1, 65, + 76, 177, + 82, 177, + -2, 110, + -1, 64, 2, 178, 15, 178, - 75, 178, - 81, 178, - -2, 114, - -1, 66, + 76, 178, + 82, 178, + -2, 112, + -1, 65, 2, 179, 15, 179, - 75, 179, - 81, 179, - -2, 115, - -1, 67, + 76, 179, + 82, 179, + -2, 114, + -1, 66, 2, 180, 15, 180, - 75, 180, - 81, 180, - -2, 116, - -1, 68, + 76, 180, + 82, 180, + -2, 115, + -1, 67, 2, 181, 15, 181, - 75, 181, - 81, 181, - -2, 117, - -1, 69, + 76, 181, + 82, 181, + -2, 116, + -1, 68, 2, 182, 15, 182, - 75, 182, - 81, 182, + 76, 182, + 82, 182, + -2, 117, + -1, 69, + 2, 183, + 15, 183, + 76, 183, + 82, 183, -2, 118, -1, 195, - 12, 230, - 13, 230, - 18, 230, - 19, 230, - 25, 230, - 39, 230, - 45, 230, - 46, 230, - 49, 230, - 55, 230, - 60, 230, - 61, 230, - 62, 230, - 63, 230, - 64, 230, - 65, 230, - 66, 230, - 67, 230, - 68, 230, - 69, 230, - 70, 230, - 71, 230, - 75, 230, - 79, 230, - 81, 230, - 84, 230, - 85, 230, + 12, 231, + 13, 231, + 18, 231, + 19, 231, + 25, 231, + 40, 231, + 46, 231, + 47, 231, + 50, 231, + 56, 231, + 61, 231, + 62, 231, + 63, 231, + 64, 231, + 65, 231, + 66, 231, + 67, 231, + 68, 231, + 69, 231, + 70, 231, + 71, 231, + 72, 231, + 76, 231, + 80, 231, + 82, 231, + 85, 231, + 86, 231, -2, 0, -1, 196, - 12, 230, - 13, 230, - 18, 230, - 19, 230, - 25, 230, - 39, 230, - 45, 230, - 46, 230, - 49, 230, - 55, 230, - 60, 230, - 61, 230, - 62, 230, - 63, 230, - 64, 230, - 65, 230, - 66, 230, - 67, 230, - 68, 230, - 69, 230, - 70, 230, - 71, 230, - 75, 230, - 79, 230, - 81, 230, - 84, 230, - 85, 230, + 12, 231, + 13, 231, + 18, 231, + 19, 231, + 25, 231, + 40, 231, + 46, 231, + 47, 231, + 50, 231, + 56, 231, + 61, 231, + 62, 231, + 63, 231, + 64, 231, + 65, 231, + 66, 231, + 67, 231, + 68, 231, + 69, 231, + 70, 231, + 71, 231, + 72, 231, + 76, 231, + 80, 231, + 82, 231, + 85, 231, + 86, 231, -2, 0, -1, 217, - 21, 228, - -2, 0, - -1, 285, 21, 229, -2, 0, + -1, 286, + 21, 230, + -2, 0, } const yyPrivate = 57344 -const yyLast = 742 +const yyLast = 778 var yyAct = [...]int16{ - 151, 322, 320, 268, 327, 148, 221, 37, 187, 144, - 281, 280, 152, 113, 77, 173, 104, 102, 101, 6, - 128, 223, 105, 193, 155, 194, 195, 196, 339, 262, - 260, 233, 317, 316, 57, 100, 294, 239, 103, 146, - 300, 313, 263, 156, 156, 283, 147, 338, 259, 123, - 337, 106, 252, 311, 155, 299, 340, 301, 264, 157, - 157, 108, 298, 109, 235, 236, 292, 251, 237, 107, - 155, 292, 174, 191, 175, 96, 250, 99, 258, 224, + 151, 324, 322, 268, 329, 148, 221, 37, 187, 144, + 282, 281, 152, 113, 77, 173, 104, 102, 101, 6, + 223, 193, 105, 194, 195, 196, 128, 262, 260, 155, + 233, 103, 342, 293, 100, 319, 239, 116, 146, 318, + 315, 263, 156, 123, 106, 147, 284, 114, 295, 116, + 156, 341, 175, 259, 340, 253, 57, 264, 157, 114, + 117, 108, 313, 109, 235, 236, 157, 112, 237, 107, + 323, 174, 117, 175, 155, 96, 250, 99, 293, 224, 226, 228, 229, 230, 238, 240, 243, 244, 245, 246, - 247, 110, 145, 225, 227, 231, 232, 234, 241, 242, - 98, 257, 321, 248, 249, 2, 3, 4, 5, 218, - 158, 104, 177, 217, 168, 162, 165, 105, 175, 160, - 164, 161, 176, 178, 189, 213, 106, 328, 216, 256, - 183, 179, 192, 163, 181, 100, 190, 197, 198, 199, + 247, 177, 145, 225, 227, 231, 232, 234, 241, 242, + 98, 176, 178, 248, 249, 104, 2, 3, 4, 5, + 158, 105, 177, 110, 168, 162, 165, 302, 150, 160, + 191, 161, 176, 178, 189, 155, 213, 343, 106, 330, + 72, 179, 192, 33, 181, 155, 190, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, - 210, 211, 255, 182, 72, 212, 177, 214, 215, 33, - 82, 84, 85, 7, 86, 87, 176, 178, 90, 91, - 223, 93, 94, 95, 116, 96, 97, 99, 83, 147, - 233, 286, 289, 116, 114, 254, 239, 288, 147, 172, - 220, 124, 253, 114, 171, 310, 309, 117, 120, 261, - 98, 112, 287, 119, 278, 279, 117, 170, 282, 10, - 308, 159, 307, 235, 236, 312, 118, 237, 147, 74, - 306, 305, 304, 303, 302, 250, 81, 285, 224, 226, - 228, 229, 230, 238, 240, 243, 244, 245, 246, 247, - 79, 79, 225, 227, 231, 232, 234, 241, 242, 48, - 78, 78, 248, 249, 122, 73, 121, 150, 180, 76, - 290, 291, 293, 56, 295, 8, 9, 9, 34, 35, - 1, 284, 296, 297, 155, 129, 130, 131, 132, 133, + 210, 211, 185, 301, 258, 212, 156, 214, 215, 188, + 256, 183, 290, 191, 252, 164, 155, 289, 300, 218, + 223, 79, 157, 217, 7, 299, 312, 257, 163, 251, + 233, 78, 288, 255, 182, 254, 239, 156, 216, 180, + 220, 124, 172, 120, 147, 311, 314, 171, 119, 261, + 287, 153, 154, 157, 279, 280, 79, 147, 283, 310, + 170, 118, 159, 10, 235, 236, 78, 309, 237, 147, + 308, 307, 306, 74, 76, 305, 250, 286, 304, 224, + 226, 228, 229, 230, 238, 240, 243, 244, 245, 246, + 247, 303, 81, 225, 227, 231, 232, 234, 241, 242, + 48, 34, 1, 248, 249, 122, 73, 121, 285, 47, + 291, 292, 294, 56, 296, 8, 9, 9, 46, 35, + 45, 44, 297, 298, 127, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, - 47, 46, 45, 44, 156, 314, 315, 127, 43, 42, - 41, 185, 319, 125, 166, 324, 325, 326, 188, 323, - 157, 329, 191, 331, 330, 155, 40, 126, 332, 333, - 100, 51, 72, 334, 53, 39, 38, 22, 52, 336, - 49, 167, 186, 335, 54, 156, 265, 80, 341, 153, - 154, 184, 219, 75, 115, 82, 84, 149, 70, 55, - 222, 157, 50, 111, 18, 19, 93, 94, 20, 0, - 96, 97, 99, 83, 71, 0, 0, 0, 0, 58, + 43, 42, 41, 125, 166, 40, 316, 317, 126, 39, + 38, 49, 186, 321, 338, 265, 326, 327, 328, 80, + 325, 184, 219, 332, 331, 334, 333, 75, 115, 149, + 335, 336, 100, 51, 72, 337, 53, 55, 222, 22, + 52, 339, 50, 167, 111, 0, 54, 0, 0, 0, + 0, 344, 0, 0, 0, 0, 0, 0, 82, 84, + 0, 70, 0, 0, 0, 0, 0, 18, 19, 93, + 94, 20, 0, 96, 97, 99, 83, 71, 0, 0, + 0, 0, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 0, 0, 0, 13, 98, 0, + 0, 24, 0, 30, 0, 0, 31, 32, 36, 100, + 51, 72, 0, 53, 267, 0, 22, 52, 0, 0, + 0, 266, 0, 54, 0, 270, 271, 269, 276, 278, + 275, 277, 272, 273, 274, 0, 84, 0, 70, 0, + 0, 0, 0, 0, 18, 19, 93, 94, 20, 0, + 96, 0, 99, 83, 71, 0, 0, 0, 0, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0, 0, 0, 13, 98, 0, 0, 24, 0, - 30, 0, 0, 31, 32, 36, 100, 51, 72, 0, - 53, 267, 0, 22, 52, 0, 0, 0, 266, 0, - 54, 0, 270, 271, 269, 275, 277, 274, 276, 272, - 273, 0, 84, 0, 70, 0, 0, 0, 0, 0, - 18, 19, 93, 94, 20, 0, 96, 0, 99, 83, - 71, 0, 0, 0, 0, 58, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 0, 0, 0, - 13, 98, 0, 0, 24, 0, 30, 0, 0, 31, - 32, 51, 72, 0, 53, 318, 0, 22, 52, 0, - 0, 0, 0, 0, 54, 0, 270, 271, 269, 275, - 277, 274, 276, 272, 273, 0, 0, 0, 70, 0, - 0, 0, 0, 0, 18, 19, 0, 0, 20, 0, - 0, 0, 17, 72, 71, 0, 0, 0, 22, 58, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - 69, 0, 0, 0, 13, 0, 0, 0, 24, 0, - 30, 0, 0, 31, 32, 18, 19, 0, 0, 20, - 0, 0, 0, 17, 33, 0, 0, 0, 0, 22, - 11, 12, 14, 15, 16, 21, 23, 25, 26, 27, - 28, 29, 0, 0, 0, 13, 0, 0, 0, 24, - 0, 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, 100, 0, 0, 13, 0, 0, 0, - 24, 169, 30, 0, 0, 31, 32, 0, 0, 0, - 0, 0, 100, 0, 0, 0, 0, 0, 82, 84, - 85, 0, 86, 87, 88, 89, 90, 91, 92, 93, + 30, 0, 0, 31, 32, 51, 72, 0, 53, 320, + 0, 22, 52, 0, 0, 0, 0, 0, 54, 0, + 270, 271, 269, 276, 278, 275, 277, 272, 273, 274, + 0, 0, 0, 70, 0, 0, 17, 72, 0, 18, + 19, 0, 22, 20, 0, 0, 0, 0, 0, 71, + 0, 0, 0, 0, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 0, 0, 0, 13, + 18, 19, 0, 24, 20, 30, 0, 0, 31, 32, + 0, 0, 0, 0, 0, 11, 12, 14, 15, 16, + 21, 23, 25, 26, 27, 28, 29, 17, 33, 0, + 13, 0, 0, 22, 24, 0, 30, 0, 0, 31, + 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 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, 100, 0, + 0, 13, 0, 0, 0, 24, 169, 30, 0, 0, + 31, 32, 0, 0, 0, 0, 0, 100, 0, 0, + 0, 0, 0, 0, 82, 84, 85, 0, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, 0, 96, + 97, 99, 83, 82, 84, 85, 0, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 0, 96, 97, + 99, 83, 100, 0, 98, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 100, 0, 98, 0, 0, 0, 0, 82, 84, + 85, 0, 86, 87, 88, 0, 90, 91, 92, 93, 94, 95, 0, 96, 97, 99, 83, 82, 84, 85, - 0, 86, 87, 88, 89, 90, 91, 92, 93, 94, - 95, 0, 96, 97, 99, 83, 100, 0, 98, 0, + 0, 86, 87, 0, 0, 90, 91, 0, 93, 94, + 95, 0, 96, 97, 99, 83, 0, 0, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 98, 0, 0, - 0, 82, 84, 85, 0, 86, 87, 88, 0, 90, - 91, 92, 93, 94, 95, 0, 96, 97, 99, 83, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 98, + 0, 0, 0, 0, 0, 0, 0, 98, } var yyPact = [...]int16{ - 17, 153, 541, 541, 385, 500, -1000, -1000, -1000, 146, + 17, 164, 555, 555, 388, 494, -1000, -1000, -1000, 120, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, - -1000, -1000, -1000, 239, -1000, 224, -1000, 618, -1000, -1000, + -1000, -1000, -1000, 204, -1000, 240, -1000, 633, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, - 36, 111, -1000, 459, -1000, 459, 141, -1000, -1000, -1000, + 29, 113, -1000, 463, -1000, 463, 117, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, - -1000, -1000, 181, -1000, -1000, 196, -1000, -1000, 252, -1000, - 25, -1000, -54, -54, -54, -54, -54, -54, -54, -54, - -54, -54, -54, -54, -54, -54, -54, -54, 37, 255, - 209, 111, -59, -1000, 118, 118, 309, -1000, 599, 21, - -1000, 187, -1000, -1000, 70, 114, -1000, -1000, -1000, 238, - -1000, 128, -1000, 296, 459, -1000, -55, -50, -1000, 459, - 459, 459, 459, 459, 459, 459, 459, 459, 459, 459, - 459, 459, 459, 459, -1000, 170, -1000, -1000, -1000, 110, - -1000, -1000, -1000, -1000, -1000, -1000, 51, 51, 107, -1000, - -1000, -1000, -1000, 168, -1000, -1000, 45, -1000, 618, -1000, - -1000, 172, -1000, 127, -1000, -1000, -1000, -1000, -1000, 76, - -1000, -1000, -1000, -1000, -1000, 22, 4, 3, -1000, -1000, - -1000, 384, 382, 118, 118, 118, 118, 21, 21, 306, - 306, 306, 121, 662, 306, 306, 121, 21, 21, 306, - 21, 382, -1000, 23, -1000, -1000, -1000, 179, -1000, 180, + -1000, -1000, 47, -1000, -1000, 191, -1000, -1000, 253, -1000, + 19, -1000, -49, -49, -49, -49, -49, -49, -49, -49, + -49, -49, -49, -49, -49, -49, -49, -49, 36, 116, + 210, 113, -60, -1000, 163, 163, 311, -1000, 614, 20, + -1000, 190, -1000, -1000, 69, 48, -1000, -1000, -1000, 169, + -1000, 159, -1000, 147, 463, -1000, -58, -53, -1000, 463, + 463, 463, 463, 463, 463, 463, 463, 463, 463, 463, + 463, 463, 463, 463, -1000, 185, -1000, -1000, -1000, 111, + -1000, -1000, -1000, -1000, -1000, -1000, 55, 55, 167, -1000, + -1000, -1000, -1000, 168, -1000, -1000, 157, -1000, 633, -1000, + -1000, 35, -1000, 158, -1000, -1000, -1000, -1000, -1000, 152, + -1000, -1000, -1000, -1000, -1000, 27, 2, 1, -1000, -1000, + -1000, 387, 385, 163, 163, 163, 163, 20, 20, 308, + 308, 308, 697, 678, 308, 308, 697, 20, 20, 308, + 20, 385, -1000, 24, -1000, -1000, -1000, 198, -1000, 160, -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, -1000, -1000, -1000, -1000, -1000, - -1000, -1000, 459, -1000, -1000, -1000, -1000, -1000, -1000, 52, - 52, 10, 52, 57, 57, 38, 40, -1000, -1000, 218, - 217, 216, 215, 214, 206, 204, 190, 189, -1000, -1000, - -1000, -1000, -1000, -1000, 32, 213, -1000, -1000, 19, -1000, - 618, -1000, -1000, -1000, 52, -1000, 7, 6, 458, -1000, - -1000, -1000, 47, 5, 51, 51, 51, 113, 47, 113, - 47, -1000, -1000, -1000, -1000, -1000, 52, 52, -1000, -1000, - -1000, 52, -1000, -1000, -1000, -1000, -1000, -1000, 51, -1000, - -1000, -1000, -1000, -1000, -1000, 26, -1000, 35, -1000, -1000, - -1000, -1000, + -1000, -1000, 463, -1000, -1000, -1000, -1000, -1000, -1000, 59, + 59, 22, 59, 104, 104, 151, 100, -1000, -1000, 235, + 222, 219, 216, 215, 214, 211, 203, 189, 170, -1000, + -1000, -1000, -1000, -1000, -1000, 41, 194, -1000, -1000, 18, + -1000, 633, -1000, -1000, -1000, 59, -1000, 13, 9, 462, + -1000, -1000, -1000, 14, 10, 55, 55, 55, 115, 115, + 14, 115, 14, -1000, -1000, -1000, -1000, -1000, 59, 59, + -1000, -1000, -1000, 59, -1000, -1000, -1000, -1000, -1000, -1000, + 55, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 30, -1000, + 106, -1000, -1000, -1000, -1000, } var yyPgo = [...]int16{ - 0, 353, 13, 352, 6, 15, 350, 263, 349, 347, - 344, 209, 265, 343, 14, 342, 10, 11, 341, 337, - 8, 336, 3, 4, 333, 2, 1, 0, 332, 12, - 5, 330, 326, 18, 191, 325, 317, 7, 316, 304, - 17, 303, 34, 300, 299, 298, 297, 293, 292, 291, - 290, 249, 9, 271, 270, 268, + 0, 334, 13, 332, 6, 15, 328, 263, 327, 319, + 318, 213, 265, 317, 14, 312, 10, 11, 311, 309, + 8, 305, 3, 4, 304, 2, 1, 0, 302, 12, + 5, 301, 300, 18, 191, 299, 298, 7, 295, 294, + 17, 293, 56, 292, 291, 290, 274, 271, 270, 268, + 259, 250, 9, 258, 252, 251, } var yyR1 = [...]int8{ @@ -518,14 +523,14 @@ var yyR1 = [...]int8{ 14, 14, 14, 55, 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, 23, 23, 24, 24, - 24, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, + 22, 22, 22, 22, 22, 22, 22, 23, 23, 24, + 24, 24, 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, - 8, 8, 5, 5, 5, 5, 44, 27, 29, 29, - 30, 30, 26, 25, 25, 52, 48, 10, 53, 53, - 17, 17, + 6, 8, 8, 5, 5, 5, 5, 44, 27, 29, + 29, 30, 30, 26, 25, 25, 52, 48, 10, 53, + 53, 17, 17, } var yyR2 = [...]int8{ @@ -545,52 +550,52 @@ var yyR2 = [...]int8{ 3, 2, 1, 2, 0, 3, 2, 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, 4, 3, 3, 1, - 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 3, 3, 3, 3, 3, 3, 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, 2, 2, - 1, 1, 1, 2, 1, 1, 1, 1, 0, 1, - 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 2, 1, 1, 1, 2, 1, 1, 1, 1, 0, + 1, 0, 1, } var yyChk = [...]int16{ - -1000, -54, 88, 89, 90, 91, 2, 10, -12, -7, - -11, 60, 61, 75, 62, 63, 64, 12, 45, 46, - 49, 65, 18, 66, 79, 67, 68, 69, 70, 71, - 81, 84, 85, 13, -55, -12, 10, -37, -32, -35, + -1000, -54, 89, 90, 91, 92, 2, 10, -12, -7, + -11, 61, 62, 76, 63, 64, 65, 12, 46, 47, + 50, 66, 18, 67, 80, 68, 69, 70, 71, 72, + 82, 85, 86, 13, -55, -12, 10, -37, -32, -35, -38, -43, -44, -45, -47, -48, -49, -50, -51, -31, - -3, 12, 19, 15, 25, -8, -7, -42, 60, 61, - 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 39, 55, 13, -51, -11, -13, 20, -14, 12, 2, - -19, 2, 39, 57, 40, 41, 43, 44, 45, 46, - 47, 48, 49, 50, 51, 52, 54, 55, 79, 56, - 14, -33, -40, 2, 75, 81, 15, -40, -37, -37, + -3, 12, 19, 15, 25, -8, -7, -42, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 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, 80, 57, + 14, -33, -40, 2, 76, 82, 15, -40, -37, -37, -42, -1, 20, -2, 12, -10, 2, 25, 20, 7, - 2, 4, 2, 24, -34, -41, -36, -46, 74, -34, + 2, 4, 2, 24, -34, -41, -36, -46, 75, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, - -34, -34, -34, -34, -52, 55, 2, 9, -30, -9, - 2, -27, -29, 84, 85, 19, 39, 55, -52, 2, + -34, -34, -34, -34, -52, 56, 2, 9, -30, -9, + 2, -27, -29, 85, 86, 19, 40, 56, -52, 2, -40, -33, -16, 15, 2, -16, -39, 22, -37, 22, - 20, 7, 2, -5, 2, 4, 52, 42, 53, -5, + 20, 7, 2, -5, 2, 4, 53, 43, 54, -5, 20, -14, 25, 2, -18, 5, -28, -20, 12, -27, - -29, 16, -37, 78, 80, 76, 77, -37, -37, -37, + -29, 16, -37, 79, 81, 77, 78, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -37, -52, 15, -27, -27, 21, 6, 2, -15, - 22, -4, -6, 2, 60, 74, 61, 75, 62, 63, - 64, 76, 77, 12, 78, 45, 46, 49, 65, 18, - 66, 79, 80, 67, 68, 69, 70, 71, 84, 85, - 57, 22, 7, 20, -2, 25, 2, 25, 2, 26, - 26, -29, 26, 39, 55, -21, 24, 17, -22, 30, - 28, 29, 35, 36, 33, 31, 34, 32, -16, -16, - -17, -16, -17, 22, -53, -52, 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, 21, 2, 22, -4, -26, 26, 26, 17, -22, - -25, 55, -26, -30, -27, -27, -27, -23, 14, -25, - -23, -25, -26, -26, -26, -24, -27, 24, 21, 2, - 21, -27, + 22, -4, -6, 2, 61, 75, 62, 76, 63, 64, + 65, 77, 78, 12, 79, 46, 47, 50, 66, 18, + 67, 80, 81, 68, 69, 70, 71, 72, 85, 86, + 58, 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, -53, -52, 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, } var yyDef = [...]int16{ @@ -599,36 +604,36 @@ var yyDef = [...]int16{ 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 0, 2, -2, 3, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 0, 106, 216, 0, 226, 0, 83, 84, -2, -2, + 0, 106, 217, 0, 227, 0, 83, 84, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - 210, 211, 0, 5, 98, 0, 124, 127, 0, 132, + 211, 212, 0, 5, 98, 0, 124, 127, 0, 132, 133, 137, 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, 81, - 82, 0, 87, 89, 0, 93, 97, 227, 122, 0, + 82, 0, 87, 89, 0, 93, 97, 228, 122, 0, 128, 0, 131, 136, 0, 42, 47, 48, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 67, 0, 69, 225, 70, 0, - 72, 220, 221, 73, 74, 217, 0, 0, 0, 80, + 0, 0, 0, 0, 67, 0, 69, 226, 70, 0, + 72, 221, 222, 73, 74, 218, 0, 0, 0, 80, 20, 21, 24, 0, 54, 25, 0, 62, 64, 66, - 85, 0, 90, 0, 96, 212, 213, 214, 215, 0, + 85, 0, 90, 0, 96, 213, 214, 215, 216, 0, 123, 126, 129, 130, 135, 138, 140, 143, 147, 148, 149, 0, 26, 0, 0, -2, -2, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 68, 0, 218, 219, 75, -2, 79, 0, - 53, 56, 58, 59, 183, 184, 185, 186, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, - 209, 61, 65, 86, 88, 91, 95, 92, 94, 0, + 40, 41, 68, 0, 219, 220, 75, -2, 79, 0, + 53, 56, 58, 59, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, + 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, + 210, 61, 65, 86, 88, 91, 95, 92, 94, 0, 0, 0, 0, 0, 0, 0, 0, 153, 155, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 45, 46, - 49, 231, 50, 71, 0, -2, 78, 51, 0, 57, - 63, 139, 222, 141, 0, 144, 0, 0, 0, 151, - 156, 152, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 76, 77, 52, 55, 142, 0, 0, 150, 154, - 157, 0, 224, 158, 159, 160, 161, 162, 0, 163, - 164, 165, 145, 146, 223, 0, 169, 0, 167, 170, - 166, 168, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, + 46, 49, 232, 50, 71, 0, -2, 78, 51, 0, + 57, 63, 139, 223, 141, 0, 144, 0, 0, 0, + 151, 156, 152, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 76, 77, 52, 55, 142, 0, 0, + 150, 154, 157, 0, 225, 158, 159, 160, 161, 162, + 0, 163, 164, 165, 166, 145, 146, 224, 0, 170, + 0, 168, 171, 167, 169, } var yyTok1 = [...]int8{ @@ -645,7 +650,7 @@ 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, + 92, 93, } var yyTok3 = [...]int8{ @@ -1738,47 +1743,53 @@ yydefault: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.descriptors = yylex.(*parser).newMap() - yyVAL.descriptors["buckets"] = yyDollar[3].bucket_set + yyVAL.descriptors["custom_values"] = yyDollar[3].bucket_set } case 163: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.descriptors = yylex.(*parser).newMap() - yyVAL.descriptors["offset"] = yyDollar[3].int + yyVAL.descriptors["buckets"] = yyDollar[3].bucket_set } case 164: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.descriptors = yylex.(*parser).newMap() - yyVAL.descriptors["n_buckets"] = yyDollar[3].bucket_set + yyVAL.descriptors["offset"] = yyDollar[3].int } case 165: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.descriptors = yylex.(*parser).newMap() - yyVAL.descriptors["n_offset"] = yyDollar[3].int + yyVAL.descriptors["n_buckets"] = yyDollar[3].bucket_set } case 166: - yyDollar = yyS[yypt-4 : yypt+1] + yyDollar = yyS[yypt-3 : yypt+1] { - yyVAL.bucket_set = yyDollar[2].bucket_set + yyVAL.descriptors = yylex.(*parser).newMap() + yyVAL.descriptors["n_offset"] = yyDollar[3].int } case 167: - yyDollar = yyS[yypt-3 : yypt+1] + yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.bucket_set = yyDollar[2].bucket_set } case 168: yyDollar = yyS[yypt-3 : yypt+1] { - yyVAL.bucket_set = append(yyDollar[1].bucket_set, yyDollar[3].float) + yyVAL.bucket_set = yyDollar[2].bucket_set } case 169: + yyDollar = yyS[yypt-3 : yypt+1] + { + yyVAL.bucket_set = append(yyDollar[1].bucket_set, yyDollar[3].float) + } + case 170: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.bucket_set = []float64{yyDollar[1].float} } - case 216: + case 217: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.node = &NumberLiteral{ @@ -1786,22 +1797,22 @@ yydefault: PosRange: yyDollar[1].item.PositionRange(), } } - case 217: + case 218: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.float = yylex.(*parser).number(yyDollar[1].item.Val) } - case 218: + case 219: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.float = yyDollar[2].float } - case 219: + case 220: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.float = -yyDollar[2].float } - case 222: + case 223: yyDollar = yyS[yypt-1 : yypt+1] { var err error @@ -1810,17 +1821,17 @@ yydefault: yylex.(*parser).addParseErrf(yyDollar[1].item.PositionRange(), "invalid repetition in series values: %s", err) } } - case 223: + case 224: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.int = -int64(yyDollar[2].uint) } - case 224: + case 225: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.int = int64(yyDollar[1].uint) } - case 225: + case 226: yyDollar = yyS[yypt-1 : yypt+1] { var err error @@ -1829,7 +1840,7 @@ yydefault: yylex.(*parser).addParseErr(yyDollar[1].item.PositionRange(), err) } } - case 226: + case 227: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.node = &StringLiteral{ @@ -1837,7 +1848,7 @@ yydefault: PosRange: yyDollar[1].item.PositionRange(), } } - case 227: + case 228: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.item = Item{ @@ -1846,12 +1857,12 @@ yydefault: Val: yylex.(*parser).unquoteString(yyDollar[1].item.Val), } } - case 228: + case 229: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.duration = 0 } - case 230: + case 231: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.strings = nil diff --git a/promql/parser/lex.go b/promql/parser/lex.go index 4e3de2a668..6da3fe6e25 100644 --- a/promql/parser/lex.go +++ b/promql/parser/lex.go @@ -135,15 +135,16 @@ 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, + "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, } // ItemTypeStr is the default string representations for common Items. It does not diff --git a/promql/parser/parse.go b/promql/parser/parse.go index 104b80ce52..f3fa27f84e 100644 --- a/promql/parser/parse.go +++ b/promql/parser/parse.go @@ -566,6 +566,15 @@ func (p *parser) buildHistogramFromMap(desc *map[string]interface{}) *histogram. p.addParseErrf(p.yyParser.lval.item.PositionRange(), "error parsing z_bucket_w number: %v", val) } } + val, ok = (*desc)["custom_values"] + if ok { + customValues, ok := val.([]float64) + if ok { + output.CustomValues = customValues + } else { + p.addParseErrf(p.yyParser.lval.item.PositionRange(), "error parsing custom_values: %v", val) + } + } buckets, spans := p.buildHistogramBucketsAndSpans(desc, "buckets", "offset") output.PositiveBuckets = buckets diff --git a/promql/test.go b/promql/test.go index 6fe233b6f4..da42468022 100644 --- a/promql/test.go +++ b/promql/test.go @@ -46,8 +46,8 @@ var ( patSpace = regexp.MustCompile("[\t ]+") patLoad = regexp.MustCompile(`^load(?:_(with_nhcb))?\s+(.+?)$`) - patEvalInstant = regexp.MustCompile(`^eval(?:_(with_nhcb))?(?:_(fail|ordered))?\s+instant\s+(?:at\s+(.+?))?\s+(.+)$`) - patEvalRange = regexp.MustCompile(`^eval(?:_(fail))?\s+range\s+from\s+(.+)\s+to\s+(.+)\s+step\s+(.+?)\s+(.+)$`) + patEvalInstant = regexp.MustCompile(`^eval(?:_(with_nhcb))?(?:_(fail|warn|ordered))?\s+instant\s+(?:at\s+(.+?))?\s+(.+)$`) + patEvalRange = regexp.MustCompile(`^eval(?:_(fail|warn))?\s+range\s+from\s+(.+)\s+to\s+(.+)\s+step\s+(.+?)\s+(.+)$`) histogramBucketReplacements = []struct { pattern *regexp.Regexp repl string @@ -233,7 +233,7 @@ func (t *test) parseEval(lines []string, i int) (int, *evalCmd, error) { rangeParts := patEvalRange.FindStringSubmatch(lines[i]) if instantParts == nil && rangeParts == nil { - return i, nil, raise(i, "invalid evaluation command. Must be either 'eval[_with_nhcb][_fail|_ordered] instant [at ] ' or 'eval[_fail] range from to step '") + return i, nil, raise(i, "invalid evaluation command. Must be either 'eval[_with_nhcb][_fail|_warn|_ordered] instant [at ] ' or 'eval[_fail|_warn] range from to step '") } isInstant := instantParts != nil @@ -314,6 +314,8 @@ func (t *test) parseEval(lines []string, i int) (int, *evalCmd, error) { cmd.ordered = true case "fail": cmd.fail = true + case "warn": + cmd.warn = true } cmd.withNhcb = withNhcb @@ -636,9 +638,9 @@ type evalCmd struct { step time.Duration line int - isRange bool // if false, instant query - fail, ordered bool - withNhcb bool + isRange bool // if false, instant query + fail, warn, ordered bool + withNhcb bool metrics map[uint64]labels.Labels expected map[uint64]entry @@ -965,6 +967,13 @@ func (t *test) execRangeEval(cmd *evalCmd, engine QueryEngine) error { return fmt.Errorf("error creating range query for %q (line %d): %w", cmd.expr, cmd.line, err) } res := q.Exec(t.context) + countWarnings, _ := res.Warnings.CountWarningsAndInfo() + if !cmd.warn && countWarnings > 0 { + return fmt.Errorf("unexpected warnings evaluating query %q (line %d): %v", cmd.expr, cmd.line, res.Warnings) + } + if cmd.warn && countWarnings == 0 { + return fmt.Errorf("expected warnings evaluating query %q (line %d) but got none", cmd.expr, cmd.line) + } if res.Err != nil { if cmd.fail { return nil @@ -996,7 +1005,7 @@ func (t *test) execInstantEval(cmd *evalCmd, engine QueryEngine) error { } if cmd.withNhcb { if !strings.Contains(iq.expr, "_bucket") { - return fmt.Errorf("expected _bucket in the expression %q", iq.expr) + return fmt.Errorf("expected '_bucket' in the expression %q", iq.expr) } for _, rep := range histogramBucketReplacements { iq.expr = rep.pattern.ReplaceAllString(iq.expr, rep.repl) @@ -1016,6 +1025,13 @@ func (t *test) runInstantQuery(iq atModifierTestCase, cmd *evalCmd, engine Query } defer q.Close() res := q.Exec(t.context) + countWarnings, _ := res.Warnings.CountWarningsAndInfo() + if !cmd.warn && countWarnings > 0 { + return fmt.Errorf("unexpected warnings evaluating query %q (line %d): %v", iq.expr, cmd.line, res.Warnings) + } + if cmd.warn && countWarnings == 0 { + return fmt.Errorf("expected warnings evaluating query %q (line %d) but got none", iq.expr, cmd.line) + } if res.Err != nil { if cmd.fail { return nil diff --git a/promql/testdata/aggregators.test b/promql/testdata/aggregators.test index 8709b393b2..86336a5d9d 100644 --- a/promql/testdata/aggregators.test +++ b/promql/testdata/aggregators.test @@ -399,7 +399,7 @@ eval instant at 1m quantile without(point)((scalar(foo)), data) {test="three samples"} 1.6 {test="uneven samples"} 2.8 -eval instant at 1m quantile without(point)(NaN, data) +eval_warn instant at 1m quantile without(point)(NaN, data) {test="two samples"} NaN {test="three samples"} NaN {test="uneven samples"} NaN diff --git a/promql/testdata/functions.test b/promql/testdata/functions.test index e01c75a7f6..d68a1f2f52 100644 --- a/promql/testdata/functions.test +++ b/promql/testdata/functions.test @@ -830,17 +830,17 @@ eval instant at 1m quantile_over_time(1, data[1m]) {test="three samples"} 2 {test="uneven samples"} 4 -eval instant at 1m quantile_over_time(-1, data[1m]) +eval_warn instant at 1m quantile_over_time(-1, data[1m]) {test="two samples"} -Inf {test="three samples"} -Inf {test="uneven samples"} -Inf -eval instant at 1m quantile_over_time(2, data[1m]) +eval_warn instant at 1m quantile_over_time(2, data[1m]) {test="two samples"} +Inf {test="three samples"} +Inf {test="uneven samples"} +Inf -eval instant at 1m (quantile_over_time(2, (data[1m]))) +eval_warn instant at 1m (quantile_over_time(2, (data[1m]))) {test="two samples"} +Inf {test="three samples"} +Inf {test="uneven samples"} +Inf diff --git a/promql/testdata/histograms.test b/promql/testdata/histograms.test index 0aab3117dc..b7214cfade 100644 --- a/promql/testdata/histograms.test +++ b/promql/testdata/histograms.test @@ -127,17 +127,17 @@ eval_with_nhcb instant at 50m histogram_quantile(1, testhistogram3_bucket) {start="negative"} -0.1 # Quantile too low. -eval_with_nhcb instant at 50m histogram_quantile(-0.1, testhistogram_bucket) +eval_with_nhcb_warn instant at 50m histogram_quantile(-0.1, testhistogram_bucket) {start="positive"} -Inf {start="negative"} -Inf # Quantile too high. -eval_with_nhcb instant at 50m histogram_quantile(1.01, testhistogram_bucket) +eval_with_nhcb_warn instant at 50m histogram_quantile(1.01, testhistogram_bucket) {start="positive"} +Inf {start="negative"} +Inf # Quantile invalid. -eval_with_nhcb instant at 50m histogram_quantile(NaN, testhistogram_bucket) +eval_with_nhcb_warn instant at 50m histogram_quantile(NaN, testhistogram_bucket) {start="positive"} NaN {start="negative"} NaN @@ -254,6 +254,9 @@ eval_with_nhcb instant at 50m histogram_quantile(0.5, rate(request_duration_seco {instance="ins1", job="job2"} 0.1 {instance="ins2", job="job2"} 0.11666666666666667 +eval instant at 50m sum(request_duration_seconds) + {} {{schema:-53 count:250 custom_values:[0.1 0.2] buckets:[100 90 60]}} + # A histogram with nonmonotonic bucket counts. This may happen when recording # rule evaluation or federation races scrape ingestion, causing some buckets # counts to be derived from fewer samples. diff --git a/promql/testdata/native_histograms.test b/promql/testdata/native_histograms.test index 1da68a385f..a4fc3d8403 100644 --- a/promql/testdata/native_histograms.test +++ b/promql/testdata/native_histograms.test @@ -269,3 +269,18 @@ eval instant at 50m histogram_sum(sum(incr_sum_histogram)) eval instant at 50m histogram_sum(sum(last_over_time(incr_sum_histogram[5m]))) {} 30 + + + +# Test native histograms with custom buckets. +load 5m + custom_buckets_histogram {{schema:-53 sum:5 count:4 custom_values:[5 10] buckets:[1 2 1]}}x10 + +eval instant at 5m histogram_fraction(5, 10, custom_buckets_histogram) + {} 0.5 + +eval instant at 5m histogram_quantile(0.5, custom_buckets_histogram) + {} 7.5 + +eval instant at 5m sum(custom_buckets_histogram) + {} {{schema:-53 sum:5 count:4 custom_values:[5 10] buckets:[1 2 1]}} diff --git a/util/annotations/annotations.go b/util/annotations/annotations.go index f5f60ba874..6415f44744 100644 --- a/util/annotations/annotations.go +++ b/util/annotations/annotations.go @@ -94,6 +94,19 @@ func (a Annotations) AsStrings(query string, maxAnnos int) []string { return arr } +func (a Annotations) CountWarningsAndInfo() (int, int) { + var countWarnings, countInfo int + for _, err := range a { + if errors.Is(err, PromQLWarning) { + countWarnings++ + } + if errors.Is(err, PromQLInfo) { + countInfo++ + } + } + return countWarnings, countInfo +} + //nolint:revive // error-naming. var ( // Currently there are only 2 types, warnings and info.