From ba9731f1011b347db853de9e5d61abf49d515b13 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 21 Apr 2026 15:58:30 -0400 Subject: [PATCH] Use glean-sym to record a metric from places Rust implementation --- Cargo.lock | 112 +++++++++++++++++++++++++++++++-- components/places/Cargo.toml | 2 + components/places/build.rs | 8 +++ components/places/metrics.yaml | 49 +++++++++++++++ components/places/src/ffi.rs | 9 ++- components/places/src/lib.rs | 5 ++ 6 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 components/places/metrics.yaml diff --git a/Cargo.lock b/Cargo.lock index 13269b3f5c..2acb5c7754 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -523,7 +523,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-link", + "windows-link 0.1.3", ] [[package]] @@ -580,7 +580,7 @@ checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", - "libloading", + "libloading 0.8.0", ] [[package]] @@ -1028,7 +1028,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading", + "libloading 0.8.0", ] [[package]] @@ -1494,6 +1494,17 @@ dependencies = [ "instant", ] +[[package]] +name = "fd-lock" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c44818c96aec5cadc9dacfb97bbcbcfc19a0de75b218412d56f57fbaab94e439" +dependencies = [ + "cfg-if", + "rustix 0.38.25", + "windows-sys 0.59.0", +] + [[package]] name = "ffi-support" version = "0.4.4" @@ -1773,6 +1784,26 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "glean-build" +version = "19.0.0" +source = "git+https://github.com/mozilla/glean?rev=85d08d6bb2a32e13c31a336bf032197bf39bec99#85d08d6bb2a32e13c31a336bf032197bf39bec99" +dependencies = [ + "xshell-venv", +] + +[[package]] +name = "glean-sym" +version = "0.1.0" +source = "git+https://github.com/mozilla/glean?rev=85d08d6bb2a32e13c31a336bf032197bf39bec99#85d08d6bb2a32e13c31a336bf032197bf39bec99" +dependencies = [ + "bytes", + "libloading 0.9.0", + "once_cell", + "serde", + "uniffi", +] + [[package]] name = "glob" version = "0.3.1" @@ -2420,6 +2451,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libloading" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "754ca22de805bb5744484a5b151a9e1a8e837d5dc232c2d7d8c2e3492edc8b60" +dependencies = [ + "cfg-if", + "windows-link 0.2.1", +] + [[package]] name = "libm" version = "0.2.7" @@ -2475,6 +2516,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f508063cc7bb32987c71511216bd5a32be15bccb6a80b52df8b9d7f01fc3aa2" +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "litemap" version = "0.8.0" @@ -3091,9 +3138,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.2" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "oneshot" @@ -3287,6 +3334,8 @@ dependencies = [ "bitflags 1.3.2", "dogear", "error-support", + "glean-build", + "glean-sym", "icu_casemap", "idna", "interrupt-support", @@ -3869,6 +3918,19 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustix" +version = "0.38.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +dependencies = [ + "bitflags 2.8.0", + "errno 0.3.1", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.48.0", +] + [[package]] name = "rustversion" version = "1.0.12" @@ -5466,6 +5528,12 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "windows-sys" version = "0.36.1" @@ -5503,6 +5571,15 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.0" @@ -5784,6 +5861,31 @@ version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a56c84a8ccd4258aed21c92f70c0f6dea75356b6892ae27c24139da456f9336" +[[package]] +name = "xshell" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d" +dependencies = [ + "xshell-macros", +] + +[[package]] +name = "xshell-macros" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547" + +[[package]] +name = "xshell-venv" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7933fb25d6b9716ede532410214bbc9b0fd08aa7a7a499788ede2d2c23dc4b02" +dependencies = [ + "fd-lock", + "xshell", +] + [[package]] name = "xz2" version = "0.1.7" diff --git a/components/places/Cargo.toml b/components/places/Cargo.toml index 0a98eae3d9..a941bd6645 100644 --- a/components/places/Cargo.toml +++ b/components/places/Cargo.toml @@ -34,6 +34,7 @@ sync-guid = { path = "../support/guid", features = ["rusqlite_support", "random" thiserror = "2" anyhow = "1.0" uniffi = { version = "0.31" } +glean-sym = { git = "https://github.com/mozilla/glean", rev = "85d08d6bb2a32e13c31a336bf032197bf39bec99" } [dev-dependencies] error-support = { path = "../support/error", features = ["testing"] } @@ -42,3 +43,4 @@ sql-support = { path = "../support/sql" } [build-dependencies] uniffi = { version = "0.31", features=["build"]} +glean-build = { git = "https://github.com/mozilla/glean", rev = "85d08d6bb2a32e13c31a336bf032197bf39bec99" } diff --git a/components/places/build.rs b/components/places/build.rs index 9889857733..deabb9fe2e 100644 --- a/components/places/build.rs +++ b/components/places/build.rs @@ -2,6 +2,14 @@ * 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/. */ +use glean_build::Builder; + fn main() { uniffi::generate_scaffolding("./src/places.udl").unwrap(); + + Builder::default() + .file("metrics.yaml") + .format("rust_sym") + .generate() + .expect("Error generating Glean Rust bindings"); } diff --git a/components/places/metrics.yaml b/components/places/metrics.yaml new file mode 100644 index 0000000000..f96c109acb --- /dev/null +++ b/components/places/metrics.yaml @@ -0,0 +1,49 @@ +# 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/. + +--- +$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 + +places_manager: + run_maintenance_time_temp: + type: timing_distribution + description: | + Time taken to execute `run_maintenance()` + + Duplication of `run_maintenance_time` for glean-sys testing. + time_unit: millisecond + bugs: + - https://github.com/mozilla/application-services/issues/5115 + data_reviews: + - https://github.com/mozilla/application-services/issues/5122 + - https://github.com/mozilla/application-services/issues/5387 + - https://github.com/mozilla/application-services/issues/5830 + notification_emails: + - synced-client-integrations@mozilla.com + - bdk@mozilla.com + expires: "never" + data_sensitivity: + - technical + no_lint: [COMMON_PREFIX] + + run_maintenance_prune_time_temp: + type: timing_distribution + description: | + Time taken to execute `prune_older_visits()` inside `run_maintenance()` + + Duplication of `run_maintenance_prune_time` for glean-sys testing. + time_unit: millisecond + bugs: + - https://github.com/mozilla/application-services/issues/5246 + data_reviews: + - https://github.com/mozilla/application-services/issues/5247 + - https://github.com/mozilla/application-services/issues/5387 + - https://github.com/mozilla/application-services/issues/5830 + notification_emails: + - synced-client-integrations@mozilla.com + - bdk@mozilla.com + expires: "never" + data_sensitivity: + - technical + no_lint: [COMMON_PREFIX] diff --git a/components/places/src/ffi.rs b/components/places/src/ffi.rs index 39386398fa..2fc479889c 100644 --- a/components/places/src/ffi.rs +++ b/components/places/src/ffi.rs @@ -8,6 +8,7 @@ use crate::api::matcher::{self, search_frecent, SearchParams}; pub use crate::api::places_api::places_api_new; pub use crate::error::{warn, Result}; pub use crate::error::{ApiResult, PlacesApiError}; +use crate::glean_metrics::places_manager; pub use crate::import::common::HistoryMigrationResult; use crate::import::import_ios_history; use crate::storage; @@ -434,7 +435,13 @@ impl PlacesConnection { db_size_limit: u32, prune_limit: u32, ) -> ApiResult { - self.with_conn(|conn| storage::run_maintenance_prune(conn, db_size_limit, prune_limit)) + let timer_id = places_manager::run_maintenance_prune_time_temp.start(); + let res = + self.with_conn(|conn| storage::run_maintenance_prune(conn, db_size_limit, prune_limit)); + + places_manager::run_maintenance_prune_time_temp.stop_and_accumulate(timer_id); + + res } #[handle_error(crate::Error)] diff --git a/components/places/src/lib.rs b/components/places/src/lib.rs index 3e7ff3df5c..432ce70113 100644 --- a/components/places/src/lib.rs +++ b/components/places/src/lib.rs @@ -38,4 +38,9 @@ pub use crate::types::*; pub use ffi::*; +#[allow(clippy::all)] // Don't lint generated code. +pub mod glean_metrics { + include!(concat!(env!("OUT_DIR"), "/glean_metrics.rs")); +} + uniffi::include_scaffolding!("places");