【问题标题】:How to integration test prometheus metrics如何集成测试普罗米修斯指标
【发布时间】:2020-06-15 14:34:31
【问题描述】:

我有一个正在运行的 golang 服务器,它在 /debug 端点上公开指标。我想测试我在测试中遇到端点时记录的指标。

如何捕获服务器记录的实际指标并在集成测试中使用它们?我在 Github 上看到很多代码示例,但都是单元测试。

【问题讨论】:

    标签: go prometheus metrics


    【解决方案1】:

    针对指标端点的 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
    

    然后,集成测试可以解析指标的纯文本表示,以断言指标的期望值。

    【讨论】:

    • 谢谢,我想我可能不得不使用 client_golang 中的 testutil 包
    猜你喜欢
    • 2020-01-10
    • 2020-11-12
    • 1970-01-01
    • 2023-02-11
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 2022-12-22
    • 1970-01-01
    相关资源
    最近更新 更多