Skip to content

Commit b7d38bd

Browse files
committed
fix(controller): measure_networks err
1 parent 454cae6 commit b7d38bd

7 files changed

Lines changed: 28 additions & 38 deletions

File tree

charts/controller/templates/controller-celery-deloyment.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,13 @@ spec:
4848
- celery -A api worker -Q priority.high --autoscale=32,1 --loglevel=WARNING
4949
{{- include "controller.limits" . | indent 8 }}
5050
{{- include "controller.envs" . | indent 8 }}
51-
- name: drycc-controller-celery-middle
52-
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
53-
imagePullPolicy: {{.Values.imagePullPolicy}}
54-
args:
55-
- /bin/bash
56-
- -c
57-
- celery -A api worker -Q priority.middle --autoscale=16,1 --loglevel=WARNING
58-
{{- include "controller.limits" . | indent 8 }}
59-
{{- include "controller.envs" . | indent 8 }}
6051
- name: drycc-controller-celery-low
6152
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
6253
imagePullPolicy: {{.Values.imagePullPolicy}}
6354
args:
6455
- /bin/bash
6556
- -c
66-
- celery -A api worker -Q priority.low --autoscale=8,1 --loglevel=WARNING
57+
- celery -A api worker -Q priority.low --autoscale=32,1 --loglevel=WARNING
6758
{{- include "controller.limits" . | indent 8 }}
6859
{{- include "controller.envs" . | indent 8 }}
6960

rootfs/api/influxdb.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import threading
22
import logging
3+
from contextlib import closing
34
from typing import Iterator
45
from django.conf import settings
56
from influxdb_client import InfluxDBClient
@@ -11,28 +12,26 @@
1112

1213

1314
def _get_influxdb_client() -> InfluxDBClient:
14-
if not hasattr(local, "influxdb_client"):
15-
local.influxdb_client = InfluxDBClient(
16-
url=settings.DRYCC_INFLUXDB_URL,
17-
token=settings.DRYCC_INFLUXDB_TOKEN,
18-
org=settings.DRYCC_INFLUXDB_ORG
19-
)
20-
return local.influxdb_client
15+
return InfluxDBClient(
16+
url=settings.DRYCC_INFLUXDB_URL,
17+
token=settings.DRYCC_INFLUXDB_TOKEN,
18+
org=settings.DRYCC_INFLUXDB_ORG
19+
)
2120

2221

2322
def _query_stream(flux_script: str) -> Iterator[FluxRecord]:
2423
client = _get_influxdb_client()
2524
try:
2625
query_api = client.query_api()
2726
records = query_api.query_stream(flux_script)
27+
with closing(records):
28+
yield from records
2829
except ApiException as e:
2930
logger.exception(e)
3031
yield from []
3132
except Exception as e:
3233
logger.exception(e)
3334
yield from []
34-
else:
35-
yield from records
3635

3736

3837
def query_container_count(

rootfs/api/management/commands/measure_networks.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.core.management.base import BaseCommand
66
from django.conf import settings
77
from api import influxdb
8-
from api.models.config import Config
8+
from api.models.app import App
99
from api.tasks import send_measurements
1010

1111
logger = logging.getLogger(__name__)
@@ -14,16 +14,16 @@
1414
class Command(BaseCommand):
1515
"""Management command for push data to manager"""
1616

17-
def _measure_networks(self, config_map, timestamp):
17+
def _measure_networks(self, app_map, timestamp):
1818
stop = timestamp - (timestamp % 3600)
1919
start = stop - 3600
2020
networks = []
21-
for record in influxdb.query_network_flow(config_map.keys(), start, stop):
21+
for record in influxdb.query_network_flow(app_map.keys(), start, stop):
2222
app_id = record["namespace"]
23-
owner_id = config_map[app_id].owner_id
23+
owner_id = app_map[app_id].owner_id
2424
networks.append({
2525
"app_id": app_id,
26-
"owner_id": owner_id,
26+
"owner": owner_id,
2727
"name": record["pod_name"],
2828
"type": "network",
2929
"unit": "bytes",
@@ -37,13 +37,13 @@ def handle(self, *args, **options):
3737
timestamp = int(time.time())
3838
task_id = uuid.uuid4().hex
3939
logger.info(f"pushing {task_id} limits to workflow_manager when {timezone.now()}")
40-
config_map = {}
41-
for config in Config.objects.all():
42-
config_map[config.app_id] = config
43-
if len(config_map) % 1000 == 0:
44-
send_measurements.delay(self._measure_networks(config_map, timestamp))
45-
config_map = {}
46-
if len(config_map) > 0:
47-
send_measurements.delay(self._measure_networks(config_map, timestamp))
40+
app_map = {}
41+
for app in App.objects.all():
42+
app_map[app.id] = app
43+
if len(app_map) % 1000 == 0:
44+
self._measure_networks(app_map, timestamp)
45+
app_map = {}
46+
if len(app_map) > 0:
47+
self._measure_networks(app_map, timestamp)
4848
logger.info(f"pushed {task_id} limits to workflow_manager when {timezone.now()}")
4949
self.stdout.write("done")

rootfs/api/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def post(self, measurements: List[Dict[str, str]]):
6868
[
6969
{
7070
"app_id": "test",
71-
"owner_id": "test",
71+
"owner": "test",
7272
"name": web,
7373
"type": "CPU",
7474
"unit": "G"
@@ -78,4 +78,4 @@ def post(self, measurements: List[Dict[str, str]]):
7878
]
7979
"""
8080
url = "%s/measurements/" % settings.WORKFLOW_MANAGER_URL
81-
return self.post(url=url, json=measurements)
81+
return super().post(url=url, json=measurements)

rootfs/api/models/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ def to_measurements(self, timestamp: float):
11631163
for container_type, scale in self.structure.items():
11641164
measurements.append({
11651165
"app_id": self.id,
1166-
"user_id": self.owner_id,
1166+
"owner": self.owner_id,
11671167
"name": container_type,
11681168
"type": "cpu",
11691169
"unit": "milli",
@@ -1172,7 +1172,7 @@ def to_measurements(self, timestamp: float):
11721172
})
11731173
measurements.append({
11741174
"app_id": self.app_id,
1175-
"user_id": self.owner_id,
1175+
"owner": self.owner_id,
11761176
"name": container_type,
11771177
"type": "memory",
11781178
"unit": "bytes",

rootfs/api/models/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def detach_resource(self, *args, **kwargs):
231231
def to_measurements(self, timestamp: float):
232232
return [{
233233
"app_id": str(self.app_id),
234-
"user_id": str(self.owner_id),
234+
"owner": str(self.owner_id),
235235
"name": self.name,
236236
"type": self.plan,
237237
"unit": "number",

rootfs/api/models/volume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def log(self, message, level=logging.INFO):
6666
def to_measurements(self, timestamp: float):
6767
return [{
6868
"app_id": str(self.app_id),
69-
"user_id": str(self.owner_id),
69+
"owner": str(self.owner_id),
7070
"name": self.name,
7171
"type": "volume",
7272
"unit": "bytes",

0 commit comments

Comments
 (0)