-
Notifications
You must be signed in to change notification settings - Fork 171
227 lines (200 loc) · 7.64 KB
/
netsim.yml
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: netsim-CI
on:
push:
branches:
- main
issue_comment:
types: [created, edited, deleted]
env:
RUST_BACKTRACE: 1
RUSTFLAGS: -Dwarnings
MSRV: "1.66"
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
jobs:
netsim:
timeout-minutes: 60
name: Run network simulations/benchmarks
if: >-
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/netsim')) || github.event_name != 'issue_comment'
runs-on: [self-hosted, linux, X64]
permissions:
issues: write
pull-requests: write
steps:
- name: Checkout
if: github.event_name != 'issue_comment'
uses: actions/checkout@v4
with:
submodules: recursive
- name: Resolve PR refs (Issue)
if: ${{ github.event_name == 'issue_comment' }}
id: refs
uses: arqu/resolve-pr-refs@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
if: github.event_name == 'issue_comment'
uses: actions/checkout@v4
with:
repository: ${{ github.event.issue.repository.full_name }}
submodules: recursive
ref: ${{ steps.refs.outputs.head_ref }}
- name: Install rust stable
uses: dtolnay/rust-toolchain@stable
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Build iroh
run: |
cargo build --profile optimized-release --workspace --all-features
- name: Detect chuck branch
if: github.event_name == 'issue_comment'
id: detect_chuck_branch
shell: bash
run: |
a='${{ github.event.comment.body }}'
if [[ $a == '/netsim branch'* ]];
then
a=$(echo "$a" | tr '\n' ' ' | tr -s " " | cut -d ' ' -f3)
branch="$a"
echo "CHUCK_BRANCH=$branch" >> ${GITHUB_ENV}
else
echo "CHUCK_BRANCH=main" >> ${GITHUB_ENV}
fi
- name: Detect chuck branch if not comment
if: github.event_name != 'issue_comment'
shell: bash
run: |
echo "CHUCK_BRANCH=main" >> ${GITHUB_ENV}
- name: Fetch and build chuck
shell: bash
run: |
cd ..
rm -rf chuck
git clone --single-branch --branch ${{ env.CHUCK_BRANCH }} https://github.com/n0-computer/chuck.git
cd chuck
cargo build --release
- name: Install netsim deps
run: |
cd ../chuck/netsim
sudo apt update
./setup.sh
- name: Copy binaries to right location
run: |
cp target/optimized-release/iroh ../chuck/netsim/bins/iroh
cp target/optimized-release/iroh-relay ../chuck/netsim/bins/iroh-relay
cp ../chuck/target/release/chuck ../chuck/netsim/bins/chuck
- name: Detect comment commands
if: github.event_name == 'issue_comment'
id: detect_comment_config
run: |
a='${{ github.event.comment.body }}'
if [[ $a == '/netsim config'* ]];
then
a=$(echo "'$a'" | tr '\n' ' ' | tr -s " " | sed -e 's/.*```\(.*\)```.*/\1/')
export NETSIM_CONFIG="$a"
echo "NETSIM_CONFIG<<EOFMARKER" >> ${GITHUB_OUTPUT}
echo "${NETSIM_CONFIG}" >> ${GITHUB_OUTPUT}
echo "EOFMARKER" >> ${GITHUB_OUTPUT}
fi
echo "'$NETSIM_CONFIG'"
- name: Run tests
run: |
cd ../chuck/netsim
sudo kill -9 $(pgrep ovs) || true
sudo mn --clean || true
c='${{ steps.detect_comment_config.outputs.NETSIM_CONFIG }}'
if [ -z "${c}" ];
then
sudo python3 main.py --integration sims/iroh
sudo python3 main.py --integration sims/integration
else
echo $c >> custom_sim.json
sudo python3 main.py custom_sim.json
fi
- name: Cleanup
run: |
sudo kill -9 $(pgrep iroh-relay) || true
sudo kill -9 $(pgrep iroh) || true
sudo kill -9 $(pgrep ovs) || true
sudo mn --clean || true
- name: Generate report
id: generate_report
run: |
cd ../chuck/netsim
python3 reports_csv.py --table > report.txt
export NETSIM_REPORT=$(cat report.txt)
echo "NETSIM_REPORT<<EOFMARKER" >> ${GITHUB_OUTPUT}
echo "${NETSIM_REPORT}" >> ${GITHUB_OUTPUT}
echo "EOFMARKER" >> ${GITHUB_OUTPUT}
- name: Setup Environment
shell: bash
run: |
echo "LAST_COMMIT_SHA=unknown" >> ${GITHUB_ENV}
echo "HEAD_REF=unknown" >> ${GITHUB_ENV}
- name: Setup Environment (Issue)
if: ${{ github.event_name == 'issue_comment' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=${{ steps.refs.outputs.head_sha }}" >> ${GITHUB_ENV}
echo "HEAD_REF=${{ steps.refs.outputs.head_ref }}" >> ${GITHUB_ENV}
- name: Setup Environment (PR)
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})" >> ${GITHUB_ENV}
echo "HEAD_REF=${{ github.event.pull_request.head.ref }}" >> ${GITHUB_ENV}
- name: Setup Environment (Push)
if: ${{ github.event_name == 'push' }}
shell: bash
run: |
echo "LAST_COMMIT_SHA=$(git rev-parse --short ${GITHUB_SHA})" >> ${GITHUB_ENV}
echo "HEAD_REF=${{ github.ref }}" >> ${GITHUB_ENV}
- name: Respond Issue
uses: peter-evans/create-or-update-comment@v2
if: github.event_name == 'issue_comment'
with:
issue-number: ${{ github.event.issue.number }}
body: |
`${{ env.HEAD_REF }}.${{ env.LAST_COMMIT_SHA }}`
Perf report:
${{ steps.generate_report.outputs.NETSIM_REPORT }}
- name: Respond PR
uses: peter-evans/create-or-update-comment@v2
if: github.event.pull_request
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
`${{ env.HEAD_REF }}.${{ env.LAST_COMMIT_SHA }}`
Perf report:
${{ steps.generate_report.outputs.NETSIM_REPORT }}
- name: Generate reports
run: |
cd ../chuck/netsim
python3 reports_csv.py --prom --commit ${{ env.LAST_COMMIT_SHA }} > report_prom.txt
python3 reports_csv.py --metro --commit ${{ env.LAST_COMMIT_SHA }} > report_metro.txt
python3 reports_csv.py --metro --integration --commit ${{ env.LAST_COMMIT_SHA }} > report_metro_integration.txt
- name: Dump report
run: |
export AWS_ACCESS_KEY_ID=${{secrets.S3_ACCESS_KEY_ID}}
export AWS_SECRET_ACCESS_KEY=${{secrets.S3_ACCESS_KEY}}
export AWS_DEFAULT_REGION=us-west-2
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install --update
cd ../chuck/netsim
aws_fname=${{ env.LAST_COMMIT_SHA }}.tar.gz
tar cvzf report.tar.gz report_prom.txt report.txt report_metro.txt report_metro_integration.txt logs/ report/ viz/
aws s3 cp ./report.tar.gz s3://${{secrets.S3_REPORT_BUCKET}}/$aws_fname --no-progress
- name: Post metrics
if: github.ref_name=='main' && github.event_name != 'issue_comment'
run: |
cd ../chuck/netsim
d=$(cat report_metro.txt)
metro_data=$(printf "%s\n " "$d")
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{secrets.METRO_TOKEN}}" --data "$metro_data" ${{secrets.METRO_ENDPOINT}}
d=$(cat report_metro_integration.txt)
metro_data=$(printf "%s\n " "$d")
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{secrets.METRO_TOKEN}}" --data "$metro_data" ${{secrets.METRO_ENDPOINT}}