When you use the increase function to query the total increments of counter-type metrics, such as the request count, error count, restart count, and sent byte count, within a specified time range, the query result may differ from your expectations. The following section shows an example.
In VMP, when you query the total increments of counter-type metrics within a specified time range, unexpected results are often caused by the usage of an inappropriate function instead of a fault. When you query the total increments of counter-type metrics within a specified time range, the following three functions may be used: increase, increase_pure, and increase_prometheus.
For each query step, the query engine only performs calculations using the lookback window that corresponds to the step. Therefore, the first step may sometimes be 0 and sometimes not 0. For example, for increase(x[5m]), at 10:05, the system mainly analyzes samples around 10:00 to 10:05. If an available sample exists before the window, increase() will preferentially use the sample as the comparison baseline by default. If no sample exists before the window, increase() will not directly treat the first sample within the window as a 'newly added sample in this window' or as a 'historical value', but will determine this based on the changes between the first sample and subsequent samples.
By default, when no sample exists before the window, increase() will consider the incremental changes between the first point and subsequent points to determine whether the first value is a newly added value within the current window or an existing value before the window.
Function selection suggestion
The differences among the three increase functions mainly lie in two aspects: how to assume the first point when no sample exists before the window, and whether to follow the Prometheus standard externally. Therefore, for routine queries, prioritize using increase(). To assume that the first value is 0, use increase_pure(). To keep the result consistent with that of native Prometheus, use increase_prometheus().
The detailed descriptions are as follows:
When the query results do not match expectations, perform the following steps to troubleshoot, identify the issue, and select the function that is most suitable for the current usage scenario.
- Check whether the metrics are counters. The function is not suitable for querying the increments of gauges.
- Check the distribution of original samples. Focus on whether the last sample exists before the window. If no sample exists, observe the incremental changes between the first point and subsequent points.
- Query both increase() and increase_prometheus() to determine whether the difference comes from Prometheus extrapolation.
- Make sure that the range window is at least twice the collection interval. This prevents result instability caused by a small number of samples within the window.