Skip to content

Commit

Permalink
KrknTelemetryOpenshift refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Tullio Sebastiani <[email protected]>

KrknTelemetryOpenshift refactoring

Signed-off-by: Tullio Sebastiani <[email protected]>
  • Loading branch information
tsebastiani committed Sep 13, 2024
1 parent 2154bde commit 78ae5c0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
38 changes: 27 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,10 +22,10 @@


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

def __init__(
self,
Expand All @@ -38,12 +38,28 @@ def __init__(
warnings.filterwarnings(
action="ignore", message="unclosed", category=ResourceWarning
)
self.kubecli = lib_kubernetes
self.__kubecli = lib_kubernetes
self.safe_logger = safe_logger
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 collect_cluster_metadata(self, chaos_telemetry: ChaosRunTelemetry):
"""
Expand All @@ -61,7 +77,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 +88,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 +233,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 +250,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 +607,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
27 changes: 24 additions & 3 deletions src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,48 @@
import threading
from queue import Queue

from krkn_lib.k8s import KrknKubernetes
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_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,
)
self.ocpcli = lib_openshift
self.__ocpcli = lib_openshift
self.__telemetry_id = telemetry_id

def get_lib_ocp(self) -> KrknOpenshift:
"""
Returns the instance of KrknOpenshift
:return: a KrknOpenshift instance
"""
return self.__ocpcli

def get_telemetry_id(self) -> str:
"""
Gets the telemetry id that represents the path
on S3 where the telemetry data is uploaded
:return: the krkn telemetry id
"""
return self.__telemetry_id

def get_ocp_prometheus_data(
self,
Expand Down Expand Up @@ -164,7 +185,7 @@ def put_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

0 comments on commit 78ae5c0

Please sign in to comment.