Skip to content

Commit

Permalink
benchTracer: add a flag to toggle legacy and new nixos svc use
Browse files Browse the repository at this point in the history
  • Loading branch information
johnalotoski committed Mar 8, 2025
1 parent b756344 commit 1630e98
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 43 deletions.
42 changes: 30 additions & 12 deletions nix/nixos/cardano-tracer-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ with builtins; let
echo "..or, once again, in a single line:"
echo "${toString cmd}"
trap 'RC="$?"; echo "Service binary 'cardano-tracer' returned status: $RC" >&2; exit $RC' EXIT
${toString cmd}
'';
in {
Expand Down Expand Up @@ -244,7 +245,7 @@ in {

executable = mkOption {
type = str;
default = "exec ${cfg.package}/bin/cardano-tracer";
default = "${cfg.package}/bin/cardano-tracer";
defaultText = "cardano-node";
description = ''
The cardano-tracer executable invocation to use.
Expand Down Expand Up @@ -359,7 +360,7 @@ in {
};

metricsComp = mkOption {
type = nullOr (attrsOf str);
type = nullOr (either str (attrsOf str));
default = null;
description = ''
Passing metric compatability mapping to cardano-tracer can be done as
Expand All @@ -369,10 +370,8 @@ in {
original name and mapped name. Only one mapping per message is
supported.
If such a set is already available as JSON, this also can be imported:
services.cardano-tracer.metricsComp =
builtins.fromJSON (builtins.readFile $PATH);
If such a set is already available as JSON in a file, this option can
be declared as a string of the path to such file.
Any metrics prefix name declared with `TraceOptionMetricsPrefix` in
cardano-node config should not be included in the attribute name.
Expand All @@ -386,18 +385,16 @@ in {
};

metricsHelp = mkOption {
type = nullOr (attrsOf str);
type = nullOr (either str (attrsOf str));
default = null;
description = ''
Passing metric help annotations to cardano-tracer can be done as a an
attribute set of strings from metric name to help text where
cardano-tracer's internal metric names have to be used as attribute
names.
If such a set is already available as JSON, this also can be imported:
services.cardano-tracer.metricsHelp =
builtins.fromJSON (builtins.readFile $PATH);
If such a set is already available as JSON in a file, this option can
be declared as a string of the path to such file.
Any metrics prefix name declared with `TraceOptionMetricsPrefix` in
cardano-node config should not be included in the attribute name.
Expand Down Expand Up @@ -690,13 +687,24 @@ in {
'';
};

stateDir = mkOption {
script = mkOption {
type = str;
default = mkScript;
internal = true;
description = ''
'';
};

stateDir = mkOption {
type = nullOr str;
default = "${cfg.stateDirBase}cardano-tracer";
description = ''
The directory to store any cardano-tracer process related data.
RTView if enabled will save its state in this directory.
For non-systemd use cases, this can be set to null or any other
string path.
'';
};

Expand All @@ -708,6 +716,16 @@ in {
'';
};

tracerConfig = mkOption {
type = attrs;
default = tracerConfig;
internal = true;
description = ''
The default nixos tracerConfig attribute set used in workbench
profile generation.
'';
};

user = mkOption {
type = str;
default = "cardano-node";
Expand Down
78 changes: 47 additions & 31 deletions nix/workbench/service/tracer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
with pkgs.lib;

let
# For testing legacy to new cardano-tracer-service transition
# useLegacyTracerService = true;
useLegacyTracerService = false;

## Given an env config, evaluate it and produce the service.
##
Expand All @@ -18,17 +21,12 @@ let
let
tracerConfig =
{
enable = true;
## In both the local and remote scenarios, it's most frequently
## convenient to act as an acceptor.
acceptingSocket = "tracer.socket";
networkMagic = profile.genesis.network_magic;
dsmPassthrough = {
# rtsOpts = ["-xc"];
} // optionalAttrs (profile.tracer.withresources or false) {
rtsOpts = [ "-scardano-tracer.gcstats" ];
};
configFile = "config.json";
logRoot = ".";
metricsHelp = "../../../cardano-tracer/configuration/metrics_help.json";
} // optionalAttrs backend.useCabalRun {
executable = "cardano-tracer";
Expand All @@ -39,6 +37,25 @@ let
};
} // optionalAttrs (profile.tracer.withresources or false) {
resourceFreq = 1000;
} // optionalAttrs useLegacyTracerService {
dsmPassthrough = {
# rtsOpts = ["-xc"];
} // optionalAttrs (profile.tracer.withresources or false) {
rtsOpts = [ "-scardano-tracer.gcstats" ];
};
logRoot = ".";
} // optionalAttrs (!useLegacyTracerService) {
logging = [
{
logRoot = ".";
logMode = "FileMode";
logFormat = "ForMachine";
}
];
rtsArgs =
# ["-xc"] ++
optionals (profile.tracer.withresources or false) ["-scardano-tracer.gcstats"];
stateDir = null;
}
;
systemdCompat.options = {
Expand All @@ -48,29 +65,26 @@ let
assertions = mkOption {};
environment = mkOption {};
};
eval =
let
extra = {
services.cardano-tracer = {
enable = true;
} // tracerConfig;
};
in evalModules {
prefix = [];
modules = [
(import ../../nixos/cardano-node-service.nix)
(import ../../nixos/cardano-submit-api-service.nix)
# (import ../../nixos/cardano-tracer-service.nix)
(import ../../nixos/cardano-tracer-service-legacy.nix pkgs)
systemdCompat
extra
{ config._module.args = { inherit pkgs; }; }
]
++ [ backend.service-modules.tracer or {} ]
eval = evalModules {
prefix = [];

modules = [
(import ../../nixos/cardano-node-service.nix)
(import ../../nixos/cardano-submit-api-service.nix)
# (import ../../nixos/cardano-tracer-service.nix)
{ config._module.args = { inherit pkgs; }; }
{ services.cardano-tracer = tracerConfig; }
systemdCompat
]
++ [ backend.service-modules.tracer or {} ]
++ optionals useLegacyTracerService
[ (import ../../nixos/cardano-tracer-service-legacy.nix pkgs) ]
++ optionals (!useLegacyTracerService)
[ (import ../../nixos/cardano-tracer-service.nix) ]
;
# args = { inherit pkgs; };
}
;

# args = { inherit pkgs; };
};
in
eval.config.services.cardano-tracer;

Expand All @@ -81,18 +95,20 @@ let
(nodeSpecs:
let
nixosServiceConfig = tracerConfigServiceConfig;
execConfig = nixosServiceConfig.configJSONfn nixosServiceConfig;
execConfig = if useLegacyTracerService
then nixosServiceConfig.configJSONfn nixosServiceConfig
else nixosServiceConfig.tracerConfig;
in {
start = rec {
value = ''
value = traceVal ''
#!${pkgs.stdenv.shell}
${nixosServiceConfig.script}
'';
JSON = pkgs.writeScript "startup-tracer.sh" value;
};

config = rec {
config = {
value = execConfig;
JSON = jsonFilePretty "config.json" (__toJSON execConfig);
};
Expand Down

0 comments on commit 1630e98

Please sign in to comment.