@nosana/node 1.1.73-dev.mr80.17352210002 → 1.1.73-dev.mr80.17376331679
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.env +1 -1
- package/dist/package.json +2 -2
- package/dist/packages/job-runtime/src/provider/ContainerProvider.d.ts +8 -0
- package/dist/packages/job-runtime/src/provider/ContainerProvider.js +175 -121
- package/dist/packages/job-runtime/src/provider/ContainerStateManager.d.ts +7 -0
- package/dist/packages/job-runtime/src/provider/ContainerStateManager.js +14 -0
- package/dist/packages/job-runtime/src/provider/ports.d.ts +3 -1
- package/dist/packages/job-runtime/src/runtime/runJob.js +1 -1
- package/dist/packages/job-runtime/src/taskManager/TaskManager.d.ts +10 -1
- package/dist/packages/job-runtime/src/taskManager/TaskManager.js +34 -7
- package/dist/packages/job-runtime/src/taskManager/operations/enforceOperationTimeout.d.ts +4 -0
- package/dist/packages/job-runtime/src/taskManager/operations/enforceOperationTimeout.js +9 -2
- package/dist/packages/job-runtime/src/taskManager/operations/runTaskManagerOperation.js +9 -3
- package/dist/src/NodeManager/index.js +6 -0
- package/dist/src/NodeManager/node/Node.js +9 -2
- package/dist/src/NodeManager/node/job/JobRuntimeSession.d.ts +26 -3
- package/dist/src/NodeManager/node/job/JobRuntimeSession.js +54 -8
- package/dist/src/NodeManager/node/job/jobHandler.d.ts +4 -2
- package/dist/src/NodeManager/node/job/jobHandler.js +5 -3
- package/dist/src/NodeManager/provider/Provider.d.ts +9 -0
- package/dist/src/NodeManager/provider/Provider.js +26 -0
- package/dist/src/exitCodes.d.ts +35 -2
- package/dist/src/exitCodes.js +52 -2
- package/dist/src/version/index.d.ts +16 -0
- package/dist/src/version/index.js +56 -45
- package/dist/src/version/updateWatcher.d.ts +35 -0
- package/dist/src/version/updateWatcher.js +81 -0
- package/npm-shrinkwrap.json +109 -93
- package/package.json +2 -2
package/dist/.env
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
BACKEND_SOLANA_ADDRESS=7rFPFnxjXHC2sfDy3qrDa9pEb4j49oivMuV7e8sYDPmB
|
|
2
2
|
FRP_SERVER_IMAGE=registry.hub.docker.com/nosana/frpc:v1.0.45
|
|
3
|
-
JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.1
|
|
3
|
+
JOB_RUNTIME_IMAGE="nosana/job-runtime:v0.2.1"
|
|
4
4
|
RESOURCE_MANAGER_IMAGE=registry.hub.docker.com/nosana/resource-manager:v1.1.19
|
|
5
5
|
FRP_SERVER_PORT=7000
|
|
6
6
|
MIN_DISK_SPACE=25
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosana/node",
|
|
3
|
-
"version": "1.1.73-dev.mr80.
|
|
3
|
+
"version": "1.1.73-dev.mr80.17376331679",
|
|
4
4
|
"description": "",
|
|
5
5
|
"bin": {
|
|
6
6
|
"nosana-node": "./dist/src/index.js"
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"lowdb": "^7.0.1",
|
|
97
97
|
"openapi-fetch": "^0.10.2",
|
|
98
98
|
"openapi-typescript": "^7.1.2",
|
|
99
|
-
"ora": "^
|
|
99
|
+
"ora": "^9.4.1",
|
|
100
100
|
"shell-quote": "^1.8.1",
|
|
101
101
|
"socket.io-client": "^4.7.5",
|
|
102
102
|
"stream": "^0.0.2",
|
|
@@ -22,6 +22,14 @@ export declare class ContainerProvider implements OrchestrationProvider {
|
|
|
22
22
|
/** The runtime socket as a host path, which is what a bind source must be. */
|
|
23
23
|
resolveHostSocketPath(): Promise<string>;
|
|
24
24
|
taskManagerContainerRunOperation(flow: Flow, op: Operation<'container/run'>, controller: AbortController, emitter: EventEmitter): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* An operation's containers as the sidecar before this one left them, when
|
|
27
|
+
* they can be followed on: the operation's own, started (running, or exited
|
|
28
|
+
* meanwhile, which is then its exit), with the frpc beside it, and the
|
|
29
|
+
* bridge of a SEV-SNP operation. Nothing when any is missing or the
|
|
30
|
+
* operation's was created but never started: it is then run again.
|
|
31
|
+
*/
|
|
32
|
+
private findOperationContainers;
|
|
25
33
|
generateFrpcContainerConfig(name: string, networks: {
|
|
26
34
|
[p: string]: {};
|
|
27
35
|
},
|
|
@@ -36,49 +36,22 @@ export class ContainerProvider {
|
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// A resumed flow re-runs operations that may already have a container, and
|
|
42
|
-
// the name below is the only handle on it.
|
|
39
|
+
// The operation's containers are named after the flow and the
|
|
40
|
+
// operation's index, which is the only handle a later sidecar has on them.
|
|
43
41
|
const index = getOpStateIndex(flow.jobDefinition.ops, op.id);
|
|
44
42
|
const name = flow.id + '-' + index;
|
|
45
|
-
// An operation runs the same way whether or not the flow it belongs to has
|
|
46
|
-
// already run, so whatever a previous run left behind under these names is
|
|
47
|
-
// removed rather than resumed from. The runtime refuses to create a
|
|
48
|
-
// container whose name is still taken, and all three are recreated below.
|
|
49
|
-
for (const leftover of [name, `frpc-${name}`, `bridge-${name}`]) {
|
|
50
|
-
if (await this.containerOrchestration.doesContainerExist(leftover)) {
|
|
51
|
-
await this.containerOrchestration.stopAndDeleteContainer(leftover);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
await this.resources.pullImage(op.args.image, {
|
|
55
|
-
auth: op.args.authentication?.docker,
|
|
56
|
-
controller,
|
|
57
|
-
project: flow.project,
|
|
58
|
-
});
|
|
59
|
-
const volumes = getVolumes(op.args, flow);
|
|
60
43
|
const gpu = getGpu(op.args, flow);
|
|
61
|
-
const entrypoint = getEntrypoint(op.args, flow);
|
|
62
|
-
const work_dir = getWorkingDir(op.args, flow);
|
|
63
|
-
const cmd = parseOpArgsCmd(op.args.cmd);
|
|
64
|
-
const env = {
|
|
65
|
-
...getGlobalEnv(flow),
|
|
66
|
-
...op.args.env,
|
|
67
|
-
NOSANA_ID: flow.id,
|
|
68
|
-
};
|
|
69
|
-
const aliases = getAliases(op.args);
|
|
70
|
-
const networks = {};
|
|
71
|
-
let idMaps = new Map();
|
|
72
44
|
const ports = getExposePorts(op);
|
|
73
45
|
// A liveness probe restarts the container under the running op, so the
|
|
74
46
|
// state manager has to know a stop may not be the op finishing.
|
|
75
47
|
const restartsOnUnhealthy = ports.some((port) => port.health_checks?.some((check) => check.restart_on_failure));
|
|
76
|
-
networks[name] = {};
|
|
77
|
-
await this.containerOrchestration.createNetwork(name, controller);
|
|
78
48
|
const exposed = isOpExposed(op);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
49
|
+
// The op only declares that it wants a TEE; the node's configured
|
|
50
|
+
// runtime decides how that is fulfilled.
|
|
51
|
+
const teeRuntime = op.args.trusted_execution_env
|
|
52
|
+
? this.containerOrchestration.teeRuntime
|
|
53
|
+
: undefined;
|
|
54
|
+
let idMaps = new Map();
|
|
82
55
|
const proxies = [];
|
|
83
56
|
let isLoadBalanced = false;
|
|
84
57
|
let deploymentHash;
|
|
@@ -95,107 +68,158 @@ export class ContainerProvider {
|
|
|
95
68
|
idMaps = generated.idMap;
|
|
96
69
|
proxies.push(...generated.proxies);
|
|
97
70
|
}
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
flowId: flow.id,
|
|
119
|
-
opId: op.id,
|
|
120
|
-
});
|
|
71
|
+
// A sidecar that restarted mid-job (a crash, the swap to a newer image)
|
|
72
|
+
// finds the operation's containers where the one before it left them,
|
|
73
|
+
// and follows them on instead of starting the operation again: the
|
|
74
|
+
// workload never notices. Its records carry the rest of the operation.
|
|
75
|
+
let containers = await this.findOperationContainers(name, teeRuntime === 'SEV-SNP');
|
|
76
|
+
const resumed = containers !== undefined;
|
|
77
|
+
emitter.emit('start', { resumed });
|
|
78
|
+
if (containers) {
|
|
79
|
+
emitter.emit('log', `Operation resumed on container ${name}, ${containers.status}`, 'info');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Whatever an earlier sidecar left behind under these names and could
|
|
83
|
+
// not be followed on (a container created but never started, one of
|
|
84
|
+
// the three missing) is removed rather than resumed from. The runtime
|
|
85
|
+
// refuses to create a container whose name is still taken, and all
|
|
86
|
+
// three are recreated below.
|
|
87
|
+
for (const leftover of [name, `frpc-${name}`, `bridge-${name}`]) {
|
|
88
|
+
if (await this.containerOrchestration.doesContainerExist(leftover)) {
|
|
89
|
+
await this.containerOrchestration.stopAndDeleteContainer(leftover);
|
|
90
|
+
}
|
|
121
91
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
92
|
+
await this.resources.pullImage(op.args.image, {
|
|
93
|
+
auth: op.args.authentication?.docker,
|
|
94
|
+
controller,
|
|
95
|
+
project: flow.project,
|
|
96
|
+
});
|
|
97
|
+
const volumes = getVolumes(op.args, flow);
|
|
98
|
+
const entrypoint = getEntrypoint(op.args, flow);
|
|
99
|
+
const work_dir = getWorkingDir(op.args, flow);
|
|
100
|
+
const cmd = parseOpArgsCmd(op.args.cmd);
|
|
101
|
+
const env = {
|
|
102
|
+
...getGlobalEnv(flow),
|
|
103
|
+
...op.args.env,
|
|
104
|
+
NOSANA_ID: flow.id,
|
|
105
|
+
};
|
|
106
|
+
const aliases = getAliases(op.args);
|
|
107
|
+
const networks = {};
|
|
108
|
+
networks[name] = {};
|
|
109
|
+
await this.containerOrchestration.createNetwork(name, controller);
|
|
110
|
+
await this.resources.pullImage(this.config.frp.containerImage, {
|
|
111
|
+
controller,
|
|
112
|
+
});
|
|
113
|
+
let sidecarConfig = this.generateFrpcContainerConfig(name, networks, flow, proxies, isLoadBalanced, deploymentHash);
|
|
114
|
+
// Keys are job wide and may have been authorized before this
|
|
115
|
+
// operation started; the seed runs between create and start.
|
|
116
|
+
sidecarConfig = withSshSidecar(sidecarConfig, {
|
|
117
|
+
jobId: flow.id,
|
|
118
|
+
opIndex: index,
|
|
119
|
+
runtime: {
|
|
120
|
+
name: this.containerOrchestration.name,
|
|
121
|
+
socketPath: await this.resolveHostSocketPath(),
|
|
122
|
+
},
|
|
123
|
+
prepare: (sidecar) => this.seedSshSidecar(flow.id, sidecar),
|
|
124
|
+
});
|
|
125
|
+
const frpcContainer = await this.containerOrchestration.runFlowContainer(this.config.frp.containerImage, sidecarConfig);
|
|
126
|
+
if (exposed) {
|
|
127
|
+
if (op.args.private) {
|
|
128
|
+
this.flows.updateflowStateSecret(flow.id, {
|
|
129
|
+
[flow.id]: generateUrlSecretObject(this.config.frp.serverAddr, idMaps, op.id),
|
|
130
|
+
urlmode: 'private',
|
|
131
|
+
});
|
|
132
|
+
emitter.emit('flow:secrets-updated', {
|
|
133
|
+
flowId: flow.id,
|
|
134
|
+
opId: op.id,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const newSecret = generateUrlSecretObject(this.config.frp.serverAddr, idMaps, op.id);
|
|
139
|
+
const currentSecrets = this.flows.getFlowSecret(flow.id, flow.id) || {};
|
|
140
|
+
const mergedSecrets = {
|
|
141
|
+
...currentSecrets,
|
|
142
|
+
...newSecret,
|
|
143
|
+
};
|
|
144
|
+
this.flows.updateflowStateSecret(flow.id, {
|
|
145
|
+
[flow.id]: mergedSecrets,
|
|
146
|
+
urlmode: 'public',
|
|
147
|
+
});
|
|
148
|
+
emitter.emit('flow:secrets-updated', {
|
|
149
|
+
flowId: flow.id,
|
|
150
|
+
opId: op.id,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (op.args.resources) {
|
|
155
|
+
// transformCollections has already resolved any SpreadMarker objects by this point
|
|
156
|
+
const resourceVolumes = await this.resources.getResourceVolumes(op.args.resources ?? [], controller, { id: flow.id, opIndex: index }, flow.project);
|
|
157
|
+
volumes.push(...resourceVolumes);
|
|
158
|
+
}
|
|
159
|
+
const createContainerOptions = {
|
|
160
|
+
name,
|
|
161
|
+
cmd,
|
|
162
|
+
env,
|
|
163
|
+
networks,
|
|
164
|
+
requires_network_mode: isOpExposed(op),
|
|
165
|
+
gpu,
|
|
166
|
+
entrypoint,
|
|
167
|
+
work_dir,
|
|
168
|
+
volumes,
|
|
169
|
+
aliases,
|
|
170
|
+
restart_policy: op.args.restart_policy,
|
|
171
|
+
runtime: teeRuntime,
|
|
172
|
+
labels: {
|
|
173
|
+
[JOB_LABEL]: flow.id,
|
|
174
|
+
[OP_LABEL]: op.id,
|
|
175
|
+
[GROUP_LABEL]: op.execution?.group ?? op.id,
|
|
176
|
+
[OP_INDEX_LABEL]: index.toString(),
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
let bridgeContainer;
|
|
180
|
+
if (teeRuntime === 'SEV-SNP') {
|
|
181
|
+
await this.resources.pullImage("busybox");
|
|
182
|
+
bridgeContainer = await this.containerOrchestration.runFlowContainer("busybox", {
|
|
183
|
+
name: `bridge-${name}`,
|
|
184
|
+
cmd: ['sleep', 'infinity'],
|
|
185
|
+
labels: { [JOB_LABEL]: flow.id },
|
|
186
|
+
aliases: createContainerOptions.aliases
|
|
136
187
|
});
|
|
188
|
+
delete createContainerOptions.aliases;
|
|
189
|
+
createContainerOptions.bind_network_to_container = `container:bridge-${name}`;
|
|
137
190
|
}
|
|
191
|
+
const container = await this.containerOrchestration.runFlowContainer(op.args.image ?? flow.jobDefinition.global?.image, createContainerOptions);
|
|
192
|
+
containers = { container, frpcContainer, bridgeContainer, status: 'running' };
|
|
138
193
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
: undefined;
|
|
149
|
-
const createContainerOptions = {
|
|
150
|
-
name,
|
|
151
|
-
cmd,
|
|
152
|
-
env,
|
|
153
|
-
networks,
|
|
154
|
-
requires_network_mode: isOpExposed(op),
|
|
155
|
-
gpu,
|
|
156
|
-
entrypoint,
|
|
157
|
-
work_dir,
|
|
158
|
-
volumes,
|
|
159
|
-
aliases,
|
|
160
|
-
restart_policy: op.args.restart_policy,
|
|
161
|
-
runtime: teeRuntime,
|
|
162
|
-
labels: {
|
|
163
|
-
[JOB_LABEL]: flow.id,
|
|
164
|
-
[OP_LABEL]: op.id,
|
|
165
|
-
[GROUP_LABEL]: op.execution?.group ?? op.id,
|
|
166
|
-
[OP_INDEX_LABEL]: index.toString(),
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
if (teeRuntime === 'SEV-SNP') {
|
|
170
|
-
await this.resources.pullImage("busybox");
|
|
171
|
-
const bridgeContainer = await this.containerOrchestration.runFlowContainer("busybox", {
|
|
172
|
-
name: `bridge-${name}`,
|
|
173
|
-
cmd: ['sleep', 'infinity'],
|
|
174
|
-
labels: { [JOB_LABEL]: flow.id },
|
|
175
|
-
aliases: createContainerOptions.aliases
|
|
176
|
-
});
|
|
177
|
-
delete createContainerOptions.aliases;
|
|
178
|
-
createContainerOptions.bind_network_to_container = `container:bridge-${name}`;
|
|
194
|
+
const { container, frpcContainer, bridgeContainer } = containers;
|
|
195
|
+
// The container is running (image pull is already done). This is the
|
|
196
|
+
// point the op-execution timeout clock starts from, so pull time isn't
|
|
197
|
+
// counted against it; a container found running has used some of its
|
|
198
|
+
// time already.
|
|
199
|
+
emitter.emit('container:started', containers.startedAt ? { startedAt: containers.startedAt } : undefined);
|
|
200
|
+
const startedInfo = await container.inspect();
|
|
201
|
+
emitter.emit('updateOpState', { providerId: container.id });
|
|
202
|
+
if (bridgeContainer) {
|
|
179
203
|
const bridgeInfo = await bridgeContainer.inspect();
|
|
180
204
|
if (bridgeInfo.NetworkSettings?.Networks["NOSANA_GATEWAY"].IPAddress) {
|
|
181
205
|
emitter.emit('setContainerInternalIp', bridgeInfo.NetworkSettings.Networks["NOSANA_GATEWAY"].IPAddress);
|
|
182
206
|
}
|
|
183
207
|
}
|
|
184
|
-
|
|
185
|
-
// The container is now running (image pull is already done). This is the
|
|
186
|
-
// point the op-execution timeout clock starts from, so pull time isn't
|
|
187
|
-
// counted against it.
|
|
188
|
-
emitter.emit('container:started');
|
|
189
|
-
const startedInfo = await container.inspect();
|
|
190
|
-
emitter.emit('updateOpState', { providerId: container.id });
|
|
191
|
-
if (teeRuntime !== 'SEV-SNP' && startedInfo.NetworkSettings?.Networks["NOSANA_GATEWAY"].IPAddress) {
|
|
208
|
+
else if (startedInfo.NetworkSettings?.Networks["NOSANA_GATEWAY"].IPAddress) {
|
|
192
209
|
emitter.emit('setContainerInternalIp', startedInfo.NetworkSettings.Networks["NOSANA_GATEWAY"].IPAddress);
|
|
193
210
|
}
|
|
194
211
|
stateManager = new ContainerStateManager(container, controller, emitter, op.args.restart_policy, restartsOnUnhealthy, gpu && this.config.gpu
|
|
195
212
|
? containerGpuStat(container, this.config.gpu)
|
|
196
213
|
: undefined);
|
|
214
|
+
// The logs up to the earlier sidecar's last line are in the records;
|
|
215
|
+
// the stream picks up after it.
|
|
216
|
+
if (resumed) {
|
|
217
|
+
const lastLog = this.flows.getOpState(flow.id, index)?.logs?.at(-1);
|
|
218
|
+
if (lastLog?.timestamp)
|
|
219
|
+
stateManager.resumeLogsAfter(lastLog.timestamp);
|
|
220
|
+
}
|
|
197
221
|
await stateManager.startMonitoring();
|
|
198
|
-
if (
|
|
222
|
+
if (exposed) {
|
|
199
223
|
exposedPortHealthCheck = new ExposedPortHealthCheck(flow.id, frpcContainer, emitter, name, restartsOnUnhealthy
|
|
200
224
|
? () => stateManager.restartContainer()
|
|
201
225
|
: undefined);
|
|
@@ -225,6 +249,36 @@ export class ContainerProvider {
|
|
|
225
249
|
exposedPortHealthCheck = undefined;
|
|
226
250
|
emitter.emit('end');
|
|
227
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* An operation's containers as the sidecar before this one left them, when
|
|
254
|
+
* they can be followed on: the operation's own, started (running, or exited
|
|
255
|
+
* meanwhile, which is then its exit), with the frpc beside it, and the
|
|
256
|
+
* bridge of a SEV-SNP operation. Nothing when any is missing or the
|
|
257
|
+
* operation's was created but never started: it is then run again.
|
|
258
|
+
*/
|
|
259
|
+
async findOperationContainers(name, bridged) {
|
|
260
|
+
const [container, frpcContainer, bridgeContainer] = await Promise.all([
|
|
261
|
+
this.containerOrchestration.getContainerByName(name),
|
|
262
|
+
this.containerOrchestration.getContainerByName(`frpc-${name}`),
|
|
263
|
+
bridged
|
|
264
|
+
? this.containerOrchestration.getContainerByName(`bridge-${name}`)
|
|
265
|
+
: undefined,
|
|
266
|
+
]);
|
|
267
|
+
if (!container || !frpcContainer || (bridged && !bridgeContainer)) {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
const { State } = await container.inspect();
|
|
271
|
+
if (!State.Running && State.Status !== 'exited')
|
|
272
|
+
return undefined;
|
|
273
|
+
const startedAt = Date.parse(State.StartedAt);
|
|
274
|
+
return {
|
|
275
|
+
container,
|
|
276
|
+
frpcContainer,
|
|
277
|
+
bridgeContainer,
|
|
278
|
+
status: State.Status,
|
|
279
|
+
startedAt: Number.isFinite(startedAt) ? startedAt : undefined,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
228
282
|
generateFrpcContainerConfig(name, networks,
|
|
229
283
|
/** The job the proxies publish for: only its id and deployment are read. */
|
|
230
284
|
flow, proxies, isLoadBalanced, deploymentHash) {
|
|
@@ -35,6 +35,13 @@ export declare class ContainerStateManager {
|
|
|
35
35
|
/** The container's GPU share, added to each of its stats. */
|
|
36
36
|
gpuStat?: (() => Promise<GpuStat | undefined>) | undefined);
|
|
37
37
|
getState(): ContainerState;
|
|
38
|
+
/**
|
|
39
|
+
* Follows the logs from after `timestamp` (ms since the epoch, or a date
|
|
40
|
+
* string): the last line an earlier sidecar recorded of a container this
|
|
41
|
+
* one took over, so the lines before it are not recorded twice. Call it
|
|
42
|
+
* before `startMonitoring`.
|
|
43
|
+
*/
|
|
44
|
+
resumeLogsAfter(timestamp: string | number): void;
|
|
38
45
|
startMonitoring(): Promise<void>;
|
|
39
46
|
private attachLogStream;
|
|
40
47
|
/**
|
|
@@ -43,6 +43,20 @@ export class ContainerStateManager {
|
|
|
43
43
|
getState() {
|
|
44
44
|
return this.state;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Follows the logs from after `timestamp` (ms since the epoch, or a date
|
|
48
|
+
* string): the last line an earlier sidecar recorded of a container this
|
|
49
|
+
* one took over, so the lines before it are not recorded twice. Call it
|
|
50
|
+
* before `startMonitoring`.
|
|
51
|
+
*/
|
|
52
|
+
resumeLogsAfter(timestamp) {
|
|
53
|
+
const ms = typeof timestamp === 'number'
|
|
54
|
+
? timestamp
|
|
55
|
+
: Number(timestamp) || Date.parse(timestamp);
|
|
56
|
+
if (Number.isFinite(ms) && ms > 0) {
|
|
57
|
+
this.lastLogTimestamp = Math.floor(ms / 1000);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
46
60
|
async startMonitoring() {
|
|
47
61
|
await Promise.all([this.attachLogStream(), this.attachStatsStream()]);
|
|
48
62
|
if (!this.restartPolicy && !this.restartsOnUnhealthy) {
|
|
@@ -4,9 +4,11 @@ import type { GpuSampler } from './gpu/gpuSampler.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* The flow records the container provider writes on top of the task
|
|
6
6
|
* manager's: exposed URLs (kept in the flow's secrets) and how an operation's
|
|
7
|
-
* container ended.
|
|
7
|
+
* container ended. It reads an operation's state for the logs an earlier
|
|
8
|
+
* sidecar recorded, when it follows on a container that one started.
|
|
8
9
|
*/
|
|
9
10
|
export interface ProviderFlowStore {
|
|
11
|
+
getOpState(id: string, opIndex: number): OpState | undefined;
|
|
10
12
|
getFlowSecret(id: string, key: string): any | undefined;
|
|
11
13
|
updateflowStateSecret(id: string, updatedFields: {
|
|
12
14
|
[key: string]: any;
|
|
@@ -206,7 +206,7 @@ export async function runJob(config) {
|
|
|
206
206
|
// Over before this sidecar restarted: only its result is left.
|
|
207
207
|
if (existing.state.endTime)
|
|
208
208
|
return;
|
|
209
|
-
// A sidecar restarted mid-job
|
|
209
|
+
// A sidecar restarted mid-job takes the job up from its records.
|
|
210
210
|
definition = existing.jobDefinition;
|
|
211
211
|
}
|
|
212
212
|
else {
|
|
@@ -272,9 +272,18 @@ export default class TaskManager {
|
|
|
272
272
|
stop(reason: StopReason): Promise<void>;
|
|
273
273
|
protected setUpOperationFunc(flow: Flow, id: string, dependent: string[]): Promise<void>;
|
|
274
274
|
protected trackGroupOperationPromise(opId: string, promise: Promise<void>): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* On a resumed flow, the operations that ended before the sidecar went are
|
|
277
|
+
* not run again: they keep the status they ended in, and their results go
|
|
278
|
+
* back in the store for the operations that read them.
|
|
279
|
+
*/
|
|
280
|
+
private restoreFinishedOperations;
|
|
275
281
|
protected getStatus(reason: StopReason, type: 'ops' | 'flow'): Status;
|
|
276
282
|
protected getOpStateIndex(opId: string): number;
|
|
277
283
|
private build;
|
|
278
|
-
/**
|
|
284
|
+
/**
|
|
285
|
+
* Records the flow, unless one being resumed is already there. Either way
|
|
286
|
+
* the store starts from the definition's variables and endpoints.
|
|
287
|
+
*/
|
|
279
288
|
private init;
|
|
280
289
|
}
|
|
@@ -275,6 +275,11 @@ export default class TaskManager {
|
|
|
275
275
|
this.currentRunningStartPromise = (async () => {
|
|
276
276
|
// Fetch existing flow to determine whether execution should continue
|
|
277
277
|
const flow = this.repository.getFlow(this.job);
|
|
278
|
+
// A flow recorded running was interrupted by its sidecar going (a
|
|
279
|
+
// crash, the swap to a newer image): it is taken up where it was left,
|
|
280
|
+
// not run again. Its start stands, the operations that were over stay
|
|
281
|
+
// over, and the rest run (on the containers they left, see the provider).
|
|
282
|
+
const resumed = flow.state.status === 'running';
|
|
278
283
|
try {
|
|
279
284
|
// If job already ended (either success or failure), no need to start again
|
|
280
285
|
// if (flow.state.endTime) return;
|
|
@@ -282,7 +287,7 @@ export default class TaskManager {
|
|
|
282
287
|
this.status = 'running';
|
|
283
288
|
this.repository.updateflowState(this.job, {
|
|
284
289
|
status: this.status,
|
|
285
|
-
startTime: Date.now(),
|
|
290
|
+
startTime: resumed ? flow.state.startTime : Date.now(),
|
|
286
291
|
});
|
|
287
292
|
this.events.emit('flow:updated', {
|
|
288
293
|
jobId: this.job,
|
|
@@ -290,6 +295,8 @@ export default class TaskManager {
|
|
|
290
295
|
});
|
|
291
296
|
// update all operations status to pending since we have started
|
|
292
297
|
[...this.opMap.keys()].forEach((op) => this.operationStatus.set(op, OperationProgressStatuses.PENDING));
|
|
298
|
+
if (resumed)
|
|
299
|
+
this.restoreFinishedOperations(flow);
|
|
293
300
|
// Loop through execution plan, group by group
|
|
294
301
|
for (const p of this.executionPlan) {
|
|
295
302
|
this.currentGroup = p.group;
|
|
@@ -464,6 +471,24 @@ export default class TaskManager {
|
|
|
464
471
|
});
|
|
465
472
|
return promise;
|
|
466
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* On a resumed flow, the operations that ended before the sidecar went are
|
|
476
|
+
* not run again: they keep the status they ended in, and their results go
|
|
477
|
+
* back in the store for the operations that read them.
|
|
478
|
+
*/
|
|
479
|
+
restoreFinishedOperations(flow) {
|
|
480
|
+
for (const opState of flow.state.opStates) {
|
|
481
|
+
const id = opState.operationId;
|
|
482
|
+
if (!id || !opState.endTime || !this.opMap.has(id))
|
|
483
|
+
continue;
|
|
484
|
+
this.operationStatus.set(id, opState.status === Statuses.SUCCESS
|
|
485
|
+
? OperationProgressStatuses.FINISHED
|
|
486
|
+
: opState.status === Statuses.FAILED
|
|
487
|
+
? OperationProgressStatuses.FAILED
|
|
488
|
+
: OperationProgressStatuses.STOPPED);
|
|
489
|
+
this.setResults(id, opState.results ?? {});
|
|
490
|
+
}
|
|
491
|
+
}
|
|
467
492
|
getStatus(reason, type) {
|
|
468
493
|
const map = {
|
|
469
494
|
[StopReasons.COMPLETED]: {
|
|
@@ -506,13 +531,15 @@ export default class TaskManager {
|
|
|
506
531
|
this.executionPlan = this.createExecutionPlan();
|
|
507
532
|
this.dependecyMap = this.createDependencyMap();
|
|
508
533
|
}
|
|
509
|
-
/**
|
|
534
|
+
/**
|
|
535
|
+
* Records the flow, unless one being resumed is already there. Either way
|
|
536
|
+
* the store starts from the definition's variables and endpoints.
|
|
537
|
+
*/
|
|
510
538
|
init() {
|
|
511
539
|
const existing = this.repository.getFlow(this.job);
|
|
512
|
-
if (existing
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
this.
|
|
516
|
-
this.setDefaults(flow.id, this.project, this.definition);
|
|
540
|
+
if (!existing || existing.state.status === 'waiting-for-job-definition') {
|
|
541
|
+
this.repository.setflow(this.job, createInitialFlow(this.job, this.project, this.definition, this.operations, this.status, Date.now()));
|
|
542
|
+
}
|
|
543
|
+
this.setDefaults(this.job, this.project, this.definition);
|
|
517
544
|
}
|
|
518
545
|
}
|
|
@@ -11,6 +11,10 @@ import type { EventEmitter } from 'events';
|
|
|
11
11
|
* the operation settles (`exit`/`error`) or is torn down (`end`), so a normally
|
|
12
12
|
* completing op never triggers it.
|
|
13
13
|
*
|
|
14
|
+
* A container a restarted sidecar found running comes with its `startedAt`,
|
|
15
|
+
* and what it has run already counts: the clock started with the container,
|
|
16
|
+
* not with this sidecar.
|
|
17
|
+
*
|
|
14
18
|
* The unit is seconds, matching the on-chain `job.timeout` convention.
|
|
15
19
|
*
|
|
16
20
|
* A missing, zero, or negative timeout disables enforcement (no-op).
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
* the operation settles (`exit`/`error`) or is torn down (`end`), so a normally
|
|
11
11
|
* completing op never triggers it.
|
|
12
12
|
*
|
|
13
|
+
* A container a restarted sidecar found running comes with its `startedAt`,
|
|
14
|
+
* and what it has run already counts: the clock started with the container,
|
|
15
|
+
* not with this sidecar.
|
|
16
|
+
*
|
|
13
17
|
* The unit is seconds, matching the on-chain `job.timeout` convention.
|
|
14
18
|
*
|
|
15
19
|
* A missing, zero, or negative timeout disables enforcement (no-op).
|
|
@@ -24,13 +28,16 @@ export function enforceOperationTimeout(emitter, timeoutSeconds, onTimeout) {
|
|
|
24
28
|
handle = undefined;
|
|
25
29
|
}
|
|
26
30
|
};
|
|
27
|
-
emitter.on('container:started', () => {
|
|
31
|
+
emitter.on('container:started', (started) => {
|
|
28
32
|
// Defensive: clear first so an unexpected duplicate can't stack timers.
|
|
29
33
|
clear();
|
|
34
|
+
const elapsedMs = started?.startedAt
|
|
35
|
+
? Math.max(Date.now() - started.startedAt, 0)
|
|
36
|
+
: 0;
|
|
30
37
|
handle = setTimeout(() => {
|
|
31
38
|
handle = undefined;
|
|
32
39
|
onTimeout();
|
|
33
|
-
}, timeoutSeconds * 1000);
|
|
40
|
+
}, Math.max(timeoutSeconds * 1000 - elapsedMs, 0));
|
|
34
41
|
});
|
|
35
42
|
emitter.on('exit', clear);
|
|
36
43
|
emitter.on('error', clear);
|
|
@@ -173,20 +173,26 @@ export async function runTaskManagerOperation(flow, op, dependent) {
|
|
|
173
173
|
* execution logic begins (e.g., launching a container or invoking a function).
|
|
174
174
|
*
|
|
175
175
|
* This is crucial for analytics, timeout enforcement, and auditing purposes.
|
|
176
|
+
*
|
|
177
|
+
* An operation `resumed` by a sidecar that restarted runs on in the container
|
|
178
|
+
* the sidecar before it started, and keeps the start recorded then.
|
|
176
179
|
*/
|
|
177
|
-
emitter.on('start', () => {
|
|
180
|
+
emitter.on('start', (started) => {
|
|
178
181
|
const opName = op.name || op.id;
|
|
179
182
|
this.addlog({
|
|
180
183
|
opId: op.id,
|
|
181
184
|
group: this.currentGroup ?? '',
|
|
182
185
|
type: 'info',
|
|
183
|
-
message: `Operation Started: ${opName}`,
|
|
186
|
+
message: `Operation ${started?.resumed ? 'Resumed' : 'Started'}: ${opName}`,
|
|
184
187
|
timestamp: Date.now(),
|
|
185
188
|
});
|
|
186
189
|
this.operationStatus.set(op.id, OperationProgressStatuses.RUNNING);
|
|
190
|
+
const recordedStart = started?.resumed
|
|
191
|
+
? this.repository.getOpState(this.job, index)?.startTime
|
|
192
|
+
: undefined;
|
|
187
193
|
this.repository.updateOpState(this.job, index, {
|
|
188
194
|
status: 'running',
|
|
189
|
-
startTime: Date.now(),
|
|
195
|
+
startTime: recordedStart || Date.now(),
|
|
190
196
|
endTime: null,
|
|
191
197
|
exitCode: null,
|
|
192
198
|
});
|
|
@@ -6,6 +6,7 @@ import { log } from './monitoring/log/NodeLog.js';
|
|
|
6
6
|
import { logStreaming } from './monitoring/streaming/LogStreamer.js';
|
|
7
7
|
import { consoleLogging } from './monitoring/log/console/ConsoleLogger.js';
|
|
8
8
|
import { validateCLIVersion } from '../version/index.js';
|
|
9
|
+
import { updateWatcher } from '../version/updateWatcher.js';
|
|
9
10
|
import { checkForMaintenance } from './checkForMaintenance.js';
|
|
10
11
|
import { ping } from './monitoring/ping/PingHandler.js';
|
|
11
12
|
import { LogMonitoringRegistry } from './monitoring/LogMonitoringRegistry.js';
|
|
@@ -163,6 +164,11 @@ export default class NodeManager {
|
|
|
163
164
|
* these stages else we want to restart the node process on error
|
|
164
165
|
*/
|
|
165
166
|
this.inJobLoop = true;
|
|
167
|
+
/**
|
|
168
|
+
* From here on a release is installed as it comes and switched to at the
|
|
169
|
+
* next point leaving costs the job nothing (see UpdateWatcher).
|
|
170
|
+
*/
|
|
171
|
+
updateWatcher.start();
|
|
166
172
|
if (!(await this.node.isApiActive())) {
|
|
167
173
|
throw new Error("Node API is detected offline");
|
|
168
174
|
}
|