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

feat(dot/babe) implement block production time metric #1648

Merged
merged 16 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.7'

services:
noot marked this conversation as resolved.
Show resolved Hide resolved
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
ports:
- 9090:9090
restart: always
6 changes: 6 additions & 0 deletions dot/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ func CollectProcessMetrics() {
time.Sleep(Refresh)
}
}

func UnregisterMetrics(tounregister map[string]interface{}) {
for k := range tounregister {
metrics.Unregister(k)
}
}
30 changes: 30 additions & 0 deletions dot/network/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"time"

gossamermetrics "github.com/ChainSafe/gossamer/dot/metrics"
"github.com/ethereum/go-ethereum/metrics"
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
badger "github.com/ipfs/go-ds-badger2"
libp2phost "github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
Expand All @@ -37,6 +39,9 @@ var (
tryAdvertiseTimeout = time.Second * 30
connectToPeersTimeout = time.Minute * 5
findPeersTimeout = time.Minute

checkPeerCountMetrics = "gossamer/network/peer_count"
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
peersStoreMetrics = "gossamer/network/peerstore_count"
)

// discovery handles discovery of new peers via the kademlia DHT
Expand All @@ -49,9 +54,16 @@ type discovery struct {
ds *badger.Datastore
pid protocol.ID
minPeers, maxPeers int

metrics map[string]interface{}
}

func newDiscovery(ctx context.Context, h libp2phost.Host, bootnodes []peer.AddrInfo, ds *badger.Datastore, pid protocol.ID, min, max int) *discovery {
metrics.Enabled = true
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
discoveryMetrics := make(map[string]interface{})
discoveryMetrics[checkPeerCountMetrics] = metrics.GetOrRegisterGauge(checkPeerCountMetrics, nil)
discoveryMetrics[peersStoreMetrics] = metrics.GetOrRegisterGauge(peersStoreMetrics, nil)
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved

return &discovery{
ctx: ctx,
h: h,
Expand All @@ -60,6 +72,8 @@ func newDiscovery(ctx context.Context, h libp2phost.Host, bootnodes []peer.AddrI
pid: pid,
minPeers: min,
maxPeers: max,

metrics: discoveryMetrics,
}
}

Expand Down Expand Up @@ -115,6 +129,8 @@ func (d *discovery) stop() error {
return nil
}

gossamermetrics.UnregisterMetrics(d.metrics)

return d.dht.Close()
}

Expand Down Expand Up @@ -185,6 +201,20 @@ func (d *discovery) findPeers(ctx context.Context) {
}

for {
defer func() {
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
checkPeerGauge, ok := d.metrics[checkPeerCountMetrics]
if ok {
g := checkPeerGauge.(metrics.Gauge)
g.Update(int64(len(d.h.Network().Peers())))
}

peerstore, ok := d.metrics[peersStoreMetrics]
if ok {
g := peerstore.(metrics.Gauge)
g.Update(int64(d.h.Peerstore().Peers().Len()))
}
}()

select {
case <-ctx.Done():
return
Expand Down
19 changes: 7 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ require (
github.com/centrifuge/go-substrate-rpc-client/v2 v2.0.1
github.com/chyeh/pubip v0.0.0-20170203095919-b7e679cf541c
github.com/cosmos/go-bip39 v1.0.0
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect
github.com/dgraph-io/badger/v2 v2.2007.2
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de
github.com/disiqueira/gotree v1.0.0
github.com/docker/docker v1.13.1
github.com/elastic/gosigar v0.14.0 // indirect
github.com/ethereum/go-ethereum v1.9.7
github.com/go-playground/validator/v10 v10.4.1
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect
github.com/golang/protobuf v1.4.3
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/uuid v1.1.5 // indirect
Expand All @@ -34,13 +32,12 @@ require (
github.com/jpillora/backoff v1.0.0 // indirect
github.com/jpillora/ipfilter v1.2.2
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/libp2p/go-libp2p v0.12.0
github.com/libp2p/go-libp2p-core v0.7.0
github.com/libp2p/go-libp2p v0.14.2
github.com/libp2p/go-libp2p-core v0.8.5
github.com/libp2p/go-libp2p-discovery v0.5.0
github.com/libp2p/go-libp2p-kad-dht v0.11.1
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/libp2p/go-libp2p-peerstore v0.2.7
github.com/libp2p/go-libp2p-secio v0.2.2
github.com/libp2p/go-sockaddr v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/multiformats/go-multiaddr v0.3.1
Expand All @@ -53,13 +50,11 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect
github.com/urfave/cli v1.20.0
github.com/wasmerio/go-ext-wasm v0.3.2-0.20200326095750-0a32be6068ec
go.opencensus.io v0.22.5 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/protobuf v1.25.0
google.golang.org/protobuf v1.26.0-rc.1
)

go 1.15
Loading