Skip to content

Conversation

@rosahbruno
Copy link
Contributor

@rosahbruno rosahbruno commented Aug 24, 2022

Description

Add functionality to delete all trailing glean.restarted events. Now before returning the formatted events for the ping, we pop items from the array until we hit one that isn't a restarted event. If the last item is not a glean.restarted event, then it will not do anything.

Glean Book Documentation PR - mozilla/glean#2172

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

When we send a ping, we want to avoid passing unnecessary trailing
restarted events. Before we return the payload, we can step backwards
through our events array and pop each restarted event until we hit an
event that is a non-restarted event. At this point we return the array
since all trailing events have been removed.

In the case that the array does not have a trailing restarted event, we
avoid invoking the new functionality completely.
We generate an array of events, in a somewhat unorthodox manner to
ensure that our original array contains multiple trailing restarted
events. We then put a few restarted events between non-restarted events
to verify that we stop removing items once we hit a non-restarted event.
We no longer keep `glean.restarted` events at the end of the events
array, so the tests needed to be updated to reflect that. The tests
check everything the same way, they just no longer check that the final
item is a `glean.restarted` event.
@rosahbruno rosahbruno force-pushed the 1723090-delete-trailing-restart-events branch from 6d4ea73 to 77e8cdd Compare August 24, 2022 17:27
@rosahbruno
Copy link
Contributor Author

I want to get a second opinion on what should be updated in the docs. If you look under glean.restarted there is verbiage that I am not entirely sure is accurate anymore. https://github.com/mozilla/glean.js/blob/9186c5aa38ab6a35b184137e6c8f8985b771e5d8/docs/reference/metrics.md#all-pings

We now strip the first restarted event from the events array as well as all trailing events. I may lack enough context to know for sure, but I would think that there is a possibility now where that event doesn't get passed at all.

I am going to do some testing with the sample projects to try and confirm as well.

Found a more straightforward way to trigger a restart without
forcing an error.
- Additional clarifying comments
- More descriptive variable names for mock events array values.
@rosahbruno rosahbruno force-pushed the 1723090-delete-trailing-restart-events branch from 54fbc1e to 9772c2e Compare August 25, 2022 18:18
@badboy
Copy link
Member

badboy commented Aug 26, 2022

Just noticed that I wrote some comments, but didn't submit them -_-

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.

Code looks good, but PR is still in draft mode. If you're ready turn it into a full PR please.

@badboy
Copy link
Member

badboy commented Aug 26, 2022

I want to get a second opinion on what should be updated in the docs. If you look under glean.restarted there is verbiage that I am not entirely sure is accurate anymore. 9186c5a/docs/reference/metrics.md#all-pings

We now strip the first restarted event from the events array as well as all trailing events. I may lack enough context to know for sure, but I would think that there is a possibility now where that event doesn't get passed at all.

I am going to do some testing with the sample projects to try and confirm as well.

I think that wording is still correct, though is leaving out a bit of context.
In general glean.restarted can end up in any ping with events, without the user needing to define anything extra.
Whether a specific ping with events has that particular event depends on whether the application was actually restarted.
Even if we strip the first and all trailing restarted events it might still occur in the middle.

@rosahbruno
Copy link
Contributor Author

Code looks good, but PR is still in draft mode. If you're ready turn it into a full PR please.

Was just waiting on some feedback for the docs part since I knew that was going to still need updating before publishing for real. I will update the docs with that additional context, look at triggering restarts without an error, then publish this.

@badboy thanks for the multiple reviews!

@badboy
Copy link
Member

badboy commented Aug 26, 2022

Code looks good, but PR is still in draft mode. If you're ready turn it into a full PR please.

Was just waiting on some feedback for the docs part since I knew that was going to still need updating before publishing for real. I will update the docs with that additional context, look at triggering restarts without an error, then publish this.

yeah, I'm not sure how to concisely add that for the single metric.
We explain glean.restarted a tiny bit more in the Glean SDKs book.

@rosahbruno
Copy link
Contributor Author

Code looks good, but PR is still in draft mode. If you're ready turn it into a full PR please.

Was just waiting on some feedback for the docs part since I knew that was going to still need updating before publishing for real. I will update the docs with that additional context, look at triggering restarts without an error, then publish this.

yeah, I'm not sure how to concisely add that for the single metric. We explain glean.restarted a tiny bit more in the Glean SDKs book.

@badboy
I added a small clarification in the metrics.md docs just to note that those leading and trailing restarted events will be omitted. I can add a note in the Glean SDKs book too, since there is already that JS specific section.

a8f8ed4

- generate barrel file to better manage `testing/core` exports
- create testing util that restarts glean by creating a new instance of
  the `EventsDatabase`
- update existing and new tests to use new restart helper
@rosahbruno rosahbruno force-pushed the 1723090-delete-trailing-restart-events branch from 1bb3d33 to b5fe0a1 Compare August 26, 2022 15:06
await testInitializeGlean(applicationId, uploadEnabled, config);
}

export * from "./utils.js";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarification for this

A more common pattern in JS/TS is to bubble all of your folder/module exports up to an index.ts file, "barrel file", and export everything from there.

That way when you are accessing different functions/variables/constants you only have to drill down to the top level of the folder when importing. So instead of pulling 3 things from index, 4 things from utils, etc, you re-export everything you need from the index then you can just import it all via import {} from '../core/testing.

This also helps to keep things more organized and modular. You start to see very quickly what may be tightly coupled to a module that doesn't need to be.

@rosahbruno
Copy link
Contributor Author

PR is now ready for review. I've made all PR changes as well as create a documentation update PR for the Glean Book.

@rosahbruno rosahbruno merged commit f2b2880 into mozilla:main Aug 29, 2022
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