Skip to content

Commit 7ec6627

Browse files
committed
chore(usage): optimize usage reporting frequency
1 parent b37e037 commit 7ec6627

7 files changed

Lines changed: 99 additions & 68 deletions

File tree

charts/controller/templates/controller-cronjob-daily.yaml

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,45 +61,3 @@ spec:
6161
{{- end }}
6262
{{- include "controller.envs" . | indent 12 }}
6363
{{- include "controller-job.envs" . | indent 12 }}
64-
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
65-
imagePullPolicy: {{.Values.pull_policy}}
66-
name: drycc-controller-measure-apps
67-
{{- if .Values.diagnosticMode.enabled }}
68-
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
69-
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
70-
{{- else }}
71-
args:
72-
- /bin/bash
73-
- -c
74-
- python -u /workspace/manage.py upload_app_usage
75-
{{- end }}
76-
{{- include "controller.envs" . | indent 12 }}
77-
{{- include "controller-job.envs" . | indent 12 }}
78-
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
79-
imagePullPolicy: {{.Values.pull_policy}}
80-
name: drycc-controller-measure-resources
81-
{{- if .Values.diagnosticMode.enabled }}
82-
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
83-
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
84-
{{- else }}
85-
args:
86-
- /bin/bash
87-
- -c
88-
- python -u /workspace/manage.py upload_resource_usage
89-
{{- end }}
90-
{{- include "controller.envs" . | indent 12 }}
91-
{{- include "controller-job.envs" . | indent 12 }}
92-
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
93-
imagePullPolicy: {{.Values.pull_policy}}
94-
name: drycc-controller-measure-volumes
95-
{{- if .Values.diagnosticMode.enabled }}
96-
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
97-
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
98-
{{- else }}
99-
args:
100-
- /bin/bash
101-
- -c
102-
- python -u /workspace/manage.py upload_volume_usage
103-
{{- end }}
104-
{{- include "controller.envs" . | indent 12 }}
105-
{{- include "controller-job.envs" . | indent 12 }}

charts/controller/templates/controller-cronjob-hourly.yaml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
containers:
3838
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
3939
imagePullPolicy: {{.Values.pull_policy}}
40-
name: drycc-controller-measure-networks
40+
name: drycc-controller-upload-network-usage
4141
{{- if .Values.diagnosticMode.enabled }}
4242
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
4343
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
@@ -51,15 +51,57 @@ spec:
5151
{{- include "controller-job.envs" . | indent 12 }}
5252
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
5353
imagePullPolicy: {{.Values.pull_policy}}
54-
name: drycc-controller-measure-loadbalancer
54+
name: drycc-controller-upload-gateway-usage
5555
{{- if .Values.diagnosticMode.enabled }}
5656
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
5757
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
5858
{{- else }}
5959
args:
6060
- /bin/bash
6161
- -c
62-
- python -u /workspace/manage.py measure_gateway
62+
- python -u /workspace/manage.py upload_gateway_usage
63+
{{- end }}
64+
{{- include "controller.envs" . | indent 12 }}
65+
{{- include "controller-job.envs" . | indent 12 }}
66+
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
67+
imagePullPolicy: {{.Values.pull_policy}}
68+
name: drycc-controller-upload-app-usage
69+
{{- if .Values.diagnosticMode.enabled }}
70+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
71+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
72+
{{- else }}
73+
args:
74+
- /bin/bash
75+
- -c
76+
- python -u /workspace/manage.py upload_app_usage
77+
{{- end }}
78+
{{- include "controller.envs" . | indent 12 }}
79+
{{- include "controller-job.envs" . | indent 12 }}
80+
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
81+
imagePullPolicy: {{.Values.pull_policy}}
82+
name: drycc-controller-upload-resources-usage
83+
{{- if .Values.diagnosticMode.enabled }}
84+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
85+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
86+
{{- else }}
87+
args:
88+
- /bin/bash
89+
- -c
90+
- python -u /workspace/manage.py upload_resource_usage
91+
{{- end }}
92+
{{- include "controller.envs" . | indent 12 }}
93+
{{- include "controller-job.envs" . | indent 12 }}
94+
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
95+
imagePullPolicy: {{.Values.pull_policy}}
96+
name: drycc-controller-upload-volume-usage
97+
{{- if .Values.diagnosticMode.enabled }}
98+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 14 }}
99+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 14 }}
100+
{{- else }}
101+
args:
102+
- /bin/bash
103+
- -c
104+
- python -u /workspace/manage.py upload_volume_usage
63105
{{- end }}
64106
{{- include "controller.envs" . | indent 12 }}
65107
{{- include "controller-job.envs" . | indent 12 }}

