Skip to content

Commit 1707ded

Browse files
authored
app: add beacon node peer_id metric (#4256)
* add beacon node peer_id metric * use node identity from go-eth2-client * clean rebase * fix lint * fix lint again * move to gen
1 parent 13e2aea commit 1707ded

9 files changed

Lines changed: 197 additions & 99 deletions

File tree

app/eth2wrap/eth2wrap_gen.go

Lines changed: 33 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/eth2wrap/genwrap/genwrap.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/eth2wrap/mocks/client.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/metrics.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ var (
8989
Help: "Constant gauge with label set to the node version of the upstream beacon node",
9090
}, []string{"version"})
9191

92+
beaconNodePeerIDGauge = promauto.NewResetGaugeVec(prometheus.GaugeOpts{
93+
Namespace: "app",
94+
Subsystem: "beacon_node",
95+
Name: "peer_id",
96+
Help: "Constant gauge with label set to the peer_id of the upstream beacon node",
97+
}, []string{"peer_id"})
98+
9299
thresholdGauge = promauto.NewGauge(prometheus.GaugeOpts{
93100
Namespace: "cluster",
94101
Name: "threshold",

app/monitoringapi.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ func beaconNodeVersionMetric(ctx context.Context, eth2Cl eth2wrap.Client, clock
286286
eth2wrap.CheckBeaconNodeVersion(ctx, version)
287287
}
288288

289+
setNodePeerID := func() {
290+
response, err := eth2Cl.NodeIdentity(ctx, &eth2api.NodeIdentityOpts{})
291+
if err != nil {
292+
log.Error(ctx, "Failed to fetch beacon node identity. Check beacon node connectivity and API availability", err)
293+
return
294+
}
295+
296+
peerID := response.Data.PeerID
297+
298+
beaconNodePeerIDGauge.Reset()
299+
beaconNodePeerIDGauge.WithLabelValues(peerID).Set(1)
300+
}
301+
289302
go func() {
290303
onStartup := make(chan struct{}, 1)
291304
onStartup <- struct{}{}
@@ -294,8 +307,10 @@ func beaconNodeVersionMetric(ctx context.Context, eth2Cl eth2wrap.Client, clock
294307
select {
295308
case <-onStartup:
296309
setNodeVersion()
310+
setNodePeerID()
297311
case <-nodeVersionTicker.Chan():
298312
setNodeVersion()
313+
setNodePeerID()
299314
case <-ctx.Done():
300315
return
301316
}

0 commit comments

Comments
 (0)