Skip to content

Commit

Permalink
ContainerInsights extension - Add dataCollectionSettings configuratio…
Browse files Browse the repository at this point in the history
…n settings (Azure#200)

* data collection settings

* add support for dataCollectionSettings

* fix indention

* avoid duplicate use of json loads

* remove whitespaces

* fix pr feedback
  • Loading branch information
ganga1980 authored Dec 2, 2022
1 parent 0487616 commit d54d6ab
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import datetime
import json
import re

from ..utils import get_cluster_rp_api_version
from .. import consts
Expand Down Expand Up @@ -453,6 +454,7 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r
subscription_id = get_subscription_id(cmd.cli_ctx)
workspace_resource_id = ''
useAADAuth = False
extensionSettings = {}

if configuration_settings is not None:
if 'loganalyticsworkspaceresourceid' in configuration_settings:
Expand All @@ -473,6 +475,26 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r
logger.info("provided useAADAuth flag is : %s", useAADAuthSetting)
if (isinstance(useAADAuthSetting, str) and str(useAADAuthSetting).lower() == "true") or (isinstance(useAADAuthSetting, bool) and useAADAuthSetting):
useAADAuth = True
if useAADAuth and ('dataCollectionSettings' in configuration_settings):
dataCollectionSettingsString = configuration_settings["dataCollectionSettings"]
logger.info("provided dataCollectionSettings is : %s", dataCollectionSettingsString)
dataCollectionSettings = json.loads(dataCollectionSettingsString)
if 'interval' in dataCollectionSettings.keys():
intervalValue = dataCollectionSettings["interval"]
if (bool(re.match(r'^[0-9]+[m]$', intervalValue))) is False:
raise InvalidArgumentValueError('interval format must be in <number>m')
intervalValue = int(intervalValue.rstrip("m"))
if intervalValue <= 0 or intervalValue > 30:
raise InvalidArgumentValueError('interval value MUST be in the range from 1m to 30m')
if 'namespaceFilteringMode' in dataCollectionSettings.keys():
namespaceFilteringModeValue = dataCollectionSettings["namespaceFilteringMode"].lower()
if namespaceFilteringModeValue not in ["off", "exclude", "include"]:
raise InvalidArgumentValueError('namespaceFilteringMode value MUST be either Off or Exclude or Include')
if 'namespaces' in dataCollectionSettings.keys():
namspaces = dataCollectionSettings["namespaces"]
if isinstance(namspaces, list) is False:
raise InvalidArgumentValueError('namespaces must be an array type')
extensionSettings["dataCollectionSettings"] = dataCollectionSettings

workspace_resource_id = workspace_resource_id.strip()

Expand Down Expand Up @@ -502,7 +524,7 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r
if is_ci_extension_type:
if useAADAuth:
logger.info("creating data collection rule and association")
_ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id)
_ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id, extensionSettings)
elif not _is_container_insights_solution_exists(cmd, workspace_resource_id):
logger.info("Creating ContainerInsights solution resource, since it doesn't exist and it is using legacy authentication")
_ensure_container_insights_for_monitoring(cmd, workspace_resource_id).result()
Expand Down Expand Up @@ -570,7 +592,7 @@ def get_existing_container_insights_extension_dcr_tags(cmd, dcr_url):
return tags


def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id):
def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id, extensionSettings):
from azure.core.exceptions import HttpResponseError

cluster_region = ''
Expand Down Expand Up @@ -665,6 +687,7 @@ def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_
"Microsoft-ContainerInsights-Group-Default"
],
"extensionName": "ContainerInsights",
"extensionSettings": extensionSettings
}
]
},
Expand Down

0 comments on commit d54d6ab

Please sign in to comment.