0
votes

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.

1

1 Answers

0
votes

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.