Skip to content

Commit 9c7468a

Browse files
committed
chore(gateway): change loadbalancer to gateway measure
1 parent 7cc04fc commit 9c7468a

5 files changed

Lines changed: 46 additions & 78 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ spec:
5959
args:
6060
- /bin/bash
6161
- -c
62-
- python -u /workspace/manage.py measure_loadbalancers
62+
- python -u /workspace/manage.py measure_gateway
6363
{{- end }}
6464
{{- include "controller.envs" . | indent 12 }}
65-
{{- include "controller-job.envs" . | indent 12 }}
65+
{{- include "controller-job.envs" . | indent 12 }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import uuid
2+
import time
3+
import logging
4+
from django.utils import timezone
5+
from django.core.management.base import BaseCommand
6+
from django.conf import settings
7+
from api.models.gateway import Gateway
8+
from api.tasks import send_measurements
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
class Command(BaseCommand):
14+
"""Management command for push data to manager"""
15+
16+
def handle(self, *args, **options):
17+
if settings.WORKFLOW_MANAGER_URL:
18+
timestamp = time.time()
19+
task_id = uuid.uuid4().hex
20+
logger.info(f"pushing {task_id} gateways to workflow_manager when {timezone.now()}")
21+
gateway_list = []
22+
for gateway in Gateway.objects.all():
23+
gateway_list.extend(gateway.to_measurements(timestamp))
24+
if len(gateway_list) % 1000 == 0:
25+
send_measurements.delay(gateway_list)
26+
gateway_list = []
27+
if len(gateway_list) > 0:
28+
send_measurements.delay(gateway_list)
29+
logger.info(f"pushed {task_id} gateways to workflow_manager when {timezone.now()}")
30+
self.stdout.write("done")

rootfs/api/management/commands/measure_loadbalancers.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

rootfs/api/models/gateway.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ def delete(self, *args, **kwargs):
142142
)
143143
return super().delete(*args, **kwargs)
144144

145+
def to_measurements(self, timestamp: float):
146+
return [{
147+
"app_id": str(self.app_id),
148+
"owner": self.owner_id,
149+
"name": settings.DRYCC_APP_GATEWAY_CLASS,
150+
"type": "gateway",
151+
"unit": "number",
152+
"usage": 1,
153+
"kwargs": {
154+
"name": self.name,
155+
},
156+
"timestamp": int(timestamp)
157+
}]
158+
145159
def _check_port(self, port, protocol):
146160
for item in self.ports:
147161
if item["port"] == port:

rootfs/api/monitor.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
last_over_time({__name__=~"%s",namespace="%s"}[%s])
1010
"""
1111

12-
query_loadbalancer_promql_tpl = """
13-
kube_service_status_load_balancer_ingress{namespace=~"%s"}
14-
"""
15-
1612
query_network_receive_flow_promql_tpl = """
1713
increase(container_network_receive_bytes_total{namespace=~"%s"}[%s])
1814
"""
@@ -74,13 +70,6 @@ async def last_metrics(namespace) -> AsyncGenerator[Iterator, str]:
7470
)
7571

7672

77-
async def query_loadbalancer(namespaces: Iterator[str], start: int, stop: int
78-
) -> list[tuple[dict[str, str], int]]:
79-
url = urljoin(settings.DRYCC_VICTORIAMETRICS_URL, "/select/0/prometheus/api/v1/query")
80-
promql = query_loadbalancer_promql_tpl % "|".join(namespaces)
81-
return await query_prom(url, {"query": promql, "start": start, "end": stop})
82-
83-
8473
async def query_network_receive_flow(namespaces: Iterator[str], start: int, stop: int
8574
) -> list[tuple[dict[str, str], int]]:
8675
url = urljoin(settings.DRYCC_VICTORIAMETRICS_URL, "/select/0/prometheus/api/v1/query")

0 commit comments

Comments
 (0)