prometheus / prometheus/client_python
feature request/RFC: leave out a label (from at least `*MetricFamily` samples) when it's value is set to `None`
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 4.4k
- 派生
- 876
- 平均合并
- 8 天 4 小时
- 30 天内合并 PR
- 1
描述
Hey.
This is somewhat related to https://github.com/prometheus/docs/issues/2977, i.e. “what to do if some values of a sample aren’t available”, which obviously may not just be the actual metric value but also values of labels.
AFAIU, labels values are always strings, so sometimes it may be possible to use a special label value to indicate an error, for example if the label would be a host, one might simply use some characters that cannot appear in hostnames or addresses and thus either an empty string or perhaps <unknown> or similar values depending on the error.
But sometimes this may not be possible, in particular when the possible label values are arbitrary (like I have a case where the label is a description which may contain any string including the empty one).
Now in the error case (at least in my use case) it's better to have the rest of the data, but it still feels wrong to use a value for it that would be valid, even though I couldn't determine it on that particular scrape.
The time series is likely anyway already interrupted, so what's IMO the cleanest solution is simply leaving out the respective label in the error case, even if I have another metric which somehow indicates that sometime is fishy (like _up or so).
(Or any better ideas?)
Now I guess often, exporters will simply have a set of *MetricFamily-objects and .add_metrics to it, which requires however all the values for the defined labels to be given.
My proposal/RFC here is: Would it make sense to special-handle a value of None (which currently seems to simply lead to an error), causing it to leave that particular label out from the printed data for the particular label only?
I guess I could look in implementing this, but on a first short glance it didn't seem straightforward, so I wanted to ask what people even think about it.
Cheers,
Chris.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先定位 *MetricFamily 类、add_metric 以及输出序列化路径的实现,然后检查当前如何验证 None 标签值。在确认项目维护者同意此 RFC 后,定义并测试仅省略受影响标签、同时保留其余样本数据的行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- observability-sre
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100