I have a golang server running that exposes metrics on a /debug
endpoint. 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.
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:
# 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.