1
1
# beacon_chain
2
- # Copyright (c) 2018-2024 Status Research & Development GmbH
2
+ # Copyright (c) 2018-2025 Status Research & Development GmbH
3
3
# Licensed and distributed under either of
4
4
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
5
5
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -161,38 +161,6 @@ proc initClock(
161
161
current_slot = currentSlot, current_epoch = currentEpoch
162
162
res
163
163
164
- proc initMetrics (
165
- vc: ValidatorClientRef
166
- ): Future [bool ] {.async : (raises: [CancelledError ]).} =
167
- if vc.config.metricsEnabled:
168
- let
169
- metricsAddress = vc.config.metricsAddress
170
- metricsPort = vc.config.metricsPort
171
- url = " http://" & $ metricsAddress & " :" & $ metricsPort & " /metrics"
172
- info " Starting metrics HTTP server" , url = url
173
- let server =
174
- block :
175
- let res = MetricsHttpServerRef .new ($ metricsAddress, metricsPort)
176
- if res.isErr ():
177
- error " Could not start metrics HTTP server" , url = url,
178
- error_msg = res.error ()
179
- return false
180
- res.get ()
181
- vc.metricsServer = Opt .some (server)
182
- try :
183
- await server.start ()
184
- except MetricsError as exc:
185
- error " Could not start metrics HTTP server" , url = url,
186
- error_msg = exc.msg, error_name = exc.name
187
- return false
188
- true
189
-
190
- proc shutdownMetrics (vc: ValidatorClientRef ) {.async : (raises: []).} =
191
- if vc.config.metricsEnabled:
192
- if vc.metricsServer.isSome ():
193
- info " Shutting down metrics HTTP server"
194
- await vc.metricsServer.get ().close ()
195
-
196
164
proc shutdownSlashingProtection (vc: ValidatorClientRef ) =
197
165
info " Closing slashing protection" , path = vc.config.validatorsDir ()
198
166
vc.attachedValidators[].slashingProtection.close ()
@@ -351,7 +319,7 @@ proc asyncInit(vc: ValidatorClientRef): Future[ValidatorClientRef] {.
351
319
352
320
vc.beaconClock = await vc.initClock ()
353
321
354
- if not (await initMetrics (vc)) :
322
+ vc.metricsServer = (await vc.config. initMetricsServer ()).valueOr :
355
323
raise newException (ValidatorClientError ,
356
324
" Could not initialize metrics server" )
357
325
@@ -368,7 +336,7 @@ proc asyncInit(vc: ValidatorClientRef): Future[ValidatorClientRef] {.
368
336
vc.attachedValidators = validatorPool
369
337
370
338
if not (await initValidators (vc)):
371
- await vc.shutdownMetrics ()
339
+ await vc.metricsServer. stopMetricsServer ()
372
340
raise newException (ValidatorClientError ,
373
341
" Could not initialize local validators" )
374
342
@@ -432,7 +400,7 @@ proc asyncInit(vc: ValidatorClientRef): Future[ValidatorClientRef] {.
432
400
)
433
401
except CancelledError :
434
402
debug " Initialization process interrupted"
435
- await vc.shutdownMetrics ()
403
+ await vc.metricsServer. stopMetricsServer ()
436
404
vc.shutdownSlashingProtection ()
437
405
return
438
406
@@ -522,7 +490,7 @@ proc asyncRun*(
522
490
except CancelledError :
523
491
debug " Main loop interrupted"
524
492
525
- await vc.shutdownMetrics ()
493
+ await vc.metricsServer. stopMetricsServer ()
526
494
vc.shutdownSlashingProtection ()
527
495
528
496
if doppelEventFut.completed ():
0 commit comments