Skip to content

Conversation

@brizental
Copy link
Contributor

@brizental brizental commented Sep 1, 2021

After tests, I confirmed none of the sample apps were recording the glean.restarted event when Glean was initialized :/ That was the case, because we were calling eventsDatabase.initialize before setting Context.uploadEnabled. That meant Context.uploadEnabled was undefined upon events database initialization and undefined being a falsy value, .shouldRecord() was returning false, which resulted in the glean.restarted and execution_counter metrics not being recorded.

In 8324569 I fix that and in 4cb6118 I add a test to ensure that if this behaviour ever changes we will see test failures.

The commits in between these two commits are there to make sure the test does fail if the behaviour is changed. I actually found a bug in the way we were reseting Glean in tests. We were not reseting all the preoperties in the Context, only a few. That would prevent the test I added from actually failing when it had to.

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
    • This is a bugfix, I guess a CHANGELOG entry is documentation enough.

@auto-assign auto-assign bot requested a review from mdboom September 1, 2021 10:28
@brizental brizental requested review from badboy and removed request for mdboom September 2, 2021 09:21
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.

//
// This is fine, we are inside a dispatched task that is guaranteed to run before any
// other task. No external API call will be executed before we leave this task.
Context.initialized = true;
Copy link
Member

Choose a reason for hiding this comment

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

Is anything else depending on this value and could now cause problems because there's still intialization happening after this value is set to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only ping submission / upload check if Glean is initialized, but both actions usually happen inside dispatched tasks (aside from onUploadDisabled, when we send the deletion-request ping undispatched). Because the initialize task is always executed before of all other dispatched tasks so we should be fine.

This is a good exercise though. We need to really think hard before adding anything to this initialize function. It's very of fragile, order matters, etc.

There is no reason not to do it and as soon as these properties
are set they can be used, so better to set them as soon as possible.

This was not causing any bugs at the moment, but might in the future.
If we had such an error message, we might not have missed the
issue about not being able to record the glean.restarted event
upon initialization. The whole problem there was trying to access
Context.uploadEnabled before it was set.
This is important in order to make sure test mimick correctly
what happens in real usage.
I know the solution here is a bit sloppy, but I decided
to pick my battles and got he easy route on this one.
@brizental brizental force-pushed the 1728128-restarted-webext-qt-verify branch from e7764e1 to 302fe31 Compare September 2, 2021 12:57
@brizental brizental merged commit 76f9034 into mozilla:main Sep 2, 2021
@brizental brizental deleted the 1728128-restarted-webext-qt-verify branch September 2, 2021 13:02
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