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 super::{metrics::*, CommonMetricData, Lifetime};
6 
7 #[derive(Debug)]
8 pub struct CoreMetrics {
9     pub client_id: UuidMetric,
10     pub first_run_date: DatetimeMetric,
11     pub first_run_hour: DatetimeMetric,
12     pub os: StringMetric,
13 }
14 
15 #[derive(Debug)]
16 pub struct AdditionalMetrics {
17     /// The number of times we encountered an IO error
18     /// when writing a pending ping to disk.
19     pub io_errors: CounterMetric,
20 
21     /// A count of the pings submitted, by ping type.
22     pub pings_submitted: LabeledMetric<CounterMetric>,
23 
24     /// The number of times we encountered an invalid timezone offset
25     /// (outside of [-24, +24] hours).
26     ///
27     /// **Note**: This metric has an expiration date set.
28     /// However because it's statically defined here we can't specify that.
29     /// Needs to be removed after 2021-06-30.
30     pub invalid_timezone_offset: CounterMetric,
31 }
32 
33 impl CoreMetrics {
new() -> CoreMetrics34     pub fn new() -> CoreMetrics {
35         CoreMetrics {
36             client_id: UuidMetric::new(CommonMetricData {
37                 name: "client_id".into(),
38                 category: "".into(),
39                 send_in_pings: vec!["glean_client_info".into()],
40                 lifetime: Lifetime::User,
41                 disabled: false,
42                 dynamic_label: None,
43             }),
44 
45             first_run_date: DatetimeMetric::new(
46                 CommonMetricData {
47                     name: "first_run_date".into(),
48                     category: "".into(),
49                     send_in_pings: vec!["glean_client_info".into()],
50                     lifetime: Lifetime::User,
51                     disabled: false,
52                     dynamic_label: None,
53                 },
54                 TimeUnit::Day,
55             ),
56 
57             first_run_hour: DatetimeMetric::new(
58                 CommonMetricData {
59                     name: "first_run_hour".into(),
60                     category: "glean.validation".into(),
61                     send_in_pings: vec!["metrics".into(), "baseline".into()],
62                     lifetime: Lifetime::User,
63                     disabled: false,
64                     dynamic_label: None,
65                 },
66                 TimeUnit::Hour,
67             ),
68 
69             os: StringMetric::new(CommonMetricData {
70                 name: "os".into(),
71                 category: "".into(),
72                 send_in_pings: vec!["glean_client_info".into()],
73                 lifetime: Lifetime::Application,
74                 disabled: false,
75                 dynamic_label: None,
76             }),
77         }
78     }
79 }
80 
81 impl AdditionalMetrics {
new() -> AdditionalMetrics82     pub fn new() -> AdditionalMetrics {
83         AdditionalMetrics {
84             io_errors: CounterMetric::new(CommonMetricData {
85                 name: "io".into(),
86                 category: "glean.error".into(),
87                 send_in_pings: vec!["metrics".into()],
88                 lifetime: Lifetime::Ping,
89                 disabled: false,
90                 dynamic_label: None,
91             }),
92 
93             pings_submitted: LabeledMetric::new(
94                 CounterMetric::new(CommonMetricData {
95                     name: "pings_submitted".into(),
96                     category: "glean.validation".into(),
97                     send_in_pings: vec!["metrics".into(), "baseline".into()],
98                     lifetime: Lifetime::Ping,
99                     disabled: false,
100                     dynamic_label: None,
101                 }),
102                 None,
103             ),
104 
105             invalid_timezone_offset: CounterMetric::new(CommonMetricData {
106                 name: "invalid_timezone_offset".into(),
107                 category: "glean.time".into(),
108                 send_in_pings: vec!["metrics".into()],
109                 lifetime: Lifetime::Ping,
110                 disabled: false,
111                 dynamic_label: None,
112             }),
113         }
114     }
115 }
116 
117 #[derive(Debug)]
118 pub struct UploadMetrics {
119     pub ping_upload_failure: LabeledMetric<CounterMetric>,
120     pub discarded_exceeding_pings_size: MemoryDistributionMetric,
121     pub pending_pings_directory_size: MemoryDistributionMetric,
122     pub deleted_pings_after_quota_hit: CounterMetric,
123     pub pending_pings: CounterMetric,
124 }
125 
126 impl UploadMetrics {
new() -> UploadMetrics127     pub fn new() -> UploadMetrics {
128         UploadMetrics {
129             ping_upload_failure: LabeledMetric::new(
130                 CounterMetric::new(CommonMetricData {
131                     name: "ping_upload_failure".into(),
132                     category: "glean.upload".into(),
133                     send_in_pings: vec!["metrics".into()],
134                     lifetime: Lifetime::Ping,
135                     disabled: false,
136                     dynamic_label: None,
137                 }),
138                 Some(vec![
139                     "status_code_4xx".into(),
140                     "status_code_5xx".into(),
141                     "status_code_unknown".into(),
142                     "unrecoverable".into(),
143                     "recoverable".into(),
144                 ]),
145             ),
146 
147             discarded_exceeding_pings_size: MemoryDistributionMetric::new(
148                 CommonMetricData {
149                     name: "discarded_exceeding_ping_size".into(),
150                     category: "glean.upload".into(),
151                     send_in_pings: vec!["metrics".into()],
152                     lifetime: Lifetime::Ping,
153                     disabled: false,
154                     dynamic_label: None,
155                 },
156                 MemoryUnit::Kilobyte,
157             ),
158 
159             pending_pings_directory_size: MemoryDistributionMetric::new(
160                 CommonMetricData {
161                     name: "pending_pings_directory_size".into(),
162                     category: "glean.upload".into(),
163                     send_in_pings: vec!["metrics".into()],
164                     lifetime: Lifetime::Ping,
165                     disabled: false,
166                     dynamic_label: None,
167                 },
168                 MemoryUnit::Kilobyte,
169             ),
170 
171             deleted_pings_after_quota_hit: CounterMetric::new(CommonMetricData {
172                 name: "deleted_pings_after_quota_hit".into(),
173                 category: "glean.upload".into(),
174                 send_in_pings: vec!["metrics".into()],
175                 lifetime: Lifetime::Ping,
176                 disabled: false,
177                 dynamic_label: None,
178             }),
179 
180             pending_pings: CounterMetric::new(CommonMetricData {
181                 name: "pending_pings".into(),
182                 category: "glean.upload".into(),
183                 send_in_pings: vec!["metrics".into()],
184                 lifetime: Lifetime::Ping,
185                 disabled: false,
186                 dynamic_label: None,
187             }),
188         }
189     }
190 }
191 
192 #[derive(Debug)]
193 pub struct DatabaseMetrics {
194     pub size: MemoryDistributionMetric,
195 }
196 
197 impl DatabaseMetrics {
new() -> DatabaseMetrics198     pub fn new() -> DatabaseMetrics {
199         DatabaseMetrics {
200             size: MemoryDistributionMetric::new(
201                 CommonMetricData {
202                     name: "size".into(),
203                     category: "glean.database".into(),
204                     send_in_pings: vec!["metrics".into()],
205                     lifetime: Lifetime::Ping,
206                     disabled: false,
207                     dynamic_label: None,
208                 },
209                 MemoryUnit::Byte,
210             ),
211         }
212     }
213 }
214