【问题标题】:can az cli command automatically retry in case of http error 429az cli 命令可以在 http 错误 429 的情况下自动重试吗
【发布时间】:2020-12-19 03:14:26
【问题描述】:

我观察到 az 命令仅在 --debug 标志传递给它时才会打印 http 标头。 例如

az storage account list --debug

并且标头被打印到 stderr 并且 stdout 不包含任何内容。

如果是 HTTP 429,错误太多,指导是在 Retry-After 响应头中提到的间隔后重试。

是否有任何机制可以让 az cli 在出现 HTTP 429 错误时自动重试 API?

编辑 -- az 命令内置的重试

urllib3.util.retry : Incremented Retry for (url='/subscriptions/REMOVED/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01'): Retry(total=3, connect=4, read=4, redirect=None, status=None)
urllib3.util.retry : Incremented Retry for (url='/subscriptions/REMOVED/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01'): Retry(total=2, connect=4, read=4, redirect=None, status=None)
urllib3.util.retry : Incremented Retry for (url='/subscriptions/REMOVED/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01'): Retry(total=1, connect=4, read=4, redirect=None, status=None)
urllib3.util.retry : Incremented Retry for (url='/subscriptions/REMOVED/providers/Microsoft.Storage/storageAccounts?api-version=2019-06-01'): Retry(total=0, connect=4, read=4, redirect=None, status=None)

【问题讨论】:

  • 为什么不while(!success && retryCount < MaxRetryCount)
  • 我不认为有,但我没有任何证据支持它
  • @ShridharRKulkarni 如果每个调用者都不必这样做,那就太好了。此外,标头仅使用 --debug 选项打印,该选项打印大量信息,调用者必须解析 stderr,查找 429,解析 Retry-After 标头并重试。
  • 我明白你的意思。据我所知,正如另一位用户所说,没有这样的内置功能可以满足您的要求。如果您尝试为自己开发一款,您可以从docs.microsoft.com/en-us/dotnet/api/… 获得灵感
  • 查看 stderr,az 命令通过 urllib3 重试选项进行 4 次重试。 (更新原帖)。所以通常需要 0.8 秒的命令,在大约 60 秒内完成,因此重试之间的延迟似乎是指数级的,但它仍然不能防止 429 错误,因为它不查看 Retry-After 标头。

标签: azure http-headers azure-cli throttling


【解决方案1】:

根据目前收到的响应,答案是“否”,调用者必须运行带有 --debug 选项的 az 命令并解析 stderr。这是示例 Groovy 代码。

def pat = /'Retry-After': '(\d+)'/
stderr.split("\n").each { line ->
    def m = line =~ pat
    if (m.size() > 0 && m.hasGroup()) {
       retryAfterDuration = Integer.parseInt(m[0][1])
       println("Found Retry-After header, value = ${retryAfterDuration}")
    }
}

这是示例响应。

                msrest.http_logger : Response status: 429
                msrest.http_logger : Response headers:
                msrest.http_logger :     'Cache-Control': 'no-cache'
                msrest.http_logger :     'Pragma': 'no-cache'
                msrest.http_logger :     'Content-Length': '207'
                msrest.http_logger :     'Content-Type': 'application/json'
                msrest.http_logger :     'Expires': '-1'
                msrest.http_logger :     'Retry-After': '17'
                msrest.http_logger :     'x-ms-request-id': 'c7102dca-4bb1-4d24-8333-0128b8b85b24'
                msrest.http_logger :     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
                msrest.http_logger :     'Server': 'Microsoft-Azure-Storage-Resource-Provider/1.0,Microsoft-HTTPAPI/2.0 Microsoft-HTTPAPI/2.0'
                msrest.http_logger :     'x-ms-ratelimit-remaining-subscription-reads': '11989'
                msrest.http_logger :     'x-ms-correlation-request-id': '3a7ba2e1-6908-414b-b162-d6f41dc10521'
                msrest.http_logger :     'x-ms-routing-request-id': 'EASTUS:20200830T234133Z:3a7ba2e1-6908-414b-b162-d6f41dc10521'
                msrest.http_logger :     'X-Content-Type-Options': 'nosniff'
                msrest.http_logger :     'Date': 'Sun, 30 Aug 2020 23:41:32 GMT'
                msrest.http_logger :     'Connection': 'close'
                msrest.http_logger : Response content:
                msrest.http_logger : {"error":{"code":"TooManyRequests","message":"The request is being throttled as the limit has been reached for operation type - List_PerHour. For more information, see - https://aka.ms/srpthrottlinglimits"}}
                msrest.exceptions : The request is being throttled as the limit has been reached for operation type - List_PerHour. For more information, see - https://aka.ms/srpthrottlinglimits

            

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-31
    • 2021-07-28
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    相关资源
    最近更新 更多