Skip to content

Commit f7db3e0

Browse files
committed
chore(usage): add identifier field
1 parent 106b321 commit f7db3e0

10 files changed

Lines changed: 83 additions & 29 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ spec:
4747
{{- end }}
4848
{{- include "controller.envs" . | indent 12 }}
4949
{{- include "controller-job.envs" . | indent 12 }}
50+
volumeMounts:
51+
- name: controller-config
52+
readOnly: false
53+
mountPath: /etc/controller
5054
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
5155
imagePullPolicy: {{.Values.imagePullPolicy}}
5256
name: drycc-controller-load-db-state-to-k8s
@@ -61,3 +65,11 @@ spec:
6165
{{- end }}
6266
{{- include "controller.envs" . | indent 12 }}
6367
{{- include "controller-job.envs" . | indent 12 }}
68+
volumeMounts:
69+
- name: controller-config
70+
readOnly: false
71+
mountPath: /etc/controller
72+
volumes:
73+
- name: controller-config
74+
configMap:
75+
name: controller-config

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ spec:
4949
{{- end }}
5050
{{- include "controller.envs" . | indent 12 }}
5151
{{- include "controller-job.envs" . | indent 12 }}
52+
volumeMounts:
53+
- name: controller-config
54+
readOnly: false
55+
mountPath: /etc/controller
5256
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
5357
imagePullPolicy: {{.Values.pull_policy}}
5458
name: drycc-controller-upload-gateway-usage
@@ -63,6 +67,10 @@ spec:
6367
{{- end }}
6468
{{- include "controller.envs" . | indent 12 }}
6569
{{- include "controller-job.envs" . | indent 12 }}
70+
volumeMounts:
71+
- name: controller-config
72+
readOnly: false
73+
mountPath: /etc/controller
6674
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
6775
imagePullPolicy: {{.Values.pull_policy}}
6876
name: drycc-controller-upload-app-usage
@@ -77,6 +85,10 @@ spec:
7785
{{- end }}
7886
{{- include "controller.envs" . | indent 12 }}
7987
{{- include "controller-job.envs" . | indent 12 }}
88+
volumeMounts:
89+
- name: controller-config
90+
readOnly: false
91+
mountPath: /etc/controller
8092
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
8193
imagePullPolicy: {{.Values.pull_policy}}
8294
name: drycc-controller-upload-resources-usage
@@ -91,6 +103,10 @@ spec:
91103
{{- end }}
92104
{{- include "controller.envs" . | indent 12 }}
93105
{{- include "controller-job.envs" . | indent 12 }}
106+
volumeMounts:
107+
- name: controller-config
108+
readOnly: false
109+
mountPath: /etc/controller
94110
- image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/controller:{{.Values.imageTag}}
95111
imagePullPolicy: {{.Values.pull_policy}}
96112
name: drycc-controller-upload-volume-usage
@@ -105,3 +121,11 @@ spec:
105121
{{- end }}
106122
{{- include "controller.envs" . | indent 12 }}
107123
{{- include "controller-job.envs" . | indent 12 }}
124+
volumeMounts:
125+
- name: controller-config
126+
readOnly: false
127+
mountPath: /etc/controller
128+
volumes:
129+
- name: controller-config
130+
configMap:
131+
name: controller-config

rootfs/api/management/commands/upload_app_usage.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import uuid
2-
import time
32
import logging
43
import random
54
from datetime import timedelta
@@ -17,21 +16,24 @@ class Command(BaseCommand):
1716

1817
def handle(self, *args, **options):
1918
if settings.WORKFLOW_MANAGER_URL:
20-
start_time, timestamp, task_id = timezone.now(), int(time.time()), uuid.uuid4().hex
21-
logger.info(f"pushing {task_id} resources to workflow_manager when {timezone.now()}")
19+
now = timezone.now()
20+
start_time, timestamp, task_id = now, int(now.timestamp()), uuid.uuid4().hex
21+
logger.info(f"pushing {task_id} resources to workflow_manager when {now}")
2222
app_list = []
2323
for app in App.objects.all():
2424
app_list.extend(app.to_usages(timestamp))
2525
if len(app_list) % 1000 == 0:
26+
logger.info(f"bulk sent: {len(app_list)}")
2627
send_usage.apply_async(
2728
args=(app_list,),
28-
eta=start_time + timedelta(seconds=random.randint(1, 1800))
29+
eta=start_time + timedelta(seconds=random.randint(1, 3600))
2930
)
3031
app_list = []
3132
if len(app_list) > 0:
33+
logger.info(f"bulk sent: {len(app_list)}")
3234
send_usage.apply_async(
3335
args=(app_list,),
34-
eta=start_time + timedelta(seconds=random.randint(1, 1800))
36+
eta=start_time + timedelta(seconds=random.randint(1, 3600))
3537
)
3638
logger.info(f"pushed {task_id} resources to workflow_manager when {timezone.now()}")
3739
self.stdout.write("done")

