PromQL If 条件和或运算符
PromQL If condition and or operator
在 PromQL 中,我想写
If metric_a>=bool 3:
return metric_b
else:
return 1
我想写成
(metric_b and metric_a>=3) or metric_a<bool 3
但我发现当我切换公制顺序时,比如A或B,B或A,查询结果会改变,也不确定我有什么意味着我的if-else
为什么 or/and 运算符会给出不一致的结果?另外,在这里呈现 if-else 语句的最佳方式是什么?
我检查了你提出的解决方案:
(metric_b and metric_a>=3) or metric_a<bool 3
它按预期工作,当 metric_a >= 3 时返回 metric_b 的值,否则返回 1。
请务必注意“VECTOR1 和 VECTOR2”不一定等于“VECTOR2 和 VECTOR1”。看看 Prometheus documentation about this:
vector1 and vector2 results in a vector consisting of the elements of
vector1 for which there are elements in vector2 with exactly matching
label sets. Other elements are dropped.
结果始终来自“and”子句的第一个向量。
例如下面的查询:
给出与以下结果不同的结果:
在 PromQL 中,我想写
If metric_a>=bool 3:
return metric_b
else:
return 1
我想写成
(metric_b and metric_a>=3) or metric_a<bool 3
但我发现当我切换公制顺序时,比如A或B,B或A,查询结果会改变,也不确定我有什么意味着我的if-else 为什么 or/and 运算符会给出不一致的结果?另外,在这里呈现 if-else 语句的最佳方式是什么?
我检查了你提出的解决方案:
(metric_b and metric_a>=3) or metric_a<bool 3
它按预期工作,当 metric_a >= 3 时返回 metric_b 的值,否则返回 1。
请务必注意“VECTOR1 和 VECTOR2”不一定等于“VECTOR2 和 VECTOR1”。看看 Prometheus documentation about this:
vector1 and vector2 results in a vector consisting of the elements of vector1 for which there are elements in vector2 with exactly matching label sets. Other elements are dropped.
结果始终来自“and”子句的第一个向量。
例如下面的查询:
给出与以下结果不同的结果: