Skip to content

Commit

Permalink
[AKS] Add --enable-azure-monitor-app-monitoring and `--disable-azur…
Browse files Browse the repository at this point in the history
…e-monitor-app-monitoring` to aks-preview (Azure#7514)
  • Loading branch information
jatakiajanvi12 authored and blackchoey committed Apr 29, 2024
1 parent 01adbcc commit 889f4f3
Show file tree
Hide file tree
Showing 10 changed files with 2,805 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Pending
+++++++
* Minimise the roles needed to introduce for Elastic SAN for enabling Azure Container Storage with elasticSan storagepool type.

3.0.0b6
+++++++
* Add `--enable-azure-monitor-app-monitoring` to the `az aks create` command.
* Add `--enable-azure-monitor-app-monitoring` and `--disable-azure-monitor-app-monitoring` to the `az aks update` command.

3.0.0b5
+++++++
* Add `--bootstrap-artifact-source` and `--bootstrap-container-registry-resource-id` to `az aks update`.
Expand Down
11 changes: 11 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@
- name: --enable-windows-recording-rules
type: bool
short-summary: Enable Windows Recording Rules when enabling the Azure Monitor Metrics addon
- name: --enable-azure-monitor-app-monitoring
type: bool
short-summary: Enable Azure Monitor Application Monitoring
- name: --nodepool-labels
type: string
short-summary: The node labels for all node pools in this cluster. See https://aka.ms/node-labels for syntax of labels.
Expand Down Expand Up @@ -698,6 +701,8 @@
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-azure-service-mesh
- name: Create a kubernetes cluster with Azure Monitor Metrics enabled.
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-azuremonitormetrics
- name: Create a kubernetes cluster with Azure Monitor App Monitoring enabled
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-azure-monitor-app-monitoring
- name: Create a kubernetes cluster with a nodepool having ip allocation mode set to "StaticBlock"
text: az aks create -g MyResourceGroup -n MyManagedCluster --os-sku Ubuntu --max-pods MaxPodsPerNode --network-plugin azure --vnet-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/NodeSubnet --pod-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/PodSubnet --pod-ip-allocation-mode StaticBlock
Expand Down Expand Up @@ -1113,6 +1118,12 @@
- name: --disable-azure-monitor-metrics
type: bool
short-summary: Disable Azure Monitor Metrics Profile. This will delete all DCRA's associated with the cluster, any linked DCRs with the data stream = prometheus-stream and the recording rule groups created by the addon for this AKS cluster.
- name: --enable-azure-monitor-app-monitoring
type: bool
short-summary: Enable Azure Monitor Application Monitoring
- name: --disable-azure-monitor-app-monitoring
type: bool
short-summary: Disable Azure Monitor Application Monitoring
- name: --enable-node-restriction
type: bool
short-summary: Enable node restriction option on cluster.
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ def load_arguments(self, _):
c.argument("ksm_metric_annotations_allow_list")
c.argument("grafana_resource_id", validator=validate_grafanaresourceid)
c.argument("enable_windows_recording_rules", action="store_true")
c.argument("enable_azure_monitor_app_monitoring", is_preview=True, action="store_true")
c.argument("enable_cost_analysis", is_preview=True, action="store_true")
c.argument('enable_ai_toolchain_operator', is_preview=True, action='store_true')
# azure container storage
Expand Down Expand Up @@ -1216,6 +1217,8 @@ def load_arguments(self, _):
),
)
c.argument("disable_azure_monitor_metrics", action="store_true")
c.argument("enable_azure_monitor_app_monitoring", action="store_true", is_preview=True)
c.argument("disable_azure_monitor_app_monitoring", action="store_true", is_preview=True)
c.argument(
"enable_vpa",
action="store_true",
Expand Down
7 changes: 6 additions & 1 deletion src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,16 @@ def aks_create(
# azure service mesh
enable_azure_service_mesh=None,
revision=None,
# azure monitor profile
# azure monitor profile - metrics
enable_azuremonitormetrics=False,
enable_azure_monitor_metrics=False,
azure_monitor_workspace_resource_id=None,
ksm_metric_labels_allow_list=None,
ksm_metric_annotations_allow_list=None,
grafana_resource_id=None,
enable_windows_recording_rules=False,
# azure monitor profile - app monitoring
enable_azure_monitor_app_monitoring=False,
# metrics profile
enable_cost_analysis=False,
# AI toolchain operator
Expand Down Expand Up @@ -808,6 +810,9 @@ def aks_update(
enable_windows_recording_rules=False,
disable_azuremonitormetrics=False,
disable_azure_monitor_metrics=False,
# azure monitor profile - app monitoring
enable_azure_monitor_app_monitoring=False,
disable_azure_monitor_app_monitoring=False,
enable_vpa=False,
disable_vpa=False,
enable_addon_autoscaling=False,
Expand Down
96 changes: 96 additions & 0 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,57 @@ def get_disable_azure_monitor_metrics(self) -> bool:
"""
return self._get_disable_azure_monitor_metrics(enable_validation=True)

def _get_enable_azure_monitor_app_monitoring(self, enable_validation=True) -> bool:
"""Internal function to obtain the value of enable_azure_monitor_app_monitoring.
This function supports the option of enable_validation. When enabled, if both
enable_azure_monitor_app_monitoring and disable_azure_monitor_app_monitoring are specified,
raise a MutuallyExclusiveArgumentError.
:return: bool
"""
# Read the original value passed by the command.
enable_azure_monitor_app_monitoring = self.raw_param.get("enable_azure_monitor_app_monitoring")

# This parameter does not need dynamic completion.
if enable_validation:
if enable_azure_monitor_app_monitoring and self._get_disable_azure_monitor_app_monitoring(False):
raise MutuallyExclusiveArgumentError(
"Cannot specify --enable-azure-monitor-app-monitoring and --disable-azure-monitor-app-monitoring "
"at the same time."
)
return enable_azure_monitor_app_monitoring

def get_enable_azure_monitor_app_monitoring(self) -> bool:
"""Obtain the value of enable_azure_monitor_app_monitoring.
If both enable_azure_monitor_app_monitoring and
disable_azure_monitor_app_monitoring are specified, raise a MutuallyExclusiveArgumentError.
:return: bool
"""
return self._get_enable_azure_monitor_app_monitoring(enable_validation=True)

def _get_disable_azure_monitor_app_monitoring(self, enable_validation=True) -> bool:
"""Internal function to obtain the value of disable_azure_monitor_app_monitoring.
This function supports the option of enable_validation. When enabled, if both
enable_azure_monitor_app_monitoring and disable_azure_monitor_app_monitoring are specified,
raise a MutuallyExclusiveArgumentError.
:return: bool
"""
# Read the original value passed by the command.
disable_azure_monitor_app_monitoring = self.raw_param.get("disable_azure_monitor_app_monitoring")
if disable_azure_monitor_app_monitoring and self._get_enable_azure_monitor_app_monitoring(False):
raise MutuallyExclusiveArgumentError(
"Cannot specify --enable-azure-monitor-app-monitoring and --disable-azure-monitor-app-monitoring "
"at the same time."
)
return disable_azure_monitor_app_monitoring

def get_disable_azure_monitor_app_monitoring(self) -> bool:
"""Obtain the value of disable_azure_monitor_app_monitoring.
If both enable_azure_monitor_app_monitoring and
disable_azure_monitor_app_monitoring are specified, raise a MutuallyExclusiveArgumentError.
:return: bool
"""
return self._get_disable_azure_monitor_app_monitoring(enable_validation=True)

def get_enable_node_restriction(self) -> bool:
"""Obtain the value of enable_node_restriction.
Expand Down Expand Up @@ -3104,6 +3155,23 @@ def set_up_azure_monitor_profile(self, mc: ManagedCluster) -> ManagedCluster:
metric_labels_allowlist=str(ksm_metric_labels_allow_list),
metric_annotations_allow_list=str(ksm_metric_annotations_allow_list))
self.context.set_intermediate("azuremonitormetrics_addon_enabled", True, overwrite_exists=True)

if self.context.get_enable_azure_monitor_app_monitoring():
if mc.azure_monitor_profile is None:
mc.azure_monitor_profile = self.models.ManagedClusterAzureMonitorProfile()
mc.azure_monitor_profile.app_monitoring = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoring()
)
mc.azure_monitor_profile.app_monitoring.auto_instrumentation = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringAutoInstrumentation(enabled=True)
)
mc.azure_monitor_profile.app_monitoring.open_telemetry_metrics = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringOpenTelemetryMetrics(enabled=True)
)
mc.azure_monitor_profile.app_monitoring.open_telemetry_logs = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringOpenTelemetryLogs(enabled=True)
)

