Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gu <[email protected]>
  • Loading branch information
tylergu committed Nov 21, 2023
1 parent c9afc74 commit 30a6442
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions performance_measurement/metrics_api_watcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
import time
from typing import List

import kubernetes
Expand Down Expand Up @@ -28,15 +29,13 @@ def write_stats(self, stats_buf: List[dict], sequence: int):
def start(self, apiclient: ApiClient, operator_name: str, ):
stats_buf: List[dict] = []
custom_api = kubernetes.client.CustomObjectsApi(apiclient)
watch = kubernetes.watch.Watch()

stream = watch.stream(func=custom_api.list_cluster_custom_object,
group="metrics.k8s.io",
version="v1beta1",
plural="pods",)
for stats in stream:
while True:
if self._stop:
break
stats = custom_api.list_cluster_custom_object(group="metrics.k8s.io",
version="v1beta1",
plural="pods",)
pod_metrics = {}
for pod in stats['items']:
pod_name = pod['metadata']['name']
Expand All @@ -52,10 +51,11 @@ def start(self, apiclient: ApiClient, operator_name: str, ):
self.write_stats(stats_buf, self._sequence)
stats_buf = []
self._sequence += 1
if len(stats_buf) > 0:
logging.info(f"Stopped, Writing {len(stats_buf)} stats to file")
self.write_stats(stats_buf, self._sequence)
self._sequence += 1
time.sleep(1)
if len(stats_buf) > 0:
logging.info(f"Stopped, Writing {len(stats_buf)} stats to file")
self.write_stats(stats_buf, self._sequence)
self._sequence += 1
return

def stop(self):
Expand Down

0 comments on commit 30a6442

Please sign in to comment.