canic-cli 0.115.0

Operator CLI for Canic fleet setup, builds, evidence, catalog, and diagnostics
Documentation
use clap::ValueEnum;
use serde::Serialize;

///
/// MetricsKind
///

#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, ValueEnum)]
#[serde(rename_all = "snake_case")]
pub(super) enum MetricsKind {
    Core,
    Placement,
    Platform,
    Runtime,
    Security,
    Storage,
}

///
/// MetricsReport
///

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub(super) struct MetricsReport {
    pub(super) fleet: String,
    pub(super) environment: String,
    pub(super) kind: MetricsKind,
    pub(super) canisters: Vec<MetricsCanisterReport>,
}

///
/// MetricsCanisterReport
///

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub(super) struct MetricsCanisterReport {
    pub(super) role: String,
    pub(super) canister_id: String,
    pub(super) status: MetricsCanisterStatus,
    pub(super) total: Option<u64>,
    pub(super) fetched: u64,
    pub(super) truncated: bool,
    pub(super) entries: Vec<MetricEntry>,
    pub(super) error: Option<String>,
}

///
/// MetricsCanisterStatus
///

#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub(super) enum MetricsCanisterStatus {
    Empty,
    Error,
    Ok,
    Unavailable,
}

impl MetricsCanisterStatus {
    pub(super) const fn label(self) -> &'static str {
        match self {
            Self::Empty => "empty",
            Self::Error => "error",
            Self::Ok => "ok",
            Self::Unavailable => "unavailable",
        }
    }
}

///
/// MetricsPage
///
/// CLI-owned rows with the total observed on the latest fetched page.
///

#[derive(Debug)]
pub(super) struct MetricsPage {
    pub(super) entries: Vec<MetricEntry>,
    pub(super) total: u64,
}

///
/// MetricEntry
///

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub(super) struct MetricEntry {
    pub(super) labels: Vec<String>,
    pub(super) principal: Option<String>,
    pub(super) value: MetricValue,
}

///
/// MetricValue
///

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub(super) enum MetricValue {
    Count {
        count: u128,
        exact: bool,
    },
    Measurement {
        count: u64,
        total: u128,
        count_overflowed: bool,
        total_overflowed: bool,
    },
    U128 {
        value: u128,
        exact: bool,
    },
}