Skip to main content

canic_core/workflow/metrics/
query.rs

1use crate::{
2    dto::{
3        metrics::{MetricEntry, MetricsKind},
4        page::{Page, PageRequest},
5    },
6    ops::runtime::metrics,
7    workflow::view::paginate::paginate_vec,
8};
9
10///
11/// MetricsQuery
12///
13/// Read-only query façade over metric snapshots.
14/// Responsible for mapping, sorting, and pagination only.
15///
16
17pub struct MetricsQuery;
18
19impl MetricsQuery {
20    #[must_use]
21    pub fn page(kind: MetricsKind, page: PageRequest) -> Page<MetricEntry> {
22        let mut entries = metrics::entries(kind);
23        entries.sort_by(|a, b| {
24            a.labels
25                .cmp(&b.labels)
26                .then_with(|| a.principal.cmp(&b.principal))
27        });
28
29        paginate_vec(entries, page)
30    }
31}