Use chronos http server for dcli metrics and remove insecure compile flag (#343)

And add cfg file to default have runtime log filtering on
This commit is contained in:
Kim De Mey 2021-04-02 17:29:38 +02:00 committed by GitHub
parent 207b783253
commit c5dace27ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 18 deletions

View File

@ -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:<base64 encoding of ENR>
```

View File

@ -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)
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)
run(config)

View File

@ -0,0 +1 @@
-d:"chronicles_runtime_filtering=on"