Skip to content

Commit 74474d2

Browse files
committed
benchTracer: add a flag to toggle legacy and new nixos svc use
1 parent cbee8c0 commit 74474d2

File tree

2 files changed

+75
-42
lines changed

2 files changed

+75
-42
lines changed

nix/nixos/cardano-tracer-service.nix

+30-12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ with builtins; let
109109
echo "..or, once again, in a single line:"
110110
echo "${toString cmd}"
111111
112+
trap 'RC="$?"; echo "Service binary 'cardano-tracer' returned status: $RC" >&2; exit $RC' EXIT
112113
${toString cmd}
113114
'';
114115
in {
@@ -244,7 +245,7 @@ in {
244245

245246
executable = mkOption {
246247
type = str;
247-
default = "exec ${cfg.package}/bin/cardano-tracer";
248+
default = "${cfg.package}/bin/cardano-tracer";
248249
defaultText = "cardano-node";
249250
description = ''
250251
The cardano-tracer executable invocation to use.
@@ -359,7 +360,7 @@ in {
359360
};
360361

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

388387
metricsHelp = mkOption {
389-
type = nullOr (attrsOf str);
388+
type = nullOr (either str (attrsOf str));
390389
default = null;
391390
description = ''
392391
Passing metric help annotations to cardano-tracer can be done as a an
393392
attribute set of strings from metric name to help text where
394393
cardano-tracer's internal metric names have to be used as attribute
395394
names.
396395
397-
If such a set is already available as JSON, this also can be imported:
398-
399-
services.cardano-tracer.metricsHelp =
400-
builtins.fromJSON (builtins.readFile $PATH);
396+
If such a set is already available as JSON in a file, this option can
397+
be declared as a string of the path to such file.
401398
402399
Any metrics prefix name declared with `TraceOptionMetricsPrefix` in
403400
cardano-node config should not be included in the attribute name.
@@ -690,13 +687,24 @@ in {
690687
'';
691688
};
692689

693-
stateDir = mkOption {
690+
script = mkOption {
694691
type = str;
692+
default = mkScript;
693+
internal = true;
694+
description = ''
695+
'';
696+
};
697+
698+
stateDir = mkOption {
699+
type = nullOr str;
695700
default = "${cfg.stateDirBase}cardano-tracer";
696701
description = ''
697702
The directory to store any cardano-tracer process related data.
698703
699704
RTView if enabled will save its state in this directory.
705+
706+
For non-systemd use cases, this can be set to null or any other
707+
string path.
700708
'';
701709
};
702710

@@ -708,6 +716,16 @@ in {
708716
'';
709717
};
710718

719+
tracerConfig = mkOption {
720+
type = attrs;
721+
default = tracerConfig;
722+
internal = true;
723+
description = ''
724+
The default nixos tracerConfig attribute set used in workbench
725+
profile generation.
726+
'';
727+
};
728+
711729
user = mkOption {
712730
type = str;
713731
default = "cardano-node";

nix/workbench/service/tracer.nix

+45-30
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
with pkgs.lib;
1010

1111
let
12+
# For testing legacy to new cardano-tracer-service transition
13+
# useLegacyTracerService = true;
14+
useLegacyTracerService = false;
1215

1316
## Given an env config, evaluate it and produce the service.
1417
##
@@ -18,17 +21,12 @@ let
1821
let
1922
tracerConfig =
2023
{
24+
enable = true;
2125
## In both the local and remote scenarios, it's most frequently
2226
## convenient to act as an acceptor.
2327
acceptingSocket = "tracer.socket";
2428
networkMagic = profile.genesis.network_magic;
25-
dsmPassthrough = {
26-
# rtsOpts = ["-xc"];
27-
} // optionalAttrs (profile.tracer.withresources or false) {
28-
rtsOpts = [ "-scardano-tracer.gcstats" ];
29-
};
3029
configFile = "config.json";
31-
logRoot = ".";
3230
metricsHelp = "../../../cardano-tracer/configuration/metrics_help.json";
3331
} // optionalAttrs backend.useCabalRun {
3432
executable = "cardano-tracer";
@@ -39,6 +37,25 @@ let
3937
};
4038
} // optionalAttrs (profile.tracer.withresources or false) {
4139
resourceFreq = 1000;
40+
} // optionalAttrs useLegacyTracerService {
41+
dsmPassthrough = {
42+
# rtsOpts = ["-xc"];
43+
} // optionalAttrs (profile.tracer.withresources or false) {
44+
rtsOpts = [ "-scardano-tracer.gcstats" ];
45+
};
46+
logRoot = ".";
47+
} // optionalAttrs (!useLegacyTracerService) {
48+
logging = [
49+
{
50+
logRoot = ".";
51+
logMode = "FileMode";
52+
logFormat = "ForMachine";
53+
}
54+
];
55+
rtsArgs =
56+
# ["-xc"] ++
57+
optionals (profile.tracer.withresources or false) ["-scardano-tracer.gcstats"];
58+
stateDir = null;
4259
}
4360
;
4461
systemdCompat.options = {
@@ -48,29 +65,25 @@ let
4865
assertions = mkOption {};
4966
environment = mkOption {};
5067
};
51-
eval =
52-
let
53-
extra = {
54-
services.cardano-tracer = {
55-
enable = true;
56-
} // tracerConfig;
57-
};
58-
in evalModules {
59-
prefix = [];
60-
modules = [
61-
(import ../../nixos/cardano-node-service.nix)
62-
(import ../../nixos/cardano-submit-api-service.nix)
63-
# (import ../../nixos/cardano-tracer-service.nix)
64-
(import ../../nixos/cardano-tracer-service-legacy.nix pkgs)
65-
systemdCompat
66-
extra
67-
{ config._module.args = { inherit pkgs; }; }
68-
]
69-
++ [ backend.service-modules.tracer or {} ]
68+
eval = evalModules {
69+
prefix = [];
70+
71+
modules = [
72+
(import ../../nixos/cardano-node-service.nix)
73+
(import ../../nixos/cardano-submit-api-service.nix)
74+
{ config._module.args = { inherit pkgs; }; }
75+
{ services.cardano-tracer = tracerConfig; }
76+
systemdCompat
77+
]
78+
++ [ backend.service-modules.tracer or {} ]
79+
++ optionals useLegacyTracerService
80+
[ (import ../../nixos/cardano-tracer-service-legacy.nix pkgs) ]
81+
++ optionals (!useLegacyTracerService)
82+
[ (import ../../nixos/cardano-tracer-service.nix) ]
7083
;
71-
# args = { inherit pkgs; };
72-
}
73-
;
84+
85+
# args = { inherit pkgs; };
86+
};
7487
in
7588
eval.config.services.cardano-tracer;
7689

@@ -81,7 +94,9 @@ let
8194
(nodeSpecs:
8295
let
8396
nixosServiceConfig = tracerConfigServiceConfig;
84-
execConfig = nixosServiceConfig.configJSONfn nixosServiceConfig;
97+
execConfig = if useLegacyTracerService
98+
then nixosServiceConfig.configJSONfn nixosServiceConfig
99+
else nixosServiceConfig.tracerConfig;
85100
in {
86101
start = rec {
87102
value = ''
@@ -92,7 +107,7 @@ let
92107
JSON = pkgs.writeScript "startup-tracer.sh" value;
93108
};
94109

95-
config = rec {
110+
config = {
96111
value = execConfig;
97112
JSON = jsonFilePretty "config.json" (__toJSON execConfig);
98113
};

0 commit comments

Comments
 (0)