-
Notifications
You must be signed in to change notification settings - Fork 135
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
Conversation
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.
a7e8265
to
2b5ea92
Compare
@@ -261,7 +262,7 @@ open class GleanInternalAPI internal constructor () { | |||
val originalEnabled = getUploadEnabled() | |||
|
|||
@Suppress("EXPERIMENTAL_API_USAGE") | |||
Dispatchers.API.launch { | |||
Dispatchers.API.executeTask { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Co-Authored-By: Alessio Placitelli <alessio.placitelli@gmail.com>
Found a much simpler approach in #791 |
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: