Skip to content

Commit 24aa35c

Browse files
authored
chore: Add script to generate cluster attributes for domain update tests (#7377)
<!-- Describe what has changed in this PR --> **What changed?** Adds a script to generate realistic cluster attributes for testing active-active domains. <!-- Tell your future self why have you made these changes --> **Why?** This script made testing out failover for active-active domains simpler. <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> **How did you test it?** Manually. <!-- Assuming the worst case, what can be broken when deploying this change to production? --> **Potential risks** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it, and also update CHANGELOG.md --> **Release notes** <!-- Is there any documentation updates should be made for config, https://cadenceworkflow.io/docs/operation-guide/setup/ ? If so, please open an PR in https://github.com/cadence-workflow/cadence-docs --> **Documentation Changes**
1 parent 8f1266f commit 24aa35c

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/bash
2+
3+
# Script to generate a domain update command with 3000 cluster attributes
4+
# Each attribute is a unique city assigned to one of three clusters
5+
6+
set -e
7+
8+
DOMAIN="${1:-test25}"
9+
NUM_ATTRIBUTES="${2:-3000}"
10+
11+
echo "Generating command with $NUM_ATTRIBUTES cluster attributes for domain: $DOMAIN"
12+
echo ""
13+
14+
# Array of city names from around the world
15+
# We'll use these as base names and add suffixes to reach 3000
16+
CITIES=(
17+
# Major world cities
18+
"london" "paris" "berlin" "madrid" "rome" "moscow" "istanbul" "athens" "vienna" "prague"
19+
"amsterdam" "brussels" "copenhagen" "dublin" "helsinki" "lisbon" "oslo" "stockholm" "warsaw" "budapest"
20+
"tokyo" "beijing" "shanghai" "seoul" "bangkok" "singapore" "hong_kong" "mumbai" "delhi" "bangalore"
21+
"sydney" "melbourne" "auckland" "wellington" "brisbane" "perth" "adelaide" "canberra"
22+
"new_york" "los_angeles" "chicago" "houston" "phoenix" "philadelphia" "san_antonio" "san_diego" "dallas" "san_jose"
23+
"austin" "jacksonville" "fort_worth" "columbus" "charlotte" "san_francisco" "indianapolis" "seattle" "denver" "washington"
24+
"boston" "el_paso" "nashville" "detroit" "portland" "las_vegas" "memphis" "louisville" "baltimore" "milwaukee"
25+
"toronto" "montreal" "vancouver" "calgary" "ottawa" "edmonton" "winnipeg" "quebec_city" "hamilton" "victoria"
26+
"mexico_city" "guadalajara" "monterrey" "puebla" "tijuana" "leon" "ciudad_juarez" "zapopan" "merida" "san_luis_potosi"
27+
"sao_paulo" "rio_de_janeiro" "brasilia" "salvador" "fortaleza" "belo_horizonte" "manaus" "curitiba" "recife" "porto_alegre"
28+
"buenos_aires" "cordoba" "rosario" "mendoza" "la_plata" "mar_del_plata" "salta" "santa_fe" "san_juan" "resistencia"
29+
"bogota" "medellin" "cali" "barranquilla" "cartagena" "cucuta" "bucaramanga" "pereira" "ibague" "santa_marta"
30+
"lima" "arequipa" "trujillo" "chiclayo" "piura" "iquitos" "cusco" "huancayo" "tacna" "ica"
31+
"santiago" "valparaiso" "concepcion" "la_serena" "antofagasta" "temuco" "rancagua" "talca" "arica" "puerto_montt"
32+
"caracas" "maracaibo" "valencia" "barquisimeto" "maracay" "ciudad_guayana" "maturin" "barcelona" "puerto_la_cruz"
33+
"quito" "guayaquil" "cuenca" "santo_domingo" "machala" "duran" "portoviejo" "manta" "loja" "ambato"
34+
"cairo" "alexandria" "giza" "shubra_el_kheima" "port_said" "suez" "luxor" "al_mahallah_al_kubra" "tanta" "asyut"
35+
"johannesburg" "cape_town" "durban" "pretoria" "port_elizabeth" "pietermaritzburg" "benoni" "tembisa" "east_london" "vereeniging"
36+
"lagos" "kano" "ibadan" "kaduna" "port_harcourt" "benin_city" "maiduguri" "zaria" "aba" "jos"
37+
"nairobi" "mombasa" "kisumu" "nakuru" "eldoret" "thika" "malindi" "kitale" "garissa" "kakamega"
38+
"addis_ababa" "dire_dawa" "mekele" "gondar" "awasa" "bahir_dar" "dessie" "jimma" "jijiga" "shashamane"
39+
"kinshasa" "lubumbashi" "mbuji_mayi" "kisangani" "kananga" "likasi" "kolwezi" "tshikapa" "beni" "bukavu"
40+
"dar_es_salaam" "mwanza" "arusha" "dodoma" "mbeya" "morogoro" "tanga" "kahama" "tabora" "zanzibar"
41+
"kampala" "gulu" "lira" "mbarara" "jinja" "bwizibwera" "mbale" "mukono" "kasese" "masaka"
42+
"khartoum" "omdurman" "khartoum_north" "nyala" "port_sudan" "kassala" "el_obeid" "gedaref" "wad_medani" "al_qadarif"
43+
"accra" "kumasi" "tamale" "sekondi_takoradi" "ashaiman" "sunyani" "cape_coast" "obuasi" "teshie" "tema"
44+
"algiers" "oran" "constantine" "annaba" "blida" "batna" "djelfa" "setif" "sidi_bel_abbes" "biskra"
45+
"casablanca" "rabat" "fes" "marrakech" "agadir" "tangier" "meknes" "oujda" "kenitra" "tetouan"
46+
"tunis" "sfax" "sousse" "ettadhamen" "kairouan" "bizerte" "gabes" "ariana" "gafsa" "kasserine"
47+
"tripoli" "benghazi" "misrata" "tarhuna" "al_khums" "az_zawiya" "ajdabiya" "tobruk" "Sabha" "gharyan"
48+
"tehran" "mashhad" "isfahan" "karaj" "tabriz" "shiraz" "qom" "ahvaz" "kermanshah" "urmia"
49+
"baghdad" "basra" "mosul" "erbil" "kirkuk" "najaf" "karbala" "sulaymaniyah" "nasiriyah" "amarah"
50+
"riyadh" "jeddah" "mecca" "medina" "dammam" "taif" "tabuk" "khamis_mushait" "buraidah" "al_hofuf"
51+
"dubai" "abu_dhabi" "sharjah" "al_ain" "ajman" "ras_al_khaimah" "fujairah" "umm_al_quwain" "khor_fakkan" "dibba"
52+
"kabul" "kandahar" "herat" "mazar_i_sharif" "kunduz" "jalalabad" "lashkar_gah" "taloqan" "puli_khumri" "ghazni"
53+
"karachi" "lahore" "faisalabad" "rawalpindi" "multan" "hyderabad" "gujranwala" "peshawar" "quetta" "islamabad"
54+
"dhaka" "chittagong" "khulna" "rajshahi" "sylhet" "rangpur" "barisal" "comilla" "narayanganj" "gazipur"
55+
"kathmandu" "pokhara" "lalitpur" "bharatpur" "biratnagar" "birgunj" "dharan" "hetauda" "janakpur" "butwal"
56+
"yangon" "mandalay" "naypyidaw" "mawlamyine" "bago" "pathein" "monywa" "sittwe" "meiktila" "myeik"
57+
"hanoi" "ho_chi_minh_city" "haiphong" "da_nang" "bien_hoa" "hue" "nha_trang" "can_tho" "rach_gia" "qui_nhon"
58+
"manila" "quezon_city" "davao" "caloocan" "cebu_city" "zamboanga" "taguig" "antipolo" "pasig" "cagayan_de_oro"
59+
"jakarta" "surabaya" "bandung" "bekasi" "medan" "tangerang" "depok" "semarang" "palembang" "makassar"
60+
"kuala_lumpur" "george_town" "ipoh" "johor_bahru" "malacca_city" "shah_alam" "kota_kinabalu" "kuching" "petaling_jaya"
61+
)
62+
63+
# Function to generate cluster attributes
64+
generate_attributes() {
65+
local num=$1
66+
local attributes=()
67+
local city_index=0
68+
local suffix=0
69+
70+
for i in $(seq 1 $num); do
71+
# Get base city name
72+
local base_city="${CITIES[$city_index]}"
73+
74+
# Add suffix if we've used all base cities
75+
if [ $suffix -gt 0 ]; then
76+
local city_name="${base_city}_${suffix}"
77+
else
78+
local city_name="${base_city}"
79+
fi
80+
81+
# Assign to a cluster (round-robin for even distribution)
82+
local cluster_num=$((i % 3))
83+
local cluster="cluster${cluster_num}"
84+
85+
# Add attribute in format: location.city:cluster
86+
attributes+=("location.${city_name}:${cluster}")
87+
88+
# Move to next city
89+
city_index=$(((city_index + 1) % ${#CITIES[@]}))
90+
91+
# If we've cycled through all cities, increment suffix
92+
if [ $city_index -eq 0 ]; then
93+
suffix=$((suffix + 1))
94+
fi
95+
done
96+
97+
# Join with commas
98+
local IFS=','
99+
echo "${attributes[*]}"
100+
}
101+
102+
echo "Generating $NUM_ATTRIBUTES unique city-cluster mappings..."
103+
ACTIVE_CLUSTERS=$(generate_attributes $NUM_ATTRIBUTES)
104+
105+
# Count the length to verify
106+
ATTR_COUNT=$(echo "$ACTIVE_CLUSTERS" | grep -o "location\." | wc -l | tr -d ' ')
107+
echo "Generated $ATTR_COUNT cluster attributes"
108+
echo ""
109+
110+
# Generate the full command
111+
COMMAND="./cadence --transport grpc --ad localhost:7833 --domain $DOMAIN domain update --active_clusters '$ACTIVE_CLUSTERS'"
112+
113+
# Save to file since it's too long to display
114+
OUTPUT_FILE="update_${DOMAIN}_${NUM_ATTRIBUTES}_attrs.sh"
115+
echo "#!/bin/bash" > "$OUTPUT_FILE"
116+
echo "" >> "$OUTPUT_FILE"
117+
echo "# Auto-generated domain update with $NUM_ATTRIBUTES cluster attributes" >> "$OUTPUT_FILE"
118+
echo "# Domain: $DOMAIN" >> "$OUTPUT_FILE"
119+
echo "" >> "$OUTPUT_FILE"
120+
echo "$COMMAND" >> "$OUTPUT_FILE"
121+
122+
chmod +x "$OUTPUT_FILE"
123+
124+
echo "========================================="
125+
echo "Command saved to: $OUTPUT_FILE"
126+
echo "========================================="
127+
echo ""
128+
echo "Command length: ${#COMMAND} characters"
129+
echo "Attribute string length: ${#ACTIVE_CLUSTERS} characters"
130+
echo ""
131+
echo "To execute:"
132+
echo " ./$OUTPUT_FILE"
133+
echo ""
134+
echo "Preview (first 500 chars):"
135+
echo "${COMMAND:0:500}..."
136+
echo ""
137+
echo "Distribution:"
138+
echo " - cluster0: ~$((NUM_ATTRIBUTES / 3)) attributes"
139+
echo " - cluster1: ~$((NUM_ATTRIBUTES / 3)) attributes"
140+
echo " - cluster2: ~$((NUM_ATTRIBUTES / 3)) attributes"

0 commit comments

Comments
 (0)