From ea24c55445559472575ee006f28b13fe568cca6a Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sat, 2 Apr 2022 15:29:00 -0700 Subject: [PATCH 1/9] use existing tags on container insights extension dcr for PUT --- .../command_modules/acs/addonconfiguration.py | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 4200bfee0bf..2a92ee7dc46 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -240,8 +240,8 @@ def sanitize_loganalytics_ws_resource_id(workspace_resource_id): return workspace_resource_id -def is_container_insights_extension_dcr_exists(cmd, dcr_url, workspace_resource_id): - containerinsights_extension_dcr_exists = False +def get_existing_container_insights_extension_dcr_tags(cmd, dcr_url): + tags = {} _MAX_RETRY_TIMES = 3 for retry_count in range(0, _MAX_RETRY_TIMES): try: @@ -249,18 +249,14 @@ def is_container_insights_extension_dcr_exists(cmd, dcr_url, workspace_resource_ cmd.cli_ctx, "GET", dcr_url ) json_response = json.loads(resp.text) - destinations = json_response["properties"]["destinations"] - if not destinations and not destinations["logAnalytics"] and len(destinations["logAnalytics"]) > 0: - destinationLogAnalyticsResourceId = destinations["logAnalytics"][0] - if destinationLogAnalyticsResourceId.tolower() == workspace_resource_id.tolower(): - containerinsights_extension_dcr_exists = True + tags = json_response["tags"] break except CLIError as e: if "ResourceNotFound" in str(e): break if retry_count >= (_MAX_RETRY_TIMES - 1): raise e - return containerinsights_extension_dcr_exists + return tags # pylint: disable=too-many-locals,too-many-branches,too-many-statements,line-too-long @@ -394,15 +390,16 @@ def ensure_container_insights_for_monitoring( f"Data Collection Rule Associations are not supported for cluster region {location}" ) dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{dcr_resource_id}?api-version=2019-11-01-preview" - # Create DCR if doesnt exists already with same destination - if not is_container_insights_extension_dcr_exists(cmd, dcr_url, workspace_resource_id): - # create the DCR - dcr_creation_body = json.dumps( - { - "location": location, - "properties": { - "dataSources": { - "extensions": [ + # get existing tags on the container insights extension DCR if the customer added any + existing_tags = get_existing_container_insights_extension_dcr_tags(cmd, dcr_url) + # create the DCR + dcr_creation_body = json.dumps( + { + "location": location, + "tags":existing_tags, + "properties": { + "dataSources": { + "extensions": [ { "name": "ContainerInsightsExtension", "streams": [ @@ -422,8 +419,8 @@ def ensure_container_insights_for_monitoring( "extensionName": "ContainerInsights", } ] - }, - "dataFlows": [ + }, + "dataFlows": [ { "streams": [ "Microsoft-Perf", @@ -442,28 +439,28 @@ def ensure_container_insights_for_monitoring( "destinations": ["la-workspace"], } ], - "destinations": { + "destinations": { "logAnalytics": [ { "workspaceResourceId": workspace_resource_id, "name": "la-workspace", } ] - }, }, - } - ) - for _ in range(3): - try: - send_raw_request( - cmd.cli_ctx, "PUT", dcr_url, body=dcr_creation_body - ) - error = None - break - except AzCLIError as e: - error = e - else: - raise error + }, + } + ) + for _ in range(3): + try: + send_raw_request( + cmd.cli_ctx, "PUT", dcr_url, body=dcr_creation_body + ) + error = None + break + except AzCLIError as e: + error = e + else: + raise error if create_dcra: # only create or delete the association between the DCR and cluster @@ -548,9 +545,19 @@ def _invoke_deployment( def add_monitoring_role_assignment(result, cluster_resource_id, cmd): service_principal_msi_id = None + is_useAADAuth = False + # Check if monitoring addon enabled with useAADAuth = True, if it does, ignore role assignment # Check if service principal exists, if it does, assign permissions to service principal # Else, provide permissions to MSI if ( + (hasattr(result, "addon_profiles")) and + (CONST_MONITORING_ADDON_NAME in result.addon_profiles) and + hasattr(result.addon_profiles[CONST_MONITORING_ADDON_NAME], "config") and + hasattr(result.addon_profiles[CONST_MONITORING_ADDON_NAME].config, "useAADAuth") and + result.addon_profiles[CONST_MONITORING_ADDON_NAME].config.useAADAuth + ): + is_useAADAuth = True + elif ( hasattr(result, "service_principal_profile") and hasattr(result.service_principal_profile, "client_id") and result.service_principal_profile.client_id.lower() != "msi" @@ -579,7 +586,9 @@ def add_monitoring_role_assignment(result, cluster_resource_id, cmd): ].identity.object_id is_service_principal = False - if service_principal_msi_id is not None: + if is_useAADAuth: + logger.info("Monitoring Metrics Publisher role assignment not required for monitoring addon with managed identity auth") + elif service_principal_msi_id is not None: if not add_role_assignment( cmd, "Monitoring Metrics Publisher", From 2c012ed0a3431b3420688ef63026b630a1bc131d Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sat, 2 Apr 2022 16:01:22 -0700 Subject: [PATCH 2/9] fix style issues --- .../command_modules/acs/addonconfiguration.py | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 2a92ee7dc46..beceb95e0c2 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -389,20 +389,22 @@ def ensure_container_insights_for_monitoring( raise ClientRequestError( f"Data Collection Rule Associations are not supported for cluster region {location}" ) - dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{dcr_resource_id}?api-version=2019-11-01-preview" + dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ + f"{dcr_resource_id}?api-version=2019-11-01-preview" # get existing tags on the container insights extension DCR if the customer added any - existing_tags = get_existing_container_insights_extension_dcr_tags(cmd, dcr_url) + existing_tags = get_existing_container_insights_extension_dcr_tags( + cmd, dcr_url) # create the DCR dcr_creation_body = json.dumps( { "location": location, - "tags":existing_tags, + "tags": existing_tags, "properties": { "dataSources": { "extensions": [ - { - "name": "ContainerInsightsExtension", - "streams": [ + { + "name": "ContainerInsightsExtension", + "streams": [ "Microsoft-Perf", "Microsoft-ContainerInventory", "Microsoft-ContainerLog", @@ -415,37 +417,37 @@ def ensure_container_insights_for_monitoring( "Microsoft-KubePVInventory", "Microsoft-KubeServices", "Microsoft-InsightsMetrics", - ], - "extensionName": "ContainerInsights", - } - ] + ], + "extensionName": "ContainerInsights", + } + ] }, "dataFlows": [ + { + "streams": [ + "Microsoft-Perf", + "Microsoft-ContainerInventory", + "Microsoft-ContainerLog", + "Microsoft-ContainerLogV2", + "Microsoft-ContainerNodeInventory", + "Microsoft-KubeEvents", + "Microsoft-KubeMonAgentEvents", + "Microsoft-KubeNodeInventory", + "Microsoft-KubePodInventory", + "Microsoft-KubePVInventory", + "Microsoft-KubeServices", + "Microsoft-InsightsMetrics", + ], + "destinations": ["la-workspace"], + } + ], + "destinations": { + "logAnalytics": [ { - "streams": [ - "Microsoft-Perf", - "Microsoft-ContainerInventory", - "Microsoft-ContainerLog", - "Microsoft-ContainerLogV2", - "Microsoft-ContainerNodeInventory", - "Microsoft-KubeEvents", - "Microsoft-KubeMonAgentEvents", - "Microsoft-KubeNodeInventory", - "Microsoft-KubePodInventory", - "Microsoft-KubePVInventory", - "Microsoft-KubeServices", - "Microsoft-InsightsMetrics", - ], - "destinations": ["la-workspace"], + "workspaceResourceId": workspace_resource_id, + "name": "la-workspace", } - ], - "destinations": { - "logAnalytics": [ - { - "workspaceResourceId": workspace_resource_id, - "name": "la-workspace", - } - ] + ] }, }, } @@ -556,7 +558,7 @@ def add_monitoring_role_assignment(result, cluster_resource_id, cmd): hasattr(result.addon_profiles[CONST_MONITORING_ADDON_NAME].config, "useAADAuth") and result.addon_profiles[CONST_MONITORING_ADDON_NAME].config.useAADAuth ): - is_useAADAuth = True + is_useAADAuth = True elif ( hasattr(result, "service_principal_profile") and hasattr(result.service_principal_profile, "client_id") and @@ -587,7 +589,8 @@ def add_monitoring_role_assignment(result, cluster_resource_id, cmd): is_service_principal = False if is_useAADAuth: - logger.info("Monitoring Metrics Publisher role assignment not required for monitoring addon with managed identity auth") + logger.info( + "Monitoring Metrics Publisher role assignment not required for monitoring addon with managed identity auth") elif service_principal_msi_id is not None: if not add_role_assignment( cmd, From cc6a07b0f09adae54161bac949955d9a2579f7d9 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Tue, 12 Apr 2022 00:22:22 -0700 Subject: [PATCH 3/9] optimize the code --- .../command_modules/acs/addonconfiguration.py | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index beceb95e0c2..15f2354d4e9 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -249,7 +249,8 @@ def get_existing_container_insights_extension_dcr_tags(cmd, dcr_url): cmd.cli_ctx, "GET", dcr_url ) json_response = json.loads(resp.text) - tags = json_response["tags"] + if json_response["tags"] is not None: + tags = json_response["tags"] break except CLIError as e: if "ResourceNotFound" in str(e): @@ -372,23 +373,14 @@ def ensure_container_insights_for_monitoring( raise error json_response = json.loads(r.text) for resource in json_response["resourceTypes"]: - region_ids = map( - lambda x: region_names_to_id[x], resource["locations"] - ) # map is lazy, so doing this for every region isn't slow - if ( - resource["resourceType"].lower() == "datacollectionrules" and - location not in region_ids - ): - raise ClientRequestError( - f"Data Collection Rules are not supported for LA workspace region {location}" - ) - if ( - resource["resourceType"].lower() == "datacollectionruleassociations" and - cluster_region not in region_ids - ): - raise ClientRequestError( - f"Data Collection Rule Associations are not supported for cluster region {location}" - ) + if (resource["resourceType"].lower() == "datacollectionrules"): + region_ids = map(lambda x: region_names_to_id[x], resource["locations"]) + if (location not in region_ids): + raise ClientRequestError(f"Data Collection Rules are not supported for LA workspace region {location}") + if (resource["resourceType"].lower() == "datacollectionruleassociations"): + region_ids = map(lambda x: region_names_to_id[x], resource["locations"]) + if (cluster_region not in region_ids): + raise ClientRequestError(f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ f"{dcr_resource_id}?api-version=2019-11-01-preview" # get existing tags on the container insights extension DCR if the customer added any From febec5043c407acf3273d4c4272db2e584fdcc03 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sat, 16 Apr 2022 22:15:01 -0700 Subject: [PATCH 4/9] add containerinsights solution in msi mode --- .../command_modules/acs/addonconfiguration.py | 129 +++++++++++++++++- 1 file changed, 124 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 15f2354d4e9..f6c5a36283f 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.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 datetime import json from azure.cli.core.azclierror import ( @@ -249,7 +250,7 @@ def get_existing_container_insights_extension_dcr_tags(cmd, dcr_url): cmd.cli_ctx, "GET", dcr_url ) json_response = json.loads(resp.text) - if json_response["tags"] is not None: + if ("tags" in json_response) and (json_response["tags"] is not None): tags = json_response["tags"] break except CLIError as e: @@ -374,13 +375,17 @@ def ensure_container_insights_for_monitoring( json_response = json.loads(r.text) for resource in json_response["resourceTypes"]: if (resource["resourceType"].lower() == "datacollectionrules"): - region_ids = map(lambda x: region_names_to_id[x], resource["locations"]) + region_ids = map( + lambda x: region_names_to_id[x], resource["locations"]) if (location not in region_ids): - raise ClientRequestError(f"Data Collection Rules are not supported for LA workspace region {location}") + raise ClientRequestError( + f"Data Collection Rules are not supported for LA workspace region {location}") if (resource["resourceType"].lower() == "datacollectionruleassociations"): - region_ids = map(lambda x: region_names_to_id[x], resource["locations"]) + region_ids = map( + lambda x: region_names_to_id[x], resource["locations"]) if (cluster_region not in region_ids): - raise ClientRequestError(f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") + raise ClientRequestError( + f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ f"{dcr_resource_id}?api-version=2019-11-01-preview" # get existing tags on the container insights extension DCR if the customer added any @@ -483,7 +488,121 @@ def ensure_container_insights_for_monitoring( error = e else: raise error + if not _is_container_insights_solution_exists(cmd, workspace_resource_id): + unix_time_in_millis = int( + ( + datetime.datetime.utcnow() - + datetime.datetime.utcfromtimestamp(0) + ).total_seconds() * 1000.0 + ) + + solution_deployment_name = "ContainerInsights-{}".format( + unix_time_in_millis + ) + + # pylint: disable=line-too-long + template = { + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "workspaceResourceId": { + "type": "string", + "metadata": { + "description": "Azure Monitor Log Analytics Resource ID" + }, + }, + "workspaceRegion": { + "type": "string", + "metadata": { + "description": "Azure Monitor Log Analytics workspace region" + }, + }, + "solutionDeploymentName": { + "type": "string", + "metadata": { + "description": "Name of the solution deployment" + }, + }, + }, + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "name": "[parameters('solutionDeploymentName')]", + "apiVersion": "2017-05-10", + "subscriptionId": "[split(parameters('workspaceResourceId'),'/')[2]]", + "resourceGroup": "[split(parameters('workspaceResourceId'),'/')[4]]", + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": {}, + "variables": {}, + "resources": [ + { + "apiVersion": "2015-11-01-preview", + "type": "Microsoft.OperationsManagement/solutions", + "location": "[parameters('workspaceRegion')]", + "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]", + "properties": { + "workspaceResourceId": "[parameters('workspaceResourceId')]" + }, + "plan": { + "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]", + "product": "[Concat('OMSGallery/', 'ContainerInsights')]", + "promotionCode": "", + "publisher": "Microsoft", + }, + } + ], + }, + "parameters": {}, + }, + } + ], + } + + params = { + "workspaceResourceId": {"value": workspace_resource_id}, + "workspaceRegion": {"value": location}, + "solutionDeploymentName": {"value": solution_deployment_name}, + } + + deployment_name = "aks-monitoring-{}".format(unix_time_in_millis) + # publish the Container Insights solution to the Log Analytics workspace + return _invoke_deployment( + cmd, + resource_group, + deployment_name, + template, + params, + validate=False, + no_wait=False, + subscription_id=subscription_id,) + +def _is_container_insights_solution_exists(cmd, workspace_resource_id): + # extract subscription ID and resource group from workspace_resource_id URL + is_exists = False + _MAX_RETRY_TIMES = 3 + parsed = parse_resource_id(workspace_resource_id) + subscription_id, resource_group, workspace_name = parsed[ + "subscription"], parsed["resource_group"], parsed["name"] + solution_resource_id = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.OperationsManagement/solutions/ContainerInsights({2})".format( + subscription_id, resource_group, workspace_name) + resources = cf_resources(cmd.cli_ctx, subscription_id) + for retry_count in range(0, _MAX_RETRY_TIMES): + try: + resources.get_by_id(solution_resource_id, '2015-11-01-preview') + is_exists = True + break + except HttpResponseError as ex: + if ex.status_code == 404: + is_exists = False + break + if retry_count >= (_MAX_RETRY_TIMES - 1): + raise ex + return is_exists def _invoke_deployment( cmd, From 80a68ce4f035ce1df9a4618a06e62917c0774c7a Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Sun, 17 Apr 2022 09:11:31 -0700 Subject: [PATCH 5/9] fix style issues --- .../cli/command_modules/acs/addonconfiguration.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index f6c5a36283f..c55c500de12 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -251,7 +251,7 @@ def get_existing_container_insights_extension_dcr_tags(cmd, dcr_url): ) json_response = json.loads(resp.text) if ("tags" in json_response) and (json_response["tags"] is not None): - tags = json_response["tags"] + tags = json_response["tags"] break except CLIError as e: if "ResourceNotFound" in str(e): @@ -374,18 +374,17 @@ def ensure_container_insights_for_monitoring( raise error json_response = json.loads(r.text) for resource in json_response["resourceTypes"]: - if (resource["resourceType"].lower() == "datacollectionrules"): + if resource["resourceType"].lower() == "datacollectionrules": region_ids = map( lambda x: region_names_to_id[x], resource["locations"]) - if (location not in region_ids): + if location not in region_ids: raise ClientRequestError( f"Data Collection Rules are not supported for LA workspace region {location}") - if (resource["resourceType"].lower() == "datacollectionruleassociations"): + if resource["resourceType"].lower() == "datacollectionruleassociations": region_ids = map( lambda x: region_names_to_id[x], resource["locations"]) - if (cluster_region not in region_ids): - raise ClientRequestError( - f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") + if cluster_region not in region_ids: + raise ClientRequestError(f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ f"{dcr_resource_id}?api-version=2019-11-01-preview" # get existing tags on the container insights extension DCR if the customer added any @@ -604,6 +603,7 @@ def _is_container_insights_solution_exists(cmd, workspace_resource_id): raise ex return is_exists + def _invoke_deployment( cmd, resource_group_name, From d5c22d8bf9288cd22aa9522875a0a695682d5bf1 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Tue, 21 Jun 2022 13:13:01 -0700 Subject: [PATCH 6/9] DCR API version and update to stream group --- .../command_modules/acs/addonconfiguration.py | 28 ++----------------- .../acs/tests/latest/test_aks_commands.py | 6 ++-- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 567bdbdc82a..4cd27e01ba4 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -379,7 +379,7 @@ def ensure_container_insights_for_monitoring( if cluster_region not in region_ids: raise ClientRequestError(f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ - f"{dcr_resource_id}?api-version=2019-11-01-preview" + f"{dcr_resource_id}?api-version=2021-09-01-preview" # get existing tags on the container insights extension DCR if the customer added any existing_tags = get_existing_container_insights_extension_dcr_tags( cmd, dcr_url) @@ -394,18 +394,7 @@ def ensure_container_insights_for_monitoring( { "name": "ContainerInsightsExtension", "streams": [ - "Microsoft-Perf", - "Microsoft-ContainerInventory", - "Microsoft-ContainerLog", - "Microsoft-ContainerLogV2", - "Microsoft-ContainerNodeInventory", - "Microsoft-KubeEvents", - "Microsoft-KubeMonAgentEvents", - "Microsoft-KubeNodeInventory", - "Microsoft-KubePodInventory", - "Microsoft-KubePVInventory", - "Microsoft-KubeServices", - "Microsoft-InsightsMetrics", + "Microsoft-ContainerInsights-Group-Default" ], "extensionName": "ContainerInsights", } @@ -414,18 +403,7 @@ def ensure_container_insights_for_monitoring( "dataFlows": [ { "streams": [ - "Microsoft-Perf", - "Microsoft-ContainerInventory", - "Microsoft-ContainerLog", - "Microsoft-ContainerLogV2", - "Microsoft-ContainerNodeInventory", - "Microsoft-KubeEvents", - "Microsoft-KubeMonAgentEvents", - "Microsoft-KubeNodeInventory", - "Microsoft-KubePodInventory", - "Microsoft-KubePVInventory", - "Microsoft-KubeServices", - "Microsoft-InsightsMetrics", + "Microsoft-ContainerInsights-Group-Default" ], "destinations": ["la-workspace"], } diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py index 5236b7f16ff..01c82ce1c5f 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py @@ -6533,7 +6533,7 @@ def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2019-11-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-09-01-preview' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ]) @@ -6606,7 +6606,7 @@ def enable_monitoring_existing_cluster_aad_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2019-11-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=021-09-01-preview' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ]) @@ -6660,7 +6660,7 @@ def test_aks_create_with_monitoring_legacy_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2019-11-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=021-09-01-preview' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ]) From f0c5332cfc8c234b773b19614d58d3b40d9c7d3a Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Tue, 21 Jun 2022 13:52:49 -0700 Subject: [PATCH 7/9] DCR API version and update to stream group --- .../cli/command_modules/acs/tests/latest/test_aks_commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py index 01c82ce1c5f..40f1a51262c 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py @@ -6606,7 +6606,7 @@ def enable_monitoring_existing_cluster_aad_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=021-09-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-09-01-preview' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ]) @@ -6660,7 +6660,7 @@ def test_aks_create_with_monitoring_legacy_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=021-09-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-09-01-preview' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ]) From daf6913c6b9f9edcc631d4517cd884701ad1afde Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Tue, 21 Jun 2022 16:07:28 -0700 Subject: [PATCH 8/9] DCR API version and update to stream group --- .../azure/cli/command_modules/acs/addonconfiguration.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 4cd27e01ba4..6868e36aac8 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -377,7 +377,8 @@ def ensure_container_insights_for_monitoring( region_ids = map( lambda x: region_names_to_id[x], resource["locations"]) if cluster_region not in region_ids: - raise ClientRequestError(f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") + raise ClientRequestError( + f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ f"{dcr_resource_id}?api-version=2021-09-01-preview" # get existing tags on the container insights extension DCR if the customer added any @@ -394,7 +395,7 @@ def ensure_container_insights_for_monitoring( { "name": "ContainerInsightsExtension", "streams": [ - "Microsoft-ContainerInsights-Group-Default" + "Microsoft-ContainerInsights-Group-Default" ], "extensionName": "ContainerInsights", } From 710ac730422dc55ed5602f896a2b2b5a3dce54a9 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Mon, 27 Jun 2022 11:25:48 -0700 Subject: [PATCH 9/9] update to use stable API version --- .../cli/command_modules/acs/addonconfiguration.py | 4 ++-- .../acs/tests/latest/test_aks_commands.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 6868e36aac8..af735bee72e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -380,7 +380,7 @@ def ensure_container_insights_for_monitoring( raise ClientRequestError( f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ - f"{dcr_resource_id}?api-version=2021-09-01-preview" + f"{dcr_resource_id}?api-version=2021-04-01" # get existing tags on the container insights extension DCR if the customer added any existing_tags = get_existing_container_insights_extension_dcr_tags( cmd, dcr_url) @@ -444,7 +444,7 @@ def ensure_container_insights_for_monitoring( } ) association_url = cmd.cli_ctx.cloud.endpoints.resource_manager + \ - f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version=2019-11-01-preview" + f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version=2021-04-01" for _ in range(3): try: send_raw_request( diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py index 40f1a51262c..77ce3240b3e 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py @@ -6533,14 +6533,14 @@ def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-09-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-04-01' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ]) # check that the DCR-A was created dcra_resource_id = f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension" - get_cmd = f'rest --method get --url https://management.azure.com{dcra_resource_id}?api-version=2019-11-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcra_resource_id}?api-version=2021-04-01' self.cmd(get_cmd, checks=[ self.check('properties.dataCollectionRuleId', f'{dcr_resource_id}') ]) @@ -6606,14 +6606,14 @@ def enable_monitoring_existing_cluster_aad_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-09-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-04-01' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ]) # check that the DCR-A was created dcra_resource_id = f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension" - get_cmd = f'rest --method get --url https://management.azure.com{dcra_resource_id}?api-version=2019-11-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcra_resource_id}?api-version=2021-04-01' self.cmd(get_cmd, checks=[ self.check('properties.dataCollectionRuleId', f'{dcr_resource_id}') ]) @@ -6660,7 +6660,7 @@ def test_aks_create_with_monitoring_legacy_auth(self, resource_group, resource_g # check that the DCR was created dataCollectionRuleName = f"MSCI-{aks_name}-{resource_group_location}" dcr_resource_id = f"/subscriptions/{subscription}/resourceGroups/{workspace_resource_group}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}" - get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-09-01-preview' + get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2021-04-01' self.cmd(get_cmd, checks=[ self.check('properties.destinations.logAnalytics[0].workspaceResourceId', f'{workspace_resource_id}') ])