Skip to content

Commit

Permalink
add pie chart for current early muxer connections
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Feb 22, 2023
1 parent 1235885 commit 21bf54d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 72 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
Since the last release, we've added additional metrics to different components.
Metrics were added to:
* [AutoNat](https://github.com/libp2p/go-libp2p/pull/2086): Current Reachability Status and Confidence, Client and Server DialResponses, Server DialRejections. The dashboard is [available here](https://github.com/libp2p/go-libp2p/blob/master/dashboards/autonat/autonat.json).
* Swarm:
- [Early Muxer Selection](https://github.com/libp2p/go-libp2p/pull/2119): Added early_muxer label indicating whether a connection was established using early muxer selection.
- [IP Version](https://github.com/libp2p/go-libp2p/pull/2114): Added ip_version label to connection metrics

## 🐞 Bugfixes <!-- omit in toc -->

Expand Down
2 changes: 1 addition & 1 deletion core/network/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ConnectionState struct {
// the transport used on this connection. For example: tcp
Transport string
// indicates whether StreamMultiplexer was selected using inlined muxer negotiation
EarlyMuxerSelection bool
UsedEarlyMuxerNegotiation bool
}

// ConnSecurity is the interface that one can mix into a connection interface to
Expand Down
66 changes: 20 additions & 46 deletions dashboards/swarm/swarm.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,64 +1064,32 @@
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "s"
"mappings": []
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "early muxer"
"options": "regular"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "green",
"fixedColor": "yellow",
"mode": "fixed"
}
}
Expand All @@ -1130,13 +1098,13 @@
{
"matcher": {
"id": "byName",
"options": "regular"
"options": "early muxer"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "yellow",
"fixedColor": "green",
"mode": "fixed"
}
}
Expand All @@ -1150,14 +1118,21 @@
"x": 12,
"y": 25
},
"id": 35,
"id": 36,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"pieType": "pie",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"tooltip": {
"mode": "single",
"sort": "none"
Expand All @@ -1170,8 +1145,7 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(rate(libp2p_swarm_handshake_latency_seconds_sum{transport=\"tcp\",early_muxer=\"true\"}[$__rate_interval])) / sum(rate(libp2p_swarm_handshake_latency_seconds_count{transport=\"tcp\",early_muxer=\"true\"}[$__rate_interval]))",
"hide": false,
"expr": "sum(libp2p_swarm_connections_opened_total{transport=\"tcp\",early_muxer=\"true\"} - libp2p_swarm_connections_closed_total{transport=\"tcp\",early_muxer=\"true\"})",
"legendFormat": "early muxer",
"range": true,
"refId": "A"
Expand All @@ -1182,15 +1156,15 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum(rate(libp2p_swarm_handshake_latency_seconds_sum{transport=\"tcp\",early_muxer=\"false\"}[$__rate_interval])) / sum(rate(libp2p_swarm_handshake_latency_seconds_count{transport=\"tcp\",early_muxer=\"false\"}[$__rate_interval]))",
"expr": "sum(libp2p_swarm_connections_opened_total{transport=\"tcp\",early_muxer=\"false\"} - libp2p_swarm_connections_closed_total{transport=\"tcp\",early_muxer=\"false\"})",
"hide": false,
"legendFormat": "regular",
"range": true,
"refId": "B"
}
],
"title": "Handshake Latency (Early Muxer Selection)",
"type": "timeseries"
"title": "Active Connections: Early Muxer Negotiation",
"type": "piechart"
},
{
"collapsed": false,
Expand Down Expand Up @@ -2618,6 +2592,6 @@
"timezone": "",
"title": "libp2p Swarm",
"uid": "a15PyhO4z",
"version": 2,
"version": 12,
"weekStart": ""
}
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func appendConnectionState(tags []string, cs network.ConnectionState) []string {
tags = append(tags, string(cs.StreamMultiplexer))

earlyMuxer := "false"
if cs.EarlyMuxerSelection {
if cs.UsedEarlyMuxerNegotiation {
earlyMuxer = "true"
}
tags = append(tags, earlyMuxer)
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/swarm/swarm_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func TestMetricsNoAllocNoCover(t *testing.T) {
mt := NewMetricsTracer()

connections := []network.ConnectionState{
{StreamMultiplexer: "yamux", Security: "tls", Transport: "tcp", EarlyMuxerSelection: true},
{StreamMultiplexer: "yamux", Security: "noise", Transport: "tcp", EarlyMuxerSelection: false},
{StreamMultiplexer: "yamux", Security: "tls", Transport: "tcp", UsedEarlyMuxerNegotiation: true},
{StreamMultiplexer: "yamux", Security: "noise", Transport: "tcp", UsedEarlyMuxerNegotiation: false},
{StreamMultiplexer: "", Security: "", Transport: "quic"},
{StreamMultiplexer: "mplex", Security: "noise", Transport: "tcp"},
}
Expand Down
14 changes: 7 additions & 7 deletions p2p/net/upgrader/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type transportConn struct {
scope network.ConnManagementScope
stat network.ConnStats

muxer protocol.ID
security protocol.ID
earlyMuxerSelection bool
muxer protocol.ID
security protocol.ID
usedEarlyMuxerNegotiation bool
}

var _ transport.CapableConn = &transportConn{}
Expand Down Expand Up @@ -57,9 +57,9 @@ func (t *transportConn) Close() error {

func (t *transportConn) ConnState() network.ConnectionState {
return network.ConnectionState{
StreamMultiplexer: t.muxer,
Security: t.security,
Transport: "tcp",
EarlyMuxerSelection: t.earlyMuxerSelection,
StreamMultiplexer: t.muxer,
Security: t.security,
Transport: "tcp",
UsedEarlyMuxerNegotiation: t.usedEarlyMuxerNegotiation,
}
}
18 changes: 9 additions & 9 deletions p2p/net/upgrader/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ func (u *upgrader) upgrade(ctx context.Context, t transport.Transport, maconn ma
}

tc := &transportConn{
MuxedConn: smconn,
ConnMultiaddrs: maconn,
ConnSecurity: sconn,
transport: t,
stat: stat,
scope: connScope,
muxer: muxer,
security: security,
earlyMuxerSelection: sconn.ConnState().EarlyMuxerSelection,
MuxedConn: smconn,
ConnMultiaddrs: maconn,
ConnSecurity: sconn,
transport: t,
stat: stat,
scope: connScope,
muxer: muxer,
security: security,
usedEarlyMuxerNegotiation: sconn.ConnState().UsedEarlyMuxerNegotiation,
}
return tc, nil
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/security/noise/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *secureSession) Close() error {
func SessionWithConnState(s *secureSession, muxer protocol.ID) *secureSession {
if s != nil {
s.connectionState.StreamMultiplexer = muxer
s.connectionState.EarlyMuxerSelection = muxer != ""
s.connectionState.UsedEarlyMuxerNegotiation = muxer != ""
}
return s
}
4 changes: 2 additions & 2 deletions p2p/security/noise/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,9 @@ func TestHandshakeWithTransportEarlyData(t *testing.T) {
defer respConn.Close()

require.Equal(t, expectedProto, initConn.connectionState.StreamMultiplexer)
require.Equal(t, expectedProto != "", initConn.connectionState.EarlyMuxerSelection)
require.Equal(t, expectedProto != "", initConn.connectionState.UsedEarlyMuxerNegotiation)
require.Equal(t, expectedProto, respConn.connectionState.StreamMultiplexer)
require.Equal(t, expectedProto != "", respConn.connectionState.EarlyMuxerSelection)
require.Equal(t, expectedProto != "", respConn.connectionState.UsedEarlyMuxerNegotiation)

initData := []byte("Test data for noise transport")
_, err := initConn.Write(initData)
Expand Down
4 changes: 2 additions & 2 deletions p2p/security/tls/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ func (t *Transport) setupConn(tlsConn *tls.Conn, remotePubKey ci.PubKey) (sec.Se
remotePeer: remotePeerID,
remotePubKey: remotePubKey,
connectionState: network.ConnectionState{
StreamMultiplexer: protocol.ID(nextProto),
EarlyMuxerSelection: nextProto != "",
StreamMultiplexer: protocol.ID(nextProto),
UsedEarlyMuxerNegotiation: nextProto != "",
},
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/security/tls/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestHandshakeWithNextProtoSucceeds(t *testing.T) {
require.True(t, clientConn.RemotePublicKey().Equals(serverKey.GetPublic()), "server public key mismatch")
require.True(t, serverConn.RemotePublicKey().Equals(clientKey.GetPublic()), "client public key mismatch")
require.Equal(t, clientConn.ConnState().StreamMultiplexer, expectedMuxer)
require.Equal(t, clientConn.ConnState().EarlyMuxerSelection, expectedMuxer != "")
require.Equal(t, clientConn.ConnState().UsedEarlyMuxerNegotiation, expectedMuxer != "")
// exchange some data
_, err = serverConn.Write([]byte("foobar"))
require.NoError(t, err)
Expand Down

0 comments on commit 21bf54d

Please sign in to comment.