Scan all metric samples for a series within a time range.
(
&self,
series_id: SeriesId,
range: &TimeRange,
)
| 79 | |
| 80 | /// Scan all metric samples for a series within a time range. |
| 81 | pub fn scan_metrics( |
| 82 | &self, |
| 83 | series_id: SeriesId, |
| 84 | range: &TimeRange, |
| 85 | ) -> Result<Vec<(i64, f64)>, QueryError> { |
| 86 | let segments = self.segment_index.query(series_id, range); |
| 87 | if segments.is_empty() { |
| 88 | return Ok(Vec::new()); |
| 89 | } |
| 90 | |
| 91 | let mut all_samples = Vec::new(); |
| 92 | |
| 93 | for seg in &segments { |
| 94 | if seg.kind != SegmentKind::Metric { |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | let path = self.l1_dir.join(&seg.path); |
| 99 | let data = reader::read_metric_segment(&path)?; |
| 100 | |
| 101 | // Filter to exact time range. |
| 102 | for (ts, val) in data.samples { |
| 103 | if range.contains(ts) { |
| 104 | all_samples.push((ts, val)); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Sort by timestamp for ordered output. |
| 110 | all_samples.sort_by_key(|&(ts, _)| ts); |
| 111 | Ok(all_samples) |
| 112 | } |
| 113 | |
| 114 | /// Aggregate metrics for a series within a time range. |
| 115 | pub fn aggregate_metrics( |