|
| 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 http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +use std::{collections::BTreeSet, fmt}; |
| 6 | + |
| 7 | +pub use crate::component_config::Component; |
| 8 | +use crate::util::slug; |
| 9 | + |
| 10 | +/// Dashboard configuration for a team |
| 11 | +pub struct TeamConfig { |
| 12 | + /// Display name for the team. |
| 13 | + /// |
| 14 | + /// This is what shows up on your dashboard titles. Spell it out however you want. |
| 15 | + pub team_name: &'static str, |
| 16 | + |
| 17 | + /// Components that your team manages. |
| 18 | + pub components: Vec<Component>, |
| 19 | + |
| 20 | + /// Track component errors |
| 21 | + /// |
| 22 | + /// This adds a panel to the main dashboard as well as creates a extra dashboard for error |
| 23 | + /// details. |
| 24 | + pub component_errors: bool, |
| 25 | + |
| 26 | + /// Track sync metrics |
| 27 | + /// |
| 28 | + /// This adds a panel to the main dashboard as well as creates a extra dashboard for sync |
| 29 | + /// errors. |
| 30 | + pub sync_metrics: bool, |
| 31 | + |
| 32 | + /// Metric to include on your main dashboard |
| 33 | + pub main_dashboard_metrics: Vec<Metric>, |
| 34 | + |
| 35 | + /// Extra dashboards to generate |
| 36 | + pub extra_dashboards: Vec<ExtraDashboard>, |
| 37 | +} |
| 38 | + |
| 39 | +/// Extra dashboard to generate for a team |
| 40 | +pub struct ExtraDashboard { |
| 41 | + pub name: &'static str, |
| 42 | + /// Metrics to include in the dashboard |
| 43 | + pub metrics: Vec<Metric>, |
| 44 | +} |
| 45 | + |
| 46 | +/// Metric to add to your team dashboard |
| 47 | +/// |
| 48 | +/// Metrics will add panels to your overview dashboard and/or create secondary dashboards. |
| 49 | +pub enum Metric { |
| 50 | + Counter(CounterMetric), |
| 51 | + LabeledCounter(LabeledCounterMetric), |
| 52 | + Distribution(DistributionMetric), |
| 53 | + LabeledDistribution(LabeledDistributionMetric), |
| 54 | +} |
| 55 | + |
| 56 | +/// Glean counter |
| 57 | +/// |
| 58 | +/// This will create time-series panels for the counter |
| 59 | +pub struct CounterMetric { |
| 60 | + /// Name to display on the dashboard |
| 61 | + pub display_name: &'static str, |
| 62 | + /// Name of the ping ("metrics" by default) |
| 63 | + pub ping: &'static str, |
| 64 | + /// Category name (top-level key in metrics.yaml) |
| 65 | + pub category: &'static str, |
| 66 | + /// Metric name (key for the metric) |
| 67 | + pub metric: &'static str, |
| 68 | + // Which applications report this metric |
| 69 | + pub applications: Vec<Application>, |
| 70 | +} |
| 71 | + |
| 72 | +/// Glean labeled counter |
| 73 | +/// |
| 74 | +/// This will create time-series panels for the counter, partitioned by the label |
| 75 | +pub struct LabeledCounterMetric { |
| 76 | + /// Name to display on the dashboard |
| 77 | + pub display_name: &'static str, |
| 78 | + /// Name of the ping ("metrics" by default) |
| 79 | + pub ping: &'static str, |
| 80 | + /// Category name (top-level key in metrics.yaml) |
| 81 | + pub category: &'static str, |
| 82 | + /// Metric name (key for the metric) |
| 83 | + pub metric: &'static str, |
| 84 | + // Which applications report this metric |
| 85 | + pub applications: Vec<Application>, |
| 86 | +} |
| 87 | + |
| 88 | +/// Glean timing/memory distribution |
| 89 | +/// |
| 90 | +/// This will create time-series panels for the 5th, 50th and 95th percentile. |
| 91 | +pub struct DistributionMetric { |
| 92 | + pub kind: DistributionMetricKind, |
| 93 | + /// Name to display on the dashboard |
| 94 | + pub display_name: &'static str, |
| 95 | + /// Label describing what we're measure, including units |
| 96 | + pub axis_label: &'static str, |
| 97 | + /// Name of the ping ("metrics" by default) |
| 98 | + pub ping: &'static str, |
| 99 | + /// Category name (top-level key in metrics.yaml) |
| 100 | + pub category: &'static str, |
| 101 | + /// Metric name (key for the metric) |
| 102 | + pub metric: &'static str, |
| 103 | + // Which applications report this metric |
| 104 | + pub applications: Vec<Application>, |
| 105 | + // Divide each value by this amount |
| 106 | + // |
| 107 | + // Note: |
| 108 | + // * Timing distributions are always stored in nanoseconds, regardless of the unit listed in |
| 109 | + // `metrics.yaml` |
| 110 | + // * Memory distributions are always stored in bytes, regardless of the unit listed in |
| 111 | + // `metrics.yaml` |
| 112 | + pub value_divisor: Option<u64>, |
| 113 | + // Filter out values lower than this amount (takes effect before the divisor) |
| 114 | + pub value_filter: Option<u64>, |
| 115 | + // Link to an extra dashboard, the inner value is the name of the dashboard |
| 116 | + pub link_to: Option<&'static str>, |
| 117 | +} |
| 118 | + |
| 119 | +/// Glean labeled timing/memory distribution |
| 120 | +/// |
| 121 | +/// This will create time-series panels for the 5th, 50th and 95th percentile. |
| 122 | +/// Percentiles will be partitioned by the metric label. |
| 123 | +pub struct LabeledDistributionMetric { |
| 124 | + pub kind: DistributionMetricKind, |
| 125 | + /// Name to display on the dashboard |
| 126 | + pub display_name: &'static str, |
| 127 | + /// Label describing what we're measure, including units |
| 128 | + pub axis_label: &'static str, |
| 129 | + /// Name of the ping ("metrics" by default) |
| 130 | + pub ping: &'static str, |
| 131 | + /// Category name (top-level key in metrics.yaml) |
| 132 | + pub category: &'static str, |
| 133 | + /// Metric name (key for the metric) |
| 134 | + pub metric: &'static str, |
| 135 | + // Which applications report this metric |
| 136 | + pub applications: Vec<Application>, |
| 137 | + // Divide each value by this amount |
| 138 | + // |
| 139 | + // Note: |
| 140 | + // * Timing distributions are always stored in nanoseconds, regardless of the unit listed in |
| 141 | + // `metrics.yaml` |
| 142 | + // * Memory distributions are always stored in bytes, regardless of the unit listed in |
| 143 | + // `metrics.yaml` |
| 144 | + pub value_divisor: Option<u64>, |
| 145 | + // Filter out values lower than this amount (takes effect before the divisor) |
| 146 | + pub value_filter: Option<u64>, |
| 147 | +} |
| 148 | + |
| 149 | +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] |
| 150 | +pub enum DistributionMetricKind { |
| 151 | + Memory, |
| 152 | + Timing, |
| 153 | + Custom, |
| 154 | +} |
| 155 | + |
| 156 | +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] |
| 157 | +pub enum Application { |
| 158 | + Android, |
| 159 | + Ios, |
| 160 | + Desktop, |
| 161 | +} |
| 162 | + |
| 163 | +#[derive(Clone, Copy, PartialEq, Eq)] |
| 164 | +pub enum ReleaseChannel { |
| 165 | + Nightly, |
| 166 | + Beta, |
| 167 | + Release, |
| 168 | +} |
| 169 | + |
| 170 | +impl TeamConfig { |
| 171 | + pub fn applications(&self) -> BTreeSet<Application> { |
| 172 | + self.components |
| 173 | + .iter() |
| 174 | + .flat_map(Component::applications) |
| 175 | + .cloned() |
| 176 | + .collect() |
| 177 | + } |
| 178 | + |
| 179 | + pub fn team_slug(&self) -> String { |
| 180 | + slug(self.team_name) |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +impl Application { |
| 185 | + pub fn slug(&self) -> &'static str { |
| 186 | + match self { |
| 187 | + Self::Android => "android", |
| 188 | + Self::Ios => "ios", |
| 189 | + Self::Desktop => "desktop", |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + pub fn bigquery_dataset(&self) -> &'static str { |
| 194 | + // There's a few datasets we can use, these were chosen because they seem to include |
| 195 | + // release, beta, and nightly data |
| 196 | + match self { |
| 197 | + Self::Android => "fenix", |
| 198 | + Self::Ios => "firefox_ios", |
| 199 | + Self::Desktop => "firefox_desktop", |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + pub fn display_name(&self, channel: ReleaseChannel) -> String { |
| 204 | + format!("{self} ({channel})") |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | +impl fmt::Display for Application { |
| 209 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 210 | + match self { |
| 211 | + Self::Android => write!(f, "Android"), |
| 212 | + Self::Ios => write!(f, "iOS"), |
| 213 | + Self::Desktop => write!(f, "Desktop"), |
| 214 | + } |
| 215 | + } |
| 216 | +} |
| 217 | + |
| 218 | +impl fmt::Display for ReleaseChannel { |
| 219 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 220 | + match self { |
| 221 | + Self::Nightly => write!(f, "nightly"), |
| 222 | + Self::Beta => write!(f, "beta"), |
| 223 | + Self::Release => write!(f, "release"), |
| 224 | + } |
| 225 | + } |
| 226 | +} |
| 227 | + |
| 228 | +impl From<CounterMetric> for Metric { |
| 229 | + fn from(m: CounterMetric) -> Self { |
| 230 | + Self::Counter(m) |
| 231 | + } |
| 232 | +} |
| 233 | + |
| 234 | +impl From<LabeledCounterMetric> for Metric { |
| 235 | + fn from(m: LabeledCounterMetric) -> Self { |
| 236 | + Self::LabeledCounter(m) |
| 237 | + } |
| 238 | +} |
| 239 | + |
| 240 | +impl From<DistributionMetric> for Metric { |
| 241 | + fn from(m: DistributionMetric) -> Self { |
| 242 | + Self::Distribution(m) |
| 243 | + } |
| 244 | +} |
| 245 | + |
| 246 | +impl From<LabeledDistributionMetric> for Metric { |
| 247 | + fn from(m: LabeledDistributionMetric) -> Self { |
| 248 | + Self::LabeledDistribution(m) |
| 249 | + } |
| 250 | +} |
0 commit comments