Skip to content

Commit e51f33a

Browse files
Remove legacy monitoring service, add service metrics, fix some stuff
1 parent 31d43ce commit e51f33a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+270
-317
lines changed

.github/workflows/release.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: release
33
on:
44
push:
55
tags:
6-
- '*'
6+
- "*"
77

88
jobs:
99
release:
@@ -17,33 +17,35 @@ jobs:
1717
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
1818

1919
- name: Set up QEMU
20-
uses: docker/setup-qemu-action@v1
20+
uses: docker/setup-qemu-action@v2
2121

2222
- name: Set up Docker Buildx
23-
uses: docker/setup-buildx-action@v1
23+
uses: docker/setup-buildx-action@v2
2424

2525
- name: Login to GitHub Container Registry
26-
uses: docker/login-action@v1
26+
uses: docker/login-action@v2
2727
with:
2828
registry: ghcr.io
2929
username: ${{ github.repository_owner }}
3030
password: ${{ github.token }}
3131

3232
- name: Build and push
3333
id: docker_build
34-
uses: docker/build-push-action@v2
34+
uses: docker/build-push-action@v3
3535
with:
3636
context: .
3737
file: docker_config/base_images/backend.Dockerfile
3838
push: true
39+
platforms: linux/amd64,linux/arm64
3940
tags: |
4041
ghcr.io/${{ github.repository_owner }}/forcad_base:latest
4142
ghcr.io/${{ github.repository_owner }}/forcad_base:${{ steps.get_version.outputs.VERSION }}
4243
43-
- name: Set up Node 13
44+
- name: Set up Node 16
4445
uses: actions/setup-node@v2
4546
with:
46-
node-version: '13'
47+
node-version: "16"
48+
4749
- name: Build frontend
4850
working-directory: front
4951
run: yarn install && yarn build

.github/workflows/tests.yml

+35-11
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,31 @@ jobs:
3131
steps:
3232
- name: Checkout
3333
uses: actions/checkout@v2
34+
3435
- name: Setup python
3536
uses: actions/setup-python@v2
3637
with:
37-
python-version: '3.9'
38+
python-version: "3.9"
39+
3840
- uses: actions/cache@v2
3941
with:
4042
path: ~/.cache/pip
4143
key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }}-${{ hashFiles('cli/requirements.txt') }}-${{ hashFiles('tests/requirements.txt') }}
4244
restore-keys: |
4345
${{ runner.os }}-pip-
46+
4447
- name: Setup tests
4548
run: python tests/setup_forcad.py
49+
4650
- name: Install requirements
4751
run: |
4852
pip install -r cli/requirements.txt
4953
pip install -r tests/requirements.txt
5054
pip install -r backend/requirements.txt
55+
5156
- name: Setup ForcAD
5257
run: ./control.py setup
58+
5359
- name: Build ForcAD
5460
run: ./control.py build
5561

@@ -74,14 +80,17 @@ jobs:
7480
steps:
7581
- name: Checkout
7682
uses: actions/checkout@v2
83+
7784
- name: Setup python
7885
uses: actions/setup-python@v2
7986
with:
80-
python-version: '3.9'
87+
python-version: "3.9"
88+
8189
- name: Install dependencies
8290
run: pip install flake8
91+
8392
- name: Run linters
84-
uses: wearerequired/lint-action@v1
93+
uses: wearerequired/lint-action@v2
8594
with:
8695
github_token: ${{ secrets.GITHUB_TOKEN }}
8796
flake8: true
@@ -91,15 +100,18 @@ jobs:
91100
steps:
92101
- name: Checkout
93102
uses: actions/checkout@v2
94-
- name: Set up Node 13
103+
104+
- name: Set up Node 16
95105
uses: actions/setup-node@v2
96106
with:
97-
node-version: '13'
107+
node-version: "16"
108+
98109
- name: Install dependencies
99110
working-directory: front
100111
run: yarn install
112+
101113
- name: Run linters
102-
uses: wearerequired/lint-action@v1
114+
uses: wearerequired/lint-action@v2
103115
with:
104116
github_token: ${{ secrets.GITHUB_TOKEN }}
105117
auto_fix: true
@@ -113,34 +125,42 @@ jobs:
113125
steps:
114126
- name: Checkout
115127
uses: actions/checkout@v2
128+
116129
- name: Setup python
117130
uses: actions/setup-python@v2
118131
with:
119-
python-version: '3.9'
132+
python-version: "3.9"
133+
120134
- name: Install skaffold
121135
run: |
122136
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v1.19.0/skaffold-linux-amd64
123137
chmod +x skaffold
124138
sudo mv skaffold /usr/local/bin
139+
125140
- name: Setup Minikube
126141
uses: manusa/actions-setup-minikube@v2.3.0
127142
with:
128-
minikube version: 'v1.17.1'
129-
kubernetes version: 'v1.19.3'
143+
minikube version: "v1.17.1"
144+
kubernetes version: "v1.19.3"
130145
github token: ${{ secrets.GITHUB_TOKEN }}
146+
131147
- name: Install cli requirements
132148
run: pip install -r cli/requirements.txt
149+
133150
- name: Copy test config
134151
run: python tests/setup_forcad.py
152+
135153
- name: Setup configuration
136154
run: ./control.py kube setup
155+
137156
- name: Kustomize build
138157
uses: karancode/kustomize-github-action@master
139158
with:
140-
kustomize_version: '3.9.2'
141-
kustomize_build_dir: 'deploy'
159+
kustomize_version: "3.9.2"
160+
kustomize_build_dir: "deploy"
142161
env:
143162
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
163+
144164
- name: Skaffold build
145165
run: ./control.py kube build
146166

@@ -152,12 +172,16 @@ jobs:
152172
steps:
153173
- name: Checkout
154174
uses: actions/checkout@v2
175+
155176
- name: Setup Terraform
156177
uses: hashicorp/setup-terraform@v1
178+
157179
- name: Terraform fmt
158180
run: terraform fmt -check
159181
continue-on-error: true
182+
160183
- name: Terraform Init
161184
run: terraform init
185+
162186
- name: Terraform Validate
163187
run: terraform validate

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.idea
3+
.vscode
34
__pycache__
45

56
docker_volumes

backend/lib/flags/judge.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def _process_attack(self, team_id: int, flag: str) -> AttackResult:
2525

2626
if ar.submit_ok:
2727
self._notifier.add(ar)
28-
self._monitor.add(ar)
28+
self._monitor.inc_ok()
29+
else:
30+
self._monitor.inc_bad()
2931

3032
return ar
3133

backend/lib/flags/notifier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, logger: Logger):
1212
self._logger = logger
1313
self._q = LightQueue(maxsize=1000)
1414

15-
# ensure no-one is writing to the same broker connection concurrently
15+
# ensure no one is writing to the same broker connection concurrently
1616
self._sio = storage.utils.SIOManager.create(write_only=True)
1717

1818
def _process(self, ar: AttackResult):

backend/lib/flags/submit_monitor.py

+8-54
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,49 @@
1-
from collections import defaultdict
21
from logging import Logger
32

43
import eventlet
5-
from eventlet.queue import Queue, Empty
6-
from kombu import Connection
7-
from kombu.messaging import Producer
8-
9-
from lib import models, config
104

115

126
class SubmitMonitor:
137
def __init__(self, logger: Logger, interval: float = 10):
148
self._logger = logger
15-
self._q = Queue()
169

1710
self._ok_submits = 0
1811
self._bad_submits = 0
19-
self._connections = 0
12+
self._requests = 0
2013

2114
self._interval = interval
2215

2316
self._was_ok = self._ok_submits
2417
self._was_bad = self._bad_submits
25-
self._was_conn = self._connections
26-
27-
self._labels = ['attacker_id', 'victim_id', 'task_id', 'submit_ok']
28-
29-
def add(self, ar: models.AttackResult) -> None:
30-
self._q.put_nowait(ar)
31-
if ar.submit_ok:
32-
self.inc_ok()
33-
else:
34-
self.inc_bad()
18+
self._was_requests = self._requests
3519

3620
def inc_ok(self) -> None:
3721
self._ok_submits += 1
3822

3923
def inc_bad(self) -> None:
4024
self._bad_submits += 1
4125

42-
def inc_conns(self) -> None:
43-
self._connections += 1
26+
def inc_requests(self) -> None:
27+
self._requests += 1
4428

