canic-cli 0.115.0

Operator CLI for Canic fleet setup, builds, evidence, catalog, and diagnostics
Documentation
//! Module: metrics::parse
//!
//! Responsibility: decode typed metric pages and project them into CLI report rows.
//! Does not own: ICP command execution, metric collection, or report rendering.
//! Boundary: projects typed pages received by the current observability transport.

use crate::metrics::model::{MetricEntry, MetricValue, MetricsPage};
use canic_contracts::dto::{
    metric_page::MetricEntry as MetricEntryDto, metrics::MetricValue as MetricValueDto, page::Page,
};

pub(super) fn metric_page(page: Page<MetricEntryDto>) -> MetricsPage {
    MetricsPage {
        entries: page.entries.into_iter().map(metric_entry).collect(),
        total: page.total,
    }
}

fn metric_entry(entry: MetricEntryDto) -> MetricEntry {
    MetricEntry {
        labels: entry.labels,
        principal: entry.principal.map(|principal| principal.to_text()),
        value: metric_value(entry.value),
    }
}

const fn metric_value(value: MetricValueDto) -> MetricValue {
    match value {
        MetricValueDto::Count { count, exact } => MetricValue::Count { count, exact },
        MetricValueDto::Measurement {
            count,
            total,
            count_overflowed,
            total_overflowed,
        } => MetricValue::Measurement {
            count,
            total,
            count_overflowed,
            total_overflowed,
        },
        MetricValueDto::U128 { value, exact } => MetricValue::U128 { value, exact },
    }
}