Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions components/remote_settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ default = []
signatures = ["dep:canonical_json", "dep:rc_crypto"]
# submitting glean telemetry is tricky on desktop for now.
telemetry-submission = []
# Record metrics directly from Rust via glean-sym, instead of through the
# `RemoteSettingsTelemetry` foreign callback.
glean-sym = ["dep:glean-sym", "glean-sym/active"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -35,9 +38,11 @@ firefox-versioning = { path = "../support/firefox-versioning" }
sha2 = "^0.10"
canonical_json = { version = "0.5", optional = true }
rc_crypto = { path = "../support/rc_crypto", optional = true }
glean-sym = { version = "71", optional = true }

[build-dependencies]
uniffi = { version = "0.32", features = ["build"] }
glean-build = { git = "https://github.com/mozilla/glean", tag = "v71.0.0" }

[dev-dependencies]
expect-test = "1.4"
Expand Down
11 changes: 11 additions & 0 deletions components/remote_settings/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

fn main() {
glean_build::Builder::default()
.file("metrics.yaml")
.format("rust_sym")
.generate()
.expect("Error generating Glean Rust bindings");
}
11 changes: 6 additions & 5 deletions components/remote_settings/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
# This file defines the metrics that will be gathered for the Remote Settings
# component. Changes to these metrics require data review.
#
# We can't record metrics from Rust directly. To work around that we:
# - Define the metrics in application-services
# - Define API calls in application-services that return the metrics
# alongside the normal results.
# - Record the metrics with Glean in the consumer code
# Metrics are recorded in one of two ways:
# - With the `glean-sym` feature, they are recorded directly from Rust.
# `build.rs` generates the Rust bindings from this file, and `glean-sym`
# does the magic at runtime.
# - Otherwise, the consumer (Android, iOS) implements the `RemoteSettingsTelemetry`
# trait and records the metrics with its own Glean-generated bindings.

---
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
Expand Down
5 changes: 5 additions & 0 deletions components/remote_settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ pub mod telemetry;
pub(crate) mod jexl_filter;
mod macros;

#[cfg(feature = "glean-sym")]
mod glean_metrics {
include!(concat!(env!("OUT_DIR"), "/glean_metrics.rs"));
}

pub use client::{Attachment, RemoteSettingsRecord, RsJsonObject};
pub use config::{BaseUrl, RemoteSettingsConfig, RemoteSettingsServer};
pub use context::RemoteSettingsContext;
Expand Down
1 change: 1 addition & 0 deletions components/remote_settings/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl RemoteSettingsService {
client: Client::new(ClientSettings::default()),
remote_state: RemoteState::default(),
}),
// TODO: elegant plug and play here?
telemetry: Mutex::new(RemoteSettingsTelemetryWrapper::noop()),
}
}
Expand Down
41 changes: 38 additions & 3 deletions components/remote_settings/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl RemoteSettingsTelemetry for NoopRemoteSettingsTelemetry {
/// Wrapper around [RemoteSettingsTelemetry] used internally.
#[derive(Clone)]
pub struct RemoteSettingsTelemetryWrapper {
// Unused with `glean-sym`: metrics are recorded directly from Rust.
#[cfg_attr(feature = "glean-sym", allow(dead_code))]
inner: Arc<dyn RemoteSettingsTelemetry>,
}

Expand All @@ -108,8 +110,40 @@ impl RemoteSettingsTelemetryWrapper {
}
}

#[cfg(feature = "glean-sym")]
fn report_uptake(&self, event: UptakeEventExtras) {
// With glean-sym, telemetry is sent directly from the
// Glean SDK. The wrapped inner implementation is not
// called.
// This allows us to transition to glean-sym without
// breaking changes.
// Once this ships and gets enabled in builds, we can
// remove the telemetry wrapper code in iOS and Android.
use crate::glean_metrics::remote_settings::{
uptake_remotesettings, UptakeRemotesettingsExtra,
};
uptake_remotesettings.record(UptakeRemotesettingsExtra {
value: event.value,
source: event.source,
age: event.age,
trigger: event.trigger,
timestamp: event.timestamp,
duration: event.duration,
errorname: event.error_name,
});
}

#[cfg(not(feature = "glean-sym"))]
fn report_uptake(&self, event: UptakeEventExtras) {
// Call the native implementation of Glean.
// Note: feature is disabled on desktop.
// When `glean-sym` is enabled, the wrapper isn't called at all
// and events are sent directly by the Glean SDK.
self.inner.report_uptake(event)
}

pub fn report_uptake_success(&self, source: &str, duration: Option<u64>) {
self.inner.report_uptake(UptakeEventExtras {
self.report_uptake(UptakeEventExtras {
value: Some(SyncStatus::Success.to_string()),
source: Some(source.to_string()),
age: None,
Expand All @@ -121,7 +155,7 @@ impl RemoteSettingsTelemetryWrapper {
}

pub fn report_uptake_up_to_date(&self, source: &str, duration: Option<u64>) {
self.inner.report_uptake(UptakeEventExtras {
self.report_uptake(UptakeEventExtras {
value: Some(SyncStatus::UpToDate.to_string()),
source: Some(source.to_string()),
age: None,
Expand All @@ -143,7 +177,8 @@ impl RemoteSettingsTelemetryWrapper {
.unwrap_or("")
.trim()
.to_string();
self.inner.report_uptake(UptakeEventExtras {

self.report_uptake(UptakeEventExtras {
value: Some(error_to_status(error).to_string()),
source: Some(source.to_string()),
age: None,
Expand Down
Loading