Skip to main content

canic_core/ids/
metrics.rs

1//! Module: ids::metrics
2//!
3//! Responsibility: metric classification identifiers.
4//! Does not own: metric storage, aggregation, or emission.
5//! Boundary: exposes stable categories used by access and system metrics.
6
7use serde::{Deserialize, Serialize};
8
9///
10/// AccessMetricKind
11///
12/// Enumerates the access predicate kind that rejected the call.
13/// Access metrics are emitted only on denial.
14/// Custom predicates report AccessMetricKind::Custom.
15/// Predicate names are recorded separately alongside the kind.
16/// Owned by ids and consumed by access metrics adapters.
17///
18
19#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
20#[remain::sorted]
21pub enum AccessMetricKind {
22    Auth,
23    Custom,
24    Env,
25    Guard,
26    Rule,
27}
28
29impl AccessMetricKind {
30    /// Return the stable metric label for this access metric kind.
31    #[must_use]
32    pub const fn as_str(self) -> &'static str {
33        match self {
34            Self::Auth => "auth",
35            Self::Custom => "custom",
36            Self::Env => "env",
37            Self::Guard => "guard",
38            Self::Rule => "rule",
39        }
40    }
41}
42
43///
44/// SystemMetricKind
45///
46/// Enumerates platform operation families recorded by system metrics.
47/// Owned by ids and consumed by runtime metrics adapters.
48///
49
50#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
51#[remain::sorted]
52pub enum SystemMetricKind {
53    CanisterCall,
54    CanisterStatus,
55    CreateCanister,
56    DeleteCanister,
57    DepositCycles,
58    HttpOutcall,
59    InstallCode,
60    RawRand,
61    ReinstallCode,
62    TimerScheduled,
63    UninstallCode,
64    UpdateSettings,
65    UpgradeCode,
66}