-
Notifications
You must be signed in to change notification settings - Fork 476
[glean]Use WorkManager for uploading glean pings #1973
Conversation
|
This is still work in progress, mostly because I found a limitation on how I was passing data to the WorkManager worker that restricts the data to 10240 bytes because it relies on androidx.work.Data object. This probably isn't an issue for baseline pings but I have concerns with events and metrics pings exceeding this size. If that is the case, another method of serializing the ping payload that is accessible to the worker may be required. Also, I need to add tests for the worker class, which I'm currently looking at the best way to do this. |
I think this requires a bit of discussion around the design: we probably want to follow a similar approach to how the legacy telemetry library was handling things. This would allow us to work around the size limitation by serializing pings to disk.
Yeah, that depends on how the work about "extending the baseline ping goes". I doubt we'll ever go over 10kB with the baseline ping, but we will probably do for other pings. |
Yeah, the old library writes pings to disk and then schedules an upload job. There will always only be one job scheduled. Once the job runs it uploads all pings that are waiting on disk. |
Codecov Report
@@ Coverage Diff @@
## master #1973 +/- ##
============================================
- Coverage 84.88% 84.63% -0.25%
- Complexity 2353 2379 +26
============================================
Files 279 281 +2
Lines 9624 9685 +61
Branches 1418 1425 +7
============================================
+ Hits 8169 8197 +28
- Misses 872 897 +25
- Partials 583 591 +8
Continue to review full report at Codecov.
|
components/service/glean/src/main/java/mozilla/components/service/glean/Glean.kt
Outdated
Show resolved
Hide resolved
6a80493 to
eff6af9
Compare
|
Okay, I finally feel pretty good about the test coverage and functionality. I was able to pull most/all of the scheduling code out of Glean.kt and implement it into the PingScheduler class (which also assumed the role of the LifecycleObserver), as well as implement a PingStorageEngine for managing writing the pings to file. This change in things forced me to do a lot of changes to the way we test the pings and unfortunately its now much harder(impossible?) to test using a mock http server where we were using it so it now tests that the work gets scheduled and that the worker does what it's supposed to do working with the HttpUploader class. I expect some criticism/feedback over the size/breadth of the refactor so please don't hold back. I think that overall this cleans up the things that needed cleaned up and puts things where they should be. I'll be leaving this a WIP until everyone weighs in. |
|
Gah, this is so weird. All tests pass locally but I'm randomly getting different test in taskcluster that fail. I've done this twice now, first time 12 tests failed, this time 2 tests failed (all in service-glean). Going to try it again and see what happens... Well, at least I got two different tests to fail this time :/ 4th times a charm! (FINALLY lol) |
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 was a lot of work, but it's looking good.
I feel like it's big enough that I may have missed things, so don't be offended if my comments are pointing out problems that don't exist.
components/service/glean/src/main/java/mozilla/components/service/glean/Glean.kt
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingUploadWorker.kt
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Show resolved
Hide resolved
components/service/glean/src/test/java/mozilla/components/service/glean/EventMetricTypeTest.kt
Show resolved
Hide resolved
components/service/glean/src/test/java/mozilla/components/service/glean/GleanTest.kt
Show resolved
Hide resolved
78cc8a7 to
592dcb3
Compare
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.
Hey Travis! I gave this a first look. In general, this looks ok. A few high level observations:
- can we remove from this PR everything that is not required for it? it would make review much easier;
- do we need to save pings in specific, separate directories for each type?
components/service/glean/src/main/java/mozilla/components/service/glean/Glean.kt
Outdated
Show resolved
Hide resolved
components/service/glean/src/main/java/mozilla/components/service/glean/Glean.kt
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
components/service/glean/src/test/java/mozilla/components/service/glean/TestLifeCycleOwner.kt
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
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 gave this a more in-depth look. I had to un-resolve some comments that were marked as resolved in the previous PR, but they were not :( Let's make sure to address all the comments before the next iteration - darn github.
components/service/glean/src/main/java/mozilla/components/service/glean/Dispatchers.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingUploadWorker.kt
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
components/service/glean/src/main/java/mozilla/components/service/glean/Glean.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...rvice/glean/src/test/java/mozilla/components/service/glean/storages/PingStorageEngineTest.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...rvice/glean/src/test/java/mozilla/components/service/glean/storages/PingStorageEngineTest.kt
Outdated
Show resolved
Hide resolved
2bab302 to
0125282
Compare
c7e8b95 to
3f936ed
Compare
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.
We're close to the finish line with this, I think. This final pass is for requesting bugs to be filed. My remaining major concern is about the Thread.sleep functions in tests. Let's not use them but rather investigate why this is failing.
components/service/glean/src/main/java/mozilla/components/service/glean/Glean.kt
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingUploadWorker.kt
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
...nents/service/glean/src/test/java/mozilla/components/service/glean/TimespanMetricTypeTest.kt
Show resolved
Hide resolved
...rvice/glean/src/test/java/mozilla/components/service/glean/storages/PingStorageEngineTest.kt
Outdated
Show resolved
Hide resolved
...rvice/glean/src/test/java/mozilla/components/service/glean/storages/PingStorageEngineTest.kt
Outdated
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
components/service/glean/src/test/java/mozilla/components/service/glean/GleanTest.kt
Show resolved
Hide resolved
75ef377 to
915864e
Compare
|
@Dexterp37 ready for another look. I believe I have addressed all of the changes you requested. |
|
FYI The merging in of the async await stuff for the test API functions helped the flakiness with passing of tests. |
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.
!
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.
🚢
| @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) | ||
| val pingStorageEngine = pingStorageEngine | ||
| @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) | ||
| val metricsPingScheduler = metricsPingScheduler |
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: You can mark them as val inside the constructor above. (maybe internal too?)
...ents/service/glean/src/main/java/mozilla/components/service/glean/scheduler/PingScheduler.kt
Outdated
Show resolved
Hide resolved
...s/service/glean/src/main/java/mozilla/components/service/glean/storages/PingStorageEngine.kt
Outdated
Show resolved
Hide resolved
Adding a storage engine for async serialization of pings Implement tests that work with WorkManager
Pull Request checklist