summaryrefslogtreecommitdiffstats
path: root/toolkit/components/glean/pytest/metrics_test_output
blob: 0ac9f7b9ba7250ba9ef7bb5e1e22e066d26d3658 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
// -*- mode: Rust -*-

// AUTOGENERATED BY glean_parser.  DO NOT EDIT.

/* 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/. */


pub mod test {
    use crate::private::*;
    use glean_core::CommonMetricData;
    use once_cell::sync::Lazy;

    #[allow(non_upper_case_globals)]
    /// generated from test.boolean_metric
    ///
    /// A multi-line
    /// description
    pub static boolean_metric: Lazy<BooleanMetric> = Lazy::new(|| {
        BooleanMetric::new(1.into(), CommonMetricData {
            name: "boolean_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        })
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.labeled_boolean_metric
    ///
    /// A multi-line
    /// description
    pub static labeled_boolean_metric: Lazy<LabeledMetric<BooleanMetric>> = Lazy::new(|| {
        LabeledMetric::new(2.into(), CommonMetricData {
            name: "labeled_boolean_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, None)
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.labeled_boolean_metric_labels
    ///
    /// A multi-line
    /// description
    pub static labeled_boolean_metric_labels: Lazy<LabeledMetric<BooleanMetric>> = Lazy::new(|| {
        LabeledMetric::new(3.into(), CommonMetricData {
            name: "labeled_boolean_metric_labels".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, Some(vec!["one_label".into(), "two_labels".into()]))
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.counter_metric
    ///
    /// A multi-line
    /// description
    pub static counter_metric: Lazy<CounterMetric> = Lazy::new(|| {
        CounterMetric::new(4.into(), CommonMetricData {
            name: "counter_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        })
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.labeled_counter_metric
    ///
    /// A multi-line
    /// description
    pub static labeled_counter_metric: Lazy<LabeledMetric<CounterMetric>> = Lazy::new(|| {
        LabeledMetric::new(5.into(), CommonMetricData {
            name: "labeled_counter_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, None)
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.labeled_counter_metric_labels
    ///
    /// A multi-line
    /// description
    pub static labeled_counter_metric_labels: Lazy<LabeledMetric<CounterMetric>> = Lazy::new(|| {
        LabeledMetric::new(6.into(), CommonMetricData {
            name: "labeled_counter_metric_labels".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, Some(vec!["one_label".into(), "two_labels".into()]))
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.string_metric
    ///
    /// A multi-line
    /// description
    pub static string_metric: Lazy<StringMetric> = Lazy::new(|| {
        StringMetric::new(7.into(), CommonMetricData {
            name: "string_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        })
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.labeled_string_metric
    ///
    /// A multi-line
    /// description
    pub static labeled_string_metric: Lazy<LabeledMetric<StringMetric>> = Lazy::new(|| {
        LabeledMetric::new(8.into(), CommonMetricData {
            name: "labeled_string_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, None)
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.labeled_string_metric_labels
    ///
    /// A multi-line
    /// description
    pub static labeled_string_metric_labels: Lazy<LabeledMetric<StringMetric>> = Lazy::new(|| {
        LabeledMetric::new(9.into(), CommonMetricData {
            name: "labeled_string_metric_labels".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, Some(vec!["one_label".into(), "two_labels".into()]))
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.string_list_metric
    ///
    /// A multi-line
    /// description
    pub static string_list_metric: Lazy<StringListMetric> = Lazy::new(|| {
        StringListMetric::new(10.into(), CommonMetricData {
            name: "string_list_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        })
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.timespan_metric
    ///
    /// A multi-line
    /// description
    pub static timespan_metric: Lazy<TimespanMetric> = Lazy::new(|| {
        TimespanMetric::new(11.into(), CommonMetricData {
            name: "timespan_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, TimeUnit::Millisecond)
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.timing_distribution_metric
    ///
    /// A multi-line
    /// description
    pub static timing_distribution_metric: Lazy<TimingDistributionMetric> = Lazy::new(|| {
        TimingDistributionMetric::new(12.into(), CommonMetricData {
            name: "timing_distribution_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, TimeUnit::Nanosecond)
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.memory_distribution_metric
    ///
    /// A multi-line
    /// description
    pub static memory_distribution_metric: Lazy<MemoryDistributionMetric> = Lazy::new(|| {
        MemoryDistributionMetric::new(13.into(), CommonMetricData {
            name: "memory_distribution_metric".into(),
            category: "test".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, MemoryUnit::Kilobyte)
    });

}
pub mod test_nested {
    use crate::private::*;
    use glean_core::CommonMetricData;
    use once_cell::sync::Lazy;

    #[allow(non_upper_case_globals)]
    /// generated from test.nested.uuid_metric
    ///
    /// A multi-line
    /// description
    pub static uuid_metric: Lazy<UuidMetric> = Lazy::new(|| {
        UuidMetric::new(14.into(), CommonMetricData {
            name: "uuid_metric".into(),
            category: "test.nested".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        })
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.nested.datetime_metric
    ///
    /// A multi-line
    /// description
    pub static datetime_metric: Lazy<DatetimeMetric> = Lazy::new(|| {
        DatetimeMetric::new(15.into(), CommonMetricData {
            name: "datetime_metric".into(),
            category: "test.nested".into(),
            send_in_pings: vec!["metrics".into()],
            lifetime: Lifetime::Application,
            disabled: false,
            ..Default::default()
        }, TimeUnit::Millisecond)
    });

    #[allow(non_upper_case_globals)]
    /// generated from test.nested.event_metric
    ///
    /// A multi-line
    /// description
    pub static event_metric: Lazy<EventMetric<NoExtraKeys>> = Lazy::new(|| {
        EventMetric::new(16.into(), CommonMetricData {
            name: "event_metric".into(),
            category: "test.nested".into(),
            send_in_pings: vec!["events".into()],
            lifetime: Lifetime::Ping,
            disabled: false,
            ..Default::default()
        })
    });

    #[derive(Clone, Copy, Hash, Eq, PartialEq)]
    pub enum EventMetricWithExtraKeys {
        AnExtraKey,
        AnotherExtraKey,
    }

    impl ExtraKeys for EventMetricWithExtraKeys {
        const ALLOWED_KEYS: &'static [&'static str] = &["an_extra_key", "another_extra_key"];

        fn index(self) -> i32 {
            self as i32
        }
    }

    /// Convert from an extra key's index to its variant.
    impl std::convert::TryFrom<i32> for EventMetricWithExtraKeys {
        type Error = EventRecordingError;

        fn try_from(value: i32) -> Result<Self, Self::Error> {
          match value {
              0 => Ok(Self::AnExtraKey),
              1 => Ok(Self::AnotherExtraKey),
              _ => Err(EventRecordingError::InvalidExtraKey),
          }
        }
    }

    /// Convert from an extra key's string representation to its variant.
    impl std::convert::TryFrom<&str> for EventMetricWithExtraKeys {
        type Error = EventRecordingError;

        fn try_from(value: &str) -> Result<Self, Self::Error> {
          match value {
              "an_extra_key" => Ok(Self::AnExtraKey),
              "another_extra_key" => Ok(Self::AnotherExtraKey),
              _ => Err(EventRecordingError::InvalidExtraKey),
          }
        }
    }

    #[allow(non_upper_case_globals)]
    /// generated from test.nested.event_metric_with_extra
    ///
    /// A multi-line
    /// description
    pub static event_metric_with_extra: Lazy<EventMetric<EventMetricWithExtraKeys>> = Lazy::new(|| {
        EventMetric::new(17.into(), CommonMetricData {
            name: "event_metric_with_extra".into(),
            category: "test.nested".into(),
            send_in_pings: vec!["events".into()],
            lifetime: Lifetime::Ping,
            disabled: false,
            ..Default::default()
        })
    });

}

#[allow(dead_code)]
pub(crate) mod __glean_metric_maps {
    use std::collections::HashMap;
    use std::convert::TryInto;

    use crate::private::*;
    use once_cell::sync::Lazy;

    pub static BOOLEAN_MAP: Lazy<HashMap<MetricId, &Lazy<BooleanMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(1.into(), &super::test::boolean_metric);
        map
    });

    pub static LABELED_BOOLEAN_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<BooleanMetric>>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(2);
        map.insert(2.into(), &super::test::labeled_boolean_metric);
        map.insert(3.into(), &super::test::labeled_boolean_metric_labels);
        map
    });

    pub static COUNTER_MAP: Lazy<HashMap<MetricId, &Lazy<CounterMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(4.into(), &super::test::counter_metric);
        map
    });

    pub static LABELED_COUNTER_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<CounterMetric>>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(2);
        map.insert(5.into(), &super::test::labeled_counter_metric);
        map.insert(6.into(), &super::test::labeled_counter_metric_labels);
        map
    });

    pub static STRING_MAP: Lazy<HashMap<MetricId, &Lazy<StringMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(7.into(), &super::test::string_metric);
        map
    });

    pub static LABELED_STRING_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<StringMetric>>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(2);
        map.insert(8.into(), &super::test::labeled_string_metric);
        map.insert(9.into(), &super::test::labeled_string_metric_labels);
        map
    });

    pub static STRING_LIST_MAP: Lazy<HashMap<MetricId, &Lazy<StringListMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(10.into(), &super::test::string_list_metric);
        map
    });

    pub static TIMESPAN_MAP: Lazy<HashMap<MetricId, &Lazy<TimespanMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(11.into(), &super::test::timespan_metric);
        map
    });

    pub static TIMING_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<TimingDistributionMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(12.into(), &super::test::timing_distribution_metric);
        map
    });

    pub static MEMORY_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<MemoryDistributionMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(13.into(), &super::test::memory_distribution_metric);
        map
    });

    pub static UUID_MAP: Lazy<HashMap<MetricId, &Lazy<UuidMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(14.into(), &super::test_nested::uuid_metric);
        map
    });

    pub static DATETIME_MAP: Lazy<HashMap<MetricId, &Lazy<DatetimeMetric>>> = Lazy::new(|| {
        let mut map = HashMap::with_capacity(1);
        map.insert(15.into(), &super::test_nested::datetime_metric);
        map
    });


    /// Helper to get the number of allowed extra keys for a given event metric.
    fn extra_keys_len<K: ExtraKeys>(_event: &EventMetric<K>) -> usize {
        K::ALLOWED_KEYS.len()
    }

    /// Wrapper to record an event based on its metric ID.
    ///
    /// # Arguments
    ///
    /// * `metric_id` - The metric's ID to look up
    /// * `extra`     - An (optional) map of (extra key id, string) pairs.
    ///                 The map will be decoded into the appropriate `ExtraKeys` type.
    /// # Returns
    ///
    /// Returns `Ok(())` if the event was found and `record` was called with the given `extra`,
    /// or an `EventRecordingError::InvalidId` if no event by that ID exists
    /// or an `EventRecordingError::InvalidExtraKey` the `extra` map could not be deserialized.
    pub(crate) fn event_record_wrapper(metric_id: u32, extra: HashMap<i32, String>) -> Result<(), EventRecordingError> {
        match metric_id {
          16 => {
              assert!(
                  extra_keys_len(&super::test_nested::event_metric) != 0 || extra.is_empty(),
                  "No extra keys allowed, but some were passed"
              );

              // In case of `NoExtraKeys` the whole iterator is impossible, so rustc complains.
              #[allow(unused_variables)]
              let extra: HashMap<_, _> = extra
                  .into_iter()
                  .map(|(k, v)| k.try_into().map(|k| (k, v)))
                  .collect::<Result<HashMap<_, _>, _>>()?;
              super::test_nested::event_metric.record(Some(extra));
              Ok(())
          }
          17 => {
              assert!(
                  extra_keys_len(&super::test_nested::event_metric_with_extra) != 0 || extra.is_empty(),
                  "No extra keys allowed, but some were passed"
              );

              // In case of `NoExtraKeys` the whole iterator is impossible, so rustc complains.
              #[allow(unused_variables)]
              let extra: HashMap<_, _> = extra
                  .into_iter()
                  .map(|(k, v)| k.try_into().map(|k| (k, v)))
                  .collect::<Result<HashMap<_, _>, _>>()?;
              super::test_nested::event_metric_with_extra.record(Some(extra));
              Ok(())
          }
           _ => Err(EventRecordingError::InvalidId),
        }
    }

    /// Wrapper to record an event based on its metric ID.
    ///
    /// # Arguments
    ///
    /// * `metric_id` - The metric's ID to look up
    /// * `extra`     - An (optional) map of (string, string) pairs.
    ///                 The map will be decoded into the appropriate `ExtraKeys` types.
    /// # Returns
    ///
    /// Returns `Ok(())` if the event was found and `record` was called with the given `extra`,
    /// or an `EventRecordingError::InvalidId` if no event by that ID exists
    /// or an `EventRecordingError::InvalidExtraKey` the `extra` map could not be deserialized.
    pub(crate) fn event_record_wrapper_str(metric_id: u32, extra: HashMap<String, String>) -> Result<(), EventRecordingError> {
        match metric_id {
          16 => {
              assert!(
                  extra_keys_len(&super::test_nested::event_metric) != 0 || extra.is_empty(),
                  "No extra keys allowed, but some were passed"
              );

              // In case of `NoExtraKeys` the whole iterator is impossible, so rustc complains.
              #[allow(unused_variables)]
              let extra = extra
                  .into_iter()
                  .map(|(k, v)| (&*k).try_into().map(|k| (k, v)))
                  .collect::<Result<HashMap<_, _>, _>>()?;
              super::test_nested::event_metric.record(Some(extra));
              Ok(())
          }
          17 => {
              assert!(
                  extra_keys_len(&super::test_nested::event_metric_with_extra) != 0 || extra.is_empty(),
                  "No extra keys allowed, but some were passed"
              );

              // In case of `NoExtraKeys` the whole iterator is impossible, so rustc complains.
              #[allow(unused_variables)]
              let extra = extra
                  .into_iter()
                  .map(|(k, v)| (&*k).try_into().map(|k| (k, v)))
                  .collect::<Result<HashMap<_, _>, _>>()?;
              super::test_nested::event_metric_with_extra.record(Some(extra));
              Ok(())
          }
           _ => Err(EventRecordingError::InvalidId),
        }
    }

    /// Wrapper to get the currently stored events for event metric.
    ///
    /// # Arguments
    ///
    /// * `metric_id` - The metric's ID to look up
    /// * `storage_name` - the storage name to look into.
    ///
    /// # Returns
    ///
    /// Returns the recorded events or `None` if nothing stored.
    ///
    /// # Panics
    ///
    /// Panics if no event by the given metric ID could be found.
    pub(crate) fn event_test_get_value_wrapper(metric_id: u32, storage_name: &str) -> Option<Vec<RecordedEvent>> {
        match metric_id {
           16 => super::test_nested::event_metric.test_get_value(storage_name),
           17 => super::test_nested::event_metric_with_extra.test_get_value(storage_name),
           _ => panic!("No event for metric id {}", metric_id),
        }
    }
}