rootfs/api/management/commands/upload_app_usage.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import uuid
22
import time
33
import logging
4+
import random
5+
from datetime import timedelta
46
from django.utils import timezone
57
from django.core.management.base import BaseCommand
68
from django.conf import settings
@@ -15,16 +17,21 @@ class Command(BaseCommand):
1517

1618
def handle(self, *args, **options):
1719
if settings.WORKFLOW_MANAGER_URL:
18-
timestamp = time.time()
19-
task_id = uuid.uuid4().hex
20+
start_time, timestamp, task_id = timezone.now(), int(time.time()), uuid.uuid4().hex
2021
logger.info(f"pushing {task_id} resources to workflow_manager when {timezone.now()}")
2122
app_list = []
2223
for app in App.objects.all():
2324
app_list.extend(app.to_usages(timestamp))
2425
if len(app_list) % 1000 == 0:
25-
send_usage.delay(app_list)
26+
send_usage.apply_async(
27+
args=(app_list,),
28+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
29+
)
2630
app_list = []
2731
if len(app_list) > 0:
28-
send_usage.delay(app_list)
32+
send_usage.apply_async(
33+
args=(app_list,),
34+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
35+
)
2936
logger.info(f"pushed {task_id} resources to workflow_manager when {timezone.now()}")
3037
self.stdout.write("done")

rootfs/api/management/commands/upload_gateway_usage.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import uuid
22
import time
33
import logging
4+
import random
5+
from datetime import timedelta
46
from django.utils import timezone
57
from django.core.management.base import BaseCommand
68
from django.conf import settings
@@ -15,16 +17,21 @@ class Command(BaseCommand):
1517

1618
def handle(self, *args, **options):
1719
if settings.WORKFLOW_MANAGER_URL:
18-
timestamp = time.time()
19-
task_id = uuid.uuid4().hex
20+
start_time, timestamp, task_id = timezone.now(), int(time.time()), uuid.uuid4().hex
2021
logger.info(f"pushing {task_id} gateways to workflow_manager when {timezone.now()}")
2122
gateway_list = []
2223
for gateway in Gateway.objects.all():
2324
gateway_list.extend(gateway.to_usages(timestamp))
2425
if len(gateway_list) % 1000 == 0:
25-
send_usage.delay(gateway_list)
26+
send_usage.apply_async(
27+
args=(gateway_list,),
28+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
29+
)
2630
gateway_list = []
2731
if len(gateway_list) > 0:
28-
send_usage.delay(gateway_list)
32+
send_usage.apply_async(
33+
args=(gateway_list,),
34+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
35+
)
2936
logger.info(f"pushed {task_id} gateways to workflow_manager when {timezone.now()}")
3037
self.stdout.write("done")

rootfs/api/management/commands/upload_network_usage.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import uuid
22
import time
33
import logging
4+
import random
5+
from datetime import timedelta
46
from asgiref.sync import async_to_sync
57
from django.utils import timezone
68
from django.core.management.base import BaseCommand
@@ -15,7 +17,7 @@
1517
class Command(BaseCommand):
1618
"""Management command for push data to manager"""
1719

18-
def _upload_network_usage(self, app_map, timestamp):
20+
def _upload_network_usage(self, start_time, app_map, timestamp):
1921
stop = timestamp - (timestamp % 3600)
2022
start = stop - 3600
2123
networks = []
@@ -49,20 +51,21 @@ def _upload_network_usage(self, app_map, timestamp):
4951
},
5052
"timestamp": start
5153
})
52-
send_usage.delay(networks)
54+
send_usage.apply_async(
55+
args=(networks,), eta=start_time + timedelta(seconds=random.randint(1, 1800))
56+
)
5357

