| 1 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 |
|
| 5 |
use std::borrow::Cow; |
| 6 |
|
| 7 |
use malloc_size_of_derive::MallocSizeOf; |
| 8 |
|
| 9 |
use super::{metrics::*, CommonMetricData, LabeledMetricData, Lifetime}; |
| 10 |
|
| 11 |
#[derive(Debug, MallocSizeOf)] |
| 12 |
pub struct CoreMetrics { |
| 13 |
pub client_id: UuidMetric, |
| 14 |
pub first_run_date: DatetimeMetric, |
| 15 |
pub os: StringMetric, |
| 16 |
pub attribution_source: StringMetric, |
| 17 |
pub attribution_medium: StringMetric, |
| 18 |
pub attribution_campaign: StringMetric, |
| 19 |
pub attribution_term: StringMetric, |
| 20 |
pub attribution_content: StringMetric, |
| 21 |
pub distribution_name: StringMetric, |
| 22 |
} |
| 23 |
|
| 24 |
#[derive(Debug, MallocSizeOf)] |
| 25 |
pub struct AdditionalMetrics { |
| 26 |
/// The number of times we encountered an IO error |
| 27 |
/// when writing a pending ping to disk. |
| 28 |
pub io_errors: CounterMetric, |
| 29 |
|
| 30 |
/// A count of the pings submitted, by ping type. |
| 31 |
pub pings_submitted: LabeledMetric<CounterMetric>, |
| 32 |
|
| 33 |
/// Time waited for the uploader at shutdown. |
| 34 |
pub shutdown_wait: TimingDistributionMetric, |
| 35 |
|
| 36 |
/// Time waited for the dispatcher to unblock during shutdown. |
| 37 |
pub shutdown_dispatcher_wait: TimingDistributionMetric, |
| 38 |
|
| 39 |
/// An experimentation identifier derived and provided by the application |
| 40 |
/// for the purpose of experimentation enrollment. |
| 41 |
pub experimentation_id: StringMetric, |
| 42 |
} |
| 43 |
|
| 44 |
impl CoreMetrics { |
| 45 |
pub fn new() -> CoreMetrics { |
| 46 |
CoreMetrics { |
| 47 |
client_id: UuidMetric::new(CommonMetricData { |
| 48 |
name: "client_id".into(), |
| 49 |
category: "".into(), |
| 50 |
send_in_pings: vec!["glean_client_info".into()], |
| 51 |
lifetime: Lifetime::User, |
| 52 |
disabled: false, |
| 53 |
dynamic_label: None, |
| 54 |
}), |
| 55 |
|
| 56 |
first_run_date: DatetimeMetric::new( |
| 57 |
CommonMetricData { |
| 58 |
name: "first_run_date".into(), |
| 59 |
category: "".into(), |
| 60 |
send_in_pings: vec!["glean_client_info".into()], |
| 61 |
lifetime: Lifetime::User, |
| 62 |
disabled: false, |
| 63 |
dynamic_label: None, |
| 64 |
}, |
| 65 |
TimeUnit::Day, |
| 66 |
), |
| 67 |
|
| 68 |
os: StringMetric::new(CommonMetricData { |
| 69 |
name: "os".into(), |
| 70 |
category: "".into(), |
| 71 |
send_in_pings: vec!["glean_client_info".into()], |
| 72 |
lifetime: Lifetime::Application, |
| 73 |
disabled: false, |
| 74 |
dynamic_label: None, |
| 75 |
}), |
| 76 |
|
| 77 |
attribution_source: StringMetric::new(CommonMetricData { |
| 78 |
name: "source".into(), |
| 79 |
category: "attribution".into(), |
| 80 |
send_in_pings: vec!["glean_client_info".into()], |
| 81 |
lifetime: Lifetime::User, |
| 82 |
disabled: false, |
| 83 |
dynamic_label: None, |
| 84 |
}), |
| 85 |
|
| 86 |
attribution_medium: StringMetric::new(CommonMetricData { |
| 87 |
name: "medium".into(), |
| 88 |
category: "attribution".into(), |
| 89 |
send_in_pings: vec!["glean_client_info".into()], |
| 90 |
lifetime: Lifetime::User, |
| 91 |
disabled: false, |
| 92 |
dynamic_label: None, |
| 93 |
}), |
| 94 |
|
| 95 |
attribution_campaign: StringMetric::new(CommonMetricData { |
| 96 |
name: "campaign".into(), |
| 97 |
category: "attribution".into(), |
| 98 |
send_in_pings: vec!["glean_client_info".into()], |
| 99 |
lifetime: Lifetime::User, |
| 100 |
disabled: false, |
| 101 |
dynamic_label: None, |
| 102 |
}), |
| 103 |
|
| 104 |
attribution_term: StringMetric::new(CommonMetricData { |
| 105 |
name: "term".into(), |
| 106 |
category: "attribution".into(), |
| 107 |
send_in_pings: vec!["glean_client_info".into()], |
| 108 |
lifetime: Lifetime::User, |
| 109 |
disabled: false, |
| 110 |
dynamic_label: None, |
| 111 |
}), |
| 112 |
|
| 113 |
attribution_content: StringMetric::new(CommonMetricData { |
| 114 |
name: "content".into(), |
| 115 |
category: "attribution".into(), |
| 116 |
send_in_pings: vec!["glean_client_info".into()], |
| 117 |
lifetime: Lifetime::User, |
| 118 |
disabled: false, |
| 119 |
dynamic_label: None, |
| 120 |
}), |
| 121 |
|
| 122 |
distribution_name: StringMetric::new(CommonMetricData { |
| 123 |
name: "name".into(), |
| 124 |
category: "distribution".into(), |
| 125 |
send_in_pings: vec!["glean_client_info".into()], |
| 126 |
lifetime: Lifetime::User, |
| 127 |
disabled: false, |
| 128 |
dynamic_label: None, |
| 129 |
}), |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
impl AdditionalMetrics { |
| 135 |
pub fn new() -> AdditionalMetrics { |
| 136 |
AdditionalMetrics { |
| 137 |
io_errors: CounterMetric::new(CommonMetricData { |
| 138 |
name: "io".into(), |
| 139 |
category: "glean.error".into(), |
| 140 |
send_in_pings: vec!["metrics".into()], |
| 141 |
lifetime: Lifetime::Ping, |
| 142 |
disabled: false, |
| 143 |
dynamic_label: None, |
| 144 |
}), |
| 145 |
|
| 146 |
pings_submitted: LabeledMetric::<CounterMetric>::new( |
| 147 |
LabeledMetricData::Common { |
| 148 |
cmd: CommonMetricData { |
| 149 |
name: "pings_submitted".into(), |
| 150 |
category: "glean.validation".into(), |
| 151 |
send_in_pings: vec!["metrics".into(), "baseline".into()], |
| 152 |
lifetime: Lifetime::Ping, |
| 153 |
disabled: false, |
| 154 |
dynamic_label: None, |
| 155 |
}, |
| 156 |
}, |
| 157 |
None, |
| 158 |
), |
| 159 |
|
| 160 |
shutdown_wait: TimingDistributionMetric::new( |
| 161 |
CommonMetricData { |
| 162 |
name: "shutdown_wait".into(), |
| 163 |
category: "glean.validation".into(), |
| 164 |
send_in_pings: vec!["metrics".into()], |
| 165 |
lifetime: Lifetime::Ping, |
| 166 |
disabled: false, |
| 167 |
dynamic_label: None, |
| 168 |
}, |
| 169 |
TimeUnit::Millisecond, |
| 170 |
), |
| 171 |
|
| 172 |
shutdown_dispatcher_wait: TimingDistributionMetric::new( |
| 173 |
CommonMetricData { |
| 174 |
name: "shutdown_dispatcher_wait".into(), |
| 175 |
category: "glean.validation".into(), |
| 176 |
send_in_pings: vec!["metrics".into()], |
| 177 |
lifetime: Lifetime::Ping, |
| 178 |
disabled: false, |
| 179 |
dynamic_label: None, |
| 180 |
}, |
| 181 |
TimeUnit::Millisecond, |
| 182 |
), |
| 183 |
|
| 184 |
// This uses a `send_in_pings` that contains "all-ping". |
| 185 |
// This works because all of our other current "all-pings" metrics |
| 186 |
// have special handling internally and are not actually processed |
| 187 |
// into a store quite like this identifier is. |
| 188 |
// |
| 189 |
// This could become an issue if we ever decide to start generating |
| 190 |
// code from the internal Glean metrics.yaml (there aren't currently |
| 191 |
// any plans for this). |
| 192 |
experimentation_id: StringMetric::new(CommonMetricData { |
| 193 |
name: "experimentation_id".into(), |
| 194 |
category: "glean.client.annotation".into(), |
| 195 |
send_in_pings: vec!["all-pings".into()], |
| 196 |
lifetime: Lifetime::Application, |
| 197 |
disabled: false, |
| 198 |
dynamic_label: None, |
| 199 |
}), |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
#[derive(Debug, MallocSizeOf)] |
| 205 |
pub struct UploadMetrics { |
| 206 |
pub ping_upload_failure: LabeledMetric<CounterMetric>, |
| 207 |
pub discarded_exceeding_pings_size: MemoryDistributionMetric, |
| 208 |
pub pending_pings_directory_size: MemoryDistributionMetric, |
| 209 |
pub deleted_pings_after_quota_hit: CounterMetric, |
| 210 |
pub pending_pings: CounterMetric, |
| 211 |
pub send_success: TimingDistributionMetric, |
| 212 |
pub send_failure: TimingDistributionMetric, |
| 213 |
pub in_flight_pings_dropped: CounterMetric, |
| 214 |
pub missing_send_ids: CounterMetric, |
| 215 |
} |
| 216 |
|
| 217 |
impl UploadMetrics { |
| 218 |
pub fn new() -> UploadMetrics { |
| 219 |
UploadMetrics { |
| 220 |
ping_upload_failure: LabeledMetric::<CounterMetric>::new( |
| 221 |
LabeledMetricData::Common { |
| 222 |
cmd: CommonMetricData { |
| 223 |
name: "ping_upload_failure".into(), |
| 224 |
category: "glean.upload".into(), |
| 225 |
send_in_pings: vec!["metrics".into()], |
| 226 |
lifetime: Lifetime::Ping, |
| 227 |
disabled: false, |
| 228 |
dynamic_label: None, |
| 229 |
}, |
| 230 |
}, |
| 231 |
Some(vec![ |
| 232 |
Cow::from("status_code_4xx"), |
| 233 |
Cow::from("status_code_5xx"), |
| 234 |
Cow::from("status_code_unknown"), |
| 235 |
Cow::from("unrecoverable"), |
| 236 |
Cow::from("recoverable"), |
| 237 |
Cow::from("incapable"), |
| 238 |
]), |
| 239 |
), |
| 240 |
|
| 241 |
discarded_exceeding_pings_size: MemoryDistributionMetric::new( |
| 242 |
CommonMetricData { |
| 243 |
name: "discarded_exceeding_ping_size".into(), |
| 244 |
category: "glean.upload".into(), |
| 245 |
send_in_pings: vec!["metrics".into()], |
| 246 |
lifetime: Lifetime::Ping, |
| 247 |
disabled: false, |
| 248 |
dynamic_label: None, |
| 249 |
}, |
| 250 |
MemoryUnit::Kilobyte, |
| 251 |
), |
| 252 |
|
| 253 |
pending_pings_directory_size: MemoryDistributionMetric::new( |
| 254 |
CommonMetricData { |
| 255 |
name: "pending_pings_directory_size".into(), |
| 256 |
category: "glean.upload".into(), |
| 257 |
send_in_pings: vec!["metrics".into()], |
| 258 |
lifetime: Lifetime::Ping, |
| 259 |
disabled: false, |
| 260 |
dynamic_label: None, |
| 261 |
}, |
| 262 |
MemoryUnit::Kilobyte, |
| 263 |
), |
| 264 |
|
| 265 |
deleted_pings_after_quota_hit: CounterMetric::new(CommonMetricData { |
| 266 |
name: "deleted_pings_after_quota_hit".into(), |
| 267 |
category: "glean.upload".into(), |
| 268 |
send_in_pings: vec!["metrics".into()], |
| 269 |
lifetime: Lifetime::Ping, |
| 270 |
disabled: false, |
| 271 |
dynamic_label: None, |
| 272 |
}), |
| 273 |
|
| 274 |
pending_pings: CounterMetric::new(CommonMetricData { |
| 275 |
name: "pending_pings".into(), |
| 276 |
category: "glean.upload".into(), |
| 277 |
send_in_pings: vec!["metrics".into()], |
| 278 |
lifetime: Lifetime::Ping, |
| 279 |
disabled: false, |
| 280 |
dynamic_label: None, |
| 281 |
}), |
| 282 |
|
| 283 |
send_success: TimingDistributionMetric::new( |
| 284 |
CommonMetricData { |
| 285 |
name: "send_success".into(), |
| 286 |
category: "glean.upload".into(), |
| 287 |
send_in_pings: vec!["metrics".into()], |
| 288 |
lifetime: Lifetime::Ping, |
| 289 |
disabled: false, |
| 290 |
dynamic_label: None, |
| 291 |
}, |
| 292 |
TimeUnit::Millisecond, |
| 293 |
), |
| 294 |
|
| 295 |
send_failure: TimingDistributionMetric::new( |
| 296 |
CommonMetricData { |
| 297 |
name: "send_failure".into(), |
| 298 |
category: "glean.upload".into(), |
| 299 |
send_in_pings: vec!["metrics".into()], |
| 300 |
lifetime: Lifetime::Ping, |
| 301 |
disabled: false, |
| 302 |
dynamic_label: None, |
| 303 |
}, |
| 304 |
TimeUnit::Millisecond, |
| 305 |
), |
| 306 |
|
| 307 |
in_flight_pings_dropped: CounterMetric::new(CommonMetricData { |
| 308 |
name: "in_flight_pings_dropped".into(), |
| 309 |
category: "glean.upload".into(), |
| 310 |
send_in_pings: vec!["metrics".into()], |
| 311 |
lifetime: Lifetime::Ping, |
| 312 |
disabled: false, |
| 313 |
dynamic_label: None, |
| 314 |
}), |
| 315 |
|
| 316 |
missing_send_ids: CounterMetric::new(CommonMetricData { |
| 317 |
name: "missing_send_ids".into(), |
| 318 |
category: "glean.upload".into(), |
| 319 |
send_in_pings: vec!["metrics".into()], |
| 320 |
lifetime: Lifetime::Ping, |
| 321 |
disabled: false, |
| 322 |
dynamic_label: None, |
| 323 |
}), |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
#[derive(Debug, MallocSizeOf)] |
| 329 |
pub struct DatabaseMetrics { |
| 330 |
pub size: MemoryDistributionMetric, |
| 331 |
|
| 332 |
/// RKV's load result, indicating success or relaying the detected error. |
| 333 |
pub rkv_load_error: StringMetric, |
| 334 |
|
| 335 |
/// The time it takes for a write-commit for the Glean database. |
| 336 |
pub write_time: TimingDistributionMetric, |
| 337 |
} |
| 338 |
|
| 339 |
impl DatabaseMetrics { |
| 340 |
pub fn new() -> DatabaseMetrics { |
| 341 |
DatabaseMetrics { |
| 342 |
size: MemoryDistributionMetric::new( |
| 343 |
CommonMetricData { |
| 344 |
name: "size".into(), |
| 345 |
category: "glean.database".into(), |
| 346 |
send_in_pings: vec!["metrics".into()], |
| 347 |
lifetime: Lifetime::Ping, |
| 348 |
disabled: false, |
| 349 |
dynamic_label: None, |
| 350 |
}, |
| 351 |
MemoryUnit::Byte, |
| 352 |
), |
| 353 |
|
| 354 |
rkv_load_error: StringMetric::new(CommonMetricData { |
| 355 |
name: "rkv_load_error".into(), |
| 356 |
category: "glean.error".into(), |
| 357 |
send_in_pings: vec!["metrics".into()], |
| 358 |
lifetime: Lifetime::Ping, |
| 359 |
disabled: false, |
| 360 |
dynamic_label: None, |
| 361 |
}), |
| 362 |
|
| 363 |
write_time: TimingDistributionMetric::new( |
| 364 |
CommonMetricData { |
| 365 |
name: "write_time".into(), |
| 366 |
category: "glean.database".into(), |
| 367 |
send_in_pings: vec!["metrics".into()], |
| 368 |
lifetime: Lifetime::Ping, |
| 369 |
disabled: true, |
| 370 |
dynamic_label: None, |
| 371 |
}, |
| 372 |
TimeUnit::Microsecond, |
| 373 |
), |
| 374 |
} |
| 375 |
} |
| 376 |
} |