diff --git a/cmd/prometheus/testdata/features.json b/cmd/prometheus/testdata/features.json index 51b3c6bcb5..c1f082e60f 100644 --- a/cmd/prometheus/testdata/features.json +++ b/cmd/prometheus/testdata/features.json @@ -77,7 +77,6 @@ "exp": true, "first_over_time": false, "floor": true, - "greatest": false, "histogram_avg": true, "histogram_count": true, "histogram_fraction": true, @@ -94,12 +93,13 @@ "label_join": true, "label_replace": true, "last_over_time": true, - "least": false, "ln": true, "log10": true, "log2": true, "mad_over_time": false, + "max_of": false, "max_over_time": true, + "min_of": false, "min_over_time": true, "minute": true, "month": true, diff --git a/docs/feature_flags.md b/docs/feature_flags.md index 5bee9814d3..f0aa41a9ab 100644 --- a/docs/feature_flags.md +++ b/docs/feature_flags.md @@ -223,10 +223,10 @@ For a **range query**, it resolves to the full range of the query (end time - st For an **instant query**, it resolves to `0s`. This is particularly useful in combination with `@end()` to look back over the entire query range, e.g., `max_over_time(metric[range()] @ end())`. -`least(, )` and `greatest(, )` select between two duration expressions. -`least` returns the smaller of the two, which is useful for capping a duration at a maximum value. -`greatest` returns the larger of the two, which is useful for enforcing a minimum value. -For example, `greatest(step(), 5s)` ensures the duration is never shorter than `5s`, while `least(range(), 1h)` caps the duration at `1h`. +`min_of(, )` and `max_of(, )` select between two duration expressions. +`min_of` returns the smaller of the two, which is useful for capping a duration at a maximum value. +`max_of` returns the larger of the two, which is useful for enforcing a minimum value. +For example, `max_of(step(), 5s)` ensures the duration is never shorter than `5s`, while `min_of(range(), 1h)` caps the duration at `1h`. **Note**: Duration expressions are not supported in the @ timestamp operator. @@ -248,8 +248,8 @@ Examples of equivalent durations: * `4h % 3h` is equivalent to `1h` or `3600s` * `(2 ^ 3) * 1m` is equivalent to `8m` or `480s` * `step() + 1` is equivalent to the query step width increased by 1s. -* `greatest(step(), 5s)` is equivalent to the larger of the query step width and `5s`. -* `least(2 * step() + 5s, 5m)` is equivalent to the smaller of twice the query step increased by `5s` and `5m`. +* `max_of(step(), 5s)` is equivalent to the larger of the query step width and `5s`. +* `min_of(2 * step() + 5s, 5m)` is equivalent to the smaller of twice the query step increased by `5s` and `5m`. ## OTLP Native Delta Support diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 30287d330c..5900da4c62 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -693,22 +693,22 @@ This second example has the same effect than the first example, and illustrates label_replace(up{job="api-server",service="a:c"}, "foo", "$name", "service", "(?P.*):(?P.*)") ``` -## `greatest()` +## `max_of()` **This function has to be enabled via the [feature flag](../feature_flags.md#experimental-promql-functions) `--enable-feature=promql-experimental-functions`.** -`greatest(a scalar, b scalar)` returns the larger of the two scalar values `a` +`max_of(a scalar, b scalar)` returns the larger of the two scalar values `a` and `b`. -## `least()` +## `min_of()` **This function has to be enabled via the [feature flag](../feature_flags.md#experimental-promql-functions) `--enable-feature=promql-experimental-functions`.** -`least(a scalar, b scalar)` returns the smaller of the two scalar values `a` +`min_of(a scalar, b scalar)` returns the smaller of the two scalar values `a` and `b`. ## `ln()` diff --git a/promql/durations.go b/promql/durations.go index 94099888c0..f0319e1acd 100644 --- a/promql/durations.go +++ b/promql/durations.go @@ -135,9 +135,9 @@ func (v *durationVisitor) evaluateDurationExpr(expr parser.Expr) (float64, error return float64(v.step.Seconds()), nil case parser.RANGE: return float64(v.queryRange.Seconds()), nil - case parser.LEAST: + case parser.MIN_OF: return math.Min(lhs, rhs), nil - case parser.GREATEST: + case parser.MAX_OF: return math.Max(lhs, rhs), nil case parser.ADD: if n.LHS == nil { diff --git a/promql/durations_test.go b/promql/durations_test.go index d11ec3885a..0f4f4df652 100644 --- a/promql/durations_test.go +++ b/promql/durations_test.go @@ -228,7 +228,7 @@ func TestCalculateDuration(t *testing.T) { expected: 150 * time.Second, }, { - name: "greatest of step and range", + name: "max_of of step and range", expr: &parser.DurationExpr{ LHS: &parser.DurationExpr{ Op: parser.STEP, @@ -236,7 +236,7 @@ func TestCalculateDuration(t *testing.T) { RHS: &parser.DurationExpr{ Op: parser.RANGE, }, - Op: parser.GREATEST, + Op: parser.MAX_OF, }, expected: 5 * time.Minute, }, diff --git a/promql/functions.go b/promql/functions.go index 5afd00e1ae..7303f688c0 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -1432,13 +1432,13 @@ func funcSqrt(vectorVals []Vector, _ Matrix, _ parser.Expressions, enh *EvalNode return simpleFloatFunc(vectorVals, enh, math.Sqrt), nil } -// === greatest(a, b parser.ValueTypeScalar) Scalar === -func funcGreatest(vectorVals []Vector, _ Matrix, _ parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) { +// === max_of(a, b parser.ValueTypeScalar) Scalar === +func funcMaxOf(vectorVals []Vector, _ Matrix, _ parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) { return append(enh.Out, Sample{F: math.Max(vectorVals[0][0].F, vectorVals[1][0].F)}), nil } -// === least(a, b parser.ValueTypeScalar) Scalar === -func funcLeast(vectorVals []Vector, _ Matrix, _ parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) { +// === min_of(a, b parser.ValueTypeScalar) Scalar === +func funcMinOf(vectorVals []Vector, _ Matrix, _ parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) { return append(enh.Out, Sample{F: math.Min(vectorVals[0][0].F, vectorVals[1][0].F)}), nil } @@ -2299,10 +2299,10 @@ var FunctionCalls = map[string]FunctionCall{ "increase": funcIncrease, "info": nil, "irate": funcIrate, - "greatest": funcGreatest, + "max_of": funcMaxOf, "label_replace": nil, // evalLabelReplace not called via this map. "label_join": nil, // evalLabelJoin not called via this map. - "least": funcLeast, + "min_of": funcMinOf, "ln": funcLn, "log10": funcLog10, "log2": funcLog2, diff --git a/promql/parser/functions.go b/promql/parser/functions.go index bc7bad7186..3e34b71700 100644 --- a/promql/parser/functions.go +++ b/promql/parser/functions.go @@ -263,8 +263,8 @@ var Functions = map[string]*Function{ Variadic: -1, ReturnType: ValueTypeVector, }, - "greatest": { - Name: "greatest", + "max_of": { + Name: "max_of", ArgTypes: []ValueType{ValueTypeScalar, ValueTypeScalar}, ReturnType: ValueTypeScalar, Experimental: true, @@ -274,8 +274,8 @@ var Functions = map[string]*Function{ ArgTypes: []ValueType{ValueTypeMatrix}, ReturnType: ValueTypeVector, }, - "least": { - Name: "least", + "min_of": { + Name: "min_of", ArgTypes: []ValueType{ValueTypeScalar, ValueTypeScalar}, ReturnType: ValueTypeScalar, Experimental: true, diff --git a/promql/parser/generated_parser.y b/promql/parser/generated_parser.y index faebcfd43e..1b22593dd2 100644 --- a/promql/parser/generated_parser.y +++ b/promql/parser/generated_parser.y @@ -159,8 +159,8 @@ START END STEP RANGE -GREATEST -LEAST +MAX_OF +MIN_OF %token preprocessorEnd // Counter reset hints. @@ -185,7 +185,7 @@ START_METRIC_SELECTOR // Type definitions for grammar rules. %type label_match_list %type label_matcher -%type aggregate_op grouping_label match_op maybe_label metric_identifier unary_op at_modifier_preprocessors string_identifier counter_reset_hint greatest_least +%type aggregate_op grouping_label match_op maybe_label metric_identifier unary_op at_modifier_preprocessors string_identifier counter_reset_hint max_of_min_of %type label_set metric %type label_set_list %type