Skip to content

Commit

Permalink
app: add cluster identifiers to all metrics (#565)
Browse files Browse the repository at this point in the history
Wraps all prometheus metrics in cluster identifiers.

category: feature 
ticket: #548
  • Loading branch information
corverroos authored May 20, 2022
1 parent ec66445 commit 88ae354
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
26 changes: 24 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package app
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"net/http"
"net/http/pprof"
"time"
Expand All @@ -32,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/automaxprocs/maxprocs"

Expand Down Expand Up @@ -100,6 +102,8 @@ type TestConfig struct {
SimnetBMockOpts []beaconmock.Option
// BroadcastCallback is called when a duty is completed and sent to the broadcast component.
BroadcastCallback func(context.Context, core.Duty, core.PubKey, core.AggSignedData) error
// DisablePromWrap disables wrapping prometheus metrics with cluster identifiers.
DisablePromWrap bool
}

// Run is the entrypoint for running a charon DVC instance.
Expand All @@ -114,7 +118,6 @@ func Run(ctx context.Context, conf Config) (err error) {
}()

_, _ = maxprocs.Set()
initStartupMetrics()
if err := log.InitLogger(conf.Log); err != nil {
return err
}
Expand Down Expand Up @@ -142,6 +145,12 @@ func Run(ctx context.Context, conf Config) (err error) {
return err
}

lockHash, err := lock.HashTreeRoot()
if err != nil {
return err
}
lockHashHex := hex.EncodeToString(lockHash[:])[:7]

tcpNode, localEnode, err := wireP2P(ctx, life, conf, lock)
if err != nil {
return err
Expand All @@ -152,12 +161,25 @@ func Run(ctx context.Context, conf Config) (err error) {
return err
}

log.Info(ctx, "Lock loaded",
log.Info(ctx, "Lock file loaded",
z.Str("cluster_hash", lockHashHex),
z.Str("cluster_name", lock.Name),
z.Int("peers", len(lock.Operators)),
z.Str("peer_id", p2p.ShortID(tcpNode.ID())),
z.Int("peer_index", nodeIdx.PeerIdx),
z.Str("enr", localEnode.Node().String()))

if !conf.TestConfig.DisablePromWrap {
// Wrap prometheus metrics with cluster and node identifiers.
prometheus.DefaultRegisterer = prometheus.WrapRegistererWith(prometheus.Labels{
"cluster_hash": lockHashHex,
"cluster_name": lock.Name,
"cluster_enr": lock.Operators[nodeIdx.PeerIdx].ENR,
"cluster_peer_id": p2p.ShortID(tcpNode.ID()),
}, prometheus.DefaultRegisterer)
}
initStartupMetrics()

wireMonitoringAPI(life, conf.MonitoringAddr, localEnode)

if err := wireCoreWorkflow(ctx, life, conf, lock, nodeIdx, tcpNode); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ func pingCluster(t *testing.T, test pingTest) {
MonitoringAddr: testutil.AvailableAddr(t).String(), // Random monitoring address
ValidatorAPIAddr: testutil.AvailableAddr(t).String(), // Random validatorapi address
TestConfig: app.TestConfig{
Lock: &lock,
P2PKey: p2pKeys[i],
PingCallback: asserter.Callback(t, i),
Lock: &lock,
P2PKey: p2pKeys[i],
PingCallback: asserter.Callback(t, i),
DisablePromWrap: true,
},
P2P: p2p.Config{
UDPBootnodes: bootnodes,
Expand Down
1 change: 1 addition & 0 deletions app/simnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func testSimnet(t *testing.T, args simnetArgs, propose bool) {
Lock: &args.Lock,
P2PKey: args.P2PKeys[i],
DisablePing: true,
DisablePromWrap: true,
SimnetKeys: []*bls_sig.SecretKey{args.SimnetKeys[i]},
ParSigExFunc: parSigExFunc,
LcastTransportFunc: lcastTransportFunc,
Expand Down

0 comments on commit 88ae354

Please sign in to comment.