Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workbench: add & integrate cardano-tracer service
- Loading branch information
Showing
12 changed files
with
292 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
pkgs: | ||
let serviceConfigToJSON = | ||
cfg: | ||
{ | ||
networkMagic = 764824073; ## Mainnet | ||
# loRequestNum = 100; | ||
network = | ||
if cfg.acceptingSocket != null | ||
then { | ||
tag = "AcceptAt"; | ||
contents = cfg.acceptingSocket; | ||
} else if cfg.connectToSocket != null | ||
then { | ||
tag = "ConnectTo"; | ||
contents = cfg.connectToSocket; | ||
} else | ||
throw "cardano-tracer-service: either acceptingSocket or connectToSocket must be provided."; | ||
logging = [{ | ||
inherit (cfg) logRoot; | ||
|
||
logMode = "FileMode"; | ||
logFormat = "ForMachine"; | ||
}]; | ||
rotation = { | ||
rpFrequencySecs = 15; | ||
rpKeepFilesNum = 10; | ||
rpLogLimitBytes = 500000000; | ||
rpMaxAgeHours = 24; | ||
}; | ||
|
||
hasEKG = [ | ||
{ epHost = "127.0.0.1"; | ||
epPort = 3100; ## supervisord.portShiftPrometheus | ||
} | ||
{ epHost = "127.0.0.1"; | ||
epPort = 3101; ## supervisord.portShiftPrometheus | ||
} | ||
]; | ||
ekgRequestFreq = 1; | ||
hasPrometheus = { | ||
epHost = "127.0.0.1"; | ||
epPort = 3200; ## supervisord.portShiftPrometheus | ||
}; | ||
}; | ||
in pkgs.commonLib.defServiceModule | ||
(lib: with lib; | ||
{ svcName = "cardano-tracer"; | ||
svcDesc = "Cardano trace processor"; | ||
|
||
svcPackageSelector = | ||
pkgs: ## Local: | ||
pkgs.cardanoNodePackages.cardano-tracer | ||
## Imported by another repo, that adds an overlay: | ||
or pkgs.cardano-tracer; | ||
## TODO: that's actually a bit ugly and could be improved. | ||
## This exe has to be available in the selected package. | ||
exeName = "cardano-tracer"; | ||
|
||
extraOptionDecls = { | ||
### You can actually change those! | ||
acceptingSocket = mayOpt str "Socket path: as acceptor."; | ||
connectToSocket = mayOpt str "Socket path: connect to."; | ||
logRoot = opt str null "Log storage root directory."; | ||
|
||
### Here be dragons, on the other hand.. | ||
configFile = mayOpt str | ||
"Config file path override -- only set if you know what you're doing. Shudder. Your 'eminence'.."; | ||
configJSONfn = opt (functionTo attrs) serviceConfigToJSON | ||
"This is NOT meant to be overridden, at all -- we only expose it so it's externally accessible."; | ||
}; | ||
|
||
configExeArgsFn = cfg: [ | ||
"--config" (if cfg.configFile != null then cfg.configFile | ||
else "${pkgs.writeText "cardano-tracer-config.json" | ||
(__toJSON (serviceConfigToJSON cfg))}") | ||
]; | ||
|
||
configSystemdExtraConfig = _: {}; | ||
|
||
configSystemdExtraServiceConfig = | ||
cfg: with cfg; { | ||
Type = "exec"; | ||
User = "cardano-node"; | ||
Group = "cardano-node"; | ||
Restart = "yes"; | ||
# RuntimeDirectory = localNodeConf.runtimeDir; | ||
# WorkingDirectory = localNodeConf.stateDir; | ||
}; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
{ pkgs | ||
, runJq | ||
|
||
## The backend is an attrset of AWS/supervisord-specific methods and parameters. | ||
, backend | ||
|
||
, profile | ||
}: | ||
|
||
with pkgs.lib; | ||
|
||
let | ||
# We're reusing configuration from a cluster node. | ||
nodes = profile.node-services; | ||
|
||
## | ||
## nodeSpecsTracerConfig :: Map NodeId NodeSpec -> TracerConfig | ||
## | ||
nodeSpecsTracerConfig = | ||
nodeSpecs: | ||
let | ||
in | ||
backend.finaliseTracerService | ||
{ | ||
## In both the local and remote scenarios, it's most frequently convenient to act as an acceptor. | ||
acceptingSocket = "tracer.socket"; | ||
|
||
## logRoot = ## ..really depends on context -- available in backend.finaliseTracerService | ||
|
||
dsmPassthrough = { | ||
# rtsOpts = ["-xc"]; | ||
}; | ||
}; | ||
|
||
## Given an env config, evaluate it and produce the service. | ||
## | ||
## tracerConfigServiceConfig :: TracerConfig -> NixosServiceConfig | ||
## | ||
tracerConfigServiceConfig = | ||
tracerConfig: | ||
let | ||
systemdCompat.options = { | ||
systemd.services = mkOption {}; | ||
systemd.sockets = mkOption {}; | ||
users = mkOption {}; | ||
assertions = mkOption {}; | ||
}; | ||
eval = let | ||
extra = { | ||
services.cardano-tracer = { | ||
enable = true; | ||
} // tracerConfig; | ||
}; | ||
in evalModules { | ||
prefix = []; | ||
modules = import ../../nixos/module-list.nix ++ [ | ||
(import ../../nixos/cardano-tracer-service.nix pkgs) | ||
systemdCompat extra | ||
]; | ||
args = { inherit pkgs; }; | ||
}; | ||
in eval.config.services.cardano-tracer; | ||
|
||
## | ||
## generator-service :: (TracerConfig, NixosServiceConfig, Config, StartScript) | ||
## | ||
tracer-service = | ||
(nodeSpecs: | ||
let | ||
tracerConfig = nodeSpecsTracerConfig nodeSpecs; | ||
nixosServiceConfig = tracerConfigServiceConfig tracerConfig; | ||
nixosServiceConfigFns = ["configJSONfn"]; | ||
execConfig = nixosServiceConfig.configJSONfn nixosServiceConfig; | ||
in { | ||
tracer-config = { | ||
value = tracerConfig; | ||
JSON = runJq "tracer-config.json" | ||
''--null-input --sort-keys | ||
--argjson x '${__toJSON tracerConfig}' | ||
'' "$x"; | ||
}; | ||
|
||
nixos-service-config = { | ||
## XXX: service == appallingly bad name -- it's bona-fide NixOS service "config", not a service! | ||
value = nixosServiceConfig; | ||
JSON = runJq "nixos-service-config.json" | ||
''--null-input --sort-keys | ||
--argjson x '${__toJSON (removeAttrs nixosServiceConfig nixosServiceConfigFns)}' | ||
'' "$x"; | ||
}; | ||
|
||
config = rec { | ||
value = execConfig; | ||
JSON = runJq "config.json" | ||
''--null-input | ||
--argjson x '${__toJSON execConfig}' | ||
'' "$x"; | ||
}; | ||
|
||
startupScript = | ||
pkgs.writeScript "startup-tracer.sh" | ||
'' | ||
#!${pkgs.stdenv.shell} | ||
${nixosServiceConfig.script} | ||
''; | ||
}) | ||
profile.node-specs.value; | ||
in | ||
{ | ||
inherit tracer-service; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.