Skip to content

Commit bc2e05d

Browse files
committed
sqlite: Use an in-memory database when delay_ping_lifetime_io=true
This restores `delay_ping_lifetime_io` behavior (not touching disk until `persist_ping_lifetime_data` is called, or in auto-mode when the counter/time is hitting the limit) The local benchmark shows it's twice as fast compared to current `main` (so compared to always hitting disk).
1 parent f878cbb commit bc2e05d

4 files changed

Lines changed: 349 additions & 67 deletions

File tree

glean-core/rlb-tests/src/bin/delayed-ping-data.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use flate2::read::GzDecoder;
1313
use glean::{ClientInfoMetrics, ConfigurationBuilder, net, private::PingType};
1414

1515
pub mod glean_metrics {
16-
use glean::{CommonMetricData, Lifetime, private::CounterMetric};
16+
use glean::{CommonMetricData, Lifetime, private::*};
1717

1818
#[allow(non_upper_case_globals)]
1919
pub static sample_counter: once_cell::sync::Lazy<CounterMetric> =
@@ -27,6 +27,24 @@ pub mod glean_metrics {
2727
..Default::default()
2828
})
2929
});
30+
31+
#[allow(non_upper_case_globals)]
32+
pub static labeled_counter: once_cell::sync::Lazy<LabeledMetric<CounterMetric>> =
33+
once_cell::sync::Lazy::new(|| {
34+
LabeledMetric::new(
35+
glean::LabeledMetricData::Common {
36+
cmd: CommonMetricData {
37+
name: "labeled_counter".into(),
38+
category: "test.metrics".into(),
39+
send_in_pings: vec!["prototype".into()],
40+
disabled: false,
41+
lifetime: Lifetime::Ping,
42+
..Default::default()
43+
},
44+
},
45+
None,
46+
)
47+
});
3048
}
3149

3250
#[derive(Debug)]
@@ -123,11 +141,13 @@ fn main() {
123141
match &*state {
124142
"accumulate_one_and_pretend_crash" => {
125143
log::debug!("incrementing by 1. exiting without shutdown.");
126-
glean_metrics::sample_counter.add(1)
144+
glean_metrics::sample_counter.add(1);
145+
glean_metrics::labeled_counter.get("label").add(1);
127146
}
128147
"accumulate_ten_and_orderly_shutdown" => {
129148
log::debug!("incrementing by 10, waiting, shutdown. should trigger a flush.");
130149
glean_metrics::sample_counter.add(10);
150+
glean_metrics::labeled_counter.get("label").add(10);
131151
glean::shutdown();
132152
}
133153
"submit_ping" => {

glean-core/rlb-tests/tests/it.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ fn delayed_ping_data() {
7979
let mut lines = payload.lines();
8080
assert!(lines.any(|line| line.contains("\"url\":") && line.contains("/prototype/")));
8181
assert!(payload.contains("\"test.metrics.sample_counter\":10"));
82+
assert!(
83+
payload.contains("\"test.metrics.labeled_counter\":{\"label\":10}}}"),
84+
"{payload}"
85+
);
8286
}
8387

8488
#[cfg(unix)]

0 commit comments

Comments
 (0)