From 73a77474b833164b30e6a64b71be9bebc20d5220 Mon Sep 17 00:00:00 2001 From: Amandine Souilleux Date: Fri, 4 Nov 2022 16:35:53 +0100 Subject: [PATCH 1/4] [sc-107107] add logging around the different API calls --- python-clusters/attach-aks-cluster/cluster.py | 8 ++++-- python-clusters/create-aks-cluster/cluster.py | 8 +++++- python-lib/dku_utils/access.py | 28 +++++++++++++++++-- .../inspect-node-pools/runnable.py | 2 -- python-runnables/resize-node-pool/runnable.py | 4 ++- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/python-clusters/attach-aks-cluster/cluster.py b/python-clusters/attach-aks-cluster/cluster.py index f483452..b2d5352 100644 --- a/python-clusters/attach-aks-cluster/cluster.py +++ b/python-clusters/attach-aks-cluster/cluster.py @@ -2,10 +2,9 @@ from dataiku.cluster import Cluster from azure.mgmt.containerservice import ContainerServiceClient -from dku_utils.access import _is_none_or_blank +from dku_utils.access import _is_none_or_blank, _print_as_json from dku_utils.cluster import make_overrides, get_subscription_id from dku_azure.auth import get_credentials_from_connection_info, get_credentials_from_connection_infoV2 -from dku_azure.utils import run_and_process_cloud_error from dku_azure.utils import run_and_process_cloud_error, get_instance_metadata, get_subscription_id class MyCluster(Cluster): @@ -51,6 +50,8 @@ def start(self): def do_fetch(): return clusters_client.managed_clusters.list_cluster_admin_credentials(resource_group, cluster_name) get_credentials_result = run_and_process_cloud_error(do_fetch) + logging.info("Kubeconfig retrieved for cluster") + logging.info("Kubeconfig retrieved for cluster %s in %s: %s", cluster_name, resource_group, _print_as_json(get_credentials_result)) kube_config_content = get_credentials_result.kubeconfigs[0].value.decode('utf8') kube_config_path = os.path.join(os.getcwd(), 'kube_config') with open(kube_config_path, 'w') as f: @@ -58,9 +59,12 @@ def do_fetch(): overrides = make_overrides(self.config, yaml.safe_load(kube_config_content), kube_config_path) # Get other cluster infos + logging.info("Retrieving cluster information for cluster %s in %s", cluster_name, resource_group) def do_inspect(): return clusters_client.managed_clusters.get(resource_group, cluster_name) get_cluster_result = run_and_process_cloud_error(do_inspect) + logging.info("Information retrieved for cluster") + logging.info("Information retrieved for cluster %s in %s: %s", cluster_name, resource_group, _print_as_json(get_cluster_result)) return [overrides, {'kube_config_path':kube_config_path, 'cluster':get_cluster_result.as_dict()}] diff --git a/python-clusters/create-aks-cluster/cluster.py b/python-clusters/create-aks-cluster/cluster.py index d2100e5..d50c472 100644 --- a/python-clusters/create-aks-cluster/cluster.py +++ b/python-clusters/create-aks-cluster/cluster.py @@ -9,7 +9,7 @@ from azure.core.exceptions import ResourceNotFoundError, HttpResponseError from msrestazure.azure_exceptions import CloudError -from dku_utils.access import _is_none_or_blank, _has_not_blank_property +from dku_utils.access import _is_none_or_blank, _has_not_blank_property, _print_as_json from dku_utils.cluster import make_overrides, get_cluster_from_connection_info from dku_kube.nvidia_utils import add_gpu_driver_if_needed from dku_azure.auth import get_credentials_from_connection_info, get_credentials_from_connection_infoV2 @@ -320,6 +320,8 @@ def start(self): logging.info("Start creation of cluster") def do_creation(): cluster_create_op = cluster_builder.build() + logging.info("Cluster creation results") + logging.info("Cluster creation results: %s", _print_as_json(cluster_create_op)) return cluster_create_op.result() create_result = run_and_process_cloud_error(do_creation) logging.info("Cluster creation finished") @@ -380,6 +382,8 @@ def do_creation(): def do_fetch(): return clusters_client.managed_clusters.list_cluster_admin_credentials(resource_group, self.cluster_name) get_credentials_result = run_and_process_cloud_error(do_fetch) + logging.info("Kubeconfig retrieved for cluster") + logging.info("Kubeconfig retrieved for cluster %s in %s: %s", self.cluster_name, resource_group, _print_as_json(get_credentials_result)) kube_config_content = get_credentials_result.kubeconfigs[0].value.decode("utf8") logging.info("Writing kubeconfig file...") kube_config_path = os.path.join(os.getcwd(), "kube_config") @@ -440,6 +444,8 @@ def do_delete(): future = clusters_client.managed_clusters.begin_delete(resource_group, cluster_name) return future.result() delete_result = run_and_process_cloud_error(do_delete) + logging.info("Cluster deletion results") + logging.info("Cluster deletion results: %s", _print_as_json(delete_result)) # delete returns void, so we poll until the cluster is really gone gone = False diff --git a/python-lib/dku_utils/access.py b/python-lib/dku_utils/access.py index 2b79e07..8ea6e3e 100644 --- a/python-lib/dku_utils/access.py +++ b/python-lib/dku_utils/access.py @@ -2,6 +2,7 @@ from collections import Mapping, Iterable import sys import json +import logging if sys.version_info > (3,): dku_basestring_type = str @@ -80,21 +81,44 @@ def _merge_objects(a, b): return a_orig def _object_to_json(o): + logging.error("===== Amandine, new field =====") r = o + logging.error("Amandine, object: %s", r) + if r is not None: + logging.error("Amandine, object type: %s", type(r)) if hasattr(o, '__dict__'): r = o.__dict__ + logging.error("Amandine, object has a dict: %s", r) if isinstance(r, dku_basestring_type): + logging.error("Amandine, object is a string") + logging.error("===== Amandine, end field =====") return r + if isinstance(r, bytearray): + logging.error("Amandine, object is a bytearray") + logging.error("===== Amandine, end field =====") + return r.decode("utf-8") if isinstance(r, Iterable): + logging.error("Amandine, object is iterable: %s", r) if hasattr(r, 'keys'): + d = dict() + logging.error("Amandine, object has keys") for field in r.keys(): - r[field] = _object_to_json(r[field]) - return r + logging.error("Amandine, field: %s - contains: %s", field, r[field]) + if not field.startswith('_'): + d[field] = _object_to_json(r[field]) + else: + logging.error("Amandine, field ignored: %s", field) + + logging.error("===== Amandine, end field =====") + return d else: + logging.error("Amandine, object is an array: %s", r) arr = [] for entry in r: arr.append(_object_to_json(entry)) + logging.error("===== Amandine, end field =====") return arr + logging.error("===== Amandine, end field =====") return r def _print_as_json(o): diff --git a/python-runnables/inspect-node-pools/runnable.py b/python-runnables/inspect-node-pools/runnable.py index 3939b05..b21a074 100644 --- a/python-runnables/inspect-node-pools/runnable.py +++ b/python-runnables/inspect-node-pools/runnable.py @@ -2,8 +2,6 @@ import dataiku import json, logging from dku_utils.cluster import get_cluster_from_dss_cluster -from dku_utils.access import _is_none_or_blank -from dku_azure.utils import run_and_process_cloud_error class MyRunnable(Runnable): def __init__(self, project_key, config, plugin_config): diff --git a/python-runnables/resize-node-pool/runnable.py b/python-runnables/resize-node-pool/runnable.py index a2a04b5..a67efcd 100644 --- a/python-runnables/resize-node-pool/runnable.py +++ b/python-runnables/resize-node-pool/runnable.py @@ -2,7 +2,7 @@ import dataiku import json, logging from dku_utils.cluster import get_cluster_from_dss_cluster -from dku_utils.access import _is_none_or_blank +from dku_utils.access import _is_none_or_blank, _print_as_json from dku_azure.utils import run_and_process_cloud_error class MyRunnable(Runnable): @@ -50,6 +50,8 @@ def do_update(): cluster_update_op = clusters.managed_clusters.begin_create_or_update(resource_group, cluster_name, cluster) return cluster_update_op.result() update_result = run_and_process_cloud_error(do_update) + logging.info("Cluster update results") + logging.info("Cluster update results: %s", _print_as_json(update_result)) logging.info("Cluster updated") return '
%s
' % json.dumps(update_result.as_dict(), indent=2) From c6f4a89ef4e839edb56b62435ecb97a69faa0785 Mon Sep 17 00:00:00 2001 From: Amandine Souilleux Date: Thu, 2 Feb 2023 17:10:54 +0100 Subject: [PATCH 2/4] [sc-107107] remove log lines for debug purpose --- python-lib/dku_utils/access.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/python-lib/dku_utils/access.py b/python-lib/dku_utils/access.py index 8ea6e3e..53e5e5f 100644 --- a/python-lib/dku_utils/access.py +++ b/python-lib/dku_utils/access.py @@ -81,44 +81,26 @@ def _merge_objects(a, b): return a_orig def _object_to_json(o): - logging.error("===== Amandine, new field =====") r = o - logging.error("Amandine, object: %s", r) - if r is not None: - logging.error("Amandine, object type: %s", type(r)) if hasattr(o, '__dict__'): r = o.__dict__ - logging.error("Amandine, object has a dict: %s", r) if isinstance(r, dku_basestring_type): - logging.error("Amandine, object is a string") - logging.error("===== Amandine, end field =====") return r if isinstance(r, bytearray): - logging.error("Amandine, object is a bytearray") - logging.error("===== Amandine, end field =====") return r.decode("utf-8") if isinstance(r, Iterable): - logging.error("Amandine, object is iterable: %s", r) if hasattr(r, 'keys'): d = dict() - logging.error("Amandine, object has keys") for field in r.keys(): - logging.error("Amandine, field: %s - contains: %s", field, r[field]) if not field.startswith('_'): d[field] = _object_to_json(r[field]) - else: - logging.error("Amandine, field ignored: %s", field) - logging.error("===== Amandine, end field =====") return d else: - logging.error("Amandine, object is an array: %s", r) arr = [] for entry in r: arr.append(_object_to_json(entry)) - logging.error("===== Amandine, end field =====") return arr - logging.error("===== Amandine, end field =====") return r def _print_as_json(o): From 7f12afb3160118103d121ad0868d35e096efab87 Mon Sep 17 00:00:00 2001 From: Amandine Souilleux Date: Mon, 13 Feb 2023 17:05:53 +0100 Subject: [PATCH 3/4] [sc-107107] corrections --- python-clusters/attach-aks-cluster/cluster.py | 2 -- python-clusters/create-aks-cluster/cluster.py | 4 +--- python-lib/dku_utils/access.py | 1 - python-runnables/resize-node-pool/runnable.py | 1 - 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/python-clusters/attach-aks-cluster/cluster.py b/python-clusters/attach-aks-cluster/cluster.py index b2d5352..ae741cd 100644 --- a/python-clusters/attach-aks-cluster/cluster.py +++ b/python-clusters/attach-aks-cluster/cluster.py @@ -50,7 +50,6 @@ def start(self): def do_fetch(): return clusters_client.managed_clusters.list_cluster_admin_credentials(resource_group, cluster_name) get_credentials_result = run_and_process_cloud_error(do_fetch) - logging.info("Kubeconfig retrieved for cluster") logging.info("Kubeconfig retrieved for cluster %s in %s: %s", cluster_name, resource_group, _print_as_json(get_credentials_result)) kube_config_content = get_credentials_result.kubeconfigs[0].value.decode('utf8') kube_config_path = os.path.join(os.getcwd(), 'kube_config') @@ -63,7 +62,6 @@ def do_fetch(): def do_inspect(): return clusters_client.managed_clusters.get(resource_group, cluster_name) get_cluster_result = run_and_process_cloud_error(do_inspect) - logging.info("Information retrieved for cluster") logging.info("Information retrieved for cluster %s in %s: %s", cluster_name, resource_group, _print_as_json(get_cluster_result)) return [overrides, {'kube_config_path':kube_config_path, 'cluster':get_cluster_result.as_dict()}] diff --git a/python-clusters/create-aks-cluster/cluster.py b/python-clusters/create-aks-cluster/cluster.py index d50c472..e770cb8 100644 --- a/python-clusters/create-aks-cluster/cluster.py +++ b/python-clusters/create-aks-cluster/cluster.py @@ -320,8 +320,7 @@ def start(self): logging.info("Start creation of cluster") def do_creation(): cluster_create_op = cluster_builder.build() - logging.info("Cluster creation results") - logging.info("Cluster creation results: %s", _print_as_json(cluster_create_op)) + logging.info("Cluster creation results: %s", _print_as_json(cluster_create_op.__dict__)) return cluster_create_op.result() create_result = run_and_process_cloud_error(do_creation) logging.info("Cluster creation finished") @@ -382,7 +381,6 @@ def do_creation(): def do_fetch(): return clusters_client.managed_clusters.list_cluster_admin_credentials(resource_group, self.cluster_name) get_credentials_result = run_and_process_cloud_error(do_fetch) - logging.info("Kubeconfig retrieved for cluster") logging.info("Kubeconfig retrieved for cluster %s in %s: %s", self.cluster_name, resource_group, _print_as_json(get_credentials_result)) kube_config_content = get_credentials_result.kubeconfigs[0].value.decode("utf8") logging.info("Writing kubeconfig file...") diff --git a/python-lib/dku_utils/access.py b/python-lib/dku_utils/access.py index 53e5e5f..8250406 100644 --- a/python-lib/dku_utils/access.py +++ b/python-lib/dku_utils/access.py @@ -2,7 +2,6 @@ from collections import Mapping, Iterable import sys import json -import logging if sys.version_info > (3,): dku_basestring_type = str diff --git a/python-runnables/resize-node-pool/runnable.py b/python-runnables/resize-node-pool/runnable.py index a67efcd..7b39de8 100644 --- a/python-runnables/resize-node-pool/runnable.py +++ b/python-runnables/resize-node-pool/runnable.py @@ -50,7 +50,6 @@ def do_update(): cluster_update_op = clusters.managed_clusters.begin_create_or_update(resource_group, cluster_name, cluster) return cluster_update_op.result() update_result = run_and_process_cloud_error(do_update) - logging.info("Cluster update results") logging.info("Cluster update results: %s", _print_as_json(update_result)) logging.info("Cluster updated") return '
%s
' % json.dumps(update_result.as_dict(), indent=2) From 97b0694a08851e02b36e318f9edbc3090727a86b Mon Sep 17 00:00:00 2001 From: Amandine Souilleux Date: Tue, 21 Feb 2023 14:27:15 +0100 Subject: [PATCH 4/4] [sc-107107] corrections --- python-clusters/create-aks-cluster/cluster.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python-clusters/create-aks-cluster/cluster.py b/python-clusters/create-aks-cluster/cluster.py index e770cb8..eab2f4c 100644 --- a/python-clusters/create-aks-cluster/cluster.py +++ b/python-clusters/create-aks-cluster/cluster.py @@ -443,7 +443,6 @@ def do_delete(): return future.result() delete_result = run_and_process_cloud_error(do_delete) logging.info("Cluster deletion results") - logging.info("Cluster deletion results: %s", _print_as_json(delete_result)) # delete returns void, so we poll until the cluster is really gone gone = False