Search code examples
promqlclamp

In promQL, how to max clamp the values of an instant vector with another instant vector


Is there a way to achieve that max clamping by passing an instant vector containing corresponding max values for each series?

In promQL, using the function clamp_max, it is possible to clamp the values of an instant vector with a scalar value, but if an instant vector is passed instead of the scalar, you get an error

Using function scalar() on that instant vector only works if the instant vector only contains one single value


Solution

  • The simplest solution for clamping v time series with max_v series is the following:

    (v < max_v) or max_v
    

    This query works in the following way:

    1. The v < max_v leaves only values smaller than max_v.
    2. The (...) or max_v fills gaps from the step 1 with max_v values.