-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metrica: retry query if quota exceeded #6459
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6459 +/- ##
==========================================
+ Coverage 61.26% 61.53% +0.27%
==========================================
Files 158 158
Lines 12889 12898 +9
Branches 1755 1756 +1
==========================================
+ Hits 7896 7937 +41
+ Misses 4743 4704 -39
- Partials 250 257 +7
|
This makes sense to me (although ideally we'd just submit the queries to Metrica in sequence and not overload it). Can we add a test of some kind to verify the quota exceeded error gets raised, and that the query gets retried after a while? |
Yes, but in this case we need to change the logic for the scheduler/worker.
That's not possible without access token. |
Hmm, is there no way to mock the calls and have a mocked object keep track of how many active queries there are? |
Honestly, I'm not sure that I can create unit test with parallel execution, because I have small experience with pytest. If you have suggestions how to do it, please share with me, and I'll try to research. |
I don't think we'd need parallel execution. Maybe we can set it up as a fixture that looks something like this: def keep_only_5_items(item):
if len(active_items) >= 5:
print('Only 5 items are allowed')
# clear active items and set flag
active_items, flag = [], True
return 429
elif not flag:
active_items.append(item)
return 200
elif flag:
print("Called again after cleared items")
return 200 with a test that calls on this function several times, and with the expectation that the |
I still don't understand how to create such a test with backoff. When we run the By the way, added simple query test. |
Alright, no worries. I can try giving it a shot this weekend or next. |
|
||
if not r.ok: | ||
error_message = f"Code: {r.status_code}, message: {r.text}" | ||
if response_data["code"] == 429: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denisov-vlad shouldn't this be if r.status_code == 429
? Can you provide an example 429 response from Metrica?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guidopetri thanks! Yes, r.status_code
is better here.
@denisov-vlad I converted the test to pytest and added a 429 test. The |
@guidopetri thank you! The updated code looks good. |
* metrica: added retries * updated poetry.lock * use poetry v1.6.1 * added simple test * convert unittest to pytest * add 429 test * fix 429 status code response? --------- Co-authored-by: Guido Petri <[email protected]>
What type of PR is this?
Description
Metrica has a limit for simultaneous queries. If you have dashboard with 5+ different queries there is always errors. I use backoff library to retry queries if it fails with 429 (quota exceeded) error.
How is this tested?
Ran queries with modified source both within query and dashboard.
Related Tickets & Documents
Mobile & Desktop Screenshots/Recordings (if there are UI changes)