Various dev-ops things (#85)

* Add metrics server
* Add --version
* Fixes for chronicles=trace + ci
This commit is contained in:
Tanguy 2022-04-14 12:49:03 +02:00 committed by GitHub
parent b88561e090
commit c06c9b578c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 8 deletions

View File

@ -215,3 +215,5 @@ jobs:
echo ldd build/testDagger echo ldd build/testDagger
ldd build/testDagger ldd build/testDagger
fi fi
echo "Testing TRACE log level"
./env.sh nim c -d:chronicles_log_level=TRACE dagger.nim

View File

@ -68,6 +68,9 @@ switch("warning", "ObservableStores:off")
switch("warning", "LockLevel:off") switch("warning", "LockLevel:off")
switch("define", "libp2p_pki_schemes=secp256k1") switch("define", "libp2p_pki_schemes=secp256k1")
#TODO this infects everything in this folder, ideally it would only
# apply to dagger.nim, but since dagger.nims is used for other purpose
# we can't use it. And dagger.cfg doesn't work
switch("define", "chronicles_sinks=textlines[dynamic],json[dynamic]") switch("define", "chronicles_sinks=textlines[dynamic],json[dynamic]")
# begin Nimble config (version 1) # begin Nimble config (version 1)

View File

@ -27,8 +27,11 @@ when isMainModule:
when defined(posix): when defined(posix):
import system/ansi_c import system/ansi_c
let config = DaggerConf.load() let config = DaggerConf.load(
version = daggerFullVersion
)
config.setupLogging() config.setupLogging()
config.setupMetrics()
case config.cmd: case config.cmd:
of StartUpCommand.noCommand: of StartUpCommand.noCommand:
@ -38,7 +41,7 @@ when isMainModule:
# permissions are insecure. # permissions are insecure.
quit QuitFailure quit QuitFailure
trace "Data dir initialized", dir = config.dataDir trace "Data dir initialized", dir = $config.dataDir
if not(checkAndCreateDataDir((config.dataDir / "repo").string)): if not(checkAndCreateDataDir((config.dataDir / "repo").string)):
# We are unable to access/create data folder or data folder's # We are unable to access/create data folder or data folder's

View File

@ -280,7 +280,8 @@ proc requestBlock*(
assert discovery.provides.len > 0 assert discovery.provides.len > 0
trace "Requesting block from peer", peer = blockPeer.id, cid debug "Requesting block from peer", providerCount = discovery.provides.len,
peer = discovery.provides[0], cid
# request block # request block
b.network.request.sendWantList( b.network.request.sendWantList(
discovery.provides[0], discovery.provides[0],

View File

@ -14,12 +14,15 @@ push: {.upraises: [].}
import std/os import std/os
import std/terminal import std/terminal
import std/options import std/options
import std/strutils
import std/typetraits import std/typetraits
import pkg/chronicles import pkg/chronicles
import pkg/chronicles/topics_registry import pkg/chronicles/topics_registry
import pkg/confutils/defs import pkg/confutils/defs
import pkg/confutils/std/net import pkg/confutils/std/net
import pkg/metrics
import pkg/metrics/chronos_httpserver
import pkg/stew/shims/net as stewnet import pkg/stew/shims/net as stewnet
import pkg/libp2p import pkg/libp2p
@ -53,6 +56,21 @@ type
defaultValue: LogKind.Auto defaultValue: LogKind.Auto
name: "log-format" }: LogKind name: "log-format" }: LogKind
metricsEnabled* {.
desc: "Enable the metrics server"
defaultValue: false
name: "metrics" }: bool
metricsAddress* {.
desc: "Listening address of the metrics server"
defaultValue: ValidIpAddress.init("127.0.0.1")
defaultValueDesc: "127.0.0.1"
name: "metrics-address" }: ValidIpAddress
metricsPort* {.
desc: "Listening HTTP port of the metrics server"
defaultValue: 8008
name: "metrics-port" }: Port
dataDir* {. dataDir* {.
desc: "The directory where dagger will store configuration and data." desc: "The directory where dagger will store configuration and data."
@ -97,7 +115,7 @@ type
bootstrapNodes* {. bootstrapNodes* {.
desc: "Specifies one or more bootstrap nodes to use when connecting to the network." desc: "Specifies one or more bootstrap nodes to use when connecting to the network."
abbr: "b" abbr: "b"
name: "bootstrap-nodes" }: seq[SignedPeerRecord] name: "bootstrap-node" }: seq[SignedPeerRecord]
maxPeers* {. maxPeers* {.
desc: "The maximum number of peers to connect to" desc: "The maximum number of peers to connect to"
@ -126,6 +144,19 @@ type
of initNode: of initNode:
discard discard
const
gitRevision* = strip(staticExec("git rev-parse --short HEAD"))[0..5]
nimBanner* = staticExec("nim --version | grep Version")
#TODO add versionMajor, Minor & Fix when we switch to semver
daggerVersion* = gitRevision
daggerFullVersion* =
"Dagger build " & daggerVersion & "\p" &
nimBanner
proc defaultDataDir*(): string = proc defaultDataDir*(): string =
let dataDir = when defined(windows): let dataDir = when defined(windows):
"AppData" / "Roaming" / "Dagger" "AppData" / "Roaming" / "Dagger"
@ -223,3 +254,15 @@ proc setupLogging*(conf: DaggerConf) =
noOutput noOutput
setLogLevel(conf.logLevel) setLogLevel(conf.logLevel)
proc setupMetrics*(config: DaggerConf) =
if config.metricsEnabled:
let metricsAddress = config.metricsAddress
notice "Starting metrics HTTP server",
url = "http://" & $metricsAddress & ":" & $config.metricsPort & "/metrics"
try:
startMetricsHttpServer($metricsAddress, config.metricsPort)
except CatchableError as exc:
raiseAssert exc.msg
except Exception as exc:
raiseAssert exc.msg # TODO fix metrics

View File

@ -86,7 +86,7 @@ proc retrieve*(
# if we got a manifest, stream the blocks # if we got a manifest, stream the blocks
if $mc in ManifestContainers: if $mc in ManifestContainers:
trace "Retrieving data set", cid, mc trace "Retrieving data set", cid, mc = $mc
without manifest =? Manifest.decode(blk.data, ManifestContainers[$mc]): without manifest =? Manifest.decode(blk.data, ManifestContainers[$mc]):
return failure("Unable to construct manifest!") return failure("Unable to construct manifest!")
@ -203,7 +203,7 @@ proc requestStorage*(
# if we got a manifest, stream the blocks # if we got a manifest, stream the blocks
if $mc notin ManifestContainers: if $mc notin ManifestContainers:
trace "Not a manifest type!", cid, mc trace "Not a manifest type!", cid, mc = $mc
return failure("Not a manifest type!") return failure("Not a manifest type!")
without var manifest =? Manifest.decode(blk.data), error: without var manifest =? Manifest.decode(blk.data), error:

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit b2d980f258ebeabdaa0eedfe3722ebf949f6dadb Subproject commit eeb3c210a37408716b6a8b45f578adf87610cef2

@ -1 +1 @@
Subproject commit 6c4ce518f55007a861fe577b48cabdca7eaa32df Subproject commit 9a872518d621bf8b390f88cd65617bca6aca1d2d