Skip to content

log-analytics extension v1.0.0b1 does not support Azure US Government Cloud #8202

Open

Description

Describe the bug

When adding the log-analytics extension to a fresh install of azure cli using az extension add --name log-analytics this defaults to installing the newest version of the extension 1.0.0b1. Unfortunately, this version does not presently support azure us government cloud. When the extension was switched over to using AAZ CodeGen, it looks like the scopes and host lists were updated to only support standard azure cloud environments.

_CLOUD_HOST_TEMPLATES = {
CloudNameEnum.AzureCloud: "https://api.loganalytics.io",
}
_CLOUD_HOST_METADATA_INDEX = "logAnalyticslogAnalyticsResourceId"
_AAD_CREDENTIAL_SCOPES = [
"https://api.loganalytics.io/.default",
]

I believe the generated code needs to be something closer to this for the extension to work with Azure US Government cloud.

 _CLOUD_HOST_TEMPLATES = { 
     CloudNameEnum.AzureCloud: "https://api.loganalytics.io", 
     CloudNameEnum.AzureUSGovernment: "https://api.loganalytics.us",
 } 
 _CLOUD_HOST_METADATA_INDEX = "logAnalyticslogAnalyticsResourceId" 
  
 _AAD_CREDENTIAL_SCOPES = [ 
     "https://api.loganalytics.io/.default", 
     "https://api.loganalytics.us/.default", 
 ] 

If I manually patch the extension to the above, then it works properly.

Related command

az monitor log-analytics query --workspace $WORKSPACE --timespan $TIMESPAN --analytics-query $QUERY

Errors

Fails with no error message and exit code 1

Issue script & Debug output

Some personal information replaced with tokens starting with $ below

cli.knack.cli: Command arguments: ['monitor', 'log-analytics', 'query', '--workspace', $WORKSPACE, '--timespan', $TIMESPAN, '--analytics-query', $QUERY, '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x1032d8720>, <function OutputProducer.on_global_arguments at 0x10347afc0>, <function CLIQuery.on_global_arguments at 0x1034b8ae0>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'monitor': ['azure.cli.command_modules.monitor', 'azext_loganalytics']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name                  Load Time    Groups  Commands
cli.azure.cli.core: monitor                   0.203        23        67
cli.azure.cli.core: Total (1)                 0.203        23        67
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: log-analytics             0.002         2         1  $HOME/.azure/cliextensions/log-analytics
cli.azure.cli.core: Total (1)                 0.002         2         1  
cli.azure.cli.core: Loaded 23 groups, 68 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command  : monitor log-analytics query
cli.azure.cli.core: Command table: monitor log-analytics query
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x105acf740>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '$HOME/.azure/commands/2024-10-26.11-48-49.monitor_log-analytics_query.20978.log'.
az_command_data_logger: command args: monitor log-analytics query --workspace {} --timespan {} --analytics-query {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x105b22480>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x105b449a0>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x105b44ae0>, <function register_upcoming_breaking_change_info.<locals>.update_breaking_change_info at 0x105b44b80>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x10347b060>, <function CLIQuery.handle_query_parameter at 0x1034b8b80>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x105b44a40>]
az_command_data_logger: extension name: log-analytics
az_command_data_logger: extension version: 1.0.0b1
cli.azure.cli.core.auth.persistence: build_persistence: location='$HOME/.azure/msal_token_cache.json', encrypt=False
cli.azure.cli.core.auth.binary_cache: load: $HOME/.azure/msal_http_cache.bin
urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
msal.authority: Initializing with Entra authority: https://login.microsoftonline.us/$ENTRA_GUID
msal.authority: openid_config("https://login.microsoftonline.us/$ENTRA_GUID/v2.0/.well-known/openid-configuration") = $OPEN_ID_CONFIG
msal.application: Broker enabled? None
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 733, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_command.py", line 155, in __call__
    return self._handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "$HOME/.azure/cliextensions/log-analytics/azext_loganalytics/aaz/latest/monitor/log_analytics/_query.py", line 36, in _handler
    self._execute_operations()
  File "$HOME/.azure/cliextensions/log-analytics/azext_loganalytics/aaz/latest/monitor/log_analytics/_query.py", line 75, in _execute_operations
    self.QueryExecute(ctx=self.ctx)()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_operation.py", line 42, in __init__
    self.client = ctx.get_http_client(self.CLIENT_TYPE)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_command_ctx.py", line 76, in get_http_client
    self._clients[client_type] = client_cls(self, credential=credential, **client_kwargs)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/core/aaz/_client.py", line 75, in __init__
    raise CloudEndpointNotSetException()
azure.cli.core.cloud.CloudEndpointNotSetException

cli.azure.cli.core.azclierror: 
az_command_data_logger: 
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x105acf9c0>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 0.310 seconds (init: 0.061, invoke: 0.249)
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 3912 in cache file under $HOME/.azure/telemetry/20241026114849630
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/bin/python /opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/lib/python3.11/site-packages/azure/cli/telemetry/__init__.py $HOME/.azure $HOME/.azure/telemetry/20241026114849630"
telemetry.process: Return from creating process 20983
telemetry.main: Finish creating telemetry upload process.

Expected behavior

Command should connect to the log analytics API endpoint in Azure US Government and return log entries.

Environment Summary

azure-cli                         2.65.0

core                              2.65.0
telemetry                          1.1.0

Extensions:
log-analytics                    1.0.0b1

Dependencies:
msal                              1.31.0
azure-mgmt-resource               23.1.1

Python location '/opt/homebrew/Cellar/azure-cli/2.65.0_2/libexec/bin/python'
Extensions directory '$HOME/.azure/cliextensions'

Python (Darwin) 3.11.10 (main, Sep  7 2024, 01:03:31) [Clang 15.0.0 (clang-1500.3.9.4)]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.

Additional context

I can work around this by manually downgrading fresh installs to the prior version 0.2.2 before AAZ Codegen was introduced using az extension add --name log-analytics --version 0.2.2 --upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Auto-AssignAuto assign by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamCode GenMonitorcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions