Skip to content

Commit

Permalink
adding node id to affected node info
Browse files Browse the repository at this point in the history
Signed-off-by: Paige Patton <[email protected]>
  • Loading branch information
paigerube14 authored and chaitanyaenr committed Feb 4, 2025
1 parent 039c1e8 commit 0413bd8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/krkn_lib/models/elastic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ElasticPodsStatus(InnerDoc):

class ElasticAffectedNodes(InnerDoc):
node_name = Text(fields={"keyword": Keyword()})
node_id = Text()
not_ready_time = Float()
ready_time = Float()
stopped_time = Float()
Expand Down Expand Up @@ -178,6 +179,7 @@ def __init__(
affected_nodes=[
ElasticAffectedNodes(
node_name=node.node_name,
node_id=node.node_id,
not_ready_time=node.not_ready_time,
ready_time=node.ready_time,
stopped_time=node.stopped_time,
Expand Down
13 changes: 9 additions & 4 deletions src/krkn_lib/models/k8s/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ class AffectedNode:
"""
Name of the node
"""
node_id: str
"""
Id of the node
"""
ready_time: float
"""
Amount of time the node took to get to a ready state
Expand All @@ -265,6 +269,7 @@ class AffectedNode:
def __init__(
self,
node_name: str = "",
node_id: str = "",
not_ready_time: float = 0,
ready_time: float = 0,
stopped_time: float = 0,
Expand All @@ -273,23 +278,23 @@ def __init__(
json_object: str = None,
):
self.node_name = node_name
self.node_id = node_id
self.not_ready_time = float(not_ready_time)
self.ready_time = float(ready_time)
self.stopped_time = float(stopped_time)
self.running_time = float(running_time)
self.terminating_time = float(terminating_time)

if json_object:
print("json object" + str(json_object))
self.node_name = json_object["node_name"]
self.node_id = json_object["node_id"]
self.set_not_ready_time(json_object["not_ready_time"])
self.set_ready_time(json_object["ready_time"])
self.set_cloud_stopping_time(json_object["stopped_time"])
self.set_cloud_running_time(json_object["running_time"])
self.set_terminating_time(json_object["terminating_time"])

def set_affected_node_status(self, status: str, total_time: float):
print("affected node status" + str(status))
if status == "Unknown":
self.set_not_ready_time(total_time)
elif status == "True":
Expand Down Expand Up @@ -355,11 +360,11 @@ def merge_affected_nodes(self):
for item in reversed(match_found):
self.affected_nodes.pop(item)

def get_affected_node_index(self, node_name):
def get_affected_node_index(self, node_id):
counter = 0

for affected_node in self.affected_nodes:
if affected_node.node_name == node_name:
if affected_node.node_id == node_id:
return self.affected_nodes[counter]
counter += 1

Expand Down
1 change: 1 addition & 0 deletions src/krkn_lib/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ def get_ChaosRunTelemetry_json(self, run_uuid: str) -> dict:
"affected_nodes": [
{
"node_name": "kind-control-plane",
"node_id": "test",
"ready_time": 2.71,
"not_ready_time": 3.14,
"stopped_time": 0,
Expand Down
7 changes: 7 additions & 0 deletions src/krkn_lib/tests/test_krkn_elastic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def check_test_ElasticChaosRunTelemetry(
"kind-control-plane",
)

self.assertEqual(
elastic_telemetry.scenarios[0]
.affected_nodes[0]
.node_id,
"test",
)

self.assertEqual(
elastic_telemetry.scenarios[0]
.affected_nodes[0].ready_time,
Expand Down
13 changes: 13 additions & 0 deletions src/krkn_lib/tests/test_krkn_telemetry_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_scenario_telemetry(self):
"affected_nodes":[
{
"node_name":"kind-control-plane",
"node_id":"test",
"ready_time":2.71,
"not_ready_time":3.14,
"stopped_time":0.0,
Expand Down Expand Up @@ -114,6 +115,18 @@ def test_scenario_telemetry(self):
self.assertIsNone(unrecovered.pod_readiness_time)
self.assertIsNone(unrecovered.pod_rescheduling_time)
self.assertIsNone(unrecovered.total_recovery_time)

self.assertEqual(len(telemetry.affected_nodes), 1)

self.assertEqual((telemetry.affected_nodes[0].node_id), "test")
self.assertEqual((telemetry.affected_nodes[0].node_name), "kind-control-plane")

self.assertEqual((telemetry.affected_nodes[0].not_ready_time), 3.14)
self.assertEqual((telemetry.affected_nodes[0].ready_time), 2.71)
self.assertEqual((telemetry.affected_nodes[0].running_time), 0)
self.assertEqual((telemetry.affected_nodes[0].stopped_time), 0)
self.assertEqual((telemetry.affected_nodes[0].terminating_time), 0)

self.assertIsNotNone(telemetry.parameters)
self.assertEqual(telemetry.parameters_base64, "")
self.assertEqual(telemetry.parameters["property"]["unit"], "unit")
Expand Down

0 comments on commit 0413bd8

Please sign in to comment.