-
Notifications
You must be signed in to change notification settings - Fork 38
155 lines (131 loc) · 5.55 KB
/
load_testing.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Load testing
on:
workflow_dispatch:
inputs:
num_instances:
description: "Amount of executor nodes to launch"
required: false
type: number
default: 100
node_port:
description: "Executor port number"
required: false
type: number
default: 8080
metrics_port:
description: "Executor metrics port number"
required: false
type: number
default: 8081
pull_request:
env:
NUM_INSTANCES: ${{ github.event.inputs.num_instances || '100' }}
NODE_PORT: ${{ github.event.inputs.node_port || '8080' }}
METRICS_PORT: ${{ github.event.inputs.metrics_port || '8081' }}
VM_AUTH_USERNAME: ${{ secrets.VM_AUTH_USERNAME }}
VM_AUTH_PASSWORD: ${{ secrets.VM_AUTH_PASSWORD }}
jobs:
run_load_tests:
runs-on: ["matterlabs-deployer-sandbox-infra"]
steps:
- name: Fail-fast on incorrect inputs
run: |
if [[ "${{ env.NUM_INSTANCES }}" -ge 1 && "${{ env.NUM_INSTANCES }}" -le 200 ]]; then
echo "Number of instances is within range."
else
echo "Error: Number of instances is not within range 1-200."
exit 1
fi
if [[ "${{ env.NODE_PORT }}" == "${{ env.METRICS_PORT }}" ]]; then
echo "Error: node_port and metrics_port should not be equal."
exit 1
fi
- name: Generate test ID from current unix timestamp
run: echo "TEST_ID=$(date +%s)" >> $GITHUB_ENV
- uses: actions/checkout@v3
# Needed for hashicorp/setup-terraform@v2
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
with:
node-version: 16
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4
with:
python-version: '3.12'
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.6
- name: Install Ansible and deps
run: |
sudo apt update && sudo apt install -y openssh-client
python -m pip install --upgrade pip
pip install -r infrastructure/loadtests/ansible/requirements.txt
ansible-galaxy install -r infrastructure/loadtests/ansible/requirements.yml
- name: Terraform Init And Apply
working-directory: infrastructure/loadtests
run: |
terraform init
terraform apply -auto-approve \
-parallelism=${{ env.NUM_INSTANCES }} \
-var="num_instances=${{ env.NUM_INSTANCES }}" \
-var="node_port=${{ env.NODE_PORT }}" \
-var="metrics_port=${{ env.METRICS_PORT }}" \
-var="test_id=${{ env.TEST_ID }}"
- name: Generate list of host:port for config generator
working-directory: node
run: |
set -o pipefail
sudo apt update && sudo apt install -y gettext-base
tmp_inventory=$(cat ../infrastructure/loadtests/ansible/gcp.yml)
echo "${tmp_inventory}" | envsubst > ../infrastructure/loadtests/ansible/gcp.yml
cat ../infrastructure/loadtests/ansible/gcp.yml
ansible-inventory -i ../infrastructure/loadtests/ansible/gcp.yml --list | \
tee /tmp/ansible_output.txt | \
grep -q "No inventory was parsed" && { echo "Error: No inventory was parsed."; exit 1; }
jq -r '.gcp_loadtest.hosts[]' < /tmp/ansible_output.txt | \
awk -v port=${{ env.NODE_PORT }} -F\" '{print $1 ":" port}' > ips_prts.txt
- name: Install node build dependencies
run: sudo apt update && sudo apt install -y clang
- uses: actions-rust-lang/setup-rust-toolchain@v1
id: setup-rust
- name: Print used Rust versions
run: |
echo "Rustc version: ${{ steps.setup-rust.outputs.rustc-version }}"
echo "Cargo version: ${{ steps.setup-rust.outputs.cargo-version }}"
echo "Rustup version: ${{ steps.setup-rust.outputs.rustup-version }}"
- name: Pre-create dirs for node artifacts
working-directory: node
run: mkdir -p artifacts/{node_configs,binaries}
- name: Generate node configs
working-directory: node
run: |
cargo run -p tools \
--bin localnet_config -- \
--input-addrs ips_prts.txt \
--metrics-server-port ${{ env.METRICS_PORT }} \
--output-dir artifacts/node_configs
- name: Build executor binary
working-directory: node
run: |
build_output=$(cargo build --release -p tools --bin executor --message-format=json) || exit 1
echo "$build_output" | jq -r 'select(.executable != null) | .executable' \
| while read binary; do
cp "$binary" artifacts/binaries/
done
- name: Run ansible
working-directory: infrastructure/loadtests/ansible
run: |
sa_name=$(gcloud iam service-accounts describe [email protected] --format='value(uniqueId)')
ansible-playbook -i gcp.yml \
--user sa_${sa_name} \
--private-key .ssh/google_compute_engine playbook.yml \
--forks ${{ env.NUM_INSTANCES }}
- name: Terraform Destroy
working-directory: infrastructure/loadtests
if: always()
run: |
terraform destroy -auto-approve \
-parallelism=${{ env.NUM_INSTANCES }} \
-var="num_instances=${{ env.NUM_INSTANCES }}" \
-var="node_port=${{ env.NODE_PORT }}" \
-var="metrics_port=${{ env.METRICS_PORT }}" \
-var="test_id=${{ env.TEST_ID }}"