Azure / azure-cli

Azure Command-Line Interface
MIT License
3.91k stars 2.87k forks source link

az monitor app-insights web-test create, required parameters not correct and defaults to kind = ping #29135

Open r300mrg opened 3 weeks ago

r300mrg commented 3 weeks ago

Describe the bug

The required parameters for the command az monitor app-insights web-test create do not appear to be configured and documented correctly.

The required parameters documented at https://learn.microsoft.com/en-us/cli/azure/monitor/app-insights/web-test?view=azure-cli-latest#az-monitor-app-insights-web-test-create, are:

--name --web-test-name -n --resource-group -g

However, via trial and error more required parameters seem to be required: --tags "hidden-link:/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/microsoft.insights/components/$APP_INSIGHTS_RESOURCE"="Resource" --defined-web-test-name --locations --web-test or --web-test-kind (and dependent associated commands)

Also the kind value defaults to ping, which is due to be retired and is set even when the --web-test-kind parameter is set to standard. If an Availability test is created via the Azure Portal, the kind value is null which can't be overwritten by Azure CLI commands.

Ping and Multistep availability is due to be retired and replaced by standard tests.

Related command

user@ubuntu:~$ az monitor app-insights web-test create \
  --subscription "$SUBSCRIPTION_ID" \
  --resource-group "$RESOURCE_GROUP" \
  --name "availability-test-01-$APP_INSIGHTS_RESOURCE"
(BadRequest) A single 'hidden-link' tag pointing to an existing AI component is required. Found none.
Code: BadRequest
Message: A single 'hidden-link' tag pointing to an existing AI component is required. Found none.
Inner error: {
    "trace": [
        "System.ArgumentException"
    ]
}
user@ubuntu:~$ az monitor app-insights web-test create \
  --subscription "$SUBSCRIPTION_ID" \
  --resource-group "$RESOURCE_GROUP" \
  --name "availability-test-01-$APP_INSIGHTS_RESOURCE" \
  --tags "hidden-link:/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/microsoft.insights/components/$APP_INSIGHTS_RESOURCE"="Resource"
(BadRequest) Value cannot be null.
Parameter name: 'properties.Name' must be specified
Code: BadRequest
Message: Value cannot be null.
Parameter name: 'properties.Name' must be specified
Inner error: {
    "trace": [
        "System.ArgumentNullException"
    ]
}
user@ubuntu:~$ az monitor app-insights web-test create \
  --subscription "$SUBSCRIPTION_ID" \
  --resource-group "$RESOURCE_GROUP" \
  --name "availability-test-01-$APP_INSIGHTS_RESOURCE" \
  --tags "hidden-link:/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/microsoft.insights/components/$APP_INSIGHTS_RESOURCE"="Resource" \
  --defined-web-test-name "availability-test-01-$APP_INSIGHTS_RESOURCE"
(BadRequest) Value cannot be null.
Parameter name: 'properties.Locations' must be specified
Code: BadRequest
Message: Value cannot be null.
Parameter name: 'properties.Locations' must be specified
Inner error: {
    "trace": [
        "System.ArgumentNullException"
    ]
}
user@ubuntu:~$ az monitor app-insights web-test create \
  --subscription "$SUBSCRIPTION_ID" \
  --resource-group "$RESOURCE_GROUP" \
  --name "availability-test-01-$APP_INSIGHTS_RESOURCE" \
  --tags "hidden-link:/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/microsoft.insights/components/$APP_INSIGHTS_RESOURCE"="Resource" \
  --defined-web-test-name "availability-test-01-$APP_INSIGHTS_RESOURCE" \
  --locations "Id"="us-ca-sjc-azr"
(BadRequest) Value cannot be null.
Parameter name: 'properties.Configuration.WebTest' must be specified
Code: BadRequest
Message: Value cannot be null.
Parameter name: 'properties.Configuration.WebTest' must be specified
Inner error: {
    "trace": [
        "System.ArgumentNullException"
    ]
}
user@ubuntu:~$ az monitor app-insights web-test create \
  --subscription "$SUBSCRIPTION_ID" \
  --resource-group "$RESOURCE_GROUP" \
  --name "availability-test-01-$APP_INSIGHTS_RESOURCE" \
  --tags "hidden-link:/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/microsoft.insights/components/$APP_INSIGHTS_RESOURCE"="Resource" \
  --defined-web-test-name "availability-test-01-$APP_INSIGHTS_RESOURCE" \
  --locations "Id"="us-ca-sjc-azr" \
  --web-test-kind "standard"
(BadRequest) Specified argument was out of the range of valid values.
Parameter name: Error code: PropertyMissingForKind. Web test 'availability-test-01-$APP_INSIGHTS_RESOURCE' is invalid. Required property 'Request' is missing for 'standard' web test
Code: BadRequest
Message: Specified argument was out of the range of valid values.
Parameter name: Error code: PropertyMissingForKind. Web test 'availability-test-01-$APP_INSIGHTS_RESOURCE' is invalid. Required property 'Request' is missing for 'standard' web test
Inner error: {
    "trace": [
        "System.ArgumentOutOfRangeException"
    ]
}
user@ubuntu:~$ 

Errors

See above related commands and the output.

Issue script & Debug output

Should be easy to replicate.

(note "kind": "ping" present in debug logs but not set via the command or required for a standard test)

cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Insights/webtests/availability-test-01-<APP_INSIGHTS_RESOURCE>?api-version=2022-06-15'
cli.azure.cli.core.sdk.policies: Request method: 'PUT'
cli.azure.cli.core.sdk.policies: Request headers:
cli.azure.cli.core.sdk.policies:     'Content-Type': 'application/json'
cli.azure.cli.core.sdk.policies:     'Content-Length': '374'
cli.azure.cli.core.sdk.policies:     'Accept': 'application/json'
cli.azure.cli.core.sdk.policies:     'x-ms-client-request-id': 'd7e06ad7-2716-11ef-bb1e-6bdaffedc136'
cli.azure.cli.core.sdk.policies:     'CommandName': 'monitor app-insights web-test create'
cli.azure.cli.core.sdk.policies:     'ParameterSetName': '--subscription --resource-group --name --tags --defined-web-test-name --locations --web-test-kind --debug'
cli.azure.cli.core.sdk.policies:     'User-Agent': 'AZURECLI/2.61.0 (DEB) azsdk-python-core/1.28.0 Python/3.11.8 (Linux-6.5.0-35-generic-x86_64-with-glibc2.35)'
cli.azure.cli.core.sdk.policies:     'Authorization': '*****'
cli.azure.cli.core.sdk.policies: Request body:
cli.azure.cli.core.sdk.policies: {"location": "westus2", "tags": {"hidden-link:/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/microsoft.insights/components/<APP_INSIGHTS_RESOURCE>": "Resource"}, "kind": "ping", "properties": {"Name": "availability-test-01-<APP_INSIGHTS_RESOURCE>", "Frequency": 300, "Timeout": 30, "Kind": "standard", "Locations": [{"Id": "us-ca-sjc-azr"}]}}
urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443
urllib3.connectionpool: https://management.azure.com:443 "PUT /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Insights/webtests/availability-test-01-<APP_INSIGHTS_RESOURCE>?api-version=2022-06-15 HTTP/1.1" 400 409
cli.azure.cli.core.sdk.policies: Response status: 400

Expected behavior

kind value either allows null or standard or is not required in favour of --web-test-kind

Documentation corrected to confirm the Required parameters.

Environment Summary

azure-cli 2.61.0

core 2.61.0 telemetry 1.1.0

Extensions: account 0.2.5 application-insights 1.2.1 functionapp 0.1.1

Dependencies: msal 1.28.0 azure-mgmt-resource 23.1.1

Python location '/opt/az/bin/python3'

Python (Linux) 3.11.8 (main, May 16 2024, 03:47:28) [GCC 11.4.0]

Additional context

No response

yonzhan commented 3 weeks ago

Thank you for opening this issue, we will look into it.

AllyW commented 2 weeks ago

Hi @r300mrg , thanks for querying.

  1. For required value gap, as cli processes users' inputs and displays service api's returns, and does not have the dependency relationship among different parameters, therefore it cannot process the validation for trivial arg inputs and might miss some required args under specific user inputs.
  2. For kind=ping default, cli will update this module in recent release for fixing it.
r300mrg commented 2 weeks ago

Hi @r300mrg , thanks for querying.

  1. For required value gap, as cli processes users' inputs and displays service api's returns, and does not have the dependency relationship among different parameters, therefore it cannot process the validation for trivial arg inputs and might miss some required args under specific user inputs.
  2. For kind=ping default, cli will update this module in recent release for fixing it.

Hi @AllyW, thank you for your reply. For the required value gaps, this really needs better documentation on https://learn.microsoft.com/en-us/cli/azure/monitor/app-insights/web-test?view=azure-cli-latest#az-monitor-app-insights-web-test-create, as it is very misleading and confusign.

Thanks