Skip to content

Commit

Permalink
Merge branch 'upstreamMaster'
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrocjdpereira committed Sep 30, 2024
2 parents 2c00291 + 8a8b06a commit 33e63fb
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 117 deletions.
34 changes: 27 additions & 7 deletions cfs-portal/src/components/InstanceGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
setMetrics((prevMetrics) => {
console.log(data)
console.log(prevMetrics)
if(data.appi_id != undefined){
if(data.appi_id !== undefined){
if(!prevMetrics){
prevMetrics = {}
}
if (!(data.appi_id in prevMetrics)){
prevMetrics[data.appi_id] = {}
}
if (data.mem_load != undefined && data.cpu_load != undefined) {
if (data.mem_load !== undefined && data.cpu_load !== undefined && data.warning !== undefined) {
return {
...prevMetrics,
[data.appi_id]: {
...prevMetrics[data.appi_id],
memLoad: data.mem_load,
cpuLoad: data.cpu_load,
warning: data.warning,
}
};
}
Expand Down Expand Up @@ -170,7 +170,7 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp
const node = metrics && metrics[params.row.id as string]?.node;
return (
<Box sx={{ position: 'relative', width: '100%' }}>
{node != undefined ? (
{node !== undefined ? (
<>
<Typography
variant="body2"
Expand All @@ -195,7 +195,7 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp
const lat = metrics && metrics[params.row.id as string]?.lat;
return (
<Box sx={{ position: 'relative', width: '100%' }}>
{lat != undefined ? (
{lat !== undefined ? (
<>
<LinearProgress
variant="determinate"
Expand Down Expand Up @@ -237,7 +237,7 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp

return (
<Box sx={{ position: 'relative', width: '100%' }}>
{memLoad != undefined ? (
{memLoad !== undefined ? (
<>
<LinearProgress
variant="determinate"
Expand Down Expand Up @@ -279,7 +279,7 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp

return (
<Box sx={{ position: 'relative', width: '100%' }}>
{cpuLoad != undefined ? (
{cpuLoad !== undefined ? (
<>
<LinearProgress
variant="determinate"
Expand Down Expand Up @@ -337,8 +337,28 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp
field: 'config-status',
headerName: 'Config Status',
width: 100,
headerAlign: 'center',
renderCell: (params: any) => renderConfigStatus(params.row['config-status'] as ConfigStatus)
}],
...minimalConfig ? [] : [{
field: 'warnings',
headerName: '',
width: 100,
renderCell: (params: any) => {
const warning = metrics && metrics[params.row.id as string]?.warning;

if (warning !== undefined && warning !== null) {
return (
<Tooltip title={warning}>
<Box display="flex" alignItems="center" justifyContent="center">
{renderOperationalStatus(OperationalStatus.FAILED)}
</Box>
</Tooltip>
);
}

}
}],
...minimalConfig ? [] : [{
field: 'actions',
headerName: '',
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ services:
depends_on:
- mongo
environment:
- OSM_HOSTNAME=10.255.32.88:9999
- OSM_HOSTNAME=nbi.10.255.32.132.nip.io
- OSS_PORT=8080
- OSS_WS_PORT=8001
- KAFKA_BOOTSTRAP_SERVERS=10.255.32.88:9999:14000
- KAFKA_BOOTSTRAP_SERVERS=10.255.32.132:31999
- MONGO_USER=root
- MONGO_PASSWORD=pass
restart: on-failure
Expand All @@ -42,8 +42,8 @@ services:
# - zookeeper
- mongo
environment:
- OSM_HOSTNAME=10.255.32.88:9999
- KAFKA_BOOTSTRAP_SERVERS=10.255.32.88:9999:14000
- OSM_HOSTNAME=nbi.10.255.32.132.nip.io
- KAFKA_BOOTSTRAP_SERVERS=10.255.32.132:31999
- MONGO_USER=root
- MONGO_PASSWORD=pass
restart: on-failure
Expand Down
8 changes: 5 additions & 3 deletions oss/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from utils.kafka.callbacks.error_handler import callback as error_handler
from utils.kafka.callbacks.get_metrics import callback as get_metrics
from utils.kafka.callbacks.get_latency import callback as get_latency
from utils.threads import (ContainerInfoThread, KafkaConsumerThread,
WebSocketServiceThread)
from utils.kafka.callbacks.get_container_info import callback as get_container_info
from utils.threads import (KafkaConsumerThread,
WebSocketServiceThread, SendMECAppsThread)


def main():
Expand All @@ -17,8 +18,9 @@ def main():
KafkaConsumerThread(cherrypy.engine, "responses", error_handler).subscribe()
KafkaConsumerThread(cherrypy.engine, "k8s-cluster", get_metrics).subscribe()
KafkaConsumerThread(cherrypy.engine, "ue-lat", get_latency).subscribe()
ContainerInfoThread(cherrypy.engine).subscribe()
KafkaConsumerThread(cherrypy.engine, "meao-oss", get_container_info).subscribe()
WebSocketServiceThread(cherrypy.engine).subscribe()
SendMECAppsThread(cherrypy.engine).subscribe()

dispatcher = set_routes()

Expand Down
42 changes: 0 additions & 42 deletions oss/utils/container_info_thread.py

This file was deleted.

49 changes: 49 additions & 0 deletions oss/utils/kafka/callbacks/get_container_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import time
from ...threads.mec_apps_thread import containers
from ...threads.websocket_service_thread import lat_queue


def callback(data):
if "containerInfo" in data and "nodeSpecs" in data:
idsMonitored = []
for containerName, container in data["containerInfo"].items():
idsMonitored.append(containerName)
node_specs = data["nodeSpecs"]
if containerName not in containers:
containers[containerName] = {
"ns": container["ns_id"],
"node": container["node"],
"node_specs": node_specs[container["node"]],
}
containers[containerName]["node_specs"]["prev_cpu"] = 0
containers[containerName]["node_specs"]["prev_timestamp"] = 0
idsToDelete = []
for container_id in containers.keys():
if container_id not in idsMonitored:
idsToDelete.append(container_id)
for id in idsToDelete:
del containers[id]

elif "warning" in data:
current_time = time.time()

warning = data["warning"]
container_name = warning["containerName"]

if container_name in containers:
containers[container_name]["warning"] = {
"msg": warning["msg"],
"timer": current_time
}

for container_name, container in containers.items():
if "warning" not in container:
container["warning"] = {
"msg": None,
"timer": None,
}
elif container["warning"] and container["warning"]["timer"]:
current_time = time.time()
if current_time - container["warning"]["timer"] > 60:
container["warning"]["timer"] = None
container["warning"]["msg"] = None
6 changes: 2 additions & 4 deletions oss/utils/kafka/callbacks/get_latency.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from ...threads.container_info_thread import containers
from ...threads.mec_apps_thread import containers
from ...threads.websocket_service_thread import lat_queue


def callback(data):
print(containers.keys())
for container_id in containers.keys():
temp_data = {
"k3s-worker1-pedrocjdpereira": data["k3s-worker1-pedrocjdpereira"],
"k3s-worker2-pedrocjdpereira": data["k3s-worker2-pedrocjdpereira"],
}
temp_data["node"] = containers[container_id]["node"]
temp_data["appi_id"] = containers[container_id]["ns"]
lat_queue.put(temp_data)
print(temp_data)
lat_queue.put(temp_data)
3 changes: 2 additions & 1 deletion oss/utils/kafka/callbacks/get_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ...threads.container_info_thread import containers
from ...threads.mec_apps_thread import containers
from ...threads.websocket_service_thread import metrics_queue


Expand All @@ -12,6 +12,7 @@ def callback(data):
"appi_id": appi_id,
"mem_load": get_mem_load(data, node_specs),
"cpu_load": get_cpu_load(data, node_specs, container_id),
"warning" : containers[container_id]["warning"]["msg"],
}

metrics_queue.put(metrics)
Expand Down
2 changes: 1 addition & 1 deletion oss/utils/kafka/get_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..container_info_thread import containers
from ..threads.mec_apps_thread import containers


def callback(data):
Expand Down
2 changes: 1 addition & 1 deletion oss/utils/threads/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .container_info_thread import ContainerInfoThread
from .kafka_consumer_thread import KafkaConsumerThread
from .websocket_service_thread import WebSocketServiceThread
from .mec_apps_thread import SendMECAppsThread
54 changes: 0 additions & 54 deletions oss/utils/threads/container_info_thread.py

This file was deleted.

42 changes: 42 additions & 0 deletions oss/utils/threads/mec_apps_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import threading
import time
import json

from cherrypy.process import plugins

from utils.db import DB
from utils.kafka import KafkaUtils, producer

containers = {}

class SendMECAppsThread(plugins.SimplePlugin):
"""Background thread that sends MEC Apps information"""

def __init__(self, bus):
super().__init__(bus)
self.t = None

def start(self):
"""Plugin entrypoint"""
self.t = threading.Thread(target=send_mec_apps)
self.t.daemon = True
self.t.start()


def send_mec_apps():
while True:
try:
mec_apps = DB._list("appis")
for mec_app in mec_apps:
if '_id' in mec_app:
mec_app['_id'] = str(mec_app['_id'])

KafkaUtils.send_message(
producer,
"meao-oss",
{"mec_apps": mec_apps},
)

time.sleep(5)
except Exception as e:
raise e

0 comments on commit 33e63fb

Please sign in to comment.