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

Remove service-glean's hard-dependency on httpurlconnection #6875

Merged

Conversation

badboy
Copy link
Member

@badboy badboy commented May 5, 2020

Remove service-glean's hard-dependency on httpurlconnection

We still test with it, so we keep it around.

BREAKING CHANGE:

Users will need to supply a configuration with a ping uploader to Glean
now.
A default lib-fetch-httpurlconnection implementation can be used like
this:

import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;
import mozilla.components.service.glean.config.Configuration;
import mozilla.components.service.glean.net.ConceptFetchHttpUploader;

val config = Configuration(httpClient = ConceptFetchHttpUploader(lazy { HttpURLConnectionClient() }))
Glean.initialize(context, true, config)

For Java this becomes:

import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;
import mozilla.components.service.glean.config.Configuration;
import mozilla.components.service.glean.net.ConceptFetchHttpUploader;

ConceptFetchHttpUploader httpClient = ConceptFetchHttpUploader.fromClient(new HttpURLConnectionClient());
Configuration config = new Configuration(httpClient);
Glean.INSTANCE.initialize(context, true, config);

Fixes #6660 (at least partly)

I'm not familiar enough with service-experiments, so @travis79 would need to take a look.

cc @pocmo for visibility.


Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Milestone: Make sure issues closed by this pull request are added to the milestone of the version currently in development.
  • Breaking Changes: If this is a breaking change, please push a draft PR on Reference Browser to address the breaking issues.

@badboy badboy requested a review from Dexterp37 May 5, 2020
if (httpClient != null) {
return GleanCoreConfiguration(serverEndpoint, channel, maxEvents, httpClient)
} else {
return GleanCoreConfiguration(serverEndpoint, channel, maxEvents)
Copy link
Contributor

@Dexterp37 Dexterp37 May 5, 2020

Choose a reason for hiding this comment

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

Is our default behaving the same as lib-fetch-httpurlconnection? Please note that this will have impact on Lockwise and Firefox Reality. I'd rather making this explicit..

Copy link
Member Author

@badboy badboy May 5, 2020

Choose a reason for hiding this comment

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

Make it explicit how?
We don't want to depend on lib-fetch-httpurlconnection.
We implement a ping uploader here: https://github.com/mozilla/glean/blob/4aab82a58c0e9db1577ebd10019447155bb846e7/glean-core/android/src/main/java/mozilla/telemetry/glean/net/HttpURLConnectionUploader.kt#L20
It's defering upload to java.net.HttpURLConnection.

IMO it makes more sense to not redefine anything like that in a-c.
That only means we would now introduce a second place we need to change if we ever touch the Glean core uploader.

Copy link
Contributor

@Dexterp37 Dexterp37 May 5, 2020

Choose a reason for hiding this comment

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

Sorry I wasn't clear :-) I mean let's just drop any default and force users to explicitly state what they want.

Copy link
Member Author

@badboy badboy May 5, 2020

Choose a reason for hiding this comment

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

If we only drop it here than that configuration API differs between a-c and direct use, which seems ... not good

Copy link
Contributor

@Dexterp37 Dexterp37 May 5, 2020

Choose a reason for hiding this comment

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

The API already differs between a-c and direct use: a-c depends on ConceptFetch while direct use doesn't know about it.

If the intent here is to make sure Mozilla users are intentional with the upload mechanism, I'm afraid this is the only option.

Copy link
Member Author

@badboy badboy May 6, 2020

Choose a reason for hiding this comment

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

That would mean we're also breaking all the current users, as they are now forced to pass this explicitly.
Are we okay with doing that?

Copy link
Contributor

@Dexterp37 Dexterp37 May 6, 2020

Choose a reason for hiding this comment

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

Are we okay with doing that?

This is what @pocmo was asking: I'm not a fan of this dance, to be honest, but we're living in A-C and we should respect the A-C's guidelines :-)

Copy link
Contributor

@pocmo pocmo May 6, 2020

Choose a reason for hiding this comment

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

but we're living in A-C and we should respect the A-C's guidelines :-)

I'm open to discussing this though. :)

I think it is a fairly cheap breakage: Apps can fix this with one line of code. Fenix shouldn't break since Fenix should never use anything but Gecko for network communication. If it breaks Fenix then this would be good. :)

Lockwise: Yeah, they would probably need to add HttpUrlConnectionClient manually once. I think that is fine.

Firefox Reality: Haven't looked at it yet. But if it breaks then this may actually be good since I assume there is a strong reason to also use Gecko for all network communication in Firefox Reality. And if they have been using HttpUrlConnection instead then this may exactly be one of the cases where the default was not obvious (or having the choice) and where the default is the opposite of what we wanted.

Copy link
Contributor

@pocmo pocmo May 6, 2020

Choose a reason for hiding this comment

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

Firefox Reality seems to use the default and I filed an issue for changing that: MozillaReality/FirefoxReality#3339

@badboy badboy force-pushed the glean-remove-hard-dependency-on-httpurl branch from 202d52d to 7f05b79 Compare May 6, 2020
@badboy
Copy link
Member Author

@badboy badboy commented May 6, 2020

I updated the PR now. I still need to test that it still works in the mentioned apps and probably prepare PRs for them.