rootfs/api/management/commands/upload_gateway_usage.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import uuid
2-
import time
32
import logging
43
import random
54
from datetime import timedelta
@@ -17,21 +16,24 @@ class Command(BaseCommand):
1716

1817
def handle(self, *args, **options):
1918
if settings.WORKFLOW_MANAGER_URL:
20-
start_time, timestamp, task_id = timezone.now(), int(time.time()), uuid.uuid4().hex
21-
logger.info(f"pushing {task_id} gateways to workflow_manager when {timezone.now()}")
19+
now = timezone.now()
20+
start_time, timestamp, task_id = now, int(now.timestamp()), uuid.uuid4().hex
21+
logger.info(f"pushing {task_id} gateways to workflow_manager when {now}")
2222
gateway_list = []
2323
for gateway in Gateway.objects.all():
2424
gateway_list.extend(gateway.to_usages(timestamp))
2525
if len(gateway_list) % 1000 == 0:
26+
logger.info(f"bulk sent: {len(gateway_list)}")
2627
send_usage.apply_async(
2728
args=(gateway_list,),
28-
eta=start_time + timedelta(seconds=random.randint(1, 1800))
29+
eta=start_time + timedelta(seconds=random.randint(1, 3600))
2930
)
3031
gateway_list = []
3132
if len(gateway_list) > 0:
33+
logger.info(f"bulk sent: {len(gateway_list)}")
3234
send_usage.apply_async(
3335
args=(gateway_list,),
34-
eta=start_time + timedelta(seconds=random.randint(1, 1800))
36+
eta=start_time + timedelta(seconds=random.randint(1, 3600))
3537
)
3638
logger.info(f"pushed {task_id} gateways to workflow_manager when {timezone.now()}")
3739
self.stdout.write("done")

rootfs/api/management/commands/upload_network_usage.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid
2-
import time
2+
import hashlib
33
import logging
44
import random
55
from datetime import timedelta
@@ -24,6 +24,7 @@ def _upload_network_usage(self, start_time, app_map, timestamp):
2424
for item in async_to_sync(monitor.query_network_usage)(app_map.keys(), start, stop):
2525
metric = item["metric"]
2626
_, value = item["value"]
27+
pod_name = metric['pod']
2728
networks.append({
2829
"app_id": str(app_map[metric['namespace']].uuid),
2930
"owner": app_map[metric['namespace']].owner_id,
@@ -32,18 +33,21 @@ def _upload_network_usage(self, start_time, app_map, timestamp):
3233
"name": metric['direction'],
3334
"usage": value,
3435
"kwargs": {
35-
"pod": metric['pod'],
36+
"pod": pod_name,
3637
},
37-
"timestamp": start
38+
"timestamp": start,
39+
"identifier": hashlib.md5(pod_name.encode("utf-8")).hexdigest(),
3840
})
41+
logger.info(f"bulk sent: {len(networks)}")
3942
send_usage.apply_async(
40-
args=(networks,), eta=start_time + timedelta(seconds=random.randint(1, 1800))
43+
args=(networks,), eta=start_time + timedelta(seconds=random.randint(1, 3600))
4144
)
4245

4346
def handle(self, *args, **options):
4447
if settings.WORKFLOW_MANAGER_URL:
45-
start_time, timestamp, task_id = timezone.now(), int(time.time()), uuid.uuid4().hex
46-
logger.info(f"pushing {task_id} networks to workflow_manager when {timezone.now()}")
48+
now = timezone.now()
49+
start_time, timestamp, task_id = now, int(now.timestamp()), uuid.uuid4().hex
50+
logger.info(f"pushing {task_id} networks to workflow_manager when {now}")
4751
app_map = {}
4852
for app in App.objects.all():
4953
app_map[app.id] = app

rootfs/api/management/commands/upload_resource_usage.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import uuid
2-
import time
32
import logging
43
import random
54
from datetime import timedelta
@@ -17,21 +16,24 @@ class Command(BaseCommand):
1716

