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 2 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
32 changes: 32 additions & 0 deletions src/krkn_lib/models/telemetry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,32 @@ def __init__(self, k8s_json_dict: any = None, json_dict: any = None):
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 to_json(self) -> str:
return json.dumps(self, default=lambda o: o.__dict__, indent=4)

@dataclass(order=False)
class ChaosRunTelemetry:
Expand Down Expand Up @@ -369,6 +395,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 @@ -405,6 +435,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 @@ -426,6 +457,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see here you added to the test the sloalert data structure, and that's fine, but you didn't test that it is correctly deserialized in the telemetry object through assertions. you should assert that slo_alert len is 2 and that sloalert[0].timestamp == 2024-10-23T15:25:47 and asloalert[0].severity == "high" etc.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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