Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/powerapi/processor/pre/k8s/monitor_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from dataclasses import dataclass
from multiprocessing import Process, Event
from signal import signal, SIGTERM, SIGINT
from time import sleep

from kubernetes import client, config, watch
from kubernetes.client import V1Pod, V1PodList, V1ContainerStatus
Expand Down Expand Up @@ -158,7 +157,9 @@ def run(self):
while not self._stop_monitoring.is_set():
resource_id = self.fetch_list_all_pod_for_all_namespaces(api_client)
self.watch_list_pod_for_all_namespaces(api_client, resource_id)
sleep(K8S_MONITOR_RETRY_DELAY_SECONDS)

if self._stop_monitoring.wait(K8S_MONITOR_RETRY_DELAY_SECONDS):
break

@staticmethod
def get_containers_id_name_from_statuses(container_statuses: list[V1ContainerStatus]) -> dict[str, str]:
Expand Down
8 changes: 4 additions & 4 deletions src/powerapi/processor/pre/openstack/monitor_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from dataclasses import dataclass
from multiprocessing import Process, Event
from signal import signal, SIGINT, SIGTERM
from time import sleep

from openstack.compute.v2.server import Server
from openstack.connection import Connection
Expand Down Expand Up @@ -88,7 +87,7 @@ def _setup_signal_handlers(self):
Setup signal handlers for the current Process.
"""
def stop_monitor(_, __):
self._stop_monitoring = True
self._stop_monitoring.set()
sys.exit(0)

signal(SIGTERM, stop_monitor)
Expand All @@ -104,11 +103,12 @@ def run(self):
# Prevents orphaned entries that no longer exist in the OpenStack API.
self.metadata_cache_manager.clear_metadata_cache()

while not self._stop_monitoring:
while not self._stop_monitoring.is_set():
for server in self.fetch_servers_metadata(openstack_api):
self.metadata_cache_manager.update_server_metadata(server)

sleep(self.config.polling_interval)
if self._stop_monitoring.wait(self.config.polling_interval):
break

@staticmethod
def build_metadata_cache_entry_from_server(server: Server) -> ServerMetadata:
Expand Down