Skip to content

Commit 57f5421

Browse files
committed
Config refactor
1 parent 8cc94ca commit 57f5421

8 files changed

Lines changed: 19 additions & 96 deletions

File tree

execution_chain/conf.nim

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ const
4848
defaultHttpPort = 8545
4949
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/authentication.md#jwt-specifications
5050
defaultEngineApiPort* = 8551
51-
defaultAdminListenAddress = (static parseIpAddress("127.0.0.1"))
52-
defaultAdminListenAddressDesc = $defaultAdminListenAddress & ", meaning local host only"
5351
logLevelDesc = getLogLevels()
5452

5553
template defaultListenAddress(): IpAddress =
@@ -175,21 +173,7 @@ type
175173
defaultValue: StdoutLogKind.Auto
176174
name: "log-format" .}: StdoutLogKind
177175

178-
metricsEnabled* {.
179-
desc: "Enable the built-in metrics HTTP server"
180-
defaultValue: false
181-
name: "metrics" .}: bool
182-
183-
metricsPort* {.
184-
desc: "Listening port of the built-in metrics HTTP server"
185-
defaultValue: defaultMetricsServerPort
186-
name: "metrics-port" .}: Port
187-
188-
metricsAddress* {.
189-
desc: "Listening IP address of the built-in metrics HTTP server"
190-
defaultValue: defaultAdminListenAddress
191-
defaultValueDesc: defaultAdminListenAddressDesc
192-
name: "metrics-address" .}: IpAddress
176+
metrics* {.flatten: (port: defaultMetricsServerPort).}: MetricsConf
193177

194178
bootstrapNodes {.
195179
separator: "\pNETWORKING OPTIONS:"
@@ -396,7 +380,6 @@ type
396380
httpAddress* {.
397381
desc: "Listening IP address of the HTTP server(rpc, ws)"
398382
defaultValue: defaultAdminListenAddress
399-
defaultValueDesc: $defaultAdminListenAddressDesc
400383
name: "http-address" .}: IpAddress
401384

402385
rpcEnabled* {.
@@ -449,7 +432,6 @@ type
449432
engineApiAddress* {.
450433
desc: "Listening address for the Engine API(http and ws)"
451434
defaultValue: defaultAdminListenAddress
452-
defaultValueDesc: $defaultAdminListenAddressDesc
453435
name: "engine-api-address" .}: IpAddress
454436

455437
engineApiWsEnabled* {.

execution_chain/nimbus.nim

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import
4848
]
4949

5050
const
51-
defaultMetricsServerPort = 8008
5251
copyright = "Copyright (c) " & compileYear & " Status Research & Development GmbH"
5352

5453
type NStartUpCmd* {.pure.} = enum
@@ -95,21 +94,7 @@ type
9594
defaultValue: StdoutLogKind.Auto
9695
name: "log-format" .}: StdoutLogKind
9796

98-
metricsEnabled* {.
99-
desc: "Enable the built-in metrics HTTP server"
100-
defaultValue: false
101-
name: "metrics" .}: bool
102-
103-
metricsPort* {.
104-
desc: "Listening port of the built-in metrics HTTP server"
105-
defaultValue: defaultMetricsServerPort
106-
name: "metrics-port" .}: Port
107-
108-
metricsAddress* {.
109-
desc: "Listening IP address of the built-in metrics HTTP server"
110-
defaultValue: defaultAdminListenAddress
111-
defaultValueDesc: $defaultAdminListenAddressDesc
112-
name: "metrics-address" .}: IpAddress
97+
metrics* {.flatten.}: MetricsConf
11398

11499
numThreads* {.
115100
defaultValue: 0,
@@ -219,7 +204,7 @@ proc runBeaconNode(p: BeaconThreadConfig) {.thread.} =
219204
let engineUrl =
220205
EngineApiUrl.init(&"http://127.0.0.1:{defaultEngineApiPort}/", Opt.some(jwtKey))
221206

222-
config.metricsEnabled = false
207+
config.metrics.enabled = false
223208
config.elUrls.add EngineApiUrlConfigValue(
224209
url: engineUrl.url, jwtSecret: some toHex(distinctBase(jwtKey))
225210
)
@@ -265,7 +250,7 @@ proc runBeaconNode(p: BeaconThreadConfig) {.thread.} =
265250

266251
proc runExecutionClient(p: ExecutionThreadConfig) {.thread.} =
267252
var config = makeConfig(ignoreUnknown = true)
268-
config.metricsEnabled = false
253+
config.metrics.enabled = false
269254
config.engineApiEnabled = true
270255
config.engineApiPort = Port(defaultEngineApiPort)
271256
config.engineApiAddress = defaultAdminListenAddress
@@ -322,7 +307,7 @@ proc runCombinedClient() =
322307
# permissions are insecure.
323308
quit QuitFailure
324309

325-
let metricsServer = (waitFor config.initMetricsServer()).valueOr:
310+
let metricsServer = (waitFor initMetricsServer(config.metrics)).valueOr:
326311
quit 1
327312

328313
# Nim GC metrics (for the main thread) will be collected in onSecond(), but

execution_chain/nimbus_execution_client.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ proc main*(config = makeConfig(), nimbus = NimbusNode(nil)) {.noinline.} =
393393
# Metrics are useful not just when running node but also during import
394394
let metricsServer =
395395
try:
396-
waitFor(initMetricsServer(config)).valueOr:
396+
waitFor(initMetricsServer(config.metrics)).valueOr:
397397
quit(QuitFailure)
398398
except CancelledError:
399399
raiseAssert "Never cancelled"

portal/client/nimbus_portal_client.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ proc run(portalClient: PortalClient, config: PortalConf) {.raises: [CatchableErr
236236
quit QuitFailure
237237

238238
## Start metrics HTTP server
239-
let metricsServer = waitFor(initMetricsServer(config)).valueOr:
239+
let metricsServer = waitFor(initMetricsServer(config.metrics)).valueOr:
240240
quit QuitFailure # Logged in initMetricsServer
241241

242242
## Start the Portal node.

portal/client/nimbus_portal_client_conf.nim

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import
2626

2727
const
2828
defaultListenAddress* = (static parseIpAddress("0.0.0.0"))
29-
defaultAdminListenAddress* = (static parseIpAddress("127.0.0.1"))
3029
defaultListenAddressDesc = $defaultListenAddress
31-
defaultAdminListenAddressDesc = $defaultAdminListenAddress
3230

3331
defaultStorageCapacity* = 2000'u32 # 2 GB default
3432
defaultStorageCapacityDesc* = $defaultStorageCapacity
@@ -164,22 +162,7 @@ type
164162
name: "debug-netkey-nodeid-prefix-unsafe"
165163
.}: Option[string]
166164

167-
metricsEnabled* {.
168-
defaultValue: false, desc: "Enable the metrics server", name: "metrics"
169-
.}: bool
170-
171-
metricsAddress* {.
172-
defaultValue: defaultAdminListenAddress,
173-
defaultValueDesc: $defaultAdminListenAddressDesc,
174-
desc: "Listening address of the metrics server",
175-
name: "metrics-address"
176-
.}: IpAddress
177-
178-
metricsPort* {.
179-
defaultValue: 8008,
180-
desc: "Listening HTTP port of the metrics server",
181-
name: "metrics-port"
182-
.}: Port
165+
metrics* {.flatten.}: MetricsConf
183166

184167
rpcEnabled* {.
185168
desc: "Enable the HTTP JSON-RPC server", defaultValue: false, name: "rpc"
@@ -188,7 +171,6 @@ type
188171
rpcAddress* {.
189172
desc: "Listening address of the HTTP JSON-RPC server",
190173
defaultValue: defaultAdminListenAddress,
191-
defaultValueDesc: $defaultAdminListenAddressDesc,
192174
name: "rpc-address"
193175
.}: IpAddress
194176

@@ -211,7 +193,6 @@ type
211193
wsAddress* {.
212194
desc: "Listening address of the WebSocket JSON-RPC server",
213195
defaultValue: defaultAdminListenAddress,
214-
defaultValueDesc: $defaultAdminListenAddressDesc,
215196
name: "ws-address"
216197
.}: IpAddress
217198

portal/tools/portalcli.nim

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import
1919
eth/[common/keys, net/nat],
2020
eth/p2p/discoveryv5/node,
2121
eth/p2p/discoveryv5/protocol as discv5_protocol,
22+
beacon_chain/nimbus_binary_common,
2223
../common/common_utils,
2324
../database/content_db,
2425
../network/wire/
@@ -95,21 +96,7 @@ type
9596
name: "network-key"
9697
.}: PrivateKey
9798

98-
metricsEnabled* {.
99-
defaultValue: false, desc: "Enable the metrics server", name: "metrics"
100-
.}: bool
101-
102-
metricsAddress* {.
103-
defaultValue: defaultAdminListenAddress,
104-
desc: "Listening address of the metrics server",
105-
name: "metrics-address"
106-
.}: IpAddress
107-
108-
metricsPort* {.
109-
defaultValue: 8008,
110-
desc: "Listening HTTP port of the metrics server",
111-
name: "metrics-port"
112-
.}: Port
99+
metrics* {.flatten.}: MetricsConf
113100

114101
protocolId* {.
115102
defaultValue: getProtocolId(PortalSubnetwork.history),
@@ -268,23 +255,11 @@ proc run(config: PortalCliConf) =
268255
bootstrapRecords = bootstrapRecords,
269256
)
270257

271-
if config.metricsEnabled:
272-
let
273-
address = config.metricsAddress
274-
port = config.metricsPort
275-
url = "http://" & $address & ":" & $port & "/metrics"
276-
277-
server = MetricsHttpServerRef.new($address, port).valueOr:
278-
error "Could not instantiate metrics HTTP server", url, error
279-
quit QuitFailure
280-
281-
info "Starting metrics HTTP server", url
282-
try:
283-
waitFor server.start()
284-
except MetricsError as exc:
285-
fatal "Could not start metrics HTTP server",
286-
url, error_msg = exc.msg, error_name = exc.name
287-
quit QuitFailure
258+
let metricsServer = (waitFor initMetricsServer(config.metrics)).valueOr:
259+
quit QuitFailure
260+
defer:
261+
if metricsServer.isSome():
262+
waitFor metricsServer.stopMetricsServer()
288263

289264
case config.cmd
290265
of ping:

tests/test_configuration.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ proc configurationMain*() =
322322
check config.logLevel == "DEBUG"
323323
check config.logFormat == StdoutLogKind.Json
324324

325-
check config.metricsEnabled == true
326-
check config.metricsPort == 127.Port
327-
check config.metricsAddress == parseIpAddress("111.222.33.203")
325+
check config.metrics.enabled == true
326+
check config.metrics.port == 127.Port
327+
check config.metrics.address == parseIpAddress("111.222.33.203")
328328

329329
privateAccess(ExecutionClientConf)
330330
check config.bootstrapNodes.len == 3

vendor/nimbus-eth2

Submodule nimbus-eth2 updated 169 files

0 commit comments

Comments
 (0)