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

[IMPORTANT] Refactoring, Krkn Scenario Plugin API introduction #123

Merged
merged 2 commits into from
Oct 3, 2024
Merged
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
12 changes: 6 additions & 6 deletions src/krkn_lib/k8s/krkn_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2143,19 +2143,19 @@ def get_nodes_infos(self) -> (list[NodeInfo], list[Taint]):
node_info.instance_type = "unknown"

if node_type_infra_label in node.metadata.labels.keys():
node_info.nodes_type= "infra"
node_info.nodes_type = "infra"
elif node_type_worker_label in node.metadata.labels.keys():
node_info.nodes_type= "worker"
node_info.nodes_type = "worker"
elif node_type_master_label in node.metadata.labels.keys():
node_info.nodes_type= "master"
node_info.nodes_type = "master"
elif node_type_workload_label in node.metadata.labels.keys():
node_info.nodes_type= "workload"
node_info.nodes_type = "workload"
elif (
node_type_application_label in node.metadata.labels.keys()
):
node_info.nodes_type= "application"
node_info.nodes_type = "application"
else:
node_info.nodes_type= "unknown"
node_info.nodes_type = "unknown"

node_info.architecture = node.status.node_info.architecture
node_info.architecture = node.status.node_info.architecture
Expand Down
50 changes: 39 additions & 11 deletions src/krkn_lib/telemetry/k8s/krkn_telemetry_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,56 @@


class KrknTelemetryKubernetes:
kubecli: KrknKubernetes = None
__kubecli: KrknKubernetes = None
__krkn_telemetry_config: dict[str, any] = None
__telemetry_request_id: str = ""
safe_logger: SafeLogger = None
default_telemetry_group = "default"
krkn_telemetry_config: dict[str, any] = None

def __init__(
self,
safe_logger: SafeLogger,
lib_kubernetes: KrknKubernetes,
krkn_telemetry_config: dict[str, any] = None,
telemetry_request_id: str = "",
):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
urllib3.disable_warnings(DeprecationWarning)
warnings.filterwarnings(
action="ignore", message="unclosed", category=ResourceWarning
)
self.kubecli = lib_kubernetes
self.__kubecli = lib_kubernetes
self.safe_logger = safe_logger
self.__telemetry_request_id = telemetry_request_id
if not krkn_telemetry_config:
self.krkn_telemetry_config = {}
self.__krkn_telemetry_config = {}
else:
self.krkn_telemetry_config = krkn_telemetry_config
self.__krkn_telemetry_config = krkn_telemetry_config

def get_lib_kubernetes(self) -> KrknKubernetes:
"""
Returns the instance of KrknKubernetes

:return: a KrknKubernetes instance
"""
return self.__kubecli

def get_telemetry_config(self) -> dict[str, any]:
"""
Returns the telemetry config section from config.yaml

:return: the telemetry config section
"""
return self.__krkn_telemetry_config

def get_telemetry_request_id(self) -> str:
"""
Gets the telemetry request id that represents the path
on S3 where the telemetry data is uploaded

:return: the krkn telemetry id
"""
return self.__telemetry_request_id

