Skip to content

Conversation

@brizental
Copy link
Contributor

@brizental brizental commented Nov 24, 2021

With the previous design it was hard and hacky to enforce the rate limit defaults at the correct time.

The new design (or old, depends on how you look at it) allows to do that easily.

It also has the following added benefits 1) logic is better encapsulated in different structures 2) the design is almost exactly the same as the one in glean-core, so transfer of knowledge and ensurace of standardized functionality is easier to do 3) it doesn't have an internal dispatcher instance 4) it's just easier to reason about it, IMO.

Note: I suggest reviewing this PR commit by commit. I did my best to isolate changes, but this is a big change and there is no going around that.

Pull Request checklist

  • Quality: Make sure this PR builds and runs cleanly.
    • Inside the glean/ folder, run:
      • npm run test Runs all tests
      • npm run lint Runs all linters
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry to CHANGELOG.md or an explanation of why it does not need one
  • Documentation: This PR includes documentation changes, an explanation of why it does not need that or a follow-up bug has been filed to do that work

@brizental brizental changed the title Bug 1742093 - Refactor upload management log to be exactly like in glean-core Bug 1742093 - Refactor upload management logic to be exactly like in glean-core Nov 24, 2021
@brizental brizental marked this pull request as ready for review November 24, 2021 15:19
@auto-assign auto-assign bot requested a review from Dexterp37 November 24, 2021 15:20
@brizental brizental requested review from Dexterp37 and badboy and removed request for Dexterp37 November 24, 2021 15:20
@brizental
Copy link
Contributor Author

Adding @badboy here as a reviewer as well, because he knows this mechanism very well and also I think it wouldn't hurt to get 2 pairs of eyes looking at this change to be more confident we caught any issues before merging.

@moz-glean
Copy link
Collaborator

Build size report

Merging #988 into main will:

  • Leave the size of full Web Extension bundle unchanged.
  • Leave the size of full Website bundle unchanged.
  • Leave the size of full Node.js bundle unchanged.
  • Leave the size of full Qt/QML bundle unchanged.

Current size New size Size increase
Web Extension
core only 64 KB 64 KB 📈 239 bytes
full bundle 86 KB 86 KB 📈 242 bytes
Website
core only 65 KB 65 KB 📈 240 bytes
full bundle 87 KB 87 KB 📈 240 bytes
Node.js
core only 63 KB 63 KB 📈 232 bytes
full bundle 91 KB 91 KB 📈 232 bytes
Qt/QML
core only 67 KB 68 KB 📈 327 bytes
full bundle 67 KB 68 KB 📈 327 bytes

@brizental brizental removed the request for review from Dexterp37 November 25, 2021 10:42
In the previous implementation we were tying the ability to retry
sending recovarebly failed upload request to the rate limiter state
i.e. a user could only retry after the rate limiter time window was
over. In order to do that we introduced a new state to the rate limiter,
the Stopped state. When max recoverable failures was fit, we would out
the rate limiter in that state. It would work just a like the Throttled
state in the sense that the rate limiter would only get out of it once
the time window was complete.

That is actually not how the implementation in glean-core works. In
there we simply stop the upload worker sending it a Done signal once max
recorable failures is hit. If the worker is re-started immediatelly
after it will be allowed to get new tasks.

That is now how the implementation works in this repository as well. I
wonder if tying the retries to the rate limiter window is still a beter
idea, but that has not caused us problems up until now in glean-core, so
for now, I'll leave it like this.'
@brizental brizental force-pushed the 1742093-rate-limit-at-upload-time branch from fc34fb7 to 32a966d Compare November 25, 2021 10:48
Copy link
Member

@badboy badboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Minimal things inline, but no need for me to re-review.

Comment on lines +214 to +215
assert.strictEqual(resultInternalServerError.result, UploadResultStatus.Success);
assert.strictEqual(resultInternalServerError.status, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Success: failure.

:D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, yeah naming is hard.

continue;
// TODO(bug1727076): Actually set a timer to continue once timeout is complete.
// Note that the timer must be cleared in case an abort signal is issued.
case UploadTaskTypes.Wait:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fall through to the Done case? If yes, all good (though maybe add a comment // explicit fallthrough).
If not it should explicitly return or it will run into the throttling 3 times immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap it falls through.

Co-authored-by: Jan-Erik Rediger <badboy@archlinux.us>
@brizental brizental merged commit bed4649 into mozilla:main Nov 26, 2021
@brizental brizental deleted the 1742093-rate-limit-at-upload-time branch November 26, 2021 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants