Skip to content
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

Bug 1687491 - Dispatch all external API calls #40

Merged
merged 11 commits into from
Feb 8, 2021

Conversation

brizental
Copy link
Contributor

Not only does this change the code to dispatch all external API calls but also it adequates the dispatcher and other parts of the code for all to work as expected.

I attempted to separate the changes as well as possible in specific commits and be very descriptive in my commit messages. Sincerely hope that makes review clearer.

It seems this could have been broken in multiple PRs, but either tests would fail or the change wouldn't make sense by itself.

brizental added 8 commits February 4, 2021 12:02
This commit makes multiple tests fail, that is because by dispatching
tasks we cannot await on them anymore and this makes tests assertion
run before tasks are completed.
Initially I was simply going to use one specific rule from this set
of recommended rules "require-await", which throws a linter error
when you `await` on an expression which does not return a promise.

That was going to help me remove the `await`s from all the functions
that no longer return promises after the dispatcher changes. It's
importat to make this a rule, because during the dispatcher devolpment
I have run into many hard to find bugs related to awaiting on sync stuff.

Anyways, it turned out this small set of linter rules flagged a bunch of
bugs which we were not aware, thus I left the whole set there.
...and `testLaunch` all `testGetValue` functions.

I considered simply using testBlockOnQueue for waiting on tasks.
But that has two main issues:

- It may hang for a long time if tasks keep being enqueued;
- It does not guarantee that we continue on the expected moment.
  For example, imagine we launch multiple tasks for setting the
  same string. When we await on `testBlockOnQueue` we will wait
  for all the setting tasks and not necessarily on the one we are
  expecting. This will result in assertions at the unexpected time.
It was inevitable to provide a way to execute recording for specific
metrics without disptaching.

Let's take for example `ping.submit`. That is a dispatched task. When we
submit a ping we always record two metrics: the sequence number and the
start_time. If by any chance we lauched three ping submissions in a row
the order the dispatcher might execute the tasks is:

- ping.submit
- ping.submit
- ping.submit
- seq.add
- start_time.set
- seq.add
- start_time.set
- seq.add
- start_time.set

This would mean that all pings would be sent with the same sequence
number and start_time, since the recordings would only happen after all
pings were submitted.

Intuitively, it seems that all metric recording inside of Glean.js
itself should be done synchronously. I opened Bug 1691037 to verify this
assumption and write documentation about this.
samples/qt-qml-app/main.qml Show resolved Hide resolved
src/glean.ts Show resolved Hide resolved
src/glean.ts Outdated Show resolved Hide resolved
src/metrics/types/datetime.ts Outdated Show resolved Hide resolved
src/storage/persistent/webext.ts Outdated Show resolved Hide resolved
src/storage/weak.ts Outdated Show resolved Hide resolved
src/storage/weak.ts Outdated Show resolved Hide resolved
src/storage/weak.ts Outdated Show resolved Hide resolved
src/storage/weak.ts Outdated Show resolved Hide resolved
brizental and others added 2 commits February 5, 2021 18:03
Co-authored-by: Alessio Placitelli <alessio.placitelli@gmail.com>
Copy link
Contributor

@Dexterp37 Dexterp37 left a comment

Choose a reason for hiding this comment

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

r+wc

})
.catch(error => {
console.error(
"IMPOSSIBLE: Something went wrong while the dispatcher was executing the tasks queue.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Bets on when we'll see this message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no bets, unless we change the executeTask to not catch errors or use the observers for something else. right now it should be impossible for this to error. i only added the catch here because the linter was complaining :D

@@ -112,7 +112,7 @@ describe("PingUploader", function() {

// Trigger uploading, but don't wait for it to finish,
// so that it is ongoing when we cancel.
uploader.triggerUpload();
void uploader.triggerUpload();
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this void here for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, this is also a complaint from the linter, about not doing anything with a statement that returns a promise. but the void is pretty cool. it is not a typescript operator, it is a javacript operator and what it does is evalute whatever expression comes after it and return undefined.

@brizental brizental merged commit 96ca320 into mozilla:main Feb 8, 2021
@brizental brizental deleted the 1687491-use-the-dispatcher-4 branch February 8, 2021 13:28
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.

2 participants