Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SLOs alert to chaos summary output [Telemetry] #136

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions src/krkn_lib/models/telemetry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,38 @@ def __init__(
def to_json(self) -> str:
return json.dumps(self, default=lambda o: o.__dict__, indent=4)

@dataclass(order=False)
class SloAlert:
"""
Represents alerts collected from prometheus
"""

timestamp: int
"""
prometheus alert name
"""
severity: str
"""
severity of the alert
"""
description: str
"""
description of the alert
"""

# def __init__(self, timestamp: int, severity: str, description: str):
# self.timestamp = timestamp
# self.severity = severity
# self.description = description

def __init__(self, json_list: list = None):
if json_list is not None:
self.timestamp = json_list[0] if len(json_list) > 0 else None
self.severity = json_list[1] if len(json_list) > 1 else None
self.description = json_list[2] if len(json_list) > 2 else None

def to_json(self) -> str:
return json.dumps(self, default=lambda o: o.__dict__, indent=4)

@dataclass(order=False)
class ChaosRunTelemetry:
Expand Down Expand Up @@ -391,6 +423,10 @@ class ChaosRunTelemetry:
"""
Network plugins deployed in the target cluster
"""
slo_alert: list[SloAlert]
"""
Alerts defined using SLOs firing during and after the chaos run
"""
total_node_count: int = 0
"""
Number of all kind of nodes in the target cluster
Expand Down Expand Up @@ -427,6 +463,7 @@ def __init__(self, json_dict: any = None):
self.timestamp = datetime.now(timezone.utc).strftime(
"%Y-%m-%dT%H:%M:%SZ"
)
self.slo_alert = list[SloAlert]()
if json_dict is not None:
scenarios = json_dict.get("scenarios")
if scenarios is None or isinstance(scenarios, list) is False:
Expand All @@ -448,6 +485,7 @@ def __init__(self, json_dict: any = None):
self.network_plugins = json_dict.get("network_plugins")
self.run_uuid = json_dict.get("run_uuid")
self.timestamp = json_dict.get("timestamp")
self.slo_alert = [SloAlert(a) for a in json_dict.get("slo_alert", [])]

def to_json(self) -> str:
return json.dumps(self, default=lambda o: o.__dict__, indent=4)
Expand Down
14 changes: 13 additions & 1 deletion src/krkn_lib/tests/test_krkn_telemetry_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ def test_scenario_telemetry(self):
"namespace":"failed-namespace"
}
]
}
},
"slo_alert": [
{
"timestamp": "2024-10-23T15:25:47Z",
"severity": "high",
"description": "API latency is too high"
},
{
"timestamp": "2024-10-23T15:30:47Z",
"severity": "medium",
"description": "Memory usage is high"
}
]
}
""" # NOQA
# wrong base64 format
Expand Down
Loading