Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
381 stars 1.2k forks source link

az load test app-component add does not work for Microsoft.Sql/servers/databases #7959

Open BlackbirdWay opened 1 week ago

BlackbirdWay commented 1 week ago

Describe the bug

When trying to add a SQL database to a load test server-side components via the Azure CLI Load Test extension, the following error is emitted: cli.azure.cli.core.azclierror: Type of app-component-id and app-component-type mismatch: microsoft.sql/servers vs Microsoft.Sql/servers/databases

When troubleshooting the issue, it looks like the problem is in this code: extensions/blob/8f63159b283c74c20d642b3c1c271090447bc2de/src/load/azext_load/data_plane/utils/validators.py#L155)

Specifically this line: provider_name = "/".join(namespace.app_component_id.split("/")[6:8]).casefold()

Since the full type of the database is not included in this split.

Related command

az load test app-component add --load-test-resource jarloadtestpoc --test-id 00000000-0000-0000-0000-000000000000 --app-component-id "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mobility-mpg-dev/providers/Microsoft.Sql/servers/jarpocsqlsrv/databases/jarpocsqldb" --app-component-type "Microsoft.Sql/servers/databases" --app-component-name jarpocsqldb --app-component-kind "v12.0,user" --debug

Errors

cli.azure.cli.core.azclierror: Type of app-component-id and app-component-type mismatch: microsoft.sql/servers vs Microsoft.Sql/servers/databases

Issue script & Debug output

az load test app-component add --load-test-resource jarloadtestpoc --test-id 00000000-0000-0000-0000-000000000000 --app-component-id "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mobility-mpg-dev/providers/Microsoft.Sql/servers/jarpocsqlsrv/databases/jarpocsqldb" --app-component-type "Microsoft.Sql/servers/databases" --app-component-name jarpocsqldb --app-component-kind "v12.0,user" --debug cli.knack.cli: Command arguments: ['load', 'test', 'app-component', 'add', '--load-test-resource', 'jarloadtestpoc', '--test-id', '00000000-0000-0000-0000-000000000000', '--app-component-id', '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mobility-mpg-dev/providers/Microsoft.Sql/servers/jarpocsqlsrv/databases/jarpocsqldb', '--app-component-type', 'Microsoft.Sql/servers/databases', '--app-component-name', 'jarpocsqldb', '--app-component-kind', 'v12.0,user', '--debug'] cli.knack.cli: init debug log: Enable color in terminal. Enable VT mode. cli.knack.cli: Event: Cli.PreExecute [] cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x01A3DA28>, <function OutputProducer.on_global_arguments at 0x01B67B18>, <function CLIQuery.on_global_arguments at 0x01D8B8E8>] cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] cli.azure.cli.core: Modules found from index for 'load': ['azext_load'] cli.azure.cli.core: Loading command modules: cli.azure.cli.core: Name Load Time Groups Commands cli.azure.cli.core: Total (0) 0.000 0 0 cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next'] cli.azure.cli.core: Loading extensions: cli.azure.cli.core: Name Load Time Groups Commands Directory cli.azure.cli.core: load 0.814 9 39 C:\Users\p1330505.azure\cliextensions\load cli.azure.cli.core: Total (1) 0.814 9 39 cli.azure.cli.core: Loaded 9 groups, 39 commands. cli.azure.cli.core: Found a match in the command table. cli.azure.cli.core: Raw command : load test app-component add cli.azure.cli.core: Command table: load test app-component add cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x03BC0488>] cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\p1330505.azure\commands\2024-09-06.16-11-59.load_test_app-component_add.23092.log'. az_command_data_logger: command args: load test app-component add --load-test-resource {} --test-id {} --app-component-id {} --app-component-type {} --app-component-name {} --app-component-kind {} --debug cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x03C19C58>] cli.knack.commands: Configured default 'mobility-mpg-dev' for arg resource_group_name cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x03C19C08>, <function register_cache_arguments..add_cache_arguments at 0x03C19CF8>, <function register_upcoming_breaking_change_info..update_breaking_change_info at 0x03C19D48>] cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x01B67B68>, <function CLIQuery.handle_query_parameter at 0x01D8B938>, <function register_ids_argument..parse_ids_arguments at 0x03C19CA8>] az_command_data_logger: extension name: load az_command_data_logger: extension version: 1.0.1 Command group 'load test app-component' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus cli.azure.cli.core.azclierror: Traceback (most recent call last): File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 654, in execute File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/invocation.py", line 113, in _validation File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 921, in _validate_arg_level File "C:\Users\p1330505.azure\cliextensions\load\azext_load\data_plane\utils\validators.py", line 158, in validate_app_component_type raise InvalidArgumentValueError( azure.cli.core.azclierror.InvalidArgumentValueError: Type of app-component-id and app-component-type mismatch: microsoft.sql/servers vs Microsoft.Sql/servers/databases

cli.azure.cli.core.azclierror: Type of app-component-id and app-component-type mismatch: microsoft.sql/servers vs Microsoft.Sql/servers/databases az_command_data_logger: Type of app-component-id and app-component-type mismatch: microsoft.sql/servers vs Microsoft.Sql/servers/databases cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x03BC05C8>] az_command_data_logger: exit code: 1 cli.main: Command ran in 1.508 seconds (init: 0.538, invoke: 0.970) telemetry.main: Begin splitting cli events and extra events, total events: 1 telemetry.client: Accumulated 0 events. Flush the clients. telemetry.main: Finish splitting cli events and extra events, cli events: 1 telemetry.save: Save telemetry record of length 3963 in cache file under C:\Users\p1330505.azure\telemetry\20240906161159419 telemetry.main: Begin creating telemetry upload process. telemetry.process: Creating upload process: "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\telemetry__init__.pyc C:\Users\p1330505.azure C:\Users\p1330505.azure\telemetry\20240906161159419" telemetry.process: Return from creating process 4664 telemetry.main: Finish creating telemetry upload process.