5458
def handle(self, *args, **options):
5559
if settings.WORKFLOW_MANAGER_URL:
56-
timestamp = int(time.time())
57-
task_id = uuid.uuid4().hex
60+
start_time, timestamp, task_id = timezone.now(), int(time.time()), uuid.uuid4().hex
5861
logger.info(f"pushing {task_id} limits to workflow_manager when {timezone.now()}")
5962
app_map = {}
6063
for app in App.objects.all():
6164
app_map[app.id] = app
6265
if len(app_map) % 1000 == 0:
63-
self._upload_network_usage(app_map, timestamp)
66+
self._upload_network_usage(start_time, app_map, timestamp)
6467
app_map = {}
6568
if len(app_map) > 0:
66-
self._upload_network_usage(app_map, timestamp)
69+
self._upload_network_usage(start_time, app_map, timestamp)
6770
logger.info(f"pushed {task_id} limits to workflow_manager when {timezone.now()}")
6871
self.stdout.write("done")

rootfs/api/management/commands/upload_resource_usage.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import uuid
22
import time
33
import logging
4+
import random
5+
from datetime import timedelta
46
from django.utils import timezone
57
from django.core.management.base import BaseCommand
68
from django.conf import settings
@@ -15,16 +17,21 @@ class Command(BaseCommand):
1517

1618
def handle(self, *args, **options):
1719
if settings.WORKFLOW_MANAGER_URL:
18-
timestamp = time.time()
19-
task_id = uuid.uuid4().hex
20+
start_time, timestamp, task_id = timezone.now(), time.time(), uuid.uuid4().hex
2021
logger.info(f"pushing {task_id} resources to workflow_manager when {timezone.now()}")
2122
resource_list = []
2223
for resource in Resource.objects.filter(status="Ready"):
2324
resource_list.extend(resource.to_usages(timestamp))
2425
if len(resource_list) % 1000 == 0:
25-
send_usage.delay(resource_list)
26+
send_usage.apply_async(
27+
args=(resource_list,),
28+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
29+
)
2630
resource_list = []
2731
if len(resource_list) > 0:
28-
send_usage.delay(resource_list)
32+
send_usage.apply_async(
33+
args=(resource_list,),
34+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
35+
)
2936
logger.info(f"pushed {task_id} resources to workflow_manager when {timezone.now()}")
3037
self.stdout.write("done")

rootfs/api/management/commands/upload_volume_usage.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import uuid
22
import time
33
import logging
4+
import random
5+
from datetime import timedelta
46
from django.utils import timezone
57
from django.core.management.base import BaseCommand
68
from django.conf import settings
@@ -15,16 +17,21 @@ class Command(BaseCommand):
1517

1618
def handle(self, *args, **options):
1719
if settings.WORKFLOW_MANAGER_URL:
18-
timestamp = time.time()
19-
task_id = uuid.uuid4().hex
20-
logger.info(f"pushing {task_id} volumes to workflow_manager when {timezone.now()}")
20+
start_time, timestamp, task_id = timezone.now(), time.time(), uuid.uuid4().hex
21+
logger.info(f"pushing {task_id} volumes to workflow_manager when {start_time}")
2122
volume_list = []
2223
for volume in Volume.objects.all():
2324
volume_list.extend(volume.to_usages(timestamp))
2425
if len(volume_list) % 1000 == 0:
25-
send_usage.delay(volume_list)
26+
send_usage.apply_async(
27+
args=(volume_list,),
28+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
29+
)
2630
volume_list = []
2731
if len(volume_list) > 0:
28-
send_usage.delay(volume_list)
32+
send_usage.apply_async(
33+
args=(volume_list,),
34+
eta=start_time + timedelta(seconds=random.randint(1, 1800))
35+
)
2936
logger.info(f"pushed {task_id} volumes to workflow_manager when {timezone.now()}")
3037
self.stdout.write("done")

0 commit comments

Comments
 (0)