按聚合返回的度量值分组

Group by measure values returned by aggregation

我正在按组 (instance) 取一个度量 (stage) 的最大值,然后我想按最大阶段显示,实例数是多少。

在 SQL 中,这将是:

select max_stage, count(*)
from
  (select instance, max(stage) as max_stage 
   from table 
   group by instance
  ) x
group by 
  max_stage 

对于 PromQL,这不起作用:

count by (stage) ((max by (instance) (stage)))

如何在外部聚合中引用最大阶段?

使用count_values代替count

count_values ("some_name", max by (instance) (stage))

https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators