Azure / azure-cli

Azure Command-Line Interface
MIT License
3.97k stars 2.95k forks source link

`az --version` performs an update check #27437

Open jessehouwing opened 11 months ago

jessehouwing commented 11 months ago

Describe the bug

When running az --version an update check is performed against az-cli and the extensions.

Azure Pipelines' AzureCLI task runs az --version to capture the version details in the logs.

It would save quite a bit of CPU if az-cli would not perform an update check in a CI/CD scenario.

There already is an core.auto-upgrade=false option, would it not make sense to piggy back on that or to add another config setting to turn off update checking.

Related command

az --version

Errors

N/a

Issue script & Debug output

N/a

Expected behavior

No update check is performed in CI.

Environment Summary

2.52.0

Additional context

No response

yonzhan commented 11 months ago

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

jiasli commented 11 months ago

There already is an core.auto-upgrade=false option

According to https://learn.microsoft.com/en-us/cli/azure/update-azure-cli#automatic-update, it should be auto-upgrade.enable=yes.

We do have az version command that doesn't make any network request (https://github.com/Azure/azure-cli/issues/27457#issuecomment-1735229430). I think what you are asking for is an option to disable update check in az --version, while https://github.com/Azure/azure-cli/issues/27457 asks for an option to enable version check in az version. 🤣

jessehouwing commented 11 months ago

Yeah, have a way to disable network access for these commands. Either with an extra parameter to --check-updates true or a setting in the config file or an environment variable.

Ideally az would detect it's in CI/CD and turn off a load of stuff that only adds logspam and slowdowns by default.

It looks like az init is making a start of collecting the desired settings ;).

jiasli commented 11 months ago

az init is actually a secret project. May I know where you heard of it? 🤣

jessehouwing commented 11 months ago

az init is actually a secret project. May I know where you heard of it? 🤣

I was looking for a way to set the default config settings, and I tried it on the console. Lo and behold it downloaded the extension and ran.

I supplied a PR for it to add a few more settings.

jiasli commented 11 months ago

Ideally az would detect it's in CI/CD and turn off a load of stuff that only adds logspam and slowdowns by default.

This is another topic we are still internally investigating. Not only Azure DevOps, we are aiming to find a unified way to detect the running environment - Azure DevOps, Azure Cloud Shell, GitHub Actions, etc.

jiasli commented 11 months ago

az init is only an experimental feature we made in https://github.com/Azure/azure-cli-extensions/pull/3969. It is never expected to be used in production. Also, az init allows the user to select the running environment. It can't really detect the running environment.

jessehouwing commented 11 months ago

az init is only an experimental feature we made in Azure/azure-cli-extensions#3969. It is never expected to be used in production. Also, az init allows the user to select the running environment. It can't really detect the running environment.

Yeah, I figured as much. The experimental nature at least. But it does seem to reccomend certain settings in an automated environment.

As you mentioned above auto-upgrade.enable=yes in the docs turns out to probably be auto-upgrade.enable=true in the code, at least there are quite a few issues that dispute the correct syntax. I went looking for what settings there are and what their values should/could be and there is VERY little documentation on those topics.

I ended up doing a search through the codebase instead. But it lead to some useful insights!

I've been digging into the performance of az and az devops in Azure Pipelines and GtHub Hosted Runners.

If these each shave off a couple of seconds, over the number of invocations on the hosted runners worldwide it would save a couple of trees and a bunch of water.

Ideally az would detect it's in a CI/CD environment and turn off:

And would allow: