Skip to content

Commit 33fe701

Browse files
authored
app: remove beacon node peer_id metric (#4264)
Remove previously added `app_beacon_node_peer_id` and move beacon node ID value to already existing metric `beaconNodeVersionGauge`. <img width="1429" height="410" alt="image" src="https://github.com/user-attachments/assets/0485537d-c3e6-4247-b640-945335394fce" /> category: feature ticket: #4197
1 parent 1707ded commit 33fe701

File tree

4 files changed

+128
-136
lines changed

4 files changed

+128
-136
lines changed

app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func Run(ctx context.Context, conf Config) (err error) {
328328

329329
consensusDebugger := consensus.NewDebugger()
330330

331-
wireMonitoringAPI(ctx, life, conf.MonitoringAddr, conf.DebugAddr, p2pNode, eth2Cl, peerIDs,
331+
wireMonitoringAPI(ctx, life, conf.MonitoringAddr, conf.DebugAddr, p2pNode, eth2Cl, conf.BeaconNodeAddrs, peerIDs,
332332
promRegistry, consensusDebugger, pubkeys, seenPubkeys, vapiCalls, len(lock.Validators))
333333

334334
err = wireCoreWorkflow(ctx, life, conf, lock, nodeIdx, p2pNode, p2pKey, eth2Cl, subEth2Cl,

app/metrics.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,8 @@ var (
8686
Namespace: "app",
8787
Subsystem: "beacon_node",
8888
Name: "version",
89-
Help: "Constant gauge with label set to the node version of the upstream beacon node",
90-
}, []string{"version"})
91-
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"})
89+
Help: "Constant gauge with labels set to the version and beacon_id of the upstream beacon node",
90+
}, []string{"version", "beacon_id"})
9891

9992
thresholdGauge = promauto.NewGauge(prometheus.GaugeOpts{
10093
Namespace: "cluster",

app/monitoringapi.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/obolnetwork/charon/app/health"
2424
"github.com/obolnetwork/charon/app/lifecycle"
2525
"github.com/obolnetwork/charon/app/log"
26+
"github.com/obolnetwork/charon/app/z"
2627
"github.com/obolnetwork/charon/cluster"
2728
"github.com/obolnetwork/charon/core"
2829
)
@@ -45,12 +46,12 @@ var (
4546
// wireMonitoringAPI constructs the monitoring API and registers it with the life cycle manager.
4647
// It serves prometheus metrics, pprof profiling and the runtime enr.
4748
func wireMonitoringAPI(ctx context.Context, life *lifecycle.Manager, promAddr, debugAddr string,
48-
p2pNode host.Host, eth2Cl eth2wrap.Client,
49+
p2pNode host.Host, eth2Cl eth2wrap.Client, beaconNodeAddrs []string,
4950
peerIDs []peer.ID, registry *prometheus.Registry, consensusDebugger http.Handler,
5051
pubkeys []core.PubKey, seenPubkeys <-chan core.PubKey, vapiCalls <-chan struct{},
5152
numValidators int,
5253
) {
53-
beaconNodeVersionMetric(ctx, eth2Cl, clockwork.NewRealClock())
54+
beaconNodeVersionMetric(ctx, eth2Cl, beaconNodeAddrs, clockwork.NewRealClock())
5455

5556
mux := http.NewServeMux()
5657

@@ -268,35 +269,37 @@ func beaconNodeSyncing(ctx context.Context, eth2Cl eth2client.NodeSyncingProvide
268269
}
269270

270271
// beaconNodeVersionMetric sets the beacon node version gauge.
271-
func beaconNodeVersionMetric(ctx context.Context, eth2Cl eth2wrap.Client, clock clockwork.Clock) {
272-
nodeVersionTicker := clock.NewTicker(10 * time.Minute)
273-
274-
setNodeVersion := func() {
275-
eth2Resp, err := eth2Cl.NodeVersion(ctx, &eth2api.NodeVersionOpts{})
276-
if err != nil {
277-
log.Error(ctx, "Failed to fetch beacon node version. Check beacon node connectivity and API availability", err)
278-
return
279-
}
280-
281-
version := eth2Resp.Data
272+
func beaconNodeVersionMetric(ctx context.Context, eth2Cl eth2wrap.Client, beaconNodeAddrs []string, clk clockwork.Clock) {
273+
nodeVersionTicker := clk.NewTicker(10 * time.Minute)
282274

275+
setNodeVersionAndID := func() {
283276
beaconNodeVersionGauge.Reset()
284-
beaconNodeVersionGauge.WithLabelValues(version).Set(1)
285277

286-
eth2wrap.CheckBeaconNodeVersion(ctx, version)
287-
}
278+
// Query each beacon node individually
279+
for _, addr := range beaconNodeAddrs {
280+
// Get a client scoped to this specific beacon node
281+
scopedClient := eth2Cl.ClientForAddress(addr)
288282

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-
}
283+
versionResp, err := scopedClient.NodeVersion(ctx, &eth2api.NodeVersionOpts{})
284+
if err != nil {
285+
log.Warn(ctx, "Failed to fetch beacon node version", err,
286+
z.Str("beacon_node_address", addr))
287+
continue
288+
}
295289

296-
peerID := response.Data.PeerID
290+
response, err := scopedClient.NodeIdentity(ctx, &eth2api.NodeIdentityOpts{})
291+
if err != nil {
292+
log.Warn(ctx, "Failed to fetch beacon node identity", err,
293+
z.Str("beacon_node_address", addr))
294+
continue
295+
}
296+
297+
version := versionResp.Data
298+
beaconID := response.Data.PeerID
299+
beaconNodeVersionGauge.WithLabelValues(version, beaconID).Set(1)
297300

298-
beaconNodePeerIDGauge.Reset()
299-
beaconNodePeerIDGauge.WithLabelValues(peerID).Set(1)
301+
eth2wrap.CheckBeaconNodeVersion(ctx, version)
302+
}
300303
}
301304

302305
go func() {
@@ -306,11 +309,9 @@ func beaconNodeVersionMetric(ctx context.Context, eth2Cl eth2wrap.Client, clock
306309
for {
307310
select {
308311
case <-onStartup:
309-
setNodeVersion()
310-
setNodePeerID()
312+
setNodeVersionAndID()
311313
case <-nodeVersionTicker.Chan():
312-
setNodeVersion()
313-
setNodePeerID()
314+
setNodeVersionAndID()
314315
case <-ctx.Done():
315316
return
316317
}

0 commit comments

Comments
 (0)