Skip to content

Conversation

@joaopaulovieira
Copy link
Member

This PR improves error metric recording and testing in the httpclient module.

request.go

  • Bug fix:
    • Ensures the attrs map is always initialized before adding the "error" field in error cases, preventing panic (assignment to entry in nil map).
  • Relevant change:
    • Key line changed:
      • Before: var attrs map[string]string
      • After: attrs := map[string]string{}
    • Always adds the error field to attrs when a generic error occurs.

register_metrics_test.go

  • New tests added:
    • Tests for error scenarios:
      • Circuit breaker open error (ErrCircuitOpen): validates increment of the circuit_open counter.
      • Generic error: validates increment of the errors counter and the registration of the error attribute.
  • Improved assertions:
    • Tests now validate not only the existence of counters, but also the suffixes of the keys and the registered attributes.
    • Uses WithChainCallback to simulate errors via a custom callback.

How to test

  • Run go test on register_metrics_test.go to ensure all success and error scenarios are covered and there are no more panics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants