本文描述阿里云 Prometheus 与 VictoriaMetrics 的计算差异
适用范围
-
VictoriaMetrics 对比版本:v1.93.12。
-
阿里云 Prometheus 的 PromQL 计算基于开源 Prometheus 2.x,行为无特殊之处。
新增时间序列开始位置 Counter 计算方法
在时间序列开始位置用 increase 计算,容易发现 VictoriaMetrics 将头部处理为非零值,而开源 Prometheus 完全忠实于 increase 本身的语义,严格遵循在两个点上计算,算出来始终为1。
-
Prometheus,例如新时间序列 up
查询
up指标的 Graph 显示,该时间序列从某一时刻起才开始出现数据点,值稳定为 1,之前时间段内无任何数据。在 Prometheus 中执行查询increase(up[2m]),Graph 页签显示该指标在近 30 分钟内增量均为 0。直接计算 increase,要从 [2m] 能取到至少两个点的位置开始算,结果自然全是 0。
-
VictoriaMetrics,例如新时间序列 vm_app_version
在 VMUI 中查询
vm_app_version指标,Graph 中显示该时间序列值恒为 1,图例标签包含版本信息short_version="v1.93.12"。
时间序列何时创建出来,对应的 increase 结果就从何时开始,并且存在类似默认补点的行为,使得 increase 结果从1开始,2m 后转为正常的 0。
窗口函数语义自动补齐
众所周知,在 Prometheus 语义下,用窗口函数不写窗口值是错误的:
在 Prometheus 中执行查询 increase(up),返回错误:expected type range vector in call to function "increase", got instant vector。
Prometheus 毫无疑问报错了
在 VMUI 中直接执行 increase(vm_app_version)(省略范围窗口参数),查询成功执行并返回了折线图结果。
VictoriaMetrics 容忍这种情况,默认补齐为采样间隔,正常返回结果,将用户错误的写法吞掉了。
Counter 类函数线性补偿行为差异
这部分的差异也主要在于 VictoriaMetrics 的 Rollup 行为:
"ideriv": newRollupFuncOneArg(rollupIderiv),
"increase": newRollupFuncOneArg(rollupDelta), // + rollupFuncsRemoveCounterResets
"increase_prometheus": newRollupFuncOneArg(rollupDeltaPrometheus), // + rollupFuncsRemoveCounterResets
"increase_pure": newRollupFuncOneArg(rollupIncreasePure), // + rollupFuncsRemoveCounterResets
"increases_over_time": newRollupFuncOneArg(rollupIncreases),
"integrate": newRollupFuncOneArg(rollupIntegrate),
// ...
VictoriaMetrics 提供了 increase / increase_pure / increase_prometheus 三种实现,其中 increase_prometheus 是跟开源 Prometheus 一致的。
increase
increase(series_selector[d]) is a rollup function, which calculates the increase over the given lookbehind window d per each time series returned from the given series_selector.
Unlike Prometheus, it takes into account the last sample before the given lookbehind window d when calculating the result. See this article for details.
Metric names are stripped from the resulting rollups. Add keep_metric_names modifier in order to keep metric names.
This function is usually applied to counters.
This function is supported by PromQL.
See also increase_pure, increase_prometheus and delta.
increase_prometheus
increase_prometheus(series_selector[d]) is a rollup function, which calculates the increase over the given lookbehind window d per each time series returned from the given series_selector. It doesn't take into account the last sample before the given lookbehind window d when calculating the result in the same way as Prometheus does. See this article for details.
Metric names are stripped from the resulting rollups. Add keep_metric_names modifier in order to keep metric names.
This function is usually applied to counters.
See also increase_pure and increase.
increase_pure
increase_pure(series_selector[d]) is a rollup function, which works the same as increase except of the following corner case - it assumes that counters always start from 0, while increase ignores the first value in a series if it is too big.
This function is usually applied to counters.
See also increase and increase_prometheus.