Skip to content

metrics: Enhance the http metrics middleware

Pre-release
Pre-release

Choose a tag to compare

@dmytrorezn dmytrorezn released this 25 Mar 15:13
· 3 commits to master since this release
f277fdb

This pull request includes changes to the middleware/metrics.go and middleware/metrics_test.go files to enhance the metrics middleware by adding status code tracking and updating the corresponding tests. The most important changes include adding status code labels, updating the metrics middleware to record status codes, and modifying the tests to validate the new status code metrics.

Enhancements to metrics middleware:

  • middleware/metrics.go: Added a new label labelStatus to track HTTP status codes and updated the MetricsMiddleware function to include this label in the metrics.
  • middleware/metrics.go: Modified the MetricsMiddleware function to record the status code of each request and include it in the label values.

Updates to tests:

  • middleware/metrics_test.go: Added a new route /404 to simulate a 404 error and updated the test cases to include this new route.
  • middleware/metrics_test.go: Updated the expected metrics to include new keys for client and server errors, and modified the assertions to check for the new status code label.