sampler_config/
common.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use serde::{Deserialize, Serialize};
6use std::fmt;
7use std::ops::Deref;
8
9#[derive(Copy, Clone, Debug, Default, Deserialize, Hash, PartialEq, Eq, Serialize)]
10pub struct ProjectId(pub u32);
11
12impl fmt::Display for ProjectId {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        write!(f, "{}", self.0)
15    }
16}
17
18impl Deref for ProjectId {
19    type Target = u32;
20
21    fn deref(&self) -> &Self::Target {
22        &self.0
23    }
24}
25
26#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Hash, Eq, Serialize)]
27pub struct CustomerId(pub u32);
28
29impl fmt::Display for CustomerId {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        write!(f, "{}", self.0)
32    }
33}
34
35impl Default for CustomerId {
36    fn default() -> Self {
37        CustomerId(1)
38    }
39}
40
41impl Deref for CustomerId {
42    type Target = u32;
43
44    fn deref(&self) -> &Self::Target {
45        &self.0
46    }
47}
48
49#[derive(Copy, Clone, Debug, Deserialize, Hash, PartialEq, Eq, Serialize)]
50pub struct MetricId(pub u32);
51
52impl fmt::Display for MetricId {
53    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54        write!(f, "{}", self.0)
55    }
56}
57
58impl Deref for MetricId {
59    type Target = u32;
60
61    fn deref(&self) -> &Self::Target {
62        &self.0
63    }
64}
65
66#[derive(Copy, Clone, Debug, Deserialize, Hash, PartialEq, Eq, Serialize)]
67pub struct EventCode(pub u32);
68
69impl fmt::Display for EventCode {
70    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71        write!(f, "{}", self.0)
72    }
73}
74
75impl Deref for EventCode {
76    type Target = u32;
77
78    fn deref(&self) -> &Self::Target {
79        &self.0
80    }
81}
82
83/// Supported Cobalt Metric types
84#[derive(Deserialize, Debug, PartialEq, Eq, Hash, Copy, Clone, Serialize)]
85pub enum MetricType {
86    /// Maps cached diffs from Uint or Int Inspect types.
87    /// NOTE: This does not use duration tracking. Durations are always set to 0.
88    Occurrence,
89
90    /// Maps raw Int Inspect types.
91    Integer,
92
93    /// Maps cached diffs from IntHistogram Inspect type.
94    IntHistogram,
95
96    /// Maps Inspect String type to StringValue (Cobalt 1.1 only).
97    String,
98}