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

WIP: 1624695: Act on changes in upload enable state outside of application #786

Closed
wants to merge 3 commits into from

Conversation

mdboom
Copy link
Contributor

@mdboom mdboom commented Mar 26, 2020

This is trickier than it needs to be because the handling of actions
based on the change in upload state is handled both on the Rust and
language wrapper side.

The solution I arrived at is to no longer pass in an initial value
for upload enabled when initializing the Rust side, but to instead let
Glean determine the upload enable state from the database -- it is
disabled if either there is no client_id or client_id == c0ffee.

Then the language bindings immediately change the upload state based
on the what the user has passed in, allowing the usual state flipping
operations to run as usual.

Even though the FfiConfiguration object loses an uploadEnabled field as
part of this change, that is purely internal API and the public API doesn't
change at all here.

Before merging:

  • Port new tests to Swift

@auto-assign auto-assign bot requested a review from Dexterp37 March 26, 2020 20:33
@badboy badboy self-assigned this Mar 27, 2020
@badboy badboy self-requested a review March 27, 2020 10:57
@badboy badboy removed their assignment Mar 27, 2020
This is trickier than it needs to be because the handling of actions
based on the change in upload state is handled both on the Rust and
language wrapper side.

The solution I arrived at is to no longer pass in an initial value
for upload enabled when initializing the Rust side, but to instead let
Glean determine the upload enable state from the database -- it is
disabled if either there is no client_id or client_id == c0ffee.

Then the language bindings immediately change the upload state based
on the what the user has passed in, allowing the usual state flipping
operations to run as usual.

Even though the FfiConfiguration object loses an uploadEnabled field as
part of this change, that is purely internal API and the public API doesn't
change at all here.
@mdboom mdboom force-pushed the deletion-request-at-init branch from a7e8265 to 2b5ea92 Compare March 27, 2020 12:56
@mdboom mdboom changed the title 1624695: Act on changes in upload enable state outside of application WIP: 1624695: Act on changes in upload enable state outside of application Mar 27, 2020
@@ -261,7 +262,7 @@ open class GleanInternalAPI internal constructor () {
val originalEnabled = getUploadEnabled()

@Suppress("EXPERIMENTAL_API_USAGE")
Dispatchers.API.launch {
Dispatchers.API.executeTask {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mh, this means that whenever users call setUploadEnabled we immediately flip, rather than enqueuing the call. We should think thorougly about what this implies.

Why are you changing this? What's the specific problem you were seeing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to happen before any of the preinit tasks run. executeTask merely adds to the "real" queue rather than the preinit queue. After preinit time, it's basically identical to launch.

@Test
fun `no sending of deletion ping if unchanged outside of run`() {
val server = getMockWebServer()
resetGlean(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we'd also want to check that we're not mistakenly resetting the client id for extra safety. Unless that's done in some existing test already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be, but it's not a bad idea to do it here as well.

@@ -199,7 +200,7 @@ public class Glean {
if isInitialized() {
let originalEnabled = getUploadEnabled()

Dispatchers.shared.launchAPI {
Dispatchers.shared.launchConcurrent {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same concern here that I had from the Android version

@@ -7,8 +7,6 @@
/// Optional values will be filled in with default values.
#[derive(Debug, Clone)]
pub struct Configuration {
/// Whether upload should be enabled.
pub upload_enabled: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this is actually required, in this case? This is basically an external package/API, we're changing internals in other places.

//! max_events: None,
//! delay_ping_lifetime_io: false,
//! channel: None,
//! };
//! glean_preview::initialize(cfg, ClientInfoMetrics::unknown())?;
//! glean_preview::set_upload_enabled(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that glen_preview::initialize, in this case, should take care of calling the right thing internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

@@ -181,7 +179,7 @@ impl Glean {
let event_data_store = EventDatabase::new(&cfg.data_path)?;

let mut glean = Self {
upload_enabled: cfg.upload_enabled,
upload_enabled: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's add a comment to not scare our future selves out. This should not trigger a wipeout of the stored client id.

.client_id
.get_value(&glean, "glean_client_info")
{
None => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we keep all the existing code and change this part slightly: let's only find if we have an existing non coffee client id. If so, forcefully trigger the deletion ping here, as done in there. This would require us to deteramine is_first_run a bit earlier.

Moreover, wouldn't the current approach generate a new deletion ping the first time a new profile starts the product with telemetry disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if we keep all the existing code and change this part slightly: let's only find if we have an existing non coffee client id. If so, forcefully trigger the deletion ping here, as done in there. This would require us to deteramine is_first_run a bit earlier.

I tried that initially, but the problem is that we need to both submit the deletion ping (which happens in Rust) and trigger the deletion ping uploader (from the language bindings).

I have some thoughts about refactoring this further to make the line between the Rust and language binding side less weird here.

Moreover, wouldn't the current approach generate a new deletion ping the first time a new profile starts the product with telemetry disabled?

Yes, that's true. Should work on that case as well, I guess.

mdboom and others added 2 commits March 27, 2020 10:59
Co-Authored-By: Alessio Placitelli <alessio.placitelli@gmail.com>
@mdboom
Copy link
Contributor Author

mdboom commented Mar 30, 2020

Found a much simpler approach in #791

@mdboom mdboom deleted the deletion-request-at-init branch April 14, 2020 19:13
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