Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

feat: Add metrics for common events #69

Closed

Conversation

lightsofapollo
Copy link
Contributor

@lightsofapollo lightsofapollo commented Dec 16, 2022

Adds metrics for common error cases (timeoout, dtls handshake failure) and few success cases (stream open / stream close)

Open questions:

  • The TCP implementation https://github.com/libp2p/js-libp2p-tcp/blob/b93f4c0a921923401264aa560ae259afc9430a93/src/socket-to-conn.ts#L22 has the ability to prefix individual connection events (such as for close or perhaps the muxer?). I was not certain this would be helpful in this context and omitted it here. Should we add it?
  • Testing metrics collection I'd love to see metrics collection be part of the test suite. I was thinking perhaps either a mock object or an interface which allows collecting metrics in memory (similar to the prom client) but tests can verify the calls later.

Closes: #64

@lightsofapollo
Copy link
Contributor Author

NOTE: I've taken the exact pattern mentioned in the TCP listener. We may want to expand certain metrics in future for WebRTC as there are some complex error conditions not captured in this initial draft.

src/transport.ts Outdated Show resolved Hide resolved
@ddimaria
Copy link
Collaborator

In the TCP version, metrics are added to the multiaddress connection. Do we want that here as well?

src/transport.ts Outdated Show resolved Hide resolved
@lightsofapollo
Copy link
Contributor Author

@ddimaria good question about the multiaddr ... I read through that file in the webrtc implementation and it wasn't entirely clear if we need metrics there except in the case of close https://github.com/libp2p/js-libp2p-webrtc/blob/main/src/maconn.ts (see close) wdyt?

@ddimaria
Copy link
Collaborator

We may want to include the close event in maconn.ts. Thoughts?

@ddimaria
Copy link
Collaborator

There are events related to the datachannel. We may want to include those in muxer.ts.

@lightsofapollo
Copy link
Contributor Author

@ddimaria I like that suggestion... The muxer is more related to the number of inbound/outbound connections which I like. I'll add that next.

@lightsofapollo lightsofapollo changed the title feat: Add metrics for common errors feat: Add metrics for common events Dec 16, 2022
@@ -11,6 +11,7 @@ describe('Multiaddr Connection', () => {
const remoteAddr = multiaddr('/ip4/1.2.3.4/udp/1234/webrtc/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ')
const maConn = new WebRTCMultiaddrConnection({
peerConnection: peerConnection,
metrics: null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we explicitly tested metrics inteface?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sinon-ts module can be used to do this in a straightforward way.

/**
* Optional metrics counter group for this connection
*/
metrics: CounterGroup | null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should accept null as a value, better to mark this optional

Suggested change
metrics: CounterGroup | null
metrics?: CounterGroup

@@ -11,6 +11,7 @@ describe('Multiaddr Connection', () => {
const remoteAddr = multiaddr('/ip4/1.2.3.4/udp/1234/webrtc/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ')
const maConn = new WebRTCMultiaddrConnection({
peerConnection: peerConnection,
metrics: null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sinon-ts module can be used to do this in a straightforward way.

@lightsofapollo
Copy link
Contributor Author

@achingbrain ❤️ Thanks! I'll have the next iteration up shortly which will be ready to review :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export metrics
3 participants