Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AKS] Add --enable-azure-monitor-app-monitoring and --disable-azure-monitor-app-monitoring to aks-preview #7514

Merged
merged 16 commits into from
Apr 24, 2024
Merged
5 changes: 5 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

3.0.0b4
+++++++
* 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.0b3
+++++++
* Add `--nodepool-initialization-taints` to `az aks create` and `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
jatakiajanvi12 marked this conversation as resolved.
Show resolved Hide resolved
jatakiajanvi12 marked this conversation as resolved.
Show resolved Hide resolved
- 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 @@ -1206,6 +1207,8 @@ def load_arguments(self, _):
),
)
c.argument("disable_azure_monitor_metrics", action="store_true")
c.argument("enable_azure_monitor_app_monitoring", action="store_true")
c.argument("disable_azure_monitor_app_monitoring", action="store_true")
jatakiajanvi12 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -806,6 +808,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 = (
jatakiajanvi12 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -4263,6 +4331,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
Loading