[8.13](backport #38294) [Metricbeat][Azure] Azure monitor/storage: Fix 429 Too Many Requests error #38457
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed commit message
Please see the issue elastic/integrations#8575.
Metricsets affected by this change: storage and monitor.
This PR fixes the issue the following way:
time.sleep
for the seconds given by the header and try again after the time is up.This is also the retry suggestion given by Retry Usage Guidance from Azure.
For monitor metricset, the previous implementation also had a different problem affecting the number of calls: we were trying to get the metrics definition for every metric, without checking if we had done that already for the combination namespace + resource ID. So, for example, this configuration:
Would lead to 2 calls for each resource, even though the namespace is the same for every metric group. This is also fixed in this PR.
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
Enable azure monitor metricset, like in this example configuration.
To reproduce the error you can change the code a bit to force it to make many requests. You can put the
getMetricsDefinitionsWithRetry
inside a for cycle for that.I added some printing lines to the code. You should see an output like this:
Please notice that running this takes around 7 minutes to first encounter the error. After that time you have to wait for the sleep time, and only then you start making requests again.
Related issues
Closes elastic/integrations#8575.
This is an automatic backport of pull request #38294 done by [Mergify](https://mergify.com).