4529
def _process_statistics(self) -> None:
4630
new_ok, new_bad = self._ok_submits, self._bad_submits
47-
new_conn = self._connections
31+
new_requests = self._requests
4832
self._logger.info(
4933
f"OK: {new_ok - self._was_ok:>6}, "
5034
f"BAD: {new_bad - self._was_bad:>6}, "
51-
f"CONN: {new_conn - self._was_conn:>6}, "
35+
f"REQ: {new_requests - self._was_requests:>6}, "
5236
f"TOTOK: {new_ok:>6}, TOTBAD: {new_bad:>6}, "
53-
f"TOTCONN: {new_conn:>6}"
37+
f"TOTREQ: {new_requests:>6}"
5438
)
5539
self._was_ok = new_ok
5640
self._was_bad = new_bad
57-
self._was_conn = new_conn
58-
59-
def _process_attacks_queue(self) -> None:
60-
conn = Connection(config.get_broker_url())
61-
with conn.channel() as channel:
62-
producer = Producer(channel)
63-
by_label = defaultdict(list)
64-
while not self._q.empty():
65-
try:
66-
ar: models.AttackResult = self._q.get_nowait()
67-
except Empty:
68-
continue
69-
else:
70-
by_label[ar.get_label_key()].append(ar)
71-
72-
for ar_list in by_label.values():
73-
if not ar_list:
74-
continue
75-
76-
monitor_message = {
77-
'type': 'flag_submit',
78-
'data': ar_list[0].get_label_values(),
79-
'value': len(ar_list),
80-
}
81-
82-
producer.publish(
83-
monitor_message,
84-
exchange='',
85-
routing_key='forcad-monitoring',
86-
)
41+
self._was_requests = new_requests
8742

8843
def __call__(self) -> None:
8944
while True:
9045
try:
9146
self._process_statistics()
92-
self._process_attacks_queue()
9347
except Exception as e:
9448
self._logger.error("Error in monitoring: %s", str(e))
9549
eventlet.sleep(self._interval)

backend/requirements.txt

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
amqp==5.0.9
2+
async-timeout==4.0.2
3+
autopep8==1.6.0
24
bidict==0.21.2
35
billiard==3.6.4.0
4-
celery==5.2.3
6+
celery==5.2.7
57
certifi==2020.12.5
8+
charset-normalizer==2.1.0
69
click==8.0.3
710
click-didyoumean==0.0.3
811
click-plugins==1.1.1
912
click-repl==0.2.0
1013
Deprecated==1.2.13
1114
dnspython==1.16.0
1215
eventlet==0.30.2
13-
Flask==2.0.2
16+
Flask==2.1.3
1417
Flask-Cors==3.0.10
15-
Flask-SocketIO==5.1.1
16-
flower @ https://github.com/mher/flower/zipball/47a0eb937a1a132a9cb5b2e137d96b93e4cdc89e
18+
Flask-SocketIO==5.2.0
19+
flower==1.1.0
1720
greenlet==1.1.2
1821
gunicorn==20.1.0
1922
hiredis==2.0.0
2023
humanize==3.12.0
24+
idna==3.3
25+
importlib-metadata==4.12.0
2126
itsdangerous==2.0.1
2227
Jinja2==3.0.3
2328
kombu==5.2.3
2429
MarkupSafe==2.0.1
2530
packaging==21.3
26-
prometheus-client==0.8.0
31+
prometheus-client==0.14.1
32+
prometheus-flask-exporter==0.20.2
2733
prompt-toolkit==3.0.18
2834
psycopg2==2.9.3
29-
pydantic==1.9.0
35+
pycodestyle==2.8.0
36+
pydantic==1.9.1
3037
pyparsing==3.0.6
3138
python-dateutil==2.8.1
32-
python-engineio==4.1.0
33-
python-socketio==5.2.1
39+
python-engineio==4.3.3
40+
python-socketio==5.7.1
3441
pytz==2021.3
3542
PyYAML==5.4.1
36-
redis==4.1.0
43+
redis==4.3.4
44+
requests==2.28.1
3745
six==1.16.0
46+
toml==0.10.2
3847
tornado==6.1
3948
typing-extensions==3.10.0.0
49+
urllib3==1.26.10
4050
vine==5.0.0
4151
wcwidth==0.2.5
4252
Werkzeug==2.0.2
4353
wrapt==1.13.3
54+
zipp==3.8.1

0 commit comments

Comments
 (0)