Skip to content

Commit 0a09f27

Browse files
authored
Merge branch 'main' into log_dedup
2 parents 19cc0d4 + 6bb38d5 commit 0a09f27

4 files changed

Lines changed: 43 additions & 13 deletions

File tree

aiopslab/orchestrator/actions/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def get_logs(namespace: str, service: str) -> str:
7070
except Exception as e:
7171
return "Error: Your service/namespace does not exist. Use kubectl to check."
7272

73-
logs = "\n".join(logs.split("\n"))
7473
logs = greedy_compress_lines(logs)
7574
print(logs)
75+
7676
return logs
7777

7878
@staticmethod

aiopslab/service/helm.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""Interface for helm operations"""
55

66
import subprocess
7-
import time
87

98
from aiopslab.service.kubectl import KubeCtl
109

@@ -190,6 +189,36 @@ def add_repo(name: str, url: str):
190189
else:
191190
print(f"Helm repo {name} added successfully: {output.decode('utf-8')}")
192191

192+
@staticmethod
193+
def status(release_name: str, namespace: str) -> str:
194+
"""Get the status of a Helm release.
195+
196+
Args:
197+
release_name (str): Name of the release.
198+
namespace (str): Namespace of the release.
199+
200+
Returns:
201+
str: Status output from Helm.
202+
203+
Raises:
204+
ValueError: If either parameter is missing.
205+
Exception: If the helm status command fails.
206+
"""
207+
208+
if not release_name or not namespace:
209+
raise ValueError("Both release_name and namespace must be provided")
210+
211+
command = f"helm status {release_name} -n {namespace}"
212+
process = subprocess.Popen(
213+
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
214+
)
215+
output, error = process.communicate()
216+
217+
if process.returncode != 0:
218+
# helm status failed
219+
raise RuntimeError(f"Failed to get status for release {release_name}: {error.decode('utf-8')}")
220+
221+
return output.decode("utf-8").strip()
193222

194223
# Example usage
195224
if __name__ == "__main__":

aiopslab/service/telemetry/prometheus.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import json
66
import yaml
7-
import time
7+
import logging
88
from subprocess import CalledProcessError
99
from aiopslab.service.helm import Helm
1010
from aiopslab.service.kubectl import KubeCtl
@@ -121,18 +121,19 @@ def _pvc_exists(self, pvc_name: str) -> bool:
121121
if "No resources found" in result or "Error" in result:
122122
return False
123123
except CalledProcessError as e:
124+
logging.exception(f"Unexpected error while checking if the PersistentVolumeClaim exists: {e}")
124125
return False
125126
return True
126127

127128
def _is_prometheus_running(self) -> bool:
128-
"""Check if Prometheus is already running in the cluster."""
129-
command = (
130-
f"kubectl get pods -n {self.namespace} -l app.kubernetes.io/name=prometheus"
131-
)
129+
"""Check if Prometheus Helm release is deployed."""
132130
try:
133-
result = KubeCtl().exec_command(command)
134-
if "Running" in result:
135-
return True
136-
except CalledProcessError:
131+
status_output = Helm.status(**self.helm_configs)
132+
for line in status_output.splitlines():
133+
if line.strip().startswith("STATUS:"):
134+
status_value = line.split(":", 1)[1].strip().lower()
135+
return status_value == "deployed"
136+
return False
137+
except Exception as e:
138+
logging.exception(f"Unexpected error while checking Prometheus status: {e}")
137139
return False
138-
return False

clients/gpt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from clients.utils.llm import GPTClient
1616
from dotenv import load_dotenv
1717

18-
from parse_result import DOCS_SHELL_ONLY
18+
from clients.utils.templates import DOCS_SHELL_ONLY
1919

2020
# Load environment variables from the .env file
2121
load_dotenv()

0 commit comments

Comments
 (0)