cbtop/incremental_snapshot/
query.rs1use std::time::Duration;
4
5use super::snapshot::SnapshotIndex;
6
7#[derive(Debug, Clone, Default)]
9pub struct SnapshotQuery {
10 pub start_ns: Option<u64>,
12 pub end_ns: Option<u64>,
14 pub fingerprint: Option<String>,
16 pub metric_name: Option<String>,
18 pub limit: Option<usize>,
20}
21
22impl SnapshotQuery {
23 pub fn new() -> Self {
25 Self::default()
26 }
27
28 pub fn time_range(mut self, start_ns: u64, end_ns: u64) -> Self {
30 self.start_ns = Some(start_ns);
31 self.end_ns = Some(end_ns);
32 self
33 }
34
35 pub fn fingerprint(mut self, fp: impl Into<String>) -> Self {
37 self.fingerprint = Some(fp.into());
38 self
39 }
40
41 pub fn metric(mut self, name: impl Into<String>) -> Self {
43 self.metric_name = Some(name.into());
44 self
45 }
46
47 pub fn limit(mut self, n: usize) -> Self {
49 self.limit = Some(n);
50 self
51 }
52
53 pub fn matches(&self, idx: &SnapshotIndex) -> bool {
55 if let Some(start) = self.start_ns {
56 if idx.timestamp_ns < start {
57 return false;
58 }
59 }
60 if let Some(end) = self.end_ns {
61 if idx.timestamp_ns > end {
62 return false;
63 }
64 }
65 if let Some(ref fp) = self.fingerprint {
66 if &idx.fingerprint != fp {
67 return false;
68 }
69 }
70 true
71 }
72}
73
74#[derive(Debug, Clone)]
76pub struct SnapshotConfig {
77 pub max_query_memory_bytes: usize,
79 pub keyframe_interval: usize,
81 pub verify_checksums: bool,
83 pub raw_max_age: Duration,
85 pub compressed_max_age: Duration,
87}
88
89impl Default for SnapshotConfig {
90 fn default() -> Self {
91 Self {
92 max_query_memory_bytes: 50 * 1024 * 1024, keyframe_interval: 10,
94 verify_checksums: true,
95 raw_max_age: Duration::from_secs(24 * 60 * 60),
96 compressed_max_age: Duration::from_secs(30 * 24 * 60 * 60),
97 }
98 }
99}