def collect_cluster_metadata(self, chaos_telemetry: ChaosRunTelemetry):
"""
Expand All @@ -61,7 +89,7 @@ def collect_cluster_metadata(self, chaos_telemetry: ChaosRunTelemetry):
self.safe_logger.info("collecting telemetry data, please wait....")

chaos_telemetry.kubernetes_objects_count = (
self.kubecli.get_all_kubernetes_object_count(
self.__kubecli.get_all_kubernetes_object_count(
[
"Deployment",
"Pod",
Expand All @@ -72,9 +100,9 @@ def collect_cluster_metadata(self, chaos_telemetry: ChaosRunTelemetry):
]
)
)
node_infos, taints = self.kubecli.get_nodes_infos()
node_infos, taints = self.__kubecli.get_nodes_infos()
chaos_telemetry.node_summary_infos = node_infos
chaos_telemetry.cluster_version = self.kubecli.get_version()
chaos_telemetry.cluster_version = self.__kubecli.get_version()
chaos_telemetry.node_taints = taints
for info in node_infos:
chaos_telemetry.total_node_count += info.count
Expand Down Expand Up @@ -217,7 +245,7 @@ def get_prometheus_pod_data(
if not prometheus_backup:
return file_list

prometheus_pod = self.kubecli.get_pod_info(
prometheus_pod = self.__kubecli.get_pod_info(
prometheus_pod_name, prometheus_namespace
)
if not prometheus_pod:
Expand All @@ -234,7 +262,7 @@ def get_prometheus_pod_data(
target_path = "/prometheus/wal"

try:
file_list = self.kubecli.archive_and_get_path_from_pod(
file_list = self.__kubecli.archive_and_get_path_from_pod(
prometheus_pod_name,
prometheus_container_name,
prometheus_namespace,
Expand Down Expand Up @@ -591,7 +619,7 @@ def put_cluster_events(
if len(exceptions) > 0:
raise Exception(", ".join(exceptions))

events_file = self.kubecli.collect_cluster_events(
events_file = self.__kubecli.collect_cluster_events(
start_timestamp,
end_timestamp,
str(get_localzone()),
Expand Down
28 changes: 19 additions & 9 deletions src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,38 @@
import os
import threading
from queue import Queue

from krkn_lib.models.telemetry import ChaosRunTelemetry
from krkn_lib.ocp import KrknOpenshift
from krkn_lib.telemetry.k8s import KrknTelemetryKubernetes
from krkn_lib.utils import SafeLogger


class KrknTelemetryOpenshift(KrknTelemetryKubernetes):
ocpcli: KrknOpenshift
__ocpcli: KrknOpenshift
__telemetry_id: str = None

def __init__(
self,
safe_logger: SafeLogger,
lib_openshift: KrknOpenshift,
telemetry_request_id: str = "",
krkn_telemetry_config: dict[str, any] = None,
):
super().__init__(
safe_logger=safe_logger,
lib_kubernetes=lib_openshift,
krkn_telemetry_config=krkn_telemetry_config,
telemetry_request_id=telemetry_request_id,
)
self.ocpcli = lib_openshift
self.__ocpcli = lib_openshift

def get_lib_ocp(self) -> KrknOpenshift:
"""
Returns the instance of KrknOpenshift

:return: a KrknOpenshift instance
"""
return self.__ocpcli

def get_ocp_prometheus_data(
self,
Expand Down Expand Up @@ -56,14 +66,14 @@ def get_ocp_prometheus_data(
def collect_cluster_metadata(self, chaos_telemetry: ChaosRunTelemetry):
super().collect_cluster_metadata(chaos_telemetry)
chaos_telemetry.cloud_infrastructure = (
self.ocpcli.get_cloud_infrastructure()
self.__ocpcli.get_cloud_infrastructure()
)
chaos_telemetry.cloud_type = self.ocpcli.get_cluster_type()
chaos_telemetry.cloud_type = self.__ocpcli.get_cluster_type()
chaos_telemetry.cluster_version = (
self.ocpcli.get_clusterversion_string()
self.__ocpcli.get_clusterversion_string()
)
chaos_telemetry.network_plugins = (
self.ocpcli.get_cluster_network_plugins()
self.__ocpcli.get_cluster_network_plugins()
)
vm_number = self.get_vm_number()
if vm_number > 0:
Expand Down Expand Up @@ -168,10 +178,10 @@ def put_ocp_logs(
dst_dir = os.path.join(archive_path, f"filtered-logs-{timestamp}")
os.mkdir(workdir)
os.mkdir(dst_dir)
archive_path = self.ocpcli.collect_filter_archive_ocp_logs(
archive_path = self.__ocpcli.collect_filter_archive_ocp_logs(
workdir,
dst_dir,
self.kubecli.get_kubeconfig_path(),
self.__kubecli.get_kubeconfig_path(),
start_timestamp,
end_timestamp,
logs_filter_patterns,
Expand Down
Loading