Deployment run record¶
The stage runner keeps one run record, run.json, in each run directory. The rerun rules read it to decide what a run repeats. narwhal deploy run --target local keeps its run record in launch in each run-* directory of the local run directory, with the rules in Resuming an interrupted run.
A run directory holds:
| Path | Contents |
|---|---|
run.json |
The run record, narwhal.deployment-run version 7, at mode 0600 |
run.lock |
The lock one runner holds while it uses the directory |
run.salt |
32 random bytes at mode 0600 that key the record's digests of inputs and files. The first run makes it, and a runner refuses one of another size, owner or mode |
stages/<stage>/attempt-<n>/ |
The files attempt n of a stage that runs once per run wrote |
stages/<stage>/<instance>/attempt-<n>/ |
The files attempt n of one stage instance wrote |
Inputs and the files an attempt writes can hold credentials, such as the engine key in a role environment. The record keeps each of their digests as hmac-sha256:<hex>, an HMAC-SHA256 of the value's SHA-256 under run.salt. Never copy run.salt out of the run directory. A diagnostic bundle leaves it out.
A runner reads only a version 7 record. It refuses an earlier one with <path> is a version <n> run record, which this build no longer reads: its stages predate the images stage of version 7; start a new run directory, which runs every stage again. Keep the old run directory with the release that wrote it, and run narwhal deploy down with that release to stop what it started.
The run directory must belong to the user who runs it. The runner creates it at mode 0700 and refuses an existing directory with wider permissions. status and down refuse the same directories and a run.json that is not a regular file the user owns.
Locking¶
A runner holds an exclusive flock on run.lock for the whole run and names itself in the record's lock field. A second runner on the same directory is refused. The refusal names the owner from lock when that owner is a live process on this host. Otherwise the holder has not recorded itself yet, and the refusal says so.
When a runner ends without clearing lock, such as after SIGKILL, the next runner adds the stale lock and its owner to stale_locks. deploy run and dev up print it, as in narwhal: deploy run: this run found a stale lock of pid 4242 of operator on workstation (narwhal deploy run --run runs/first-deploy), .... With --format json, the owner is in the result's data.stale_lock. The runner stops any helper processes that the interrupted stage left, records that stage as interrupted and continues. If helpers survive, it refuses to run until they stop. It also refuses to run when a recorded owner runs on this host without holding run.lock.
An interrupted stage runs a new attempt, unless its action can take over the work the attempt recorded, such as the Jobs in jobs. In that case the runner resumes the same attempt in its own directory. This needs two conditions: the stage's definition and the input_digests the attempt started from match, and no output of an earlier stage changed. A changed output marks the interrupted stage invalidated, as it does a passed stage.
Signals¶
SIGINT and SIGTERM end the current stage. The runner records the attempt as cancelled, with its failure context and the processes the attempt started, and stops the run. The next run starts again at that stage.
Record fields¶
| Field | Content |
|---|---|
schema, schema_version |
narwhal.deployment-run and 7 |
run_id |
32 hexadecimal characters, fixed for the life of the run directory |
target |
dev, ssh or kubernetes. A runner for another target refuses the directory |
narwhal_version |
Narwhal version of the last runner |
revision |
Approved revision the last runner deployed |
graph_sha256 |
Digest of the stage graph and rerun rules the last runner read |
created_at, updated_at |
Unix seconds |
lock |
null, or owner and acquired_at. owner holds pid, boot_id, start_ticks, hostname, user and argv |
stale_locks |
Every stale lock a runner found in this directory: its owner, acquired_at, and found_at |
inputs |
Each run input's digest, keyed under run.salt, and source. Credentials enter only as keyed digests |
until |
The last stage the last run was asked to reach, or null for the whole graph |
stages |
One record per stage instance, keyed by stage name, such as discover or engine-check[engine-2] |
Each stage record:
| Field | Content |
|---|---|
stage, scope, instance |
Stage name, scope letter from the stage graph, and instance. A stage that runs once per run has the empty instance |
status |
One of running, passed, failed, cancelled, timeout, interrupted or invalidated. interrupted marks an attempt whose runner ended without recording its end. invalidated marks a passed stage that must rerun. Either an output before it changed, or, for a stage whose product reruns its other instances, another instance's product changed |
attempt |
Attempt number in this run directory, from 1 |
directory |
The attempt's directory, relative to the run directory |
definition |
Digest of the stage's place in the graph and the rules that rerun it. A changed definition reruns the stage |
input_digests |
Digest of each fact whose change reruns this stage, keyed like slo or engine_identity[engine-2]. The digest of an input is keyed under run.salt. The digest of a product is its sha256: digest, because the record holds the product itself. A passed attempt records the digests when it passes. Any other attempt keeps the digests it started from, without the facts that the stage produces |
outputs |
Each regular file a passed attempt wrote: path relative to the run directory, hmac_sha256, the keyed digest of its contents, size and mode |
live_outputs |
Paths, relative to the run directory, of the files and directories in the attempt directory that the stage's processes keep writing. They have no digest, and their changes never rerun the stage |
products |
Each value the stage produces for later stages. A running, failed, cancelled, timed-out or interrupted attempt keeps the values of the last passed one |
processes |
Identities of the long-lived processes the stage started. A running attempt keeps those of the attempt before it until it returns its own |
command |
null for a stage that runs in the runner. For a command stage, argv, cwd, exit_code and log, with paths relative to the run directory |
started_at, ended_at |
Unix seconds. A running stage has no ended_at |
invalidation |
Why an invalidated stage must rerun, or null |
jobs |
Names of the Kubernetes Jobs the attempt creates, each written to the record before its Job is created. A resumed attempt keeps them. Empty when the attempt creates no Job |
job_uids |
The metadata.uid of each Job in jobs that the attempt created, by name. The runner writes it as soon as the API returns it. A resumed attempt adopts only the Job with the recorded uid. It fails on another Job under the same name. The runner removes a Job with no recorded uid and creates it again |
stale_jobs |
Jobs of earlier attempts of this stage that are not yet removed. A new attempt takes over the jobs and stale_jobs of the earlier attempt. It drops a name only after it removes the Job. A crash at any point leaves every Job named |
reasons |
Why the attempt ran, such as slo changed. A resumed attempt keeps the reasons it first ran for |
observed_at |
Unix seconds at which each live product, such as a process identity or a route, was last found to hold. The runner skips the recheck only when the target gives that fact a maximum age and this observation is younger |
failure |
null for a running, passed or invalidated stage. Otherwise message, recovery, the gate section that covers the stage, and context |
reused |
null for a stage that ran. A passed or invalidated stage whose files were copied from an earlier run has these fields. run_id and run are the ID and directory of the earlier run. attempt is the attempt the files came from. The fields measured_at and digests follow. measured_at is when that run measured the files. It is carried over when that run reused them. digests holds each digest compared, keyed like input_digests. Each host fingerprint appears as host_fingerprint[<role>], keyed under run.salt. The stage's command is null. Its outputs are the copies, with digests keyed under this run's salt |
The runner skips a stage when all of these hold:
- Its record shows
passed, whether the stage ran or was reused. - Its
definitionandinput_digestsmatch the current graph and inputs. - Every file in
outputshas its recorded digest, size and mode. - Every process or route the stage produced is still there, or was observed within its maximum age.
When an output changes, the runner marks every later passed stage invalidated before it reruns anything. Those stages rerun even if the run stops first.
A stage instance that the fleet no longer runs keeps its record until the run stops what it started. On SSH hosts these are the stages of a router host that left the pair, and the witness-start and load-balancer of a pair that the fleet file dropped. The run then removes their records from stages.
Deployment status¶
After each narwhal deploy run, whether it passed, failed or was interrupted, the command builds a summary of the run, narwhal.deployment-status version 1, and copies it to runs/deployment/deployment-status.json in the run's deployment directory on each router host. The routers export it as deployment metrics.
The command skips the copy until the roles stage passes on every host. A failed copy prints a warning and does not fail the run. A second interrupt skips the copy.
On Kubernetes, the fleet controller builds the same document at the start and end of each pass. It writes the document to the ConfigMap deployment-status, which the router pods mount at /narwhal-deployment. Its target is kubernetes. A failed write is logged and does not fail the pass.
| Field | Content |
|---|---|
schema, schema_version |
narwhal.deployment-status and 1 |
fleet, target, run_id |
The fleet name is spec.ssh.monitoring.fleetName, or on Kubernetes the chart's monitoring.fleet, which defaults to the release name. The target is the deployment target, such as ssh. run_id is the ID of the run |
updated_at |
When a stage of the run last ended, Unix seconds |
last_passed_at |
When the last run that passed every stage up to monitoring, or up to trial for a run with --trial, ended. A failed run keeps the previous value |
qualified_at, profiled_at, calibrated_at |
When preflight, profile and calibrate last passed, or null. For a reused profile or calibrate, the record's reused.measured_at |
stages |
Each stage instance with stage, instance and state, the stage record's status. A reused stage also has reused_from, the ID of the earlier run |
fabric |
Each fabric-edge instance with edge, measured_gbps, the lowest bandwidth measured, and budget_gbps, the highest that one of its KV handoffs needs |
engines |
Each engine with iid, generation, the binding digest of its attestation, and attested_at |
engine_nodes |
On Kubernetes only, each engine with iid, the node it runs on, and ready. The controller writes ready at the start and end of each pass. It shows whether that node was Ready at that time |