Add client metrics for http and ws transports #344
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Not ready for merge
I've opened this PR in order to spur some discussion on how metrics could be reported by opamp-go clients and servers without introducing a dependency on open-telemetry or another metrics library. The goal here is to let library users inspect opamp-go's internal client metrics.
This PR adds client-side metrics collection for WS and HTTP transports. Collected metrics are in a custom format that can be translated to other metrics definitions by the library user. A TODO at this point is to add some library routines that can translate these metrics into common formats. It's unclear to me exactly where that should happen at the moment.
Counters have been added for message transmission metadata, as well as a ringbuffer that collects message latencies as well as key message attributes.
Library users can pass a
types.ClientMetrics
object toStartSettings
and then inspect the results periodically. The methods that the counters and ringbuffers expose are goroutine-safe. If the metrics object is not passed, a default one with a minimal buffer is created, so this change should non-breaking for library users.Some implementation details have been modified in order to ease testing. Specifically, some internal types have been replaced with interfaces in senders and receivers so that they can be replaced with fakes in tests.
The use of
*websocket.Conn
has been replaced withinternal.WebsocketConn
in several places for this reason as well.Finally, some definitions of the server have changed in order to reflect the need for the number of bytes transmitted to be known by the caller. While this is not necessary for client-side metrics collection, it will help facilitate a similar change to the server so that metrics can be collected there too.
If this change or a change like it is merged, then we could also implement this part of the spec, building on top of the internal collection: https://github.com/observIQ/opamp-spec/blob/808917457e973c251fd6c968bbb2b9dd38cb9f3d/specification.md#own-telemetry-reporting (thanks @rnishtala-sumo for the suggestion)