多节点服务跨路径聚合请求时长直方图PromQL查询问题咨询
问题:跨节点路径聚合直方图分位数时的单调性警告与指标选型困惑
背景
我们的服务包含多个节点,每个节点会为其处理请求的每个路径生成request_duration_histogram指标,抓取的样本示例如下(仅展示少量路径、节点和桶,实际场景更多):
request_duration_histogram_bucket{le="Infinity", path="path1", source="source1"} request_duration_histogram_bucket{le="Infinity", path="path2", source="source1"} request_duration_histogram_bucket{le="1", path="path1", source="source1"} request_duration_histogram_bucket{le="1", path="path2", source="source1"} request_duration_histogram_bucket{le="0.1", path="path1", source="source1"} request_duration_histogram_bucket{le="0.1", path="path2", source="source1"} request_duration_histogram_bucket{le="Infinity", path="path1", source="source2"} request_duration_histogram_bucket{le="Infinity", path="path2", source="source2"} request_duration_histogram_bucket{le="1", path="path1", source="source2"} request_duration_histogram_bucket{le="1", path="path2", source="source2"} request_duration_histogram_bucket{le="0.1", path="path1", source="source2"} request_duration_histogram_bucket{le="0.1", path="path2", source="source2"} request_duration_histogram_count{path="path1", source="source1"} request_duration_histogram_sum{path="path1", source="source1"} request_duration_histogram_count{path="path2", source="source1"} request_duration_histogram_sum{path="path2", source="source1"} request_duration_histogram_count{path="path1", source="source2"} request_duration_histogram_sum{path="path1", source="source2"} request_duration_histogram_count{path="path2", source="source2"} request_duration_histogram_sum{path="path2", source="source2"}
当前查询与警告
我们尝试在Grafana中计算整个服务(聚合所有路径和节点)的0.95分位数(已了解基于直方图计算分位数的局限性),使用的PromQL查询如下:
histogram_quantile( 0.95, sum( rate( request_duration_histogram_bucket[$__rate_interval] ) ) by (le) )
执行后收到以下警告:
PromQL info: input to histogram_quantile needed to be fixed for monotonicity (and may give inaccurate results) for metric name ""
对问题的分析
查阅官方文档后,我们理解该警告源于跨节点和路径聚合时,违反了histogram_quantile的输入要求:路径的请求速率在两次抓取间隔内可能下降,破坏了传入函数的向量单调性。
我们不确定该警告是否过于严格,还是这类全局聚合场景根本无法使用直方图查询。
已知的两种情况
- 使用
sum(increase(...))替代sum(rate(...))可以消除该警告; - 不能在
by(...)子句中添加path或source标签,因为需要的是所有路径和节点的整体分位数。
疑问
我们是否应该改用带预计算分位数的Summary指标(即使需要在Grafana端进行服务端聚合)?
内容的提问来源于stack exchange,提问作者Iacopo Pace
相关产品推荐
相关产品推荐