@badboy badboy requested review from pocmo and Dexterp37 May 6, 2020
docs/changelog.md Outdated Show resolved Hide resolved
* This looses the lazyness of creating the `client`.
*/
@JvmStatic
fun fromClient(client: Client): ConceptFetchHttpUploader {
Copy link
Contributor

@Dexterp37 Dexterp37 May 6, 2020

Choose a reason for hiding this comment

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

Firefox Reality would need to use a different uploader. Do we need to do this for other uploaders as well? @pocmo

Copy link
Contributor

@pocmo pocmo May 6, 2020

Choose a reason for hiding this comment

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

I'm not sure I fully understand. The 1:1 migration for Firefox Reality would be to continue using HttpUrlConnectionClient (MozillaReality/FirefoxReality#3339)?

Copy link
Member Author

@badboy badboy May 6, 2020

Choose a reason for hiding this comment

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

Client is coming from concept-fetch.
So as long as whatever they want to use adheres to that they're fine.

docs/changelog.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Dexterp37 Dexterp37 left a comment

LGTM. Let's update our Glean docs for A-C consumers. Also cc @mdboom

@badboy badboy force-pushed the glean-remove-hard-dependency-on-httpurl branch 3 times, most recently from 148be00 to 510fad9 Compare May 6, 2020
@codecov
Copy link

@codecov codecov bot commented May 6, 2020

Codecov Report

Merging #6875 into master will increase coverage by 0.17%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #6875      +/-   ##
============================================
+ Coverage     77.07%   77.24%   +0.17%     
+ Complexity     4867     4711     -156     
============================================
  Files           653      641      -12     
  Lines         24011    23290     -721     
  Branches       3519     3409     -110     
============================================
- Hits          18506    17991     -515     
+ Misses         4040     3898     -142     
+ Partials       1465     1401      -64     
Impacted Files Coverage Δ Complexity Δ
...ain/java/mozilla/components/service/glean/Glean.kt 62.50% <ø> (-2.21%) 4.00 <0.00> (-1.00)
...a/components/service/glean/config/Configuration.kt 83.33% <50.00%> (-16.67%) 3.00 <0.00> (ø)
...ents/service/glean/net/ConceptFetchHttpUploader.kt 100.00% <100.00%> (ø) 7.00 <0.00> (ø)
...r/toolbar/behavior/BrowserToolbarBottomBehavior.kt 71.05% <0.00%> (-8.95%) 13.00% <0.00%> (-11.00%)
...java/mozilla/components/lib/crash/CrashReporter.kt 84.70% <0.00%> (-1.01%) 30.00% <0.00%> (-2.00%)
...components/browser/awesomebar/BrowserAwesomeBar.kt 95.69% <0.00%> (-0.14%) 32.00% <0.00%> (ø%)
...ozilla/components/feature/tabs/ext/BrowserState.kt 100.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
...lla/components/feature/tabs/ext/TabSessionState.kt 100.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
...ponents/feature/tabs/tabstray/TabsTrayPresenter.kt 93.93% <0.00%> (ø) 9.00% <0.00%> (ø%)
...ts/concept/engine/manifest/WebAppManifestParser.kt 85.34% <0.00%> (ø) 6.00% <0.00%> (ø%)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c29ab1d...5bb9171. Read the comment docs.

@badboy badboy force-pushed the glean-remove-hard-dependency-on-httpurl branch 2 times, most recently from f79abaf to 51219e9 Compare May 11, 2020
badboy and others added 2 commits May 13, 2020
We still test with it, so we keep it around.

⚠️ **BREAKING CHANGE** ⚠️

Users will need to supply a configuration with a ping uploader to Glean
now.
A default lib-fetch-httpurlconnection implementation can be used like
this:

```kotlin
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;
import mozilla.components.service.glean.config.Configuration;
import mozilla.components.service.glean.net.ConceptFetchHttpUploader;

val config = Configuration(httpClient = ConceptFetchHttpUploader(lazy { HttpURLConnectionClient() }))
Glean.initialize(context, true, config)
```

For Java this becomes:

```java
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;
import mozilla.components.service.glean.config.Configuration;
import mozilla.components.service.glean.net.ConceptFetchHttpUploader;

ConceptFetchHttpUploader httpClient = ConceptFetchHttpUploader.fromClient(new HttpURLConnectionClient());
Configuration config = new Configuration(httpClient);
Glean.INSTANCE.initialize(context, true, config);
```

Co-authored-by: Alessio Placitelli <alessio.placitelli@gmail.com>
@badboy badboy force-pushed the glean-remove-hard-dependency-on-httpurl branch from 51219e9 to 5bb9171 Compare May 13, 2020
@Dexterp37
Copy link
Contributor

@Dexterp37 Dexterp37 commented May 13, 2020

Please go ahead and merge this ;)

@badboy
Copy link
Member Author

@badboy badboy commented May 13, 2020

bors r=Dexterp37

pocmo
pocmo approved these changes May 13, 2020
Copy link
Contributor

@pocmo pocmo left a comment

👍

@bors
Copy link

@bors bors bot commented May 13, 2020

Build succeeded:

@bors bors bot merged commit 6719e01 into mozilla-mobile:master May 13, 2020
2 of 118 checks passed
@badboy badboy deleted the glean-remove-hard-dependency-on-httpurl branch May 19, 2020
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.

4 participants