return mc

def set_up_azure_container_storage(self, mc: ManagedCluster) -> ManagedCluster:
Expand Down Expand Up @@ -4268,6 +4336,34 @@ def update_azure_monitor_profile(self, mc: ManagedCluster) -> ManagedCluster:
self.models.ManagedClusterAzureMonitorProfileMetrics(enabled=False) # pylint: disable=no-member
)

if self.context.get_enable_azure_monitor_app_monitoring():
if mc.azure_monitor_profile is None:
mc.azure_monitor_profile = self.models.ManagedClusterAzureMonitorProfile()
mc.azure_monitor_profile.app_monitoring = self.models.ManagedClusterAzureMonitorProfileAppMonitoring()
mc.azure_monitor_profile.app_monitoring.auto_instrumentation = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringAutoInstrumentation(enabled=True)
)
mc.azure_monitor_profile.app_monitoring.open_telemetry_metrics = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringOpenTelemetryMetrics(enabled=True)
)
mc.azure_monitor_profile.app_monitoring.open_telemetry_logs = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringOpenTelemetryLogs(enabled=True)
)

if self.context.get_disable_azure_monitor_app_monitoring():
if mc.azure_monitor_profile is None:
mc.azure_monitor_profile = self.models.ManagedClusterAzureMonitorProfile()
mc.azure_monitor_profile.app_monitoring = self.models.ManagedClusterAzureMonitorProfileAppMonitoring()
mc.azure_monitor_profile.app_monitoring.auto_instrumentation = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringAutoInstrumentation(enabled=False)
)
mc.azure_monitor_profile.app_monitoring.open_telemetry_metrics = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringOpenTelemetryMetrics(enabled=False)
)
mc.azure_monitor_profile.app_monitoring.open_telemetry_logs = (
self.models.ManagedClusterAzureMonitorProfileAppMonitoringOpenTelemetryLogs(enabled=False)
)

# TODO: should remove get value from enable_azuremonitormetrics once the option is removed
# TODO: should remove get value from disable_azuremonitormetrics once the option is removed
if (
Expand Down
Loading

0 comments on commit 889f4f3

Please sign in to comment.