-
Notifications
You must be signed in to change notification settings - Fork 721
/
supervisor.nix
175 lines (162 loc) · 5.64 KB
/
supervisor.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
let
basePort = 30000;
cacheDirDefault = "${__getEnv "HOME"}/.cache/cardano-workbench";
stateDir = "run/current";
in
{ pkgs
, lib
, workbench
##
, cacheDir ? cacheDirDefault
, extraSupervisorConfig ? {}
, useCabalRun ? false
, enableEKG ? true
##
, ...
}:
with lib;
let
backend =
rec
{ name = "supervisor";
## Generic Nix bits:
topologyForNodeSpec =
{ profile, nodeSpec }:
let inherit (nodeSpec) name i; in
workbench.runWorkbench
"topology-${name}.json"
"topology projection-for local-${nodeSpec.kind} ${toString i} ${profile.name} ${profile.topology.files} ${toString basePort}";
nodePublicIP =
{ i, name, ... }@nodeSpec:
"127.0.0.1";
finaliseNodeService =
let time_fmtstr =
"{ " + escape [''"''] (concatStringsSep ''\n, '' time_entries) + " }";
time_entries = [
''"wall_clock_s": %e''
''"user_cpu_s": %U''
''"sys_cpu_s": %S''
''"avg_cpu_pct": "%P"''
''"rss_peak_kb": %M''
''"signals_received": %k''
''"ctxsw_involuntary": %c''
''"ctxsw_volunt_waits": %w''
''"pageflt_major": %F''
''"pageflt_minor": %R''
''"swaps": %W''
''"io_fs_reads": %I''
''"io_fs_writes": %O''
''"cmdline": "%C"''
''"exit_code": %x''
];
in
profile: { name, i, isProducer, ... }: svc: recursiveUpdate svc
({
stateDir = stateDir + "/${name}";
## Everything is local in the supervisord setup:
socketPath = "node.socket";
topology = "topology.json";
nodeConfigFile = "config.json";
} // optionalAttrs useCabalRun {
# Make the shell function take over.
executable = "cardano-node";
# executable = ''time -f "${time_fmtstr}" -o kernel-resource-summary.json cabal run exe:cardano-node ''${WB_FLAGS_RTS} -- +RTS -sghc-rts-report.txt -RTS'';
} // optionalAttrs isProducer {
operationalCertificate = "../genesis/node-keys/node${toString i}.opcert";
kesKey = "../genesis/node-keys/node-kes${toString i}.skey";
vrfKey = "../genesis/node-keys/node-vrf${toString i}.skey";
} // optionalAttrs profile.node.tracer {
tracerSocketPathConnect = "../tracer/tracer.socket";
});
finaliseNodeConfig =
{ port, ... }: cfg: recursiveUpdate cfg
(
{
AlonzoGenesisFile = "../genesis/genesis.alonzo.json";
ShelleyGenesisFile = "../genesis/genesis-shelley.json";
ByronGenesisFile = "../genesis/byron/genesis.json";
}
// optionalAttrs enableEKG
{
hasEKG = port + supervisord.portShiftEkg;
hasPrometheus = [
"127.0.0.1" (port + supervisord.portShiftPrometheus)
];
setupBackends = [
"EKGViewBK"
];
}
);
finaliseNodeArgs =
profile: nodeSpec: args: args;
finaliseGeneratorService =
svc: recursiveUpdate svc
({
sigKey = "../genesis/utxo-keys/utxo1.skey";
nodeConfigFile = "config.json";
runScriptFile = "run-script.json";
} // optionalAttrs useCabalRun {
executable = "cabal run exe:tx-generator --";
});
finaliseGeneratorConfig =
cfg: recursiveUpdate cfg
({
AlonzoGenesisFile = "../genesis/genesis.alonzo.json";
ShelleyGenesisFile = "../genesis/genesis-shelley.json";
ByronGenesisFile = "../genesis/byron/genesis.json";
} // optionalAttrs useCabalRun {
executable = "tx-generator";
});
finaliseTracerService =
svc: recursiveUpdate svc
({
configFile = "config.json";
logRoot = ".";
} // optionalAttrs useCabalRun {
executable = "cardano-tracer";
});
materialise-profile =
{ profileNix }:
pkgs.runCommand "workbench-profile-outputs-${profileNix.name}-supervisord" {}
''
mkdir $out
cp ${supervisord.mkSupervisorConf profileNix} $out/supervisor.conf
'';
## IMPORTANT: keep in sync with envArgs in 'workbench/default.nix/generateProfiles/environment'.
env-args-base =
{
inherit (pkgs) cardanoLib;
inherit stateDir cacheDir basePort;
staggerPorts = true;
};
## Backend-specific Nix bits:
supervisord =
{
inherit
extraSupervisorConfig;
portShiftEkg = 100;
portShiftPrometheus = 200;
## mkSupervisorConf :: Profile -> SupervisorConf
mkSupervisorConf =
profile:
pkgs.callPackage ./supervisor-conf.nix
{ inherit (profile) node-services generator-service;
inherit
pkgs lib stateDir
basePort
extraSupervisorConfig;
};
};
};
all-profiles =
workbench.all-profiles
{ inherit backend;
envArgs = backend.env-args-base;
};
in
{
inherit cacheDir stateDir basePort;
inherit workbench;
inherit backend;
inherit all-profiles;
}