From ea925ecec0ee6dbd0303b105e5751b0e158b40a3 Mon Sep 17 00:00:00 2001 From: siriteja <32883500+sirireddy12@users.noreply.github.com> Date: Tue, 21 Jun 2022 12:32:45 +0530 Subject: [PATCH] Track onboarding sources using correlation_id parameter (#5008) --- src/connectedk8s/HISTORY.rst | 5 +++++ src/connectedk8s/azext_connectedk8s/_constants.py | 2 ++ src/connectedk8s/azext_connectedk8s/_params.py | 2 ++ src/connectedk8s/azext_connectedk8s/_validators.py | 8 ++++++++ src/connectedk8s/azext_connectedk8s/custom.py | 2 +- src/connectedk8s/setup.py | 2 +- 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/connectedk8s/HISTORY.rst b/src/connectedk8s/HISTORY.rst index 4dc7d81c863..b4b54a0ab57 100644 --- a/src/connectedk8s/HISTORY.rst +++ b/src/connectedk8s/HISTORY.rst @@ -2,6 +2,11 @@ Release History =============== +1.2.9 +++++++ + +* Add correlation-id parameter to internally track onboarding sources + 1.2.8 ++++++ diff --git a/src/connectedk8s/azext_connectedk8s/_constants.py b/src/connectedk8s/azext_connectedk8s/_constants.py index 0aab43c5729..7ff5b15540f 100644 --- a/src/connectedk8s/azext_connectedk8s/_constants.py +++ b/src/connectedk8s/azext_connectedk8s/_constants.py @@ -21,6 +21,8 @@ PublicCloud_OriginalName = 'AZURECLOUD' USGovCloud_OriginalName = 'AZUREUSGOVERNMENT' Dogfood_RMEndpoint = 'https://api-dogfood.resources.windows-int.net/' +Client_Request_Id_Header = 'x-ms-client-request-id' +Default_Onboarding_Source_Tracking_Guid = "77ade16b-0f55-403b-b7d2-739554a897f2" Helm_Environment_File_Fault_Type = 'helm-environment-file-error' Invalid_Location_Fault_Type = 'location-validation-error' Load_Kubeconfig_Fault_Type = 'kubeconfig-load-error' diff --git a/src/connectedk8s/azext_connectedk8s/_params.py b/src/connectedk8s/azext_connectedk8s/_params.py index 2621410e70e..b9b39edc42f 100644 --- a/src/connectedk8s/azext_connectedk8s/_params.py +++ b/src/connectedk8s/azext_connectedk8s/_params.py @@ -5,6 +5,7 @@ # pylint: disable=line-too-long import os.path +from ._validators import override_client_request_id_header from argcomplete.completers import FilesCompleter from azure.cli.core.commands.parameters import get_location_type, get_enum_type, file_type, tags_type from azure.cli.core.commands.validators import get_default_location_from_resource_group @@ -36,6 +37,7 @@ def load_arguments(self, _): c.argument('cl_oid', options_list=['--custom-locations-oid'], help="OID of 'custom-locations' app") c.argument('onboarding_timeout', options_list=['--onboarding-timeout'], arg_group='Timeout', help='Time required (in seconds) for the arc-agent pods to be installed on the kubernetes cluster. Override this value if the hardware/network constraints on your cluster requires more time for installing the arc-agent pods.') c.argument('no_wait', options_list=['--no-wait'], arg_group='Timeout', help="Do not wait for the long-running operation to finish.") + c.argument('correlation_id', options_list=['--correlation-id'], help='A guid that is used to internally track the source of cluster onboarding. Please do not modify it unless advised', validator=override_client_request_id_header) with self.argument_context('connectedk8s update') as c: c.argument('cluster_name', options_list=['--name', '-n'], id_part='name', help='The name of the connected cluster.') diff --git a/src/connectedk8s/azext_connectedk8s/_validators.py b/src/connectedk8s/azext_connectedk8s/_validators.py index d46d7e58f7e..b21f7d8f035 100644 --- a/src/connectedk8s/azext_connectedk8s/_validators.py +++ b/src/connectedk8s/azext_connectedk8s/_validators.py @@ -2,6 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +import azext_connectedk8s._constants as consts def example_name_or_id_validator(cmd, namespace): @@ -17,3 +18,10 @@ def example_name_or_id_validator(cmd, namespace): type='storageAccounts', name=namespace.storage_account ) + + +def override_client_request_id_header(cmd, namespace): + if namespace.correlation_id is not None: + cmd.cli_ctx.data['headers'][consts.Client_Request_Id_Header] = namespace.correlation_id + else: + cmd.cli_ctx.data['headers'][consts.Client_Request_Id_Header] = consts.Default_Onboarding_Source_Tracking_Guid diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index e1a03ef7d3c..71203888665 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -56,7 +56,7 @@ # pylint: disable=line-too-long -def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_proxy="", http_proxy="", no_proxy="", proxy_cert="", location=None, +def create_connectedk8s(cmd, client, resource_group_name, cluster_name, correlation_id=None, https_proxy="", http_proxy="", no_proxy="", proxy_cert="", location=None, kube_config=None, kube_context=None, no_wait=False, tags=None, distribution='auto', infrastructure='auto', disable_auto_upgrade=False, cl_oid=None, onboarding_timeout="600"): logger.warning("This operation might take a while...\n") diff --git a/src/connectedk8s/setup.py b/src/connectedk8s/setup.py index c52b83cf7aa..a05e924a6a3 100644 --- a/src/connectedk8s/setup.py +++ b/src/connectedk8s/setup.py @@ -17,7 +17,7 @@ # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = '1.2.8' +VERSION = '1.2.9' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers