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} Enable AzureMonitorMetrics Addon (Managed Prometheus for public preview) #5428

Merged
merged 121 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
a1f5c1d
local copy of new api
bragi92 Aug 2, 2022
d71876e
WIP
bragi92 Aug 6, 2022
aa67027
WIP
bragi92 Aug 8, 2022
278366d
wip
bragi92 Aug 8, 2022
73536f2
grafana working
bragi92 Aug 10, 2022
370ca3c
now working
bragi92 Aug 10, 2022
aa6bbcd
.
bragi92 Aug 10, 2022
74c7e8a
.
bragi92 Aug 10, 2022
319991a
.
bragi92 Aug 10, 2022
359c434
.
bragi92 Aug 10, 2022
6bbfb43
whl file
bragi92 Aug 10, 2022
5e36cdf
.
bragi92 Aug 10, 2022
16b2279
.
bragi92 Aug 10, 2022
4b33d4f
..
bragi92 Aug 10, 2022
9d383db
.
bragi92 Aug 10, 2022
e3bf702
.
bragi92 Aug 10, 2022
056bd49
.
bragi92 Aug 10, 2022
10efdc4
.
bragi92 Aug 11, 2022
d20e372
.
bragi92 Aug 11, 2022
daf17df
.
bragi92 Aug 11, 2022
796a60e
validation + recording rules api call
bragi92 Aug 15, 2022
c0aa28b
new whl file
bragi92 Aug 15, 2022
e4a3c7f
remove dcra
bragi92 Aug 16, 2022
509d0e8
.
bragi92 Aug 16, 2022
bdb0904
pt1m
bragi92 Aug 16, 2022
fd3bde6
Merge branch 'main' into kaveesh/prom_cli_preview
bragi92 Aug 17, 2022
e591308
merge main and update setup version to 9.94
bragi92 Aug 17, 2022
00cf4d8
bug fixes
bragi92 Aug 19, 2022
d0743e9
new bits
bragi92 Aug 19, 2022
bd66b53
bug fixes
bragi92 Aug 19, 2022
c2158db
new monitoring data reader role
bragi92 Aug 19, 2022
a1293c5
.
bragi92 Aug 22, 2022
3d9b8b8
merge from main
bragi92 Aug 22, 2022
64af05e
.
bragi92 Aug 22, 2022
1227611
..
bragi92 Aug 22, 2022
31c22b6
.
bragi92 Aug 22, 2022
710ca27
.
bragi92 Aug 22, 2022
d61d544
update to storage blob
bragi92 Aug 22, 2022
2732a54
feature check
bragi92 Aug 23, 2022
1296c35
more udpates
bragi92 Aug 24, 2022
3ff8e72
.
bragi92 Aug 24, 2022
a2404f1
Merge branch 'main' into kaveesh/prom_cli_preview
bragi92 Aug 24, 2022
e0ce1a3
.
bragi92 Aug 24, 2022
dfe94e1
.
bragi92 Aug 24, 2022
e24bfa5
.
bragi92 Aug 26, 2022
c1c5279
preview bits
bragi92 Aug 26, 2022
6410e5c
.
bragi92 Aug 26, 2022
8797f33
.
bragi92 Aug 26, 2022
1db2eb1
.
bragi92 Aug 26, 2022
1534817
.
bragi92 Aug 26, 2022
d052e1f
.
bragi92 Aug 26, 2022
dccfbe6
.
bragi92 Aug 27, 2022
6214faa
.
bragi92 Aug 27, 2022
bb30835
.
bragi92 Aug 27, 2022
a83ac69
.
bragi92 Sep 7, 2022
7a4e44f
merge conlficts from main
bragi92 Sep 12, 2022
a843ef0
missed merge
bragi92 Sep 12, 2022
c6659d8
some feedback
bragi92 Sep 12, 2022
5b376f6
new line
bragi92 Sep 12, 2022
253ec23
feedback
bragi92 Sep 12, 2022
bc4a2fd
.
bragi92 Sep 13, 2022
1ab809b
.
bragi92 Sep 13, 2022
ef5f998
.
bragi92 Sep 13, 2022
b85a696
.
bragi92 Sep 13, 2022
9415f60
.
bragi92 Sep 13, 2022
aeb5894
.
bragi92 Sep 13, 2022
3900b09
..
bragi92 Sep 13, 2022
055abb1
.
bragi92 Sep 13, 2022
8adf5be
.
bragi92 Sep 13, 2022
7f1567a
.
bragi92 Sep 13, 2022
056094e
.
bragi92 Sep 14, 2022
a4ecc29
.
bragi92 Sep 16, 2022
fbbc06b
.
bragi92 Sep 16, 2022
bf89700
merge conflicts
bragi92 Sep 16, 2022
da4a7e9
.
bragi92 Sep 16, 2022
7b37168
.
bragi92 Sep 16, 2022
6f4ec70
.
bragi92 Sep 19, 2022
6454aa7
pr feedback, cleaner code
bragi92 Sep 20, 2022
3919ab3
formatting update for azdev style
bragi92 Sep 21, 2022
11b15b6
linter exceptions
bragi92 Sep 21, 2022
6f1c43f
linter
bragi92 Sep 21, 2022
35d1d99
header, useragent update
bragi92 Sep 26, 2022
b24c172
merge conflicts
bragi92 Sep 26, 2022
0f7b4d1
error string, do not fail if unable to set role assingment for monito…
bragi92 Sep 28, 2022
3dad6e8
merge from main, resolve conflicts
bragi92 Sep 28, 2022
c9e25c6
bugbash updates
bragi92 Oct 3, 2022
9933b01
.
bragi92 Oct 6, 2022
bfce5c6
.
bragi92 Oct 6, 2022
ce81bbc
isalnum
bragi92 Oct 6, 2022
3c75f14
.
bragi92 Oct 6, 2022
743a409
.
bragi92 Oct 6, 2022
d203f0c
.
bragi92 Oct 11, 2022
9402187
Merge pull request #2 from bragi92/kaveesh/pr_feedback
bragi92 Oct 11, 2022
33ddd37
Merge branch 'Azure:main' into kaveesh/prom_cli_preview
bragi92 Oct 11, 2022
32a1696
Merge branch 'main' into kaveesh/prom_cli_preview
bragi92 Oct 11, 2022
95bb99a
Merge branch 'kaveesh/prom_cli_preview' of https://github.com/bragi92…
bragi92 Oct 11, 2022
ffad5c2
missing whitespace
bragi92 Oct 11, 2022
580994e
Tests
bragi92 Oct 11, 2022
9ade23a
live test failure
bragi92 Oct 11, 2022
5284145
.
bragi92 Oct 11, 2022
e363bf9
.
bragi92 Oct 11, 2022
2061590
.
bragi92 Oct 11, 2022
3ad084b
.
bragi92 Oct 11, 2022
fa9a283
.
bragi92 Oct 11, 2022
61641bb
.
bragi92 Oct 11, 2022
b6644b6
.
bragi92 Oct 11, 2022
436ff83
.
bragi92 Oct 11, 2022
40b29ad
.
bragi92 Oct 11, 2022
7008813
add recording for test replay
bragi92 Oct 11, 2022
72ff0ed
resolve merge conflicts
bragi92 Oct 11, 2022
bf443a3
msi check
bragi92 Oct 11, 2022
a261001
msi check comment for now
bragi92 Oct 11, 2022
66812ba
typo
bragi92 Oct 12, 2022
30a172a
proper msi check
bragi92 Oct 12, 2022
fe280ff
Update src/aks-preview/azext_aks_preview/_help.py
bragi92 Oct 12, 2022
6d09c84
Update src/aks-preview/azext_aks_preview/_help.py
bragi92 Oct 12, 2022
a4efbcd
Update src/aks-preview/azext_aks_preview/_help.py
bragi92 Oct 12, 2022
182c6a4
Update src/aks-preview/azext_aks_preview/_help.py
bragi92 Oct 12, 2022
a5a1b69
Update src/aks-preview/azext_aks_preview/_help.py
bragi92 Oct 12, 2022
ce27a1e
Update src/aks-preview/azext_aks_preview/_help.py
bragi92 Oct 12, 2022
df2a915
pr feedback
bragi92 Oct 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ aks update:
assign_kubelet_identity:
rule_exclusions:
- option_length_too_long
azure_monitor_workspace_resource_id:
rule_exclusions:
- option_length_too_long
disable_azuremonitormetrics:
rule_exclusions:
- option_length_too_long
enable_azuremonitormetrics:
rule_exclusions:
- option_length_too_long
ksm_metric_annotations_allow_list:
rule_exclusions:
- option_length_too_long
ksm_metric_labels_allow_list:
rule_exclusions:
- option_length_too_long
arcdata dc create:
parameters:
logs_ui_private_key_file:
Expand Down
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
+++++++

0.5.106
+++++++

* Add support for AzureMonitorMetrics Addon (managed prometheus metrics in public preview) for AKS

0.5.105
+++++++

Expand Down
20 changes: 19 additions & 1 deletion src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,24 @@
- name: --defender-config
type: string
short-summary: Path to JSON file containing Microsoft Defender profile configurations.
- name: --enable-azuremonitormetrics
type: bool
short-summary: Enable Azure Monitor Metrics Profile
- name: --azure-monitor-workspace-resource-id
type: string
short-summary: Resource ID of the Azure Monitor Workspace
- name: --ksm-metric-labels-allow-list
type: string
short-summary: Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional labels provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (e.g. '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '*' can be provided per resource instead to allow any labels, but that has severe performance implications (e.g. '=pods=[*]').
- name: --ksm-metric-annotations-allow-list
type: string
short-summary: Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional labels provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (e.g.'=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '*' can be provided per resource instead to allow any labels, but that has severe performance implications (e.g. '=pods=[*]').
- name: --grafana-resource-id
type: string
short-summary: Resource ID of the Azure Managed Grafana Workspace
bragi92 marked this conversation as resolved.
Show resolved Hide resolved
- name: --disable-azuremonitormetrics
type: bool
short-summary: Disable Azure Monitor Metrics Profile
- name: --enable-node-restriction
type: bool
short-summary: Enable node restriction option on cluster.
Expand Down Expand Up @@ -880,7 +898,7 @@
- name: Update a kubernetes cluster with standard SKU load balancer to use two AKS created IPs for the load balancer outbound connection usage.
text: az aks update -g MyResourceGroup -n MyManagedCluster --load-balancer-managed-outbound-ip-count 2
- name: Update a kubernetes cluster with standard SKU load balancer to use the provided public IPs for the load balancer outbound connection usage.
text: az aks update -g MyResourceGroup -n MyManagedCluster --load-balancer-outbound-ips <ip-resource-id-1,ip-resource-id-2>
text: az aks update -g MyResourceGroup -n MyManagedCluster --load-balancer-outbound-ips `<`ip-resource-id-1,ip-resource-id-2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the < wrapped in single quotation marks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, I think it somehow got added accidently during a merge conflict.

Thanks for the catch!

- name: Update a kubernetes cluster with standard SKU load balancer to use the provided public IP prefixes for the load balancer outbound connection usage.
text: az aks update -g MyResourceGroup -n MyManagedCluster --load-balancer-outbound-ip-prefixes <ip-prefix-resource-id-1,ip-prefix-resource-id-2>
- name: Update a kubernetes cluster with two outbound AKS managed IPs an idle flow timeout of 5 minutes and 8000 allocated ports per machine
Expand Down
10 changes: 10 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
validate_enable_custom_ca_trust,
validate_defender_config_parameter,
validate_defender_disable_and_enable_parameters,
validate_azuremonitorworkspaceresourceid,
validate_grafanaresourceid,
validate_ksm_labels,
validate_ksm_annotations
)

# candidates for enumeration
Expand Down Expand Up @@ -432,6 +436,12 @@ def load_arguments(self, _):
c.argument('enable_private_cluster', action='store_true', is_preview=True, help='enable private cluster for apiserver vnet integration')
c.argument('disable_private_cluster', action='store_true', is_preview=True, help='disable private cluster for apiserver vnet integration')
c.argument('private_dns_zone', is_preview=True)
c.argument('enable_azuremonitormetrics', action='store_true', is_preview=True)
c.argument('azure_monitor_workspace_resource_id', validator=validate_azuremonitorworkspaceresourceid, is_preview=True)
c.argument('ksm_metric_labels_allow_list', validator=validate_ksm_labels, is_preview=True)
c.argument('ksm_metric_annotations_allow_list', validator=validate_ksm_annotations, is_preview=True)
c.argument('grafana_resource_id', validator=validate_grafanaresourceid, is_preview=True)
c.argument('disable_azuremonitormetrics', action='store_true', is_preview=True)
c.argument('enable_vpa', action='store_true', is_preview=True, help="enable vertical pod autoscaler for cluster")
c.argument('disable_vpa', action='store_true', is_preview=True, help="disable vertical pod autoscaler for cluster")
c.argument('cluster_snapshot_id', validator=validate_cluster_snapshot_id, is_preview=True)
Expand Down
84 changes: 84 additions & 0 deletions src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,87 @@ def validate_defender_config_parameter(namespace):
def validate_defender_disable_and_enable_parameters(namespace):
if namespace.disable_defender and namespace.enable_defender:
raise ArgumentUsageError('Providing both --disable-defender and --enable-defender flags is invalid')


def sanitize_resource_id(resource_id):
resource_id = resource_id.strip()
if not resource_id.startswith("/"):
resource_id = "/" + resource_id
if resource_id.endswith("/"):
resource_id = resource_id.rstrip("/")
return resource_id.lower()


def validate_azuremonitorworkspaceresourceid(namespace):
resource_id = namespace.azure_monitor_workspace_resource_id
if resource_id is None:
return
resource_id = sanitize_resource_id(resource_id)
if (bool(re.match(r'/subscriptions/.*/resourcegroups/.*/providers/microsoft.monitor/accounts/.*', resource_id))) is False:
raise CLIError("--azure-monitor-workspace-resource-id not in the correct format. It should match `/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/microsoft.monitor/accounts/<resourceName>`")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use specific error type ArgumentUsageError instead of CLIError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated



def validate_grafanaresourceid(namespace):
resource_id = namespace.grafana_resource_id
if resource_id is None:
return
resource_id = sanitize_resource_id(resource_id)
if (bool(re.match(r'/subscriptions/.*/resourcegroups/.*/providers/microsoft.dashboard/grafana/.*', resource_id))) is False:
raise CLIError("--grafana-resource-id not in the correct format. It should match `/subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/microsoft.dashboard/grafana/<resourceName>`")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use specific error type ArgumentUsageError instead of CLIError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated



def validate_ksm_parameter(ksmparam):
labelValueMap = {}
ksmStrLength = len(ksmparam)
EOF = -1
next = ""
name = ""
firstWordPos = 0
for i, v in enumerate(ksmparam):
if i + 1 == ksmStrLength:
next = EOF
else:
next = ord(ksmparam[i + 1])
if i - 1 >= 0:
previous = ord(ksmparam[i - 1])
else:
previous = v
if v == "=":
if previous == ord(",") or next != ord("["):
raise InvalidArgumentValueError("Please format --metric properly. For eg. : --ksm-metric-labels-allow-list \"=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)\" and --ksm-metric-annotations-allow-list \"namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...\"")
name = ksmparam[firstWordPos:i]
labelValueMap[name] = []
firstWordPos = i + 1
elif v == "[":
if previous != ord("="):
raise InvalidArgumentValueError("Please format --metric properly. For eg. : --ksm-metric-labels-allow-list \"=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)\" and --ksm-metric-annotations-allow-list \"namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...\"")
firstWordPos = i + 1
elif v == "]":
# if after metric group, has char not comma or end.
if next != EOF and next != ord(","):
raise InvalidArgumentValueError("Please format --metric properly. For eg. : --ksm-metric-labels-allow-list \"=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)\" and --ksm-metric-annotations-allow-list \"namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...\"")
if previous != ord("["):
labelValueMap[name].append(ksmparam[firstWordPos:i])
firstWordPos = i + 1
elif v == ",":
# if starts or ends with comma
if previous == v or next == EOF or next == ord("]"):
raise InvalidArgumentValueError("Please format --metric properly. For eg. : --ksm-metric-labels-allow-list \"=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)\" and --ksm-metric-annotations-allow-list \"namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...\"")
if previous != ord("]"):
labelValueMap[name].append(ksmparam[firstWordPos:i])
firstWordPos = i + 1
for label in labelValueMap:
if (bool(re.match(r'^[a-zA-Z_][A-Za-z0-9_]+$', label))) is False:
raise InvalidArgumentValueError("Please format --metric properly. For eg. : --ksm-metric-labels-allow-list \"=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)\" and --ksm-metric-annotations-allow-list \"namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...\"")


def validate_ksm_labels(namespace):
if namespace.ksm_metric_labels_allow_list is None:
return
validate_ksm_parameter(namespace.ksm_metric_labels_allow_list)


def validate_ksm_annotations(namespace):
if namespace.ksm_metric_annotations_allow_list is None:
return
validate_ksm_parameter(namespace.ksm_metric_annotations_allow_list)
2 changes: 1 addition & 1 deletion src/aks-preview/azext_aks_preview/addonconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
if addon_profile.enabled and check_enabled:
raise CLIError('The monitoring addon is already enabled for this managed cluster.\n'
'To change monitoring configuration, run "az aks disable-addons -a monitoring"'
'before enabling it again.')
' before enabling it again.')
if not workspace_resource_id:
workspace_resource_id = ensure_default_log_analytics_workspace_for_monitoring(
cmd,
Expand Down
Loading