Skip to content

Commit

Permalink
FXIOS-1220Fixes #6933: Added a follow-up commit to send hashed dev…
Browse files Browse the repository at this point in the history
…ice id to glean deletion ping (#7660)

- updated metrics yaml type to string in order to support hashed device id instead of uuid
- changed client guid protection level to public so that we can use it for deletion ping
  • Loading branch information
nbhasin2 authored and dnarcese committed Nov 17, 2020
1 parent e9c0cb6 commit 527275b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
24 changes: 17 additions & 7 deletions Client/Telemetry/TelemetryWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import MozillaAppServices
import Shared
import Telemetry
import Account
import Sync

class TelemetryWrapper {
let legacyTelemetry = Telemetry.default
Expand Down Expand Up @@ -155,13 +157,8 @@ class TelemetryWrapper {
// Save the profile so we can record settings from it when the notification below fires.
self.profile = profile

// Get the FxA device id and record it in Glean for the deletion-request ping
profile.getCachedClients().upon { maybeClient in
guard
let deviceId = maybeClient.successValue?.first?.fxaDeviceId.flatMap(UUID.init(uuidString:)) else { return }
GleanMetrics.Deletion.fxaDeviceId.set(deviceId)
}

setSyncDeviceId()

// Register an observer to record settings and other metrics that are more appropriate to
// record on going to background rather than during initialization.
NotificationCenter.default.addObserver(
Expand All @@ -171,6 +168,19 @@ class TelemetryWrapper {
object: nil
)
}

// Sets hashed fxa sync device id for glean deletion ping
func setSyncDeviceId() {
guard let prefs = profile?.prefs else { return }
// Grab our token so we can use the hashed_fxa_uid and clientGUID from our scratchpad for deletion-request ping
RustFirefoxAccounts.shared.syncAuthState.token(Date.now(), canBeExpired: true) >>== { (token, kSync) in
let scratchpadPrefs = prefs.branch("sync.scratchpad")
guard let scratchpad = Scratchpad.restoreFromPrefs(scratchpadPrefs, syncKeyBundle: KeyBundle.fromKSync(kSync)) else { return }

let deviceId = (scratchpad.clientGUID + token.hashedFxAUID).sha256.hexEncodedString
GleanMetrics.Deletion.syncDeviceId.set(deviceId)
}
}

// Function for recording metrics that are better recorded when going to background due
// to the particular measurement, or availability of the information.
Expand Down
4 changes: 2 additions & 2 deletions Client/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ legacy.ids:
expires: never

deletion:
fxa_device_id:
type: uuid
sync_device_id:
type: string
lifetime: user
description: |
The FxA device id.
Expand Down
2 changes: 1 addition & 1 deletion Docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The following metrics are added to the ping:

| Name | Type | Description | Data reviews | Extras | Expiration | [Data Sensitivity](https://wiki.mozilla.org/Firefox/Data_Collection) |
| --- | --- | --- | --- | --- | --- | --- |
| deletion.fxa_device_id |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The FxA device id. |[1](TBD)||never | |
| deletion.sync_device_id |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The FxA device id. |[1](https://github.com/mozilla-mobile/firefox-ios/pull/7629#issuecomment-723312428)||never | |
| legacy.ids.client_id |[uuid](https://mozilla.github.io/glean/book/user/metrics/uuid.html) |The client id from legacy telemetry. |[1](https://bugzilla.mozilla.org/show_bug.cgi?id=1635427)||never | |

## events
Expand Down
2 changes: 1 addition & 1 deletion Sync/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ open class Scratchpad {

// What's our client name?
let clientName: String
let clientGUID: String
let fxaDeviceId: String
let hashedUID: String?
public let clientGUID: String

var hashedDeviceID: String? {
guard let hashedUID = hashedUID else {
Expand Down

1 comment on commit 527275b

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

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

Uh oh! Looks like an error! Details

InterpreterError at template.tasks[0][1].extra[0].treeherder[1].symbol: unknown context value cron

Please sign in to comment.