use log::LevelFilter;
use crate::net::PingUploader;
use std::collections::HashMap;
use std::path::PathBuf;
use std::time::Duration;
pub(crate) const DEFAULT_GLEAN_ENDPOINT: &str = "https://incoming.telemetry.mozilla.org";
#[derive(Debug)]
pub struct Configuration {
pub upload_enabled: bool,
pub data_path: PathBuf,
pub application_id: String,
pub max_events: Option<usize>,
pub delay_ping_lifetime_io: bool,
pub server_endpoint: Option<String>,
pub uploader: Option<Box<dyn PingUploader + 'static>>,
pub use_core_mps: bool,
pub trim_data_to_registered_pings: bool,
pub log_level: Option<LevelFilter>,
pub rate_limit: Option<crate::PingRateLimit>,
pub enable_event_timestamps: bool,
pub experimentation_id: Option<String>,
pub enable_internal_pings: bool,
pub ping_schedule: HashMap<String, Vec<String>>,
pub ping_lifetime_threshold: usize,
pub ping_lifetime_max_time: Duration,
}
#[derive(Debug)]
pub struct Builder {
pub upload_enabled: bool,
pub data_path: PathBuf,
pub application_id: String,
pub max_events: Option<usize>,
pub delay_ping_lifetime_io: bool,
pub server_endpoint: Option<String>,
pub uploader: Option<Box<dyn PingUploader + 'static>>,
pub use_core_mps: bool,
pub trim_data_to_registered_pings: bool,
pub log_level: Option<LevelFilter>,
pub rate_limit: Option<crate::PingRateLimit>,
pub enable_event_timestamps: bool,
pub experimentation_id: Option<String>,
pub enable_internal_pings: bool,
pub ping_schedule: HashMap<String, Vec<String>>,
pub ping_lifetime_threshold: usize,
pub ping_lifetime_max_time: Duration,
}
impl Builder {
pub fn new<P: Into<PathBuf>, S: Into<String>>(
upload_enabled: bool,
data_path: P,
application_id: S,
) -> Self {
Self {
upload_enabled,
data_path: data_path.into(),
application_id: application_id.into(),
max_events: None,
delay_ping_lifetime_io: false,
server_endpoint: None,
uploader: None,
use_core_mps: false,
trim_data_to_registered_pings: false,
log_level: None,
rate_limit: None,
enable_event_timestamps: true,
experimentation_id: None,
enable_internal_pings: true,
ping_schedule: HashMap::new(),
ping_lifetime_threshold: 0,
ping_lifetime_max_time: Duration::ZERO,
}
}
pub fn build(self) -> Configuration {
Configuration {
upload_enabled: self.upload_enabled,
data_path: self.data_path,
application_id: self.application_id,
max_events: self.max_events,
delay_ping_lifetime_io: self.delay_ping_lifetime_io,
server_endpoint: self.server_endpoint,
uploader: self.uploader,
use_core_mps: self.use_core_mps,
trim_data_to_registered_pings: self.trim_data_to_registered_pings,
log_level: self.log_level,
rate_limit: self.rate_limit,
enable_event_timestamps: self.enable_event_timestamps,
experimentation_id: self.experimentation_id,
enable_internal_pings: self.enable_internal_pings,
ping_schedule: self.ping_schedule,
ping_lifetime_threshold: self.ping_lifetime_threshold,
ping_lifetime_max_time: self.ping_lifetime_max_time,
}
}
pub fn with_max_events(mut self, max_events: usize) -> Self {
self.max_events = Some(max_events);
self
}
pub fn with_delay_ping_lifetime_io(mut self, value: bool) -> Self {
self.delay_ping_lifetime_io = value;
self
}
pub fn with_server_endpoint<S: Into<String>>(mut self, server_endpoint: S) -> Self {
self.server_endpoint = Some(server_endpoint.into());
self
}
pub fn with_uploader<U: PingUploader + 'static>(mut self, uploader: U) -> Self {
self.uploader = Some(Box::new(uploader));
self
}
pub fn with_use_core_mps(mut self, value: bool) -> Self {
self.use_core_mps = value;
self
}
pub fn with_trim_data_to_registered_pings(mut self, value: bool) -> Self {
self.trim_data_to_registered_pings = value;
self
}
pub fn with_event_timestamps(mut self, value: bool) -> Self {
self.enable_event_timestamps = value;
self
}
pub fn with_experimentation_id(mut self, value: String) -> Self {
self.experimentation_id = Some(value);
self
}
pub fn with_internal_pings(mut self, value: bool) -> Self {
self.enable_internal_pings = value;
self
}
pub fn with_ping_schedule(mut self, value: HashMap<String, Vec<String>>) -> Self {
self.ping_schedule = value;
self
}
pub fn with_ping_lifetime_threshold(mut self, value: usize) -> Self {
self.ping_lifetime_threshold = value;
self
}
pub fn with_ping_lifetime_max_time(mut self, value: Duration) -> Self {
self.ping_lifetime_max_time = value;
self
}
}