1817
def handle(self, *args, **options):
1918
if settings.WORKFLOW_MANAGER_URL:
20-
start_time, timestamp, task_id = timezone.now(), time.time(), uuid.uuid4().hex
21-
logger.info(f"pushing {task_id} resources to workflow_manager when {timezone.now()}")
19+
now = timezone.now()
20+
start_time, timestamp, task_id = now, int(now.timestamp()), uuid.uuid4().hex
21+
logger.info(f"pushing {task_id} resources to workflow_manager when {now}")
2222
resource_list = []
2323
for resource in Resource.objects.filter(status="Ready"):
2424
resource_list.extend(resource.to_usages(timestamp))
2525
if len(resource_list) % 1000 == 0:
26+
logger.info(f"bulk sent: {len(resource_list)}")
2627
send_usage.apply_async(
2728
args=(resource_list,),
28-
eta=start_time + timedelta(seconds=random.randint(1, 1800))
29+
eta=start_time + timedelta(seconds=random.randint(1, 3600))
2930
)
3031
resource_list = []
3132
if len(resource_list) > 0:
33+
logger.info(f"bulk sent: {len(resource_list)}")
3234
send_usage.apply_async(
3335
args=(resource_list,),
34-
eta=start_time + timedelta(seconds=random.randint(1, 1800))
36+
eta=start_time + timedelta(seconds=random.randint(1, 3600))
3537
)
3638
logger.info(f"pushed {task_id} resources to workflow_manager when {timezone.now()}")
3739
self.stdout.write("done")

rootfs/api/management/commands/upload_volume_usage.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid
2-
import time
2+
import hashlib
33
import logging
44
import random
55
from datetime import timedelta
@@ -24,6 +24,7 @@ def _upload_volume_usage(self, start_time, app_map, timestamp):
2424
for item in async_to_sync(monitor.query_volume_usage)(app_map.keys(), start, stop):
2525
metric = item["metric"]
2626
_, value = item["value"]
27+
pvc_name = metric['persistentvolumeclaim']
2728
volumes.append({
2829
"app_id": str(app_map[metric['namespace']].uuid),
2930
"owner": app_map[metric['namespace']].owner_id,
@@ -32,18 +33,21 @@ def _upload_volume_usage(self, start_time, app_map, timestamp):
3233
"name": metric["storageclass"],
3334
"usage": value,
3435
"kwargs": {
35-
"persistentvolumeclaim": metric['persistentvolumeclaim'],
36+
"persistentvolumeclaim": pvc_name,
3637
},
37-
"timestamp": start
38+
"timestamp": start,
39+
"identifier": hashlib.md5(pvc_name.encode("utf-8")).hexdigest(),
3840
})
41+
logger.info(f"bulk sent: {len(volumes)}")
3942
send_usage.apply_async(
40-
args=(volumes,), eta=start_time + timedelta(seconds=random.randint(1, 1800))
43+
args=(volumes,), eta=start_time + timedelta(seconds=random.randint(1, 3600))
4144
)
4245

4346
def handle(self, *args, **options):
4447
if settings.WORKFLOW_MANAGER_URL:
45-
start_time, timestamp, task_id = timezone.now(), int(time.time()), uuid.uuid4().hex
46-
logger.info(f"pushing {task_id} volumes to workflow_manager when {timezone.now()}")
48+
now = timezone.now()
49+
start_time, timestamp, task_id = now, int(now.timestamp()), uuid.uuid4().hex
50+
logger.info(f"pushing {task_id} volumes to workflow_manager when {now}")
4751
app_map = {}
4852
for app in App.objects.all():
4953
app_map[app.id] = app

rootfs/api/models/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ def to_usages(self, timestamp: float):
741741
"ptype": ptype,
742742
},
743743
"timestamp": int(timestamp),
744+
"identifier": self.uuid.hex,
744745
})
745746
return usage
746747

rootfs/api/models/gateway.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import hashlib
23
import threading
34
from django.db import models
45
from django.conf import settings
@@ -153,7 +154,8 @@ def to_usages(self, timestamp: float):
153154
"kwargs": {
154155
"name": self.name,
155156
},
156-
"timestamp": int(timestamp)
157+
"timestamp": int(timestamp),
158+
"identifier": hashlib.md5(self.name.encode("utf-8")).hexdigest(),
157159
}]
158160

159161
def _check_port(self, port, protocol):

rootfs/api/models/resource.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def to_usages(self, timestamp: float):
218218
"kwargs": {
219219
"name": self.name,
220220
},
221-
"timestamp": int(timestamp)
221+
"timestamp": int(timestamp),
222+
"identifier": self.uuid.hex,
222223
}]
223224

224225
def _retrieve_status(self):

0 commit comments

Comments
 (0)