62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
use std::time::Duration;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum RetentionTime {
|
|
Short,
|
|
Medium,
|
|
Long,
|
|
}
|
|
|
|
impl RetentionTime {
|
|
pub fn debug_tag(&self) -> &'static str {
|
|
use RetentionTime::*;
|
|
match self {
|
|
Short => "ST",
|
|
Medium => "MT",
|
|
Long => "LT",
|
|
}
|
|
}
|
|
|
|
pub fn table_prefix(&self) -> &'static str {
|
|
use RetentionTime::*;
|
|
match self {
|
|
Short => "st_",
|
|
Medium => "mt_",
|
|
Long => "lt_",
|
|
}
|
|
}
|
|
|
|
pub fn ttl_events_d0(&self) -> Duration {
|
|
let day = 60 * 60 * 24;
|
|
let margin_max = Duration::from_secs(day * 2);
|
|
let ttl = self.ttl_ts_msp();
|
|
let margin = ttl / 10;
|
|
let margin = if margin >= margin_max { margin_max } else { margin };
|
|
ttl + margin
|
|
}
|
|
|
|
pub fn ttl_events_d1(&self) -> Duration {
|
|
// TTL now depends only on RetentionTime, not on data type or shape.
|
|
self.ttl_events_d0()
|
|
}
|
|
|
|
pub fn ttl_ts_msp(&self) -> Duration {
|
|
let day = 60 * 60 * 24;
|
|
match self {
|
|
RetentionTime::Short => Duration::from_secs(day * 40),
|
|
RetentionTime::Medium => Duration::from_secs(day * 31 * 13),
|
|
RetentionTime::Long => Duration::from_secs(day * 31 * 12 * 17),
|
|
}
|
|
}
|
|
|
|
pub fn ttl_binned(&self) -> Duration {
|
|
// Current choice is to keep the TTL the same as for events
|
|
self.ttl_events_d0()
|
|
}
|
|
|
|
pub fn ttl_channel_status(&self) -> Duration {
|
|
// Current choice is to keep the TTL the same as for events
|
|
self.ttl_events_d0()
|
|
}
|
|
}
|