Skip to content

Commit 1b95aef

Browse files
committed
workbench | profiles: simplify jq profile definition
1 parent 596403b commit 1b95aef

File tree

7 files changed

+64
-70
lines changed

7 files changed

+64
-70
lines changed

nix/workbench/profile.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ case "$op" in
3030

3131
all-profiles | generate-all | all )
3232
with_era_profiles '
33-
map (profiles(.; null; null; []))
33+
map (generate_all_era_profiles(.; null; null))
3434
| add
3535
';;
3636

3737
all-profile-names | names | all-names )
3838
with_era_profiles '
39-
map (profile_names(.; null; null; []))
39+
map (generate_all_era_profiles(.; null; null) | map(.name))
4040
| add
4141
';;
4242

@@ -45,7 +45,9 @@ case "$op" in
4545
local name=${1:?$usage}
4646

4747
with_era_profiles '
48-
map (has_profile(.; null; null; []; $name))
48+
map (generate_all_era_profiles(.; null; null)
49+
| map (.name == $name)
50+
| any)
4951
| any
5052
' --exit-status --arg name "$name" >/dev/null
5153
;;

nix/workbench/profiles/adhoc.jq

Lines changed: 0 additions & 20 deletions
This file was deleted.

nix/workbench/profiles/variants.jq renamed to nix/workbench/profiles/prof1-variants.jq

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,24 @@ def all_profile_variants:
470470
, $scenario_chainsync * $chaindb_early_alonzo * $p2p *
471471
{ name: "chainsync-early-alonzo-p2p"
472472
}
473+
474+
## Last, but not least, the profile used by "nix-shell -A devops":
475+
, { name: "devops"
476+
, scenario: "idle"
477+
, genesis:
478+
{ slot_duration: 0.2
479+
, parameter_k: 10
480+
, epoch_length: 1000
481+
, active_slots_coeff: 0.1
482+
, genesis_future_offset: "10 seconds"
483+
, utxo: 0
484+
485+
, shelley:
486+
{ updateQuorum: 1
487+
}
488+
}
489+
, analysis:
490+
{ type: null
491+
}
492+
}
473493
];

nix/workbench/profiles/derived.jq renamed to nix/workbench/profiles/prof2-derived.jq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include "defaults";
1+
include "prof0-defaults";
22
include "genesis";
33
include "lib";
44

nix/workbench/profiles/profiles.jq

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
## - era-dependent defaults for the aforementioned sections:
1818
## - profiles/defaults.jq
1919
##
20-
## - overlaid with generated profile variants + ad-hoc profiles:
21-
## - profiles/variants.jq and profiles/adhoc.jq
20+
## - overlaid with generated profile variants (including adhoc profiles):
21+
## - profiles/variants.jq
2222
##
2323
## - each then further overlaid with derived parameters, computed from the above:
2424
## - profiles/derived.jq
@@ -58,39 +58,54 @@
5858
## ..which simply calls ./profiles.nix with {} params.
5959
##
6060

61-
include "topology";
62-
include "defaults";
63-
include "adhoc";
64-
include "variants";
65-
include "derived";
61+
include "prof0-defaults";
62+
include "prof1-variants";
63+
include "prof2-derived";
6664

67-
def compute_profiles($era; $mcompo; $topo; $extra_profiles):
65+
##
66+
## This is the workbench's entry point for everything profile.
67+
##
68+
## generate_all_era_profiles :: Era -> Maybe Composition -> Topology -> Map Name Profile
69+
##
70+
def generate_all_era_profiles($era; $mcompo; $topo):
6871
($mcompo // topology_composition($topo // {}) // {}) as $compo
6972

70-
## Profiles are variants + custom (or aux) profiles:
71-
| all_profile_variants + adhoc_profiles + $extra_profiles
72-
| map (## Each profile extends defaults:
73+
| all_profile_variants
74+
| map (## Each profile is defined as extension of defaults:
7375
era_defaults($era) * .
7476

75-
## Profiles can define their own cluster composition.
77+
## Profiles define their own cluster composition:
7678
| . * { composition: (.composition // $compo) }
7779

78-
## Compute the derived params.
80+
## Finally, compute the derived ("computed") params.
7981
| add_derived_params
8082
);
81-
82-
def profiles($era; $mcompo; $topo; $extra_profiles):
83-
compute_profiles($era; $mcompo; $topo; $extra_profiles)
8483
| map (## Assemble into a dictionary..
8584
{ "\(.name)": .
8685
})
8786
| add;
8887

89-
def profile_names($era; $mcompo; $topo; $extra_profiles):
90-
compute_profiles($era; $mcompo; $topo; $extra_profiles)
91-
| map (.name);
9288

93-
def has_profile($era; $mcompo; $topo; $extra_profiles; $name):
94-
compute_profiles($era; $mcompo; $topo; $extra_profiles)
95-
| map (.name == $name)
96-
| any;
89+
## Cluster composition is an extract from the topology,
90+
## that classifies nodes into BFT, regular pools and dense pools,
91+
## based on the 'pools' field.
92+
##
93+
## Testable with:
94+
##
95+
## jq -n 'include "composition" { search: "nix/workbench/profiles" }; topology_composition({ coreNodes: { bft1: { pools: 0 } } })'
96+
##
97+
def topology_composition($topo):
98+
$topo
99+
| (.Producers // .coreNodes // {})
100+
| to_entries
101+
| map (.value.pools // 0)
102+
| length as $n_hosts
103+
| map (select (. == 0)) as $bfts
104+
| map (select (. != 0)) as $pools
105+
| ($pools | map (select (. == 1))) as $singular_pools
106+
| ($pools | map (select (. > 1))) as $dense_pools
107+
| ($singular_pools | length) as $n_singular_hosts
108+
| { n_bft_hosts: ($bfts | length)
109+
, n_singular_hosts: ($singular_pools | length)
110+
, n_dense_hosts: ($dense_pools | length)
111+
};

nix/workbench/profiles/topology.jq

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)