use std::time::Duration;
use super::snapshot::SnapshotIndex;
#[derive(Debug, Clone, Default)]
pub struct SnapshotQuery {
pub start_ns: Option<u64>,
pub end_ns: Option<u64>,
pub fingerprint: Option<String>,
pub metric_name: Option<String>,
pub limit: Option<usize>,
}
impl SnapshotQuery {
pub fn new() -> Self {
Self::default()
}
pub fn time_range(mut self, start_ns: u64, end_ns: u64) -> Self {
self.start_ns = Some(start_ns);
self.end_ns = Some(end_ns);
self
}
pub fn fingerprint(mut self, fp: impl Into<String>) -> Self {
self.fingerprint = Some(fp.into());
self
}
pub fn metric(mut self, name: impl Into<String>) -> Self {
self.metric_name = Some(name.into());
self
}
pub fn limit(mut self, n: usize) -> Self {
self.limit = Some(n);
self
}
pub fn matches(&self, idx: &SnapshotIndex) -> bool {
if let Some(start) = self.start_ns {
if idx.timestamp_ns < start {
return false;
}
}
if let Some(end) = self.end_ns {
if idx.timestamp_ns > end {
return false;
}
}
if let Some(ref fp) = self.fingerprint {
if &idx.fingerprint != fp {
return false;
}
}
true
}
}
#[derive(Debug, Clone)]
pub struct SnapshotConfig {
pub max_query_memory_bytes: usize,
pub keyframe_interval: usize,
pub verify_checksums: bool,
pub raw_max_age: Duration,
pub compressed_max_age: Duration,
}
impl Default for SnapshotConfig {
fn default() -> Self {
Self {
max_query_memory_bytes: 50 * 1024 * 1024, keyframe_interval: 10,
verify_checksums: true,
raw_max_age: Duration::from_secs(24 * 60 * 60),
compressed_max_age: Duration::from_secs(30 * 24 * 60 * 60),
}
}
}