Expected behavior

The app component resource is added to the test.

Environment Summary

azure-cli 2.64.0

core 2.64.0 telemetry 1.1.0

Extensions: load 1.0.1

Dependencies: msal 1.30.0 azure-mgmt-resource 23.1.1

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users\p1330505.azure\cliextensions'

Python (Windows) 3.11.8 (tags/v3.11.8:db85d51, Feb 6 2024, 21:52:07) [MSC v.1937 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

yonzhan commented 1 week ago

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

RodrigoDiasDeOliveira commented 1 week ago

The error you are encountering, "Type of app-component-id and app-component-type mismatch: microsoft.sql/servers vs Microsoft.Sql/servers/databases", is caused by a mismatch between the app-component-id and app-component-type parameters when trying to add a SQL database as a component for load testing via the Azure CLI Load Test extension.

Root Cause The issue lies in the way the code handles the app-component-id. Specifically, the code attempts to extract the provider name from the app-component-id using the line:

python Copiar código provider_name = "/".join(namespace.app_component_id.split("/")[6:8]).casefold() This split is extracting only part of the resource type, which results in an incorrect comparison later on, causing the mismatch.

For your specific case, it seems that the code is extracting only microsoft.sql/servers, while the actual full type is Microsoft.Sql/servers/databases.

Possible Solutions

  1. Modify the Command: Try modifying the command by changing the app-component-type to match the extracted type microsoft.sql/servers. Although this might not be the complete resource type, it could bypass the validation step:

bash

az load test app-component add --load-test-resource jarloadtestpoc --test-id 00000000-0000-0000-0000-000000000000 --app-component-id "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mobility-mpg-dev/providers/Microsoft.Sql/servers/jarpocsqlsrv/databases/jarpocsqldb" --app-component-type "microsoft.sql/servers" --app-component-name jarpocsqldb --app-component-kind "v12.0,user" --debug

  1. Fix in the Extension Code: If modifying the command doesn't work or if you have control over the extension code, you might want to modify the validators.py file to handle the full resource type.

You can adjust the provider_name extraction logic to capture the full path:

python

provider_name = "/".join(namespace.app_component_id.split("/")[6:9]).casefold() This will include the databases part in the provider_name.

  1. Create an Issue on GitHub: If you don't have control over the extension's code, consider reporting this issue on the Azure CLI GitHub repository or the repository for the specific extension. This way, the maintainers can update the code to handle the full resource path correctly.

Summary Try modifying the command to use microsoft.sql/servers as the app-component-type. If you can edit the extension code, update the extraction logic to include the full path. Report the issue on GitHub if you cannot resolve it locally.

I wsih i could help, regards

BlackbirdWay commented 1 week ago

The error you are encountering, "Type of app-component-id and app-component-type mismatch: microsoft.sql/servers vs Microsoft.Sql/servers/databases", is caused by a mismatch between the app-component-id and app-component-type parameters when trying to add a SQL database as a component for load testing via the Azure CLI Load Test extension.

Root Cause The issue lies in the way the code handles the app-component-id. Specifically, the code attempts to extract the provider name from the app-component-id using the line:

python Copiar código provider_name = "/".join(namespace.app_component_id.split("/")[6:8]).casefold() This split is extracting only part of the resource type, which results in an incorrect comparison later on, causing the mismatch.

For your specific case, it seems that the code is extracting only microsoft.sql/servers, while the actual full type is Microsoft.Sql/servers/databases.

Possible Solutions

  1. Modify the Command: Try modifying the command by changing the app-component-type to match the extracted type microsoft.sql/servers. Although this might not be the complete resource type, it could bypass the validation step:

bash

az load test app-component add --load-test-resource jarloadtestpoc --test-id 00000000-0000-0000-0000-000000000000 --app-component-id "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mobility-mpg-dev/providers/Microsoft.Sql/servers/jarpocsqlsrv/databases/jarpocsqldb" --app-component-type "microsoft.sql/servers" --app-component-name jarpocsqldb --app-component-kind "v12.0,user" --debug 2. Fix in the Extension Code: If modifying the command doesn't work or if you have control over the extension code, you might want to modify the validators.py file to handle the full resource type.

You can adjust the provider_name extraction logic to capture the full path:

python

provider_name = "/".join(namespace.app_component_id.split("/")[6:9]).casefold() This will include the databases part in the provider_name.

  1. Create an Issue on GitHub: If you don't have control over the extension's code, consider reporting this issue on the Azure CLI GitHub repository or the repository for the specific extension. This way, the maintainers can update the code to handle the full resource path correctly.

Summary Try modifying the command to use microsoft.sql/servers as the app-component-type. If you can edit the extension code, update the extraction logic to include the full path. Report the issue on GitHub if you cannot resolve it locally.

I wsih i could help, regards

Thanks @RodrigoDiasDeOliveira, but I couldn't get this working with your 3 options because:

  1. When I modified the type for the SQL database to --app-component-type "microsoft.sql/servers", it did not show up on Server-side metrics area of the page once a test was run.
  2. The code is run via Azure DevOps pipeline using custom agent that I do not have permissions to modify.
  3. I thought that's what I was doing here :)