Skip to content

Commit

Permalink
Avoid breaking if no errors are found
Browse files Browse the repository at this point in the history
  • Loading branch information
ycedres committed Oct 10, 2024
1 parent 5f681ed commit ba22374
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 47 deletions.
3 changes: 0 additions & 3 deletions health-check/src/uyuni_health_check/containers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ def build_image(name, image_path=None, build_args=[], verbose=False):
# podman_args,
)

if process.returncode != 0:
raise HealthException(f"Failed to build {name} image")


def image_exists(image):
"""
Expand Down
55 changes: 11 additions & 44 deletions health-check/src/uyuni_health_check/loki/logs_gatherer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,6 @@

conf = ConfigLoader()

def NO_show_full_error_logs(from_datetime=None, to_datetime=None, since=7, loki=None):
"""
Get and show the error logs
"""
print()
print(Markdown(f"- Getting error messages over the last {since} days..."))
#from_time = (datetime.utcnow() - timedelta(days=since)).isoformat()
#loki_url = loki or "http://uyuni_health_check_loki:3100"
loki_container_name = conf.global_config['loki']['loki_container_name']
loki_port = conf.global_config['loki']['loki_port']
loki_url = f"http://{loki_container_name}:{loki_port}"
podman(
[
"run",
"--rm",
"--replace",
"--network",
"health-check-network",
"--name",
"uyuni_health_check_logcli",
"logcli",
"query",
"--quiet",
"--output=jsonl",
f"--addr={loki_url}",
f"--from={from_datetime}",
f"--to={to_datetime}",
"--limit=150",
'{job=~".+"} |~ `(?i)error|(?i)severe|(?i)critical|(?i)fatal`',
],
quiet=False,
use_print=True,
)
print()

def show_full_error_logs(from_datetime, to_datetime, since, console: "Console", loki=None):
"""
Expand All @@ -54,21 +20,22 @@ def show_full_error_logs(from_datetime, to_datetime, since, console: "Console",
)
print()
query = f"{{job=~\".+\"}} |~ \"(?i)error|(?i)severe|(?i)critical|(?i)fatal\""

import pdb; pdb.set_trace;
stdout, stderr = query_loki(from_dt=from_datetime, to_dt=to_datetime, since = since, query=query)
lines = stdout.strip().split("\n")
json_objects = []

for line in lines:
try:
json_data = json.loads(line)
json_objects.append(json_data)
except json.JSONDecodeError as e:
console.print(f"[red]Failed to parse JSON:[/red] {e}")
console.print(f"[yellow]Raw output:[/yellow] {line}")
if len(lines[0]) != 0:
for line in lines:
try:
json_data = json.loads(line)
json_objects.append(json_data)
except json.JSONDecodeError as e:
console.print(f"[red]Failed to parse JSON:[/red] {e}")
console.print(f"[yellow]Raw output:[/yellow] {line}")

combined_json = json.dumps(json_objects, indent=4)
outputter.print_paginated_json(combined_json)
combined_json = json.dumps(json_objects, indent=4)
outputter.print_paginated_json(combined_json)


def show_error_logs_stats(from_datetime, to_datetime, since, console: "Console", loki=None):
Expand Down

0 comments on commit ba22374

Please sign in to comment.