Azure / Azure/azure-cli

Creating a metrics alert condition doesn't handle spaces in metric namespaces

Open
#17,597 1 comment 0 reactions 1 assignee Claimed by @kairu-ms View on GitHub
act-observability-squad feature-request Monitor Monitor - Metrics
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

## Describe the bug

When creating a metrics alert condition using `az monitor metrics alert condition create` for a metric namespace that contains a space, using the condition in `az monitor metrics alert create` fails.

## To reproduce

Create an alert condition. Note that both the metric name and namespace contain a space.

```powershell
$condition = $(az monitor metrics alert condition create --type static --aggregation Maximum --namespace "Custom Namespace" --metric "Custom Metric" --operator GreaterThan --threshold 1)
```

Printing this condition out shows that the metric name is surrounded in quotes, the namespace is not:

```powershell
$condition
"max Custom Namespace.'Custom Metric' > 1.0"
```

Attempting to use this condition to create a metric alert results in an error:

```powershell
az monitor metrics alert create --name "Monitor metrics alert create test" --condition $condition
line 1:21 mismatched input ''' expecting OPERATOR
usage error: --condition {avg,min,max,total,count} [NAMESPACE.]METRIC
[{=,!=,>,>=,<,<=} THRESHOLD]
[{<,>,><} dynamic SENSITIVITY VIOLATION of EVALUATION [since DATETIME]]
[where DIMENSION {includes,excludes} VALUE [or VALUE ...]
[and DIMENSION {includes,excludes} VALUE [or VALUE ...] ...]]
```

Omitting the metric namespace from `az monitor metrics alert condition create` results in the following string:

```powershell
$condition
"max 'Custom Metric' > 1.0"
```

Which also throws the same error as that shared above.

The following command appears to work without issue, so it looks like the placement of the quotes isn't correct when using `az monitor metrics alert condition create`.

```powershell
az monitor metrics alert create --name "Monitor metrics alert create test" --condition "max 'Custom Namespace.Custom Metric' > 1.0"
```

## Expected behavior

`az monitor metrics alert condition create` should be able to handle spaces in both metric names and metric namespaces.

## Environment summary
```
Windows-10-10.0.18362-SP0
Python 3.6.8
Installer: MSI

azure-cli 2.21.0

Extensions:
application-insights 0.1.13
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.