Skip to content

Commit 9a01565

Browse files
committed
workbench: add a workbench subcommand to create a JSON with perf's Nomad Clients
1 parent b0ded1a commit 9a01565

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

nix/workbench/backend/nomad/cloud.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ backend_nomadcloud() {
394394
# ".attributes.unique.platform.aws.mac".
395395
if test -z "${NOMAD_CLIENTS_FILE:-}" || ! test -f "${NOMAD_CLIENTS_FILE}"
396396
then
397-
fatal "No \"\$NOMAD_CLIENTS_FILE\""
397+
fatal "No \"\$NOMAD_CLIENTS_FILE\". For reproducible builds provide this file that ensures cluster nodes are always placed on the same machines, or create a new one with 'wb nomad nodes' if Nomad Clients have suffered changes and runs fail with \"placement errors\""
398398
fi
399399
# For each (instance-type, datacener/region) we look incrementally for
400400
# the unique AWS EC2 "instance-id" only after ordering the Nomad

nix/workbench/nomad.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ usage_nomad() {
2121
Gets Cardano World's AWS S3 crdentials from Vault in JSON
2222
(WARNING: shows secrets!!!).
2323
24+
$(helpcmd nodes)
25+
Creates a JSON array with all the SRE's perf nodes in a
26+
format that can be used to ensure cloud runs are
27+
reproducible.
28+
2429
$(helpcmd agents start SERVER-NAME CLIENT-NAME TASK-DRIVER-NAME)
2530
Start a default 1 server 1 client Nomad cluster.
2631
$(helpcmd agents stop SERVER-NAME CLIENT-NAME TASK-DRIVER-NAME)
@@ -311,6 +316,97 @@ wb_nomad() {
311316
esac
312317
;;
313318
################################################################################
319+
### nodes ) ###################################################################
320+
################################################################################
321+
nodes )
322+
local usage="USAGE: wb nomad ${op}"
323+
local nomad_address="https://nomad.world.dev.cardano.org"
324+
local nomad_token
325+
nomad_token=$(wb_nomad vault world nomad-token)
326+
# Fetch the status of all nodes of class "perf"
327+
local perf_nodes
328+
perf_nodes="$(NOMAD_TOKEN="${nomad_token}" NOMAD_NAMESPACE=perf nomad node status -address="${nomad_address}" -filter 'NodeClass=="perf"' -json)"
329+
# Create the base JSON string but without the "attributes" because those
330+
# are only available when fetching the status of individual nodes.
331+
local nodes_json
332+
nodes_json="$( \
333+
echo "${perf_nodes}" \
334+
| \
335+
jq \
336+
"map( { \
337+
\"id\": .ID \
338+
, \"name\": .Name \
339+
, \"datacenter\": .Datacenter \
340+
, \"ip\": .Address \
341+
, \"attributes\": null \
342+
} )" \
343+
)"
344+
# For each node
345+
local nodes_ids
346+
nodes_ids="$( \
347+
echo "${nodes_json}" \
348+
| \
349+
jq -S -r "map(.id) | sort | join (\" \")" \
350+
)"
351+
for node_id in ${nodes_ids[*]}
352+
do
353+
# Fetch the attributes
354+
local node_attributes
355+
node_attributes="$(NOMAD_TOKEN="${nomad_token}" NOMAD_NAMESPACE=perf nomad node status -address="${nomad_address}" -json "${node_id}" | jq .Attributes)"
356+
# Add the attributes of this node to the JSON string
357+
nodes_json="$( \
358+
echo "${nodes_json}" \
359+
| \
360+
jq --argjson attrs "${node_attributes}" " \
361+
.[] \
362+
|= ( \
363+
if ( .id == \"${node_id}\" ) \
364+
then ( \
365+
.attributes \
366+
|= \
367+
{ \
368+
\"os\": { \
369+
\"name\": \$attrs[\"os.name\"] \
370+
, \"version\": \$attrs[\"os.version\"] \
371+
} \
372+
, \"platform\": { \
373+
\"aws\": { \
374+
\"ami-id\": \$attrs[\"platform.aws.ami-id\"] \
375+
, \"instance-type\": \$attrs[\"platform.aws.instance-type\"] \
376+
, \"placement\": { \
377+
\"availability-zone\": \$attrs[\"platform.aws.placement.availability-zone\"] \
378+
} \
379+
} \
380+
} \
381+
, \"unique\": { \
382+
\"hostname\": \$attrs[\"unique.hostname\"] \
383+
, \"network\": { \
384+
\"ip-address\": \$attrs[\"unique.network.ip-address\"] \
385+
} \
386+
, \"platform\": { \
387+
\"aws\": { \
388+
\"hostname\": \$attrs[\"unique.platform.aws.hostname\" ] \
389+
, \"instance-id\": \$attrs[\"unique.platform.aws.instance-id\" ] \
390+
, \"local-hostname\": \$attrs[\"unique.platform.aws.local-hostname\" ] \
391+
, \"local-ipv4\": \$attrs[\"unique.platform.aws.local-ipv4\" ] \
392+
, \"mac\": \$attrs[\"unique.platform.aws.mac\" ] \
393+
, \"public-hostname\": \$attrs[\"unique.platform.aws.public-hostname\"] \
394+
, \"public-ipv4\": \$attrs[\"unique.platform.aws.public-ipv4\" ] \
395+
} \
396+
} \
397+
} \
398+
} \
399+
) else ( \
400+
. \
401+
) end \
402+
) \
403+
" \
404+
)"
405+
done
406+
# Output the JSON string ordered by Nomad Client "id"
407+
echo "${nodes_json}" | jq '. | sort_by(.id)'
408+
;;
409+
################################################################################
314410
### agents ) ###################################################################
315411
################################################################################
316412
agents )

0 commit comments

Comments
 (0)