From 557aac382dd639855163973f8eadf25320151fc5 Mon Sep 17 00:00:00 2001 From: sukun Date: Wed, 22 Feb 2023 17:05:24 +0530 Subject: [PATCH 1/3] add identify metrics metrics added: address count protocol count peer push support --- CHANGELOG.md | 4 + dashboards/identify/identify.json | 800 ++++++++++++++++++ .../grafana-dashboards/dashboard.json | 355 -------- p2p/protocol/identify/id.go | 23 + p2p/protocol/identify/metrics.go | 97 +++ p2p/protocol/identify/metrics_test.go | 18 +- 6 files changed, 939 insertions(+), 358 deletions(-) create mode 100644 dashboards/identify/identify.json delete mode 100644 p2p/protocol/identify/grafana-dashboards/dashboard.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 227f165e8b..2f30228324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ Metrics were added to: * 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 +* Identify: + - Metrics for Identify, IdentifyPush, PushesTriggered (https://github.com/libp2p/go-libp2p/pull/2069) + - Address Count, Protocol Count, Peer Protocol Support (https://github.com/libp2p/go-libp2p/pull/2126) + ## 🐞 Bugfixes diff --git a/dashboards/identify/identify.json b/dashboards/identify/identify.json new file mode 100644 index 0000000000..373aa43b49 --- /dev/null +++ b/dashboards/identify/identify.json @@ -0,0 +1,800 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "panel", + "id": "gauge", + "name": "Gauge", + "version": "" + }, + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.3.6" + }, + { + "type": "panel", + "id": "piechart", + "name": "Pie chart", + "version": "" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "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 + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "increase(libp2p_identify_identify_pushes_triggered_total[$__rate_interval])", + "legendFormat": "{{trigger}}", + "range": true, + "refId": "A" + } + ], + "title": "Pushes triggered", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "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 + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "rate(libp2p_identify_identify_total[$__rate_interval])", + "legendFormat": "{{dir}}", + "range": true, + "refId": "A" + } + ], + "title": "Identify Messages", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "none" + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "address count" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "blue", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 0, + "y": 9 + }, + "id": 9, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": false, + "expr": "libp2p_identify_addrs_count", + "legendFormat": "address count", + "range": true, + "refId": "A" + } + ], + "title": "Outgoing Address Count", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "protocols count" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "purple", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 6, + "y": 9 + }, + "id": 17, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "9.3.6", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "libp2p_identify_protocols_count", + "legendFormat": "protocols count", + "range": true, + "refId": "A" + } + ], + "title": "Outgoing Protocols Count", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "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 + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 9 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "rate(libp2p_identify_identify_push_total[$__rate_interval])", + "legendFormat": "{{dir}}", + "range": true, + "refId": "A" + } + ], + "title": "Identify Push Messages", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "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 + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "address count" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "blue", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 17 + }, + "id": 11, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum( rate(libp2p_identify_addrs_received_sum[$__rate_interval])) / sum( rate(libp2p_identify_addrs_received_count[$__rate_interval]))", + "legendFormat": "address count", + "range": true, + "refId": "A" + } + ], + "title": "Incoming Address Count (Avg)", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "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 + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "protocols count" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "purple", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 17 + }, + "id": 13, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(rate( libp2p_identify_protocols_received_sum[$__rate_interval])) / sum(rate(libp2p_identify_protocols_received_count[$__rate_interval]))", + "legendFormat": "protocols count", + "range": true, + "refId": "A" + } + ], + "title": "Incoming Protocols Count (Avg)", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 25 + }, + "id": 15, + "options": { + "legend": { + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "pieType": "pie", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "libp2p_identify_conn_push_support", + "legendFormat": "{{support}}", + "range": true, + "refId": "A" + } + ], + "title": "Peers: Push Support", + "type": "piechart" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "libp2p Identify", + "uid": "0NDzQQ0Vz", + "version": 2, + "weekStart": "" +} \ No newline at end of file diff --git a/p2p/protocol/identify/grafana-dashboards/dashboard.json b/p2p/protocol/identify/grafana-dashboards/dashboard.json deleted file mode 100644 index c00850e3f3..0000000000 --- a/p2p/protocol/identify/grafana-dashboards/dashboard.json +++ /dev/null @@ -1,355 +0,0 @@ -{ - "__inputs": [ - { - "name": "DS_PROMETHEUS", - "label": "Prometheus", - "description": "", - "type": "datasource", - "pluginId": "prometheus", - "pluginName": "Prometheus" - } - ], - "__elements": {}, - "__requires": [ - { - "type": "grafana", - "id": "grafana", - "name": "Grafana", - "version": "9.3.6" - }, - { - "type": "datasource", - "id": "prometheus", - "name": "Prometheus", - "version": "1.0.0" - }, - { - "type": "panel", - "id": "timeseries", - "name": "Time series", - "version": "" - } - ], - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": { - "type": "grafana", - "uid": "-- Grafana --" - }, - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "target": { - "limit": 100, - "matchAny": false, - "tags": [], - "type": "dashboard" - }, - "type": "dashboard" - } - ] - }, - "editable": true, - "fiscalYearStartMonth": 0, - "graphTooltip": 0, - "id": null, - "links": [], - "liveNow": false, - "panels": [ - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "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 - }, - { - "color": "red", - "value": 80 - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 0 - }, - "id": 4, - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom", - "showLegend": true - }, - "tooltip": { - "mode": "multi", - "sort": "none" - } - }, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "editorMode": "code", - "expr": "rate(libp2p_identify_identify_total[$__rate_interval])", - "legendFormat": "{{dir}}", - "range": true, - "refId": "A" - } - ], - "title": "Identify Messages", - "type": "timeseries" - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "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 - }, - { - "color": "red", - "value": 80 - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 8, - "w": 12, - "x": 12, - "y": 0 - }, - "id": 5, - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom", - "showLegend": true - }, - "tooltip": { - "mode": "multi", - "sort": "none" - } - }, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "editorMode": "code", - "expr": "rate(libp2p_identify_identify_push_total[$__rate_interval])", - "legendFormat": "{{dir}}", - "range": true, - "refId": "A" - } - ], - "title": "Identify Push Messages", - "type": "timeseries" - }, - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "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 - }, - { - "color": "red", - "value": 80 - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 9, - "w": 12, - "x": 0, - "y": 8 - }, - "id": 2, - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom", - "showLegend": true - }, - "tooltip": { - "mode": "multi", - "sort": "none" - } - }, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "${DS_PROMETHEUS}" - }, - "editorMode": "code", - "expr": "rate(libp2p_identify_identify_pushes_triggered_total[$__rate_interval])", - "legendFormat": "{{trigger}}", - "range": true, - "refId": "A" - } - ], - "title": "Pushes triggered", - "type": "timeseries" - } - ], - "schemaVersion": 37, - "style": "dark", - "tags": [], - "templating": { - "list": [] - }, - "time": { - "from": "now-1h", - "to": "now" - }, - "timepicker": {}, - "timezone": "", - "title": "libp2p Identify", - "uid": "0NDzQQ0Vz", - "version": 4, - "weekStart": "" -} diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 3bbe58bf7d..601f23b312 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -491,6 +491,7 @@ func (ids *idService) handleIdentifyResponse(s network.Stream, isPush bool) erro if !ok { // might already have disconnected return nil } + prevPushSupport := e.PushSupport sup, err := ids.Host.Peerstore().SupportsProtocols(c.RemotePeer(), IDPush) if supportsIdentifyPush := err == nil && len(sup) > 0; supportsIdentifyPush { e.PushSupport = identifyPushSupported @@ -498,6 +499,10 @@ func (ids *idService) handleIdentifyResponse(s network.Stream, isPush bool) erro e.PushSupport = identifyPushUnsupported } ids.conns[c] = e + if ids.metricsTracer != nil && e.PushSupport != prevPushSupport { + ids.metricsTracer.IncrementPushSupport(e.PushSupport) + ids.metricsTracer.DecrementPushSupport(prevPushSupport) + } return nil } @@ -581,6 +586,11 @@ func (ids *idService) createBaseIdentifyResponse(conn network.Conn, snapshot *id } mes.ListenAddrs = append(mes.ListenAddrs, addr.Bytes()) } + if ids.metricsTracer != nil { + ids.metricsTracer.NumProtocols(len(mes.Protocols)) + ids.metricsTracer.NumAddrs(len(mes.ListenAddrs)) + } + // set our public key ownKey := ids.Host.Peerstore().PubKey(ids.Host.ID()) @@ -684,6 +694,11 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo lmaddrs = append(lmaddrs, maddr) } + if ids.metricsTracer != nil { + ids.metricsTracer.NumProtocolsReceived(len(mesProtocols)) + ids.metricsTracer.NumAddrsReceived(len(lmaddrs)) + } + // NOTE: Do not add `c.RemoteMultiaddr()` to the peerstore if the remote // peer doesn't tell us to do so. Otherwise, we'll advertise it. // @@ -886,6 +901,10 @@ func (nn *netNotifiee) Connected(_ network.Network, c network.Conn) { ids.conns[c] = entry{} ids.connsMu.Unlock() + if ids.metricsTracer != nil { + ids.metricsTracer.IncrementPushSupport(identifyPushSupportUnknown) + } + nn.IDService().IdentifyWait(c) } @@ -894,8 +913,12 @@ func (nn *netNotifiee) Disconnected(_ network.Network, c network.Conn) { // Stop tracking the connection. ids.connsMu.Lock() + e, ok := ids.conns[c] delete(ids.conns, c) ids.connsMu.Unlock() + if ok && ids.metricsTracer != nil { + ids.metricsTracer.DecrementPushSupport(e.PushSupport) + } if ids.Host.Network().Connectedness(c.RemotePeer()) != network.Connected { // Last disconnect. diff --git a/p2p/protocol/identify/metrics.go b/p2p/protocol/identify/metrics.go index f8ffc6dddf..109667b551 100644 --- a/p2p/protocol/identify/metrics.go +++ b/p2p/protocol/identify/metrics.go @@ -35,17 +35,71 @@ var ( }, []string{"dir"}, ) + connectionPushSupport = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: metricNamespace, + Name: "conn_push_support", + Help: "Identify Connection Push Support", + }, + []string{"support"}, + ) + protocolsCount = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: metricNamespace, + Name: "protocols_count", + Help: "Protocols Count", + }, + ) + addrsCount = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: metricNamespace, + Name: "addrs_count", + Help: "Address Count", + }, + ) + numProtocolsReceived = prometheus.NewHistogram( + prometheus.HistogramOpts{ + Namespace: metricNamespace, + Name: "protocols_received", + Help: "Number of Protocols received", + Buckets: buckets, + }, + ) + numAddrsReceived = prometheus.NewHistogram( + prometheus.HistogramOpts{ + Namespace: metricNamespace, + Name: "addrs_received", + Help: "Number of addrs received", + Buckets: buckets, + }, + ) collectors = []prometheus.Collector{ pushesTriggered, identify, identifyPush, + connectionPushSupport, + protocolsCount, + addrsCount, + numProtocolsReceived, + numAddrsReceived, } + // 1 to 20 and then up to 100 in steps of 5 + buckets = append( + prometheus.LinearBuckets(1, 1, 20), + prometheus.LinearBuckets(25, 5, 16)..., + ) ) type MetricsTracer interface { TriggeredPushes(event any) Identify(network.Direction) IdentifyPush(network.Direction) + IncrementPushSupport(identifyPushSupport) + DecrementPushSupport(identifyPushSupport) + NumProtocols(int) + NumAddrs(int) + NumProtocolsReceived(int) + NumAddrsReceived(int) } type metricsTracer struct{} @@ -105,3 +159,46 @@ func (t *metricsTracer) IdentifyPush(dir network.Direction) { *tags = append(*tags, metricshelper.GetDirection(dir)) identifyPush.WithLabelValues(*tags...).Inc() } + +func (t *metricsTracer) IncrementPushSupport(s identifyPushSupport) { + tags := metricshelper.GetStringSlice() + defer metricshelper.PutStringSlice(tags) + + *tags = append(*tags, getPushSupport(s)) + connectionPushSupport.WithLabelValues(*tags...).Inc() +} + +func (t *metricsTracer) DecrementPushSupport(s identifyPushSupport) { + tags := metricshelper.GetStringSlice() + defer metricshelper.PutStringSlice(tags) + + *tags = append(*tags, getPushSupport(s)) + connectionPushSupport.WithLabelValues(*tags...).Dec() +} + +func (t *metricsTracer) NumProtocols(n int) { + protocolsCount.Set(float64(n)) +} + +func (t *metricsTracer) NumAddrs(n int) { + addrsCount.Set(float64(n)) +} + +func (t *metricsTracer) NumProtocolsReceived(n int) { + numProtocolsReceived.Observe(float64(n)) +} + +func (t *metricsTracer) NumAddrsReceived(n int) { + numAddrsReceived.Observe(float64(n)) +} + +func getPushSupport(s identifyPushSupport) string { + switch s { + case identifyPushSupported: + return "supported" + case identifyPushUnsupported: + return "not supported" + default: + return "unknown" + } +} diff --git a/p2p/protocol/identify/metrics_test.go b/p2p/protocol/identify/metrics_test.go index 567c1d9e2b..8263d2a986 100644 --- a/p2p/protocol/identify/metrics_test.go +++ b/p2p/protocol/identify/metrics_test.go @@ -16,12 +16,24 @@ func TestMetricsNoAllocNoCover(t *testing.T) { event.EvtLocalProtocolsUpdated{}, event.EvtNATDeviceTypeChanged{}, } + + pushSupport := []identifyPushSupport{ + identifyPushSupportUnknown, + identifyPushSupported, + identifyPushUnsupported, + } dirs := []network.Direction{network.DirInbound, network.DirOutbound, network.DirUnknown} tr := NewMetricsTracer() tests := map[string]func(){ - "TriggeredPushes": func() { tr.TriggeredPushes(events[rand.Intn(len(events))]) }, - "Identify": func() { tr.Identify(dirs[rand.Intn(len(dirs))]) }, - "IdentifyPush": func() { tr.IdentifyPush(dirs[rand.Intn(len(dirs))]) }, + "TriggeredPushes": func() { tr.TriggeredPushes(events[rand.Intn(len(events))]) }, + "Identify": func() { tr.Identify(dirs[rand.Intn(len(dirs))]) }, + "IdentifyPush": func() { tr.IdentifyPush(dirs[rand.Intn(len(dirs))]) }, + "IncrementPushSupport": func() { tr.IncrementPushSupport(pushSupport[rand.Intn(len(pushSupport))]) }, + "DecrementPushSupport": func() { tr.DecrementPushSupport(pushSupport[rand.Intn(len(pushSupport))]) }, + "NumProtocols": func() { tr.NumProtocols(rand.Intn(100)) }, + "NumAddrs": func() { tr.NumAddrs(rand.Intn(100)) }, + "NumProtocolsReceived": func() { tr.NumProtocolsReceived(rand.Intn(100)) }, + "NumAddrsReceived": func() { tr.NumAddrsReceived(rand.Intn(100)) }, } for method, f := range tests { allocs := testing.AllocsPerRun(1000, f) From 0f0778ce496e9f14a9e2ef18f28f972b2350fa3c Mon Sep 17 00:00:00 2001 From: sukun Date: Thu, 23 Feb 2023 09:29:56 +0530 Subject: [PATCH 2/3] address review changes --- p2p/protocol/identify/id.go | 73 +++++++++-------------- p2p/protocol/identify/metrics.go | 84 ++++++++++++++------------- p2p/protocol/identify/metrics_test.go | 16 ++--- 3 files changed, 74 insertions(+), 99 deletions(-) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 601f23b312..7b21bc194e 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -307,11 +307,8 @@ func (ids *idService) sendPushes(ctx context.Context) { if err != nil { // connection might have been closed recently return } - if ids.metricsTracer != nil { - ids.metricsTracer.IdentifyPush(network.DirOutbound) - } // TODO: find out if the peer supports push if we didn't have any information about push support - if err := ids.sendIdentifyResp(str); err != nil { + if err := ids.sendIdentifyResp(str, true); err != nil { log.Debugw("failed to send identify push", "peer", c.RemotePeer(), "error", err) return } @@ -401,28 +398,19 @@ func (ids *idService) identifyConn(c network.Conn) error { return err } - if ids.metricsTracer != nil { - ids.metricsTracer.Identify(network.DirInbound) - } return ids.handleIdentifyResponse(s, false) } // handlePush handles incoming identify push streams func (ids *idService) handlePush(s network.Stream) { ids.handleIdentifyResponse(s, true) - if ids.metricsTracer != nil { - ids.metricsTracer.IdentifyPush(network.DirInbound) - } } func (ids *idService) handleIdentifyRequest(s network.Stream) { - if ids.metricsTracer != nil { - ids.metricsTracer.Identify(network.DirOutbound) - } - _ = ids.sendIdentifyResp(s) + _ = ids.sendIdentifyResp(s, false) } -func (ids *idService) sendIdentifyResp(s network.Stream) error { +func (ids *idService) sendIdentifyResp(s network.Stream, isPush bool) error { if err := s.Scope().SetService(ServiceName); err != nil { s.Reset() return fmt.Errorf("failed to attaching stream to identify service: %w", err) @@ -432,11 +420,21 @@ func (ids *idService) sendIdentifyResp(s network.Stream) error { ids.currentSnapshot.Lock() snapshot := ids.currentSnapshot.snapshot ids.currentSnapshot.Unlock() + + log.Debugw("sending snapshot", "seq", snapshot.seq, "protocols", snapshot.protocols, "addrs", snapshot.addrs) + + mes := ids.createBaseIdentifyResponse(s.Conn(), &snapshot) + mes.SignedPeerRecord = ids.getSignedRecord(&snapshot) + log.Debugf("%s sending message to %s %s", ID, s.Conn().RemotePeer(), s.Conn().RemoteMultiaddr()) - if err := ids.writeChunkedIdentifyMsg(s, &snapshot); err != nil { + if err := ids.writeChunkedIdentifyMsg(s, mes); err != nil { return err } + if ids.metricsTracer != nil { + ids.metricsTracer.IdentifySent(isPush, len(mes.Protocols), len(mes.ListenAddrs)) + } + ids.connsMu.Lock() defer ids.connsMu.Unlock() e, ok := ids.conns[s.Conn()] @@ -485,24 +483,28 @@ func (ids *idService) handleIdentifyResponse(s network.Stream, isPush bool) erro ids.consumeMessage(mes, c, isPush) + if ids.metricsTracer != nil { + ids.metricsTracer.IdentifyReceived(isPush, len(mes.Protocols), len(mes.ListenAddrs)) + } + ids.connsMu.Lock() defer ids.connsMu.Unlock() e, ok := ids.conns[c] if !ok { // might already have disconnected return nil } - prevPushSupport := e.PushSupport sup, err := ids.Host.Peerstore().SupportsProtocols(c.RemotePeer(), IDPush) if supportsIdentifyPush := err == nil && len(sup) > 0; supportsIdentifyPush { e.PushSupport = identifyPushSupported } else { e.PushSupport = identifyPushUnsupported } - ids.conns[c] = e - if ids.metricsTracer != nil && e.PushSupport != prevPushSupport { - ids.metricsTracer.IncrementPushSupport(e.PushSupport) - ids.metricsTracer.DecrementPushSupport(prevPushSupport) + + if ids.metricsTracer != nil { + ids.metricsTracer.PeerPushSupport(e.PushSupport) } + + ids.conns[c] = e return nil } @@ -541,19 +543,14 @@ func (ids *idService) updateSnapshot() { log.Debugw("updating snapshot", "seq", snapshot.seq, "addrs", snapshot.addrs) } -func (ids *idService) writeChunkedIdentifyMsg(s network.Stream, snapshot *identifySnapshot) error { - c := s.Conn() - log.Debugw("sending snapshot", "seq", snapshot.seq, "protocols", snapshot.protocols, "addrs", snapshot.addrs) - - mes := ids.createBaseIdentifyResponse(c, snapshot) - sr := ids.getSignedRecord(snapshot) - mes.SignedPeerRecord = sr +func (ids *idService) writeChunkedIdentifyMsg(s network.Stream, mes *pb.Identify) error { writer := pbio.NewDelimitedWriter(s) - if sr == nil || proto.Size(mes) <= legacyIDSize { + if mes.SignedPeerRecord == nil || proto.Size(mes) <= legacyIDSize { return writer.WriteMsg(mes) } + sr := mes.SignedPeerRecord mes.SignedPeerRecord = nil if err := writer.WriteMsg(mes); err != nil { return err @@ -586,11 +583,6 @@ func (ids *idService) createBaseIdentifyResponse(conn network.Conn, snapshot *id } mes.ListenAddrs = append(mes.ListenAddrs, addr.Bytes()) } - if ids.metricsTracer != nil { - ids.metricsTracer.NumProtocols(len(mes.Protocols)) - ids.metricsTracer.NumAddrs(len(mes.ListenAddrs)) - } - // set our public key ownKey := ids.Host.Peerstore().PubKey(ids.Host.ID()) @@ -694,11 +686,6 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo lmaddrs = append(lmaddrs, maddr) } - if ids.metricsTracer != nil { - ids.metricsTracer.NumProtocolsReceived(len(mesProtocols)) - ids.metricsTracer.NumAddrsReceived(len(lmaddrs)) - } - // NOTE: Do not add `c.RemoteMultiaddr()` to the peerstore if the remote // peer doesn't tell us to do so. Otherwise, we'll advertise it. // @@ -901,10 +888,6 @@ func (nn *netNotifiee) Connected(_ network.Network, c network.Conn) { ids.conns[c] = entry{} ids.connsMu.Unlock() - if ids.metricsTracer != nil { - ids.metricsTracer.IncrementPushSupport(identifyPushSupportUnknown) - } - nn.IDService().IdentifyWait(c) } @@ -913,12 +896,8 @@ func (nn *netNotifiee) Disconnected(_ network.Network, c network.Conn) { // Stop tracking the connection. ids.connsMu.Lock() - e, ok := ids.conns[c] delete(ids.conns, c) ids.connsMu.Unlock() - if ok && ids.metricsTracer != nil { - ids.metricsTracer.DecrementPushSupport(e.PushSupport) - } if ids.Host.Network().Connectedness(c.RemotePeer()) != network.Connected { // Last disconnect. diff --git a/p2p/protocol/identify/metrics.go b/p2p/protocol/identify/metrics.go index 109667b551..3536bb53f5 100644 --- a/p2p/protocol/identify/metrics.go +++ b/p2p/protocol/identify/metrics.go @@ -35,11 +35,11 @@ var ( }, []string{"dir"}, ) - connectionPushSupport = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ + peerPushSupport = prometheus.NewCounterVec( + prometheus.CounterOpts{ Namespace: metricNamespace, - Name: "conn_push_support", - Help: "Identify Connection Push Support", + Name: "peer_push_support_total", + Help: "Identify Peer Push Support", }, []string{"support"}, ) @@ -77,7 +77,7 @@ var ( pushesTriggered, identify, identifyPush, - connectionPushSupport, + peerPushSupport, protocolsCount, addrsCount, numProtocolsReceived, @@ -91,15 +91,17 @@ var ( ) type MetricsTracer interface { + // TriggeredPushes counts IdentifyPushes triggered by event TriggeredPushes(event any) - Identify(network.Direction) - IdentifyPush(network.Direction) - IncrementPushSupport(identifyPushSupport) - DecrementPushSupport(identifyPushSupport) - NumProtocols(int) - NumAddrs(int) - NumProtocolsReceived(int) - NumAddrsReceived(int) + + // PeerPushSupport counts peers by Push Support + PeerPushSupport(identifyPushSupport) + + // IdentifyReceived tracks metrics on receiving an identify response + IdentifyReceived(isPush bool, numProtocols int, numAddrs int) + + // IdentifySent tracks metrics on sending an identify response + IdentifySent(isPush bool, numProtocols int, numAddrs int) } type metricsTracer struct{} @@ -144,52 +146,52 @@ func (t *metricsTracer) TriggeredPushes(ev any) { pushesTriggered.WithLabelValues(*tags...).Inc() } -func (t *metricsTracer) Identify(dir network.Direction) { +func (t *metricsTracer) IncrementPushSupport(s identifyPushSupport) { tags := metricshelper.GetStringSlice() defer metricshelper.PutStringSlice(tags) - *tags = append(*tags, metricshelper.GetDirection(dir)) - identify.WithLabelValues(*tags...).Inc() + *tags = append(*tags, getPushSupport(s)) + peerPushSupport.WithLabelValues(*tags...).Inc() } -func (t *metricsTracer) IdentifyPush(dir network.Direction) { +func (t *metricsTracer) IdentifySent(isPush bool, numProtocols int, numAddrs int) { tags := metricshelper.GetStringSlice() defer metricshelper.PutStringSlice(tags) - *tags = append(*tags, metricshelper.GetDirection(dir)) - identifyPush.WithLabelValues(*tags...).Inc() -} - -func (t *metricsTracer) IncrementPushSupport(s identifyPushSupport) { - tags := metricshelper.GetStringSlice() - defer metricshelper.PutStringSlice(tags) + if isPush { + *tags = append(*tags, metricshelper.GetDirection(network.DirOutbound)) + identifyPush.WithLabelValues(*tags...).Inc() + } else { + *tags = append(*tags, metricshelper.GetDirection(network.DirInbound)) + identify.WithLabelValues(*tags...).Inc() + } - *tags = append(*tags, getPushSupport(s)) - connectionPushSupport.WithLabelValues(*tags...).Inc() + protocolsCount.Set(float64(numProtocols)) + addrsCount.Set(float64(numAddrs)) } -func (t *metricsTracer) DecrementPushSupport(s identifyPushSupport) { +func (t *metricsTracer) IdentifyReceived(isPush bool, numProtocols int, numAddrs int) { tags := metricshelper.GetStringSlice() defer metricshelper.PutStringSlice(tags) - *tags = append(*tags, getPushSupport(s)) - connectionPushSupport.WithLabelValues(*tags...).Dec() -} - -func (t *metricsTracer) NumProtocols(n int) { - protocolsCount.Set(float64(n)) -} + if isPush { + *tags = append(*tags, metricshelper.GetDirection(network.DirInbound)) + identifyPush.WithLabelValues(*tags...).Inc() + } else { + *tags = append(*tags, metricshelper.GetDirection(network.DirOutbound)) + identify.WithLabelValues(*tags...).Inc() + } -func (t *metricsTracer) NumAddrs(n int) { - addrsCount.Set(float64(n)) + numProtocolsReceived.Observe(float64(numProtocols)) + numAddrsReceived.Observe(float64(numAddrs)) } -func (t *metricsTracer) NumProtocolsReceived(n int) { - numProtocolsReceived.Observe(float64(n)) -} +func (t *metricsTracer) PeerPushSupport(support identifyPushSupport) { + tags := metricshelper.GetStringSlice() + defer metricshelper.PutStringSlice(tags) -func (t *metricsTracer) NumAddrsReceived(n int) { - numAddrsReceived.Observe(float64(n)) + *tags = append(*tags, getPushSupport(support)) + peerPushSupport.WithLabelValues(*tags...).Inc() } func getPushSupport(s identifyPushSupport) string { diff --git a/p2p/protocol/identify/metrics_test.go b/p2p/protocol/identify/metrics_test.go index 8263d2a986..b13eba2530 100644 --- a/p2p/protocol/identify/metrics_test.go +++ b/p2p/protocol/identify/metrics_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/libp2p/go-libp2p/core/event" - "github.com/libp2p/go-libp2p/core/network" ) func TestMetricsNoAllocNoCover(t *testing.T) { @@ -22,18 +21,13 @@ func TestMetricsNoAllocNoCover(t *testing.T) { identifyPushSupported, identifyPushUnsupported, } - dirs := []network.Direction{network.DirInbound, network.DirOutbound, network.DirUnknown} + tr := NewMetricsTracer() tests := map[string]func(){ - "TriggeredPushes": func() { tr.TriggeredPushes(events[rand.Intn(len(events))]) }, - "Identify": func() { tr.Identify(dirs[rand.Intn(len(dirs))]) }, - "IdentifyPush": func() { tr.IdentifyPush(dirs[rand.Intn(len(dirs))]) }, - "IncrementPushSupport": func() { tr.IncrementPushSupport(pushSupport[rand.Intn(len(pushSupport))]) }, - "DecrementPushSupport": func() { tr.DecrementPushSupport(pushSupport[rand.Intn(len(pushSupport))]) }, - "NumProtocols": func() { tr.NumProtocols(rand.Intn(100)) }, - "NumAddrs": func() { tr.NumAddrs(rand.Intn(100)) }, - "NumProtocolsReceived": func() { tr.NumProtocolsReceived(rand.Intn(100)) }, - "NumAddrsReceived": func() { tr.NumAddrsReceived(rand.Intn(100)) }, + "TriggeredPushes": func() { tr.TriggeredPushes(events[rand.Intn(len(events))]) }, + "PeerPushSupport": func() { tr.PeerPushSupport(pushSupport[rand.Intn(len(pushSupport))]) }, + "IdentifyReceived": func() { tr.IdentifyReceived(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) }, + "IdentifySent": func() { tr.IdentifySent(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) }, } for method, f := range tests { allocs := testing.AllocsPerRun(1000, f) From 81f80d204c3f70b2789e4dfcfd481e49c78c0837 Mon Sep 17 00:00:00 2001 From: sukun Date: Thu, 23 Feb 2023 11:29:49 +0530 Subject: [PATCH 3/3] update dashboards --- CHANGELOG.md | 2 +- dashboards/identify/identify.json | 88 +++++++++++++++++++++------ p2p/protocol/identify/id.go | 2 +- p2p/protocol/identify/metrics.go | 18 +++--- p2p/protocol/identify/metrics_test.go | 2 +- 5 files changed, 82 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f30228324..7fe709896c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ Metrics were added to: - [IP Version](https://github.com/libp2p/go-libp2p/pull/2114): Added ip_version label to connection metrics * Identify: - Metrics for Identify, IdentifyPush, PushesTriggered (https://github.com/libp2p/go-libp2p/pull/2069) - - Address Count, Protocol Count, Peer Protocol Support (https://github.com/libp2p/go-libp2p/pull/2126) + - Address Count, Protocol Count, Connection IDPush Support (https://github.com/libp2p/go-libp2p/pull/2126) ## 🐞 Bugfixes diff --git a/dashboards/identify/identify.json b/dashboards/identify/identify.json index 373aa43b49..491766dbb9 100644 --- a/dashboards/identify/identify.json +++ b/dashboards/identify/identify.json @@ -11,12 +11,6 @@ ], "__elements": {}, "__requires": [ - { - "type": "panel", - "id": "gauge", - "name": "Gauge", - "version": "" - }, { "type": "grafana", "id": "grafana", @@ -35,6 +29,12 @@ "name": "Prometheus", "version": "1.0.0" }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, { "type": "panel", "id": "timeseries", @@ -304,6 +304,9 @@ }, "id": 9, "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", "orientation": "auto", "reduceOptions": { "calcs": [ @@ -312,8 +315,7 @@ "fields": "", "values": false }, - "showThresholdLabels": false, - "showThresholdMarkers": true + "textMode": "auto" }, "pluginVersion": "9.3.6", "targets": [ @@ -331,7 +333,7 @@ } ], "title": "Outgoing Address Count", - "type": "gauge" + "type": "stat" }, { "datasource": { @@ -381,6 +383,9 @@ }, "id": 17, "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", "orientation": "auto", "reduceOptions": { "calcs": [ @@ -389,8 +394,7 @@ "fields": "", "values": false }, - "showThresholdLabels": false, - "showThresholdMarkers": true + "textMode": "auto" }, "pluginVersion": "9.3.6", "targets": [ @@ -407,7 +411,7 @@ } ], "title": "Outgoing Protocols Count", - "type": "gauge" + "type": "stat" }, { "datasource": { @@ -600,10 +604,34 @@ "uid": "${DS_PROMETHEUS}" }, "editorMode": "code", - "expr": "sum( rate(libp2p_identify_addrs_received_sum[$__rate_interval])) / sum( rate(libp2p_identify_addrs_received_count[$__rate_interval]))", - "legendFormat": "address count", + "expr": "histogram_quantile(0.5, sum(rate(libp2p_identify_addrs_received_bucket[$__rate_interval])) by (le))", + "legendFormat": "50th percentile", "range": true, "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "histogram_quantile(0.90, sum(rate(libp2p_identify_addrs_received_bucket[$__rate_interval])) by (le))", + "hide": false, + "legendFormat": "90th percentile", + "range": true, + "refId": "B" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "histogram_quantile(0.99, sum(rate(libp2p_identify_addrs_received_bucket[$__rate_interval])) by (le))", + "hide": false, + "legendFormat": "99 percentile", + "range": true, + "refId": "C" } ], "title": "Incoming Address Count (Avg)", @@ -708,10 +736,34 @@ "uid": "${DS_PROMETHEUS}" }, "editorMode": "code", - "expr": "sum(rate( libp2p_identify_protocols_received_sum[$__rate_interval])) / sum(rate(libp2p_identify_protocols_received_count[$__rate_interval]))", - "legendFormat": "protocols count", + "expr": "histogram_quantile(0.5, sum(rate(libp2p_identify_protocols_received_bucket[$__rate_interval])) by (le))", + "legendFormat": "50th percentile", "range": true, "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "histogram_quantile(0.90, sum(rate(libp2p_identify_protocols_received_bucket[$__rate_interval])) by (le))", + "hide": false, + "legendFormat": "90th percentile", + "range": true, + "refId": "B" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "histogram_quantile(0.99, sum(rate(libp2p_identify_protocols_received_bucket[$__rate_interval])) by (le))", + "hide": false, + "legendFormat": "99th percentile", + "range": true, + "refId": "C" } ], "title": "Incoming Protocols Count (Avg)", @@ -771,13 +823,13 @@ "uid": "${DS_PROMETHEUS}" }, "editorMode": "code", - "expr": "libp2p_identify_conn_push_support", + "expr": "increase(libp2p_identify_conn_push_support_total[$__rate_interval])", "legendFormat": "{{support}}", "range": true, "refId": "A" } ], - "title": "Peers: Push Support", + "title": "New Connections: Push Support", "type": "piechart" } ], diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 7b21bc194e..390e8afb7a 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -501,7 +501,7 @@ func (ids *idService) handleIdentifyResponse(s network.Stream, isPush bool) erro } if ids.metricsTracer != nil { - ids.metricsTracer.PeerPushSupport(e.PushSupport) + ids.metricsTracer.ConnPushSupport(e.PushSupport) } ids.conns[c] = e diff --git a/p2p/protocol/identify/metrics.go b/p2p/protocol/identify/metrics.go index 3536bb53f5..28598fa33b 100644 --- a/p2p/protocol/identify/metrics.go +++ b/p2p/protocol/identify/metrics.go @@ -35,11 +35,11 @@ var ( }, []string{"dir"}, ) - peerPushSupport = prometheus.NewCounterVec( + connPushSupportTotal = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: metricNamespace, - Name: "peer_push_support_total", - Help: "Identify Peer Push Support", + Name: "conn_push_support_total", + Help: "Identify Connection Push Support", }, []string{"support"}, ) @@ -77,7 +77,7 @@ var ( pushesTriggered, identify, identifyPush, - peerPushSupport, + connPushSupportTotal, protocolsCount, addrsCount, numProtocolsReceived, @@ -94,8 +94,8 @@ type MetricsTracer interface { // TriggeredPushes counts IdentifyPushes triggered by event TriggeredPushes(event any) - // PeerPushSupport counts peers by Push Support - PeerPushSupport(identifyPushSupport) + // ConnPushSupport counts peers by Push Support + ConnPushSupport(identifyPushSupport) // IdentifyReceived tracks metrics on receiving an identify response IdentifyReceived(isPush bool, numProtocols int, numAddrs int) @@ -151,7 +151,7 @@ func (t *metricsTracer) IncrementPushSupport(s identifyPushSupport) { defer metricshelper.PutStringSlice(tags) *tags = append(*tags, getPushSupport(s)) - peerPushSupport.WithLabelValues(*tags...).Inc() + connPushSupportTotal.WithLabelValues(*tags...).Inc() } func (t *metricsTracer) IdentifySent(isPush bool, numProtocols int, numAddrs int) { @@ -186,12 +186,12 @@ func (t *metricsTracer) IdentifyReceived(isPush bool, numProtocols int, numAddrs numAddrsReceived.Observe(float64(numAddrs)) } -func (t *metricsTracer) PeerPushSupport(support identifyPushSupport) { +func (t *metricsTracer) ConnPushSupport(support identifyPushSupport) { tags := metricshelper.GetStringSlice() defer metricshelper.PutStringSlice(tags) *tags = append(*tags, getPushSupport(support)) - peerPushSupport.WithLabelValues(*tags...).Inc() + connPushSupportTotal.WithLabelValues(*tags...).Inc() } func getPushSupport(s identifyPushSupport) string { diff --git a/p2p/protocol/identify/metrics_test.go b/p2p/protocol/identify/metrics_test.go index b13eba2530..2cf5a209a1 100644 --- a/p2p/protocol/identify/metrics_test.go +++ b/p2p/protocol/identify/metrics_test.go @@ -25,7 +25,7 @@ func TestMetricsNoAllocNoCover(t *testing.T) { tr := NewMetricsTracer() tests := map[string]func(){ "TriggeredPushes": func() { tr.TriggeredPushes(events[rand.Intn(len(events))]) }, - "PeerPushSupport": func() { tr.PeerPushSupport(pushSupport[rand.Intn(len(pushSupport))]) }, + "ConnPushSupport": func() { tr.ConnPushSupport(pushSupport[rand.Intn(len(pushSupport))]) }, "IdentifyReceived": func() { tr.IdentifyReceived(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) }, "IdentifySent": func() { tr.IdentifySent(rand.Intn(2) == 0, rand.Intn(20), rand.Intn(20)) }, }