diff --git a/src/krkn_lib/telemetry/k8s/krkn_telemetry_kubernetes.py b/src/krkn_lib/telemetry/k8s/krkn_telemetry_kubernetes.py index f63e0dc..fb63f12 100644 --- a/src/krkn_lib/telemetry/k8s/krkn_telemetry_kubernetes.py +++ b/src/krkn_lib/telemetry/k8s/krkn_telemetry_kubernetes.py @@ -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, @@ -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): """ @@ -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", @@ -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 @@ -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: @@ -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, @@ -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()), diff --git a/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py b/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py index 9db1956..15347fe 100644 --- a/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py +++ b/src/krkn_lib/telemetry/ocp/krkn_telemetry_openshift.py @@ -3,6 +3,7 @@ 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 @@ -10,12 +11,14 @@ 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__( @@ -23,7 +26,25 @@ def __init__( 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, @@ -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,