Skip to content

Add log setting to dump failing HTTP request/response values using a ring buffer #77

Open
@hodgesrm

Description

@hodgesrm

Diagnosing HTTP call failures often requires detailed logging of the request/response. The problem is that such logging is either feast or famine:

  • HTTP logging is turned off so there's no additional information beyond the error type itself
  • HTTP logging is turned on so the log is flooded with information that is useless if there are no errors. Even when there's an error you need to trek through irrelevant information to get to the error.

As a result users tend to keep logging off and then have to repeat operations with logging on once an error appears. This is inefficient and does not help with errors that appear intermittently.

We can address this problem using an in-memory ring buffer to hold the last N request/responses. If an error occurs we dump the ring buffer as if logging had been turned on. This gives clients diagnostic information without requiring HTTP logging to be turned on.

There are some subtleties in the implementation that must be considered.

  • If HTTP logging is turned on the ring buffer is disabled.
  • The ring buffer keeps entries in memory, so they cannot be large. Binary data like OVA uploads should not be stored.
  • Clients should be able to control the number of entries to keep and dump in the event of an error. Just keeping the last request is a good default.
  • Each Client struct should have its own ring buffer to prevent confusion in concurrent applications.

Golang has a ring implementation that may be helpful for implementation. See https://golang.org/pkg/container/ring/ for more information.

Metadata

Metadata

Assignees

Labels

Code qualityIssue related to cod maintainability, usability, observabilityenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions