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
5 changes: 5 additions & 0 deletions autoconnect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ default = ["bigtable"]
bigtable = ["autopush_common/bigtable", "autoconnect_settings/bigtable"]
emulator = ["bigtable"]
log_vapid = []
glean = [
"autopush_common/glean",
"autoconnect_settings/glean",
"autoconnect_ws/glean",
]
1 change: 1 addition & 0 deletions autoconnect/autoconnect-settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ autopush_common.workspace = true
# specify the default via the calling crate, in order to simplify default chains.
bigtable = ["autopush_common/bigtable"]
emulator = ["bigtable"]
glean = []
12 changes: 12 additions & 0 deletions autoconnect/autoconnect-settings/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use autoconnect_common::{
registry::ClientRegistry,
};
use autopush_common::db::{client::DbClient, DbSettings, StorageType};
#[cfg(feature = "glean")]
use autopush_common::glean::GleanSettings;

use crate::{Settings, ENV_PREFIX};

Expand All @@ -30,6 +32,8 @@ pub struct AppState {
pub broadcaster: Arc<RwLock<BroadcastChangeTracker>>,

pub settings: Settings,
#[cfg(feature = "glean")]
pub glean_settings: GleanSettings,
pub router_url: String,
pub endpoint_url: String,
}
Expand Down Expand Up @@ -91,6 +95,12 @@ impl AppState {

let router_url = settings.router_url();
let endpoint_url = settings.endpoint_url();
#[cfg(feature = "glean")]
let glean_settings: GleanSettings =
serde_json::from_str(&settings.glean_settings.clone().unwrap_or_else(|| {
panic!("Glean feature enabled, but no glean_settings configured")
}))
.unwrap_or_else(|e| panic!("Glean settings are indecipherable.{:?}", e));

Ok(Self {
db,
Expand All @@ -102,6 +112,8 @@ impl AppState {
settings,
router_url,
endpoint_url,
#[cfg(feature = "glean")]
glean_settings,
})
}

Expand Down
4 changes: 4 additions & 0 deletions autoconnect/autoconnect-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ pub struct Settings {
///
/// By default, the number of available physical CPUs is used as the worker count.
pub actix_workers: Option<usize>,

/// various Glean settings.
pub glean_settings: Option<String>,
}

impl Default for Settings {
Expand Down Expand Up @@ -139,6 +142,7 @@ impl Default for Settings {
msg_limit: 150,
actix_max_connections: None,
actix_workers: None,
glean_settings: None,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions autoconnect/autoconnect-ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ async-stream = "0.3"
ctor.workspace = true

autoconnect_common = { workspace = true, features = ["test-support"] }

[features]
glean = ["autoconnect_ws_sm/glean"]
3 changes: 3 additions & 0 deletions autoconnect/autoconnect-ws/autoconnect-ws-sm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ tokio.workspace = true
serde_json.workspace = true

autoconnect_common = { workspace = true, features = ["test-support"] }

[features]
glean = []
35 changes: 35 additions & 0 deletions autoconnect/autoconnect-ws/autoconnect-ws-sm/src/unidentified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use autoconnect_common::{
protocol::{BroadcastValue, ClientMessage, ServerMessage},
};
use autoconnect_settings::{AppState, Settings};
#[cfg(feature = "glean")]
use autopush_common::glean::{Glean, GleanEvent, GleanSettings, MetricSet};
use autopush_common::{
db::{User, USER_RECORD_VERSION},
util::{ms_since_epoch, ms_utc_midnight},
Expand Down Expand Up @@ -157,6 +159,39 @@ impl UnidentifiedClient {
let _ = self.app_state.metrics.incr("ua.already_connected");
return Err(SMErrorKind::AlreadyConnected.into());
}
#[cfg(feature = "glean")]
{
// Compose the "Glean" metric string and write it to STDOUT, which is the
// expected destination.
let glean_settings: GleanSettings = self.app_state.glean_settings.clone();

// This is the individual data to report. the `Glean` struct below will
// associate it with the correct Category and Event
let mut metric_set = MetricSet::default();
metric_set
.add_string("autoconnect.uaid", &user.uaid.to_string()) // `metrics:cat`.`metrics:
.map_err(|e| {
SMErrorKind::Internal(format!(
"Failed to construct Glean record: {:?}",
e
))
})?;
let glean_string = Glean::try_new(
&glean_settings,
GleanEvent {
category: "autoconnect", // metrics.yaml Category
name: "dau", // metrics.yaml, owner event name
},
"autopush", // ping.yaml, name of the ping (Server specific)
metric_set,
None,
None,
)
.map_err(|e| {
SMErrorKind::Internal(format!("Failed to compose Glean record: {:?}", e))
})?;
println!("{}", glean_string);
}
return Ok(GetOrCreateUser {
user,
existing_user: true,
Expand Down
2 changes: 2 additions & 0 deletions autoendpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ emulator = ["bigtable"]
stub = []
# Verbosely log vapid assertions (NOT ADVISED FOR WIDE PRODUCTION USE)
log_vapid = []

glean = ["autopush_common/glean"]
32 changes: 32 additions & 0 deletions autoendpoint/src/routes/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::server::AppState;

use autopush_common::db::User;
use autopush_common::endpoint::make_endpoint;
#[cfg(feature = "glean")]
use autopush_common::glean::{Glean, GleanEvent, GleanSettings, MetricSet};

/// Handle the `POST /v1/{router_type}/{app_id}/registration` route
pub async fn register_uaid_route(
Expand Down Expand Up @@ -189,6 +191,36 @@ pub async fn get_channels_route(
.with_tag("os", &os)
.with_tag("browser", &browser)
.send();
#[cfg(feature = "glean")]
{
// Compose the "Glean" metric string and write it to STDOUT, which is the
// expected destination.
let glean_settings: &GleanSettings = app_state.glean_settings.as_ref();

// This is the individual data to report. the `Glean` struct below will
// associate it with the correct Category and Event
let mut metric_set = MetricSet::default();
metric_set
.add_string("autoendpoint.uaid", &user.uaid.to_string())
.map_err(|e| {
ApiErrorKind::General(format!("Failed to construct Glean record: {:?}", e))
})?;
let glean_string = Glean::try_new(
glean_settings,
GleanEvent {
category: "autoendpoint",
name: "dau",
},
"autopush",
metric_set,
None,
None,
)
.map_err(|e| {
ApiErrorKind::General(format!("Failed to compose Glean record: {:?}", e))
})?;
println!("{}", glean_string);
}
}
let channel_ids = db.get_channels(&uaid).await?;

Expand Down
11 changes: 11 additions & 0 deletions autoendpoint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ use autopush_common::{
middleware::sentry::SentryWrapper,
};

#[cfg(feature = "glean")]
use autopush_common::glean::GleanSettings;

use crate::error::{ApiError, ApiErrorKind, ApiResult};
use crate::metrics;
#[cfg(feature = "stub")]
Expand Down Expand Up @@ -45,6 +48,8 @@ pub struct AppState {
pub apns_router: Arc<ApnsRouter>,
#[cfg(feature = "stub")]
pub stub_router: Arc<StubRouter>,
#[cfg(feature = "glean")]
pub glean_settings: Box<GleanSettings>,
}

pub struct Server;
Expand Down Expand Up @@ -107,6 +112,10 @@ impl Server {
);
#[cfg(feature = "stub")]
let stub_router = Arc::new(StubRouter::new(settings.stub.clone())?);

#[cfg(feature = "glean")]
let glean_settings: Box<GleanSettings> = Box::new(settings.glean_settings.clone());

let app_state = AppState {
metrics: metrics.clone(),
settings,
Expand All @@ -117,6 +126,8 @@ impl Server {
apns_router,
#[cfg(feature = "stub")]
stub_router,
#[cfg(feature = "glean")]
glean_settings,
};

spawn_pool_periodic_reporter(
Expand Down
7 changes: 7 additions & 0 deletions autoendpoint/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use fernet::{Fernet, MultiFernet};
use serde::Deserialize;
use url::Url;

#[cfg(feature = "glean")]
use autopush_common::glean::GleanSettings;

use crate::routers::apns::settings::ApnsSettings;
use crate::routers::fcm::settings::FcmSettings;
#[cfg(feature = "stub")]
Expand Down Expand Up @@ -47,6 +50,8 @@ pub struct Settings {
pub apns: ApnsSettings,
#[cfg(feature = "stub")]
pub stub: StubSettings,
#[cfg(feature = "glean")]
pub glean_settings: GleanSettings,
}

impl Default for Settings {
Expand Down Expand Up @@ -81,6 +86,8 @@ impl Default for Settings {
apns: ApnsSettings::default(),
#[cfg(feature = "stub")]
stub: StubSettings::default(),
#[cfg(feature = "glean")]
glean_settings: GleanSettings::default(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion autopush-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ form_urlencoded = { version = "1.2", optional = true }
[dev-dependencies]
mockito = "0.31"
tempfile = "3.2.0"
tokio = { workspace=true, features = ["macros"] }
tokio = { workspace = true, features = ["macros"] }
actix-rt = "2.8"

[features]
Expand All @@ -79,3 +79,4 @@ bigtable = [
emulator = [
"bigtable",
] # used for testing big table, requires an external bigtable emulator running.
glean = []
Loading