Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagation metrics #2003

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 113 additions & 7 deletions metrics_config/grafana_metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "11.0.0"
"version": "11.1.1"
},
{
"type": "panel",
"id": "histogram",
"name": "Histogram",
"version": ""
},
{
"type": "datasource",
Expand Down Expand Up @@ -215,6 +221,7 @@
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
Expand All @@ -226,7 +233,7 @@
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "11.0.0",
"pluginVersion": "11.1.1",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -287,6 +294,7 @@
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
Expand All @@ -298,7 +306,7 @@
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "11.0.0",
"pluginVersion": "11.1.1",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -462,6 +470,7 @@
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
Expand All @@ -473,7 +482,7 @@
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "11.0.0",
"pluginVersion": "11.1.1",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -534,6 +543,7 @@
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
Expand All @@ -545,7 +555,7 @@
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "11.0.0",
"pluginVersion": "11.1.1",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -2097,6 +2107,103 @@
],
"title": "Bandwidth by Protocol",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"fillOpacity": 80,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineWidth": 1,
"stacking": {
"group": "A",
"mode": "none"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 67
},
"id": 29,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"disableTextWrap": false,
"editorMode": "builder",
"exemplar": false,
"expr": "PropagationTimes_count{label=\"block propagation time (sec)\"}",
"format": "time_series",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "{{label}}",
"range": true,
"refId": "A",
"useBackend": false
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "PropagationTimes_count{label=\"header propagation time (sec)\"}",
"format": "time_series",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "{{label}}",
"range": true,
"refId": "B",
"useBackend": false
}
],
"title": "Propagation Times",
"type": "histogram"
}
],
"refresh": "5s",
Expand All @@ -2109,11 +2216,10 @@
"from": "now-15m",
"to": "now"
},
"timeRangeUpdatedDuringEditOrView": false,
"timepicker": {},
"timezone": "",
"title": "Go-quai Metrics Under Development",
"uid": "adae3653-aaad-4a59-9c93-5827d20896b9-v3",
"version": 4,
"version": 1,
"weekStart": ""
}
14 changes: 14 additions & 0 deletions metrics_config/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var enabled bool

var registeredGauges = make(map[string]*prometheus.GaugeVec)
var registeredCounters = make(map[string]*prometheus.CounterVec)
var registeredHistograms = make(map[string]*prometheus.HistogramVec)

// Init enables or disables the metrics system. Since we need this to run before
// any other code gets to create meters and timers, we'll actually do an ugly hack
Expand Down Expand Up @@ -112,6 +113,19 @@ func NewCounterVec(name string, help string) *prometheus.CounterVec {
return counterVec
}

func NewHistogramVec(name string, help string) *prometheus.HistogramVec {
if histVec, exists := registeredHistograms[name]; exists {
return histVec
}
histVec := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: name,
Help: help,
}, []string{"label"})
prometheus.Register(histVec)
registeredHistograms[name] = histVec
return histVec
}

func NewTimer(name string, help string) *prometheus.Timer {
timeHistogram := prometheus.NewHistogram(prometheus.HistogramOpts{
Name: name,
Expand Down
11 changes: 11 additions & 0 deletions p2p/node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/dominant-strategies/go-quai/core/types"
"github.com/dominant-strategies/go-quai/log"
"github.com/dominant-strategies/go-quai/metrics_config"
"github.com/dominant-strategies/go-quai/p2p"
"github.com/dominant-strategies/go-quai/p2p/node/pubsubManager"
"github.com/dominant-strategies/go-quai/p2p/node/streamManager"
Expand All @@ -23,6 +24,12 @@ import (
"github.com/dominant-strategies/go-quai/common"
)

var (
propagationTimes = metrics_config.NewHistogramVec("PropagationTimes", "message propagation times by type (sec)")
blockPropagationHist = propagationTimes.WithLabelValues("block propagation time (sec)")
headerPropagationHist = propagationTimes.WithLabelValues("header propagation time (sec)")
)

const requestTimeout = 10 * time.Second

// Starts the node and all of its services
Expand Down Expand Up @@ -371,8 +378,12 @@ func (p *P2PNode) handleBroadcast(sourcePeer peer.ID, Id string, topic string, d

switch v := data.(type) {
case types.WorkObjectHeaderView:
dt := uint64(time.Now().Unix()) - v.Time()
headerPropagationHist.Observe(float64(dt))
p.cacheAdd(v.Hash(), &v, nodeLocation)
case types.WorkObjectBlockView:
dt := uint64(time.Now().Unix()) - v.Time()
blockPropagationHist.Observe(float64(dt))
p.cacheAdd(v.Hash(), &v, nodeLocation)
}

Expand Down
Loading