连接Prometheus查询,同时保留左侧的数据。

huangapple go评论72阅读模式
英文:

join prometheus queries while keeping data from the left side

问题

我想构建一个PromQL查询,它连接了两个向量:一个包含一些指标,另一个包含信息。问题是信息向量不包含所有与“joining label”相关的信息,但我不想错过指标向量的数据。

例如:kafka_consumergroup_lag 是一个具有 consumergroup 标签的指标向量,而 catalog_entities_info 是一个带有 consumergroupteam 标签以及每个条目的 1 标尺值的信息向量。我想将 team 标签添加到 kafka_consumergroup_lag 中。但是 catalog_entities_info 并不包含所有的 consumergroup,在这种情况下,我希望在结果向量中添加空的 team(或者可能是一些占位符,甚至根本不添加任何东西)。

到目前为止,我尝试过:

(sum(kafka_consumergroup_lag[1d]) by (consumergroup) >= 100)
* on(consumergroup) group_left(team)
catalog_entities_info

但是这个查询会过滤掉在 catalog_entities_info 中不存在的滞后的 consumergroup

英文:

I want to build promql query that joins two vectors: one with some metrics and other is informational. The caveat is that info vector doesn't have all the information for "joining label", but I don't want to miss the data from metrics vector.

For example: kafka_consumergroup_lag is the metrics vector with consumergroup label, and catalog_entities_info is the gauge info vector with consumergroup and team label and 1 gauge value for every entry. I want to add team label to kafka_consumergroup_lag. But catalog_entities_info doesn't have all consumergroup and in this case I want to add empty team (or maybe some placeholder, or even not adding anything at all) into resulting vector.

So far I tried:

(sum(kafka_consumergroup_lag[1d]) by (consumergroup) >= 100)
* on(consumergroup) group_left(team)
catalog_entities_info

but this query will filter out lagging consumergroups which are absent in catalog_entities_info.

答案1

得分: 0

现在我唯一的解决方案是使用查询重复:

(
  (sum(kafka_consumergroup_lag[1d]) by (consumergroup) >= 100)
  * on(consumergroup) group_left(team)
  catalog_entities_info
)
or ignoring(team) (sum(kafka_consumergroup_lag[1d]) by (consumergroup) >= 100)

第一部分将在可能的情况下添加 team 标签,第二部分的 or 将添加丢失的数据(在忽略添加的 team 标签的同时合并向量非常重要,否则我们将会有重复的数据)。

英文:

For now the only solution I have is with query duplication:

(
  (sum(kafka_consumergroup_lag[1d]) by (consumergroup) >= 100)
  * on(consumergroup) group_left(team)
  catalog_entities_info
)
or ignoring(team) (sum(kafka_consumergroup_lag[1d]) by (consumergroup) >= 100)

First half will add team label where possible, and second or half will add missed data (important to merge vectors while ignoring added team label, otherwise we will have duplicates).

huangapple
  • 本文由 发表于 2023年7月17日 16:37:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702740.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定