Skip to content

Commit d43e55e

Browse files
committed
Define server_knobs_config metric in internal_metrics.rs
1 parent 111b06c commit d43e55e

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

glean-core/metrics.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,23 @@ glean.internal.metrics:
425425
description: |
426426
Map of metric identifiers (category.name) to boolean values
427427
indicating whether the metric is enabled.
428+
properties:
429+
key:
430+
type: string
431+
value:
432+
type: boolean
428433
pings_enabled:
429434
type: object
430435
description: |
431436
Map of ping names to boolean values indicating whether
432437
the ping is enabled.
438+
properties:
439+
key:
440+
type: string
441+
value:
442+
type: boolean
433443
event_threshold:
434-
type: integer
444+
type: number
435445
description: |
436446
Optional threshold for event buffering before an events
437447
ping is collected and submitted. Can be null if not set.

glean-core/src/core/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,17 +1113,6 @@ impl Glean {
11131113
.get_value(self, None)
11141114
}
11151115

1116-
/// Returns the ObjectMetric used to store Server Knobs configuration.
1117-
pub(crate) fn server_knobs_metric() -> metrics::ObjectMetric {
1118-
metrics::ObjectMetric::new(CommonMetricData {
1119-
name: "server_knobs_config".into(),
1120-
category: "glean.internal".into(),
1121-
send_in_pings: vec![INTERNAL_STORAGE.into()],
1122-
lifetime: Lifetime::Application,
1123-
..Default::default()
1124-
})
1125-
}
1126-
11271116
/// Set configuration to override the default state, typically initiated from a
11281117
/// remote_settings experiment or rollout
11291118
///
@@ -1153,8 +1142,9 @@ impl Glean {
11531142
drop(remote_settings_config); // Release lock before storage operation
11541143

11551144
// Store the configuration using the server knobs ObjectMetric
1156-
let server_knobs_metric = Self::server_knobs_metric();
1157-
server_knobs_metric.set_sync(self, serde_json::to_value(&config_clone).unwrap());
1145+
self.additional_metrics
1146+
.server_knobs_config
1147+
.set_sync(self, serde_json::to_value(&config_clone).unwrap());
11581148

11591149
// Update remote_settings epoch
11601150
self.remote_settings_epoch.fetch_add(1, Ordering::SeqCst);

glean-core/src/internal_metrics.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ pub struct AdditionalMetrics {
4444
/// The number of times we had to clamp an event timestamp
4545
/// for exceeding the range of a signed 64-bit integer (9223372036854775807).
4646
pub event_timestamp_clamped: CounterMetric,
47+
48+
/// Server knobs configuration received from remote settings.
49+
pub server_knobs_config: ObjectMetric,
4750
}
4851

4952
impl CoreMetrics {
@@ -211,6 +214,15 @@ impl AdditionalMetrics {
211214
disabled: false,
212215
dynamic_label: None,
213216
}),
217+
218+
server_knobs_config: ObjectMetric::new(CommonMetricData {
219+
name: "server_knobs_config".into(),
220+
category: "glean.internal.metrics".into(),
221+
send_in_pings: vec!["glean_internal_info".into()],
222+
lifetime: Lifetime::Application,
223+
disabled: false,
224+
dynamic_label: None,
225+
}),
214226
}
215227
}
216228
}

glean-core/src/ping/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ impl PingMaker {
163163
};
164164

165165
// Get the Server Knobs configuration, if available.
166-
let server_knobs_metric = crate::Glean::server_knobs_metric();
167-
if let Some(config_json) = server_knobs_metric.get_value(glean, INTERNAL_STORAGE) {
166+
if let Some(config_json) = glean
167+
.additional_metrics
168+
.server_knobs_config
169+
.get_value(glean, INTERNAL_STORAGE)
170+
{
168171
let server_knobs_config = serde_json::from_str(&config_json).unwrap();
169172
map.as_object_mut()
170173
.unwrap() // safe unwrap, we created the object above
@@ -605,7 +608,13 @@ mod test {
605608
let ping_info1 = ping_maker.get_ping_info(&glean, "store1", None, TimeUnit::Minute);
606609
let ping_info2 = ping_maker.get_ping_info(&glean, "store2", None, TimeUnit::Minute);
607610

608-
assert_eq!(ping_info1["server_knobs_config"]["metrics_enabled"]["test.counter"], true);
609-
assert_eq!(ping_info2["server_knobs_config"]["metrics_enabled"]["test.counter"], true);
611+
assert_eq!(
612+
ping_info1["server_knobs_config"]["metrics_enabled"]["test.counter"],
613+
true
614+
);
615+
assert_eq!(
616+
ping_info2["server_knobs_config"]["metrics_enabled"]["test.counter"],
617+
true
618+
);
610619
}
611620
}

0 commit comments

Comments
 (0)