简体   繁体   English

如何集成测试普罗米修斯指标

[英]How to integration test prometheus metrics

I have a golang server running that exposes metrics on a /debug endpoint.我有一个正在运行的 golang 服务器,它在/debug端点上公开指标。 I want to test the metrics recorded when I hit an endpoint in my tests.我想测试在我的测试中达到端点时记录的指标。

How do I capture the actual metrics recorded by my server and use them in my integration test?如何捕获服务器记录的实际指标并在集成测试中使用它们? I saw lots of code examples on Github but they were all unit tests.我在 Github 上看到了很多代码示例,但它们都是单元测试。

The response body of an HTTP GET request against the metrics endpoint, in your case /debug , will return a plain-text representation of the metrics that looks like this:针对指标端点的 HTTP GET 请求的响应正文(在您的情况下为/debug )将返回指标的纯文本表示,如下所示:

# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0

The integration test can then parse the plain-text representation of the metrics to assert the desired value of the metric.然后,集成测试可以解析度量的纯文本表示,以断言度量的期望值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM