From c5dace27cad9f3f832f40f0e37b8063125cc9871 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Fri, 2 Apr 2021 17:29:38 +0200 Subject: [PATCH] Use chronos http server for dcli metrics and remove insecure compile flag (#343) And add cfg file to default have runtime log filtering on --- doc/discv5.md | 6 ++---- eth/p2p/discoveryv5/dcli.nim | 31 +++++++++++++++++-------------- eth/p2p/discoveryv5/dcli.nim.cfg | 1 + 3 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 eth/p2p/discoveryv5/dcli.nim.cfg diff --git a/doc/discv5.md b/doc/discv5.md index 452dfaa..42de633 100644 --- a/doc/discv5.md +++ b/doc/discv5.md @@ -98,11 +98,9 @@ nim c -d:chronicles_log_level:trace -d:release --threads:on eth/p2p/discoveryv5/ ``` ### Metrics -To compile in an HTTP endpoint for accessing the metrics add the `insecure` -compile time flag: +To run dcli with metrics enabled provide the `metrics` flag: + ```sh -# Build dcli with metrics -nim c -d:insecure -d:chronicles_log_level:trace -d:release --threads:on eth/p2p/discoveryv5/dcli # Run dcli with metrics ./eth/p2p/discoveryv5/dcli --metrics --bootnode:enr: ``` diff --git a/eth/p2p/discoveryv5/dcli.nim b/eth/p2p/discoveryv5/dcli.nim index e54736d..42c9393 100644 --- a/eth/p2p/discoveryv5/dcli.nim +++ b/eth/p2p/discoveryv5/dcli.nim @@ -1,8 +1,9 @@ import - std/[options, strutils], - chronos, chronicles, chronicles/topics_registry, confutils, metrics, - stew/byteutils, confutils/std/net, - eth/keys, eth/net/nat, enr, node, protocol + std/[options, strutils, tables], + confutils, confutils/std/net, chronicles, chronicles/topics_registry, + chronos, metrics, metrics/chronos_httpserver, stew/byteutils, + ../../keys, ../../net/nat, + ./enr, ./node, ./protocol type DiscoveryCmd* = enum @@ -124,7 +125,7 @@ proc completeCmdArg*(T: type Node, val: TaintedString): seq[string] = proc parseCmdArg*(T: type PrivateKey, p: TaintedString): T = try: result = PrivateKey.fromHex(string(p)).tryGet() - except CatchableError as e: + except CatchableError: raise newException(ConfigurationError, "Invalid private key") proc completeCmdArg*(T: type PrivateKey, val: TaintedString): seq[string] = @@ -152,13 +153,16 @@ proc run(config: DiscoveryConf) = d.open() - when defined(insecure): - if config.metricsEnabled: - let - address = config.metricsAddress - port = config.metricsPort - info "Starting metrics HTTP server", address, port - metrics.startHttpServer($address, port) + if config.metricsEnabled: + let + address = config.metricsAddress + port = config.metricsPort + notice "Starting metrics HTTP server", + url = "http://" & $address & ":" & $port & "/metrics" + try: + chronos_httpserver.startMetricsHttpServer($address, port) + except CatchableError as exc: raise exc + except Exception as exc: raiseAssert exc.msg # TODO fix metrics case config.cmd of ping: @@ -188,7 +192,6 @@ proc run(config: DiscoveryConf) = when isMainModule: let config = DiscoveryConf.load() - if config.logLevel != LogLevel.NONE: - setLogLevel(config.logLevel) + setLogLevel(config.logLevel) run(config) diff --git a/eth/p2p/discoveryv5/dcli.nim.cfg b/eth/p2p/discoveryv5/dcli.nim.cfg new file mode 100644 index 0000000..fd1581b --- /dev/null +++ b/eth/p2p/discoveryv5/dcli.nim.cfg @@ -0,0 +1 @@ +-d:"chronicles_runtime_filtering=on"