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

Enable gzip compression for Sync PATCH payloads #803

Merged
merged 13 commits into from May 10, 2024

Conversation

ayoy
Copy link
Contributor

@ayoy ayoy commented Apr 30, 2024

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/0/1206919211758354/f
iOS PR: duckduckgo/iOS#2805
macOS PR: https://github.com/duckduckgo/macos-browser/pull/2723
What kind of version bump will this require?: Patch

Description:
This change adds gzip compression to all Sync data PATCH requests.

Steps to test this PR:

  1. Run both iOS and macOS apps from branches in linked PRs.
  2. Connect devices with Sync and smoke test syncing data.

Internal references:

Software Engineering Expectations
Technical Design Template

@ayoy ayoy self-assigned this Apr 30, 2024
@ayoy ayoy requested a review from bwaresiak April 30, 2024 07:17
@ayoy ayoy marked this pull request as ready for review April 30, 2024 07:17
@ayoy ayoy assigned bwaresiak and unassigned ayoy Apr 30, 2024
return api.createAuthenticatedJSONRequest(url: endpoints.syncPatch, method: .PATCH, authToken: try getToken(), json: body)
let headers = ["Content-Encoding": "gzip"]

let body = try JSONSerialization.data(withJSONObject: json, options: []).gzipped()
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed on zoom, we 1) could proceed here even if gzipping fails 2) it would be good to know if it fails - it is not actionable, but information that certain volume of patches fail could be a signal itself.

@ayoy ayoy assigned ayoy and unassigned bwaresiak Apr 30, 2024
do {
return try requestMaker.makePatchRequest(with: syncRequest, clientTimestamp: timestamp, isCompressed: true)
} catch let error as GzipError {
dataProvider.handleSyncError(error)
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 will be emitted by dataProvider.syncErrorPublisher and handled on the client side (e.g. in SyncBookmarksAdapter) by firing a suitable "sync failed" pixel (e.g. syncBookmarksFailed). This is acceptable even though sync didn't actually fail here, only the compression failed. We aren't expecting huge volume of compression errors anyway, and if they become an issue we may add a dedicated pixel.

@ayoy ayoy requested a review from SabrinaTardio May 6, 2024 12:19
@ayoy ayoy assigned SabrinaTardio and unassigned ayoy May 6, 2024

struct SyncPayloadCompressor: SyncPayloadCompressing {
func compress(_ payload: Data) throws -> Data {
try payload.gzipped()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can simulate an error here by using @testable import Gzip on the top and throw GzipError(code: 100, msg: nil)

@ayoy ayoy removed the DO NOT MERGE label May 10, 2024
Copy link
Contributor

@SabrinaTardio SabrinaTardio left a comment

Choose a reason for hiding this comment

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

LGTM a couple of non blocking nit to consider

Sources/DDGSync/internal/SyncRequestMaker.swift Outdated Show resolved Hide resolved
Sources/DDGSync/internal/SyncPayloadCompressor.swift Outdated Show resolved Hide resolved
@ayoy ayoy merged commit 72be4e7 into main May 10, 2024
7 checks passed
@ayoy ayoy deleted the dominik/sync-payload-compression branch May 10, 2024 12:41
samsymons added a commit that referenced this pull request May 10, 2024
* main:
  Enable gzip compression for Sync PATCH payloads (#803)
  autofill: send current language in runtime config (#808)
  Password manager survey update (#811)
  on iOS allow bookmarks in top hits (#812)
  Rename tests to avoid conflicts (#813)
  Bat.js fix (fix for installing content blocking rules multiple times) (#779)
  Pixels automatic naming prefixing fixed (#810)
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.

None yet

3 participants