Skip to main content

canic_core/domain/
metrics.rs

1//! Module: domain::metrics
2//!
3//! Responsibility: define pure metric-family selector values shared by runtime
4//! metric projection, workflow queries, and endpoint DTOs.
5//! Does not own: metric row DTO structs, metric recording, or CLI metrics
6//! transport models.
7//! Boundary: DTOs re-export these values to preserve the public API path while
8//! internal code imports them from the domain owner.
9
10use candid::CandidType;
11use serde::Deserialize;
12
13///
14/// MetricsKind
15///
16/// Metric tier selector.
17///
18
19#[derive(CandidType, Clone, Copy, Debug, Deserialize)]
20#[remain::sorted]
21pub enum MetricsKind {
22    Core,
23    Placement,
24    Platform,
25    Runtime,
26    Security,
27    Storage,
28}
29
30///
31/// CanisterOpsMetricOperation
32///
33/// Canister operation metric dimension used by public metrics projection.
34///
35
36#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
37#[remain::sorted]
38pub enum CanisterOpsMetricOperation {
39    Create,
40    Delete,
41    Install,
42    Reinstall,
43    Restore,
44    Snapshot,
45    Upgrade,
46}
47
48impl CanisterOpsMetricOperation {
49    /// Return the stable public metrics label for this operation.
50    #[must_use]
51    pub const fn metric_label(self) -> &'static str {
52        match self {
53            Self::Create => "create",
54            Self::Delete => "delete",
55            Self::Install => "install",
56            Self::Reinstall => "reinstall",
57            Self::Restore => "restore",
58            Self::Snapshot => "snapshot",
59            Self::Upgrade => "upgrade",
60        }
61    }
62}
63
64///
65/// CanisterOpsMetricOutcome
66///
67/// Canister operation outcome dimension used by public metrics projection.
68///
69
70#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
71#[remain::sorted]
72pub enum CanisterOpsMetricOutcome {
73    Completed,
74    Failed,
75    Skipped,
76    Started,
77}
78
79impl CanisterOpsMetricOutcome {
80    /// Return the stable public metrics label for this outcome.
81    #[must_use]
82    pub const fn metric_label(self) -> &'static str {
83        match self {
84            Self::Completed => "completed",
85            Self::Failed => "failed",
86            Self::Skipped => "skipped",
87            Self::Started => "started",
88        }
89    }
90}
91
92///
93/// CanisterOpsMetricReason
94///
95/// Bounded canister operation reason dimension used by public metrics projection.
96///
97
98#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
99#[remain::sorted]
100pub enum CanisterOpsMetricReason {
101    AlreadyExists,
102    Cycles,
103    InvalidState,
104    ManagementCall,
105    MissingWasm,
106    NewAllocation,
107    NotFound,
108    Ok,
109    PolicyDenied,
110    PoolReuse,
111    PoolTopup,
112    StatePropagation,
113    Topology,
114    TopologyPropagation,
115    Unknown,
116}
117
118impl CanisterOpsMetricReason {
119    /// Return the stable public metrics label for this reason.
120    #[must_use]
121    pub const fn metric_label(self) -> &'static str {
122        match self {
123            Self::AlreadyExists => "already_exists",
124            Self::NewAllocation => "new_allocation",
125            Self::Cycles => "cycles",
126            Self::InvalidState => "invalid_state",
127            Self::ManagementCall => "management_call",
128            Self::MissingWasm => "missing_wasm",
129            Self::NotFound => "not_found",
130            Self::Ok => "ok",
131            Self::PolicyDenied => "policy_denied",
132            Self::PoolReuse => "pool_reuse",
133            Self::PoolTopup => "pool_topup",
134            Self::StatePropagation => "state_propagation",
135            Self::Topology => "topology",
136            Self::TopologyPropagation => "topology_propagation",
137            Self::Unknown => "unknown",
138        }
139    }
140}
141
142///
143/// LifecycleMetricPhase
144///
145/// Lifecycle phase dimension used by public metrics projection.
146///
147
148#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
149#[remain::sorted]
150pub enum LifecycleMetricPhase {
151    Init,
152    PostUpgrade,
153}
154
155impl LifecycleMetricPhase {
156    /// Return the stable public metrics label for this phase.
157    #[must_use]
158    pub const fn metric_label(self) -> &'static str {
159        match self {
160            Self::Init => "init",
161            Self::PostUpgrade => "post_upgrade",
162        }
163    }
164}
165
166///
167/// LifecycleMetricRole
168///
169/// Lifecycle canister role dimension used by public metrics projection.
170///
171
172#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
173#[remain::sorted]
174pub enum LifecycleMetricRole {
175    Nonroot,
176    Root,
177}
178
179impl LifecycleMetricRole {
180    /// Return the stable public metrics label for this role.
181    #[must_use]
182    pub const fn metric_label(self) -> &'static str {
183        match self {
184            Self::Nonroot => "nonroot",
185            Self::Root => "root",
186        }
187    }
188}
189
190///
191/// LifecycleMetricStage
192///
193/// Lifecycle stage dimension used by public metrics projection.
194///
195
196#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
197#[remain::sorted]
198pub enum LifecycleMetricStage {
199    Bootstrap,
200    Runtime,
201}
202
203impl LifecycleMetricStage {
204    /// Return the stable public metrics label for this stage.
205    #[must_use]
206    pub const fn metric_label(self) -> &'static str {
207        match self {
208            Self::Bootstrap => "bootstrap",
209            Self::Runtime => "runtime",
210        }
211    }
212}
213
214///
215/// LifecycleMetricOutcome
216///
217/// Lifecycle outcome dimension used by public metrics projection.
218///
219
220#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
221#[remain::sorted]
222pub enum LifecycleMetricOutcome {
223    Completed,
224    Failed,
225    Scheduled,
226    Skipped,
227    Started,
228    Waiting,
229}
230
231impl LifecycleMetricOutcome {
232    /// Return the stable public metrics label for this outcome.
233    #[must_use]
234    pub const fn metric_label(self) -> &'static str {
235        match self {
236            Self::Completed => "completed",
237            Self::Failed => "failed",
238            Self::Scheduled => "scheduled",
239            Self::Skipped => "skipped",
240            Self::Started => "started",
241            Self::Waiting => "waiting",
242        }
243    }
244}
245
246///
247/// WasmStoreMetricOperation
248///
249/// Wasm-store operation dimension used by public metrics projection.
250///
251
252#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
253#[remain::sorted]
254pub enum WasmStoreMetricOperation {
255    BootstrapChunkSync,
256    ChunkPublish,
257    ChunkUpload,
258    ManifestPromote,
259    Prepare,
260    ReleasePublish,
261    SourceResolve,
262}
263
264impl WasmStoreMetricOperation {
265    /// Return the stable public metrics label for this operation.
266    #[must_use]
267    pub const fn metric_label(self) -> &'static str {
268        match self {
269            Self::BootstrapChunkSync => "bootstrap_chunk_sync",
270            Self::ChunkPublish => "chunk_publish",
271            Self::ChunkUpload => "chunk_upload",
272            Self::ManifestPromote => "manifest_promote",
273            Self::Prepare => "prepare",
274            Self::ReleasePublish => "release_publish",
275            Self::SourceResolve => "source_resolve",
276        }
277    }
278}
279
280///
281/// WasmStoreMetricSource
282///
283/// Wasm-store source dimension used by public metrics projection.
284///
285
286#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
287#[remain::sorted]
288pub enum WasmStoreMetricSource {
289    Bootstrap,
290    Embedded,
291    ManagedFleet,
292    Resolver,
293    Store,
294    TargetStore,
295}
296
297impl WasmStoreMetricSource {
298    /// Return the stable public metrics label for this source.
299    #[must_use]
300    pub const fn metric_label(self) -> &'static str {
301        match self {
302            Self::Bootstrap => "bootstrap",
303            Self::Embedded => "embedded",
304            Self::ManagedFleet => "managed_fleet",
305            Self::Resolver => "resolver",
306            Self::Store => "store",
307            Self::TargetStore => "target_store",
308        }
309    }
310}
311
312///
313/// WasmStoreMetricOutcome
314///
315/// Wasm-store outcome dimension used by public metrics projection.
316///
317
318#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
319#[remain::sorted]
320pub enum WasmStoreMetricOutcome {
321    Completed,
322    Failed,
323    Skipped,
324    Started,
325}
326
327impl WasmStoreMetricOutcome {
328    /// Return the stable public metrics label for this outcome.
329    #[must_use]
330    pub const fn metric_label(self) -> &'static str {
331        match self {
332            Self::Completed => "completed",
333            Self::Failed => "failed",
334            Self::Skipped => "skipped",
335            Self::Started => "started",
336        }
337    }
338}
339
340///
341/// WasmStoreMetricReason
342///
343/// Bounded wasm-store reason dimension used by public metrics projection.
344///
345
346#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
347#[remain::sorted]
348pub enum WasmStoreMetricReason {
349    CacheHit,
350    CacheMiss,
351    Capacity,
352    HashMismatch,
353    InvalidState,
354    ManagementCall,
355    MissingChunk,
356    MissingManifest,
357    Ok,
358    StoreCall,
359    UnsupportedInline,
360}
361
362impl WasmStoreMetricReason {
363    /// Return the stable public metrics label for this reason.
364    #[must_use]
365    pub const fn metric_label(self) -> &'static str {
366        match self {
367            Self::CacheHit => "cache_hit",
368            Self::CacheMiss => "cache_miss",
369            Self::Capacity => "capacity",
370            Self::HashMismatch => "hash_mismatch",
371            Self::InvalidState => "invalid_state",
372            Self::ManagementCall => "management_call",
373            Self::MissingChunk => "missing_chunk",
374            Self::MissingManifest => "missing_manifest",
375            Self::Ok => "ok",
376            Self::StoreCall => "store_call",
377            Self::UnsupportedInline => "unsupported_inline",
378        }
379    }
380}
381
382///
383/// ManagementCallMetricOperation
384///
385/// Management canister operation dimension used by runtime metrics recording.
386///
387
388#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
389#[remain::sorted]
390pub enum ManagementCallMetricOperation {
391    CanisterStatus,
392    ClearChunkStore,
393    CreateCanister,
394    DeleteCanister,
395    DepositCycles,
396    EcdsaPublicKey,
397    GetCycles,
398    InstallChunkedCode,
399    InstallCode,
400    LoadCanisterSnapshot,
401    RawRand,
402    SignWithEcdsa,
403    StopCanister,
404    StoredChunks,
405    TakeCanisterSnapshot,
406    UninstallCode,
407    UpdateSettings,
408    UploadChunk,
409}
410
411///
412/// ManagementCallMetricOutcome
413///
414/// Management canister outcome dimension used by runtime metrics recording.
415///
416
417#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
418#[remain::sorted]
419pub enum ManagementCallMetricOutcome {
420    Completed,
421    Failed,
422    Started,
423}
424
425///
426/// ManagementCallMetricReason
427///
428/// Bounded management canister reason dimension used by runtime metrics recording.
429///
430
431#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
432#[remain::sorted]
433pub enum ManagementCallMetricReason {
434    Infra,
435    Ok,
436}
437
438///
439/// PlatformCallMetricSurface
440///
441/// Platform call surface dimension used by public metrics projection.
442///
443
444#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
445#[remain::sorted]
446pub enum PlatformCallMetricSurface {
447    Generic,
448    Http,
449    Ledger,
450    Management,
451}
452
453impl PlatformCallMetricSurface {
454    /// Return the stable public metrics label for this surface.
455    #[must_use]
456    pub const fn metric_label(self) -> &'static str {
457        match self {
458            Self::Generic => "generic",
459            Self::Http => "http",
460            Self::Ledger => "ledger",
461            Self::Management => "management",
462        }
463    }
464}
465
466///
467/// PlatformCallMetricMode
468///
469/// Platform call mode dimension used by public metrics projection.
470///
471
472#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
473#[remain::sorted]
474pub enum PlatformCallMetricMode {
475    BoundedWait,
476    UnboundedWait,
477    Update,
478}
479
480impl PlatformCallMetricMode {
481    /// Return the stable public metrics label for this mode.
482    #[must_use]
483    pub const fn metric_label(self) -> &'static str {
484        match self {
485            Self::BoundedWait => "bounded_wait",
486            Self::UnboundedWait => "unbounded_wait",
487            Self::Update => "update",
488        }
489    }
490}
491
492///
493/// PlatformCallMetricOutcome
494///
495/// Platform call outcome dimension used by public metrics projection.
496///
497
498#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
499#[remain::sorted]
500pub enum PlatformCallMetricOutcome {
501    Completed,
502    Failed,
503    Started,
504}
505
506impl PlatformCallMetricOutcome {
507    /// Return the stable public metrics label for this outcome.
508    #[must_use]
509    pub const fn metric_label(self) -> &'static str {
510        match self {
511            Self::Completed => "completed",
512            Self::Failed => "failed",
513            Self::Started => "started",
514        }
515    }
516}
517
518///
519/// PlatformCallMetricReason
520///
521/// Bounded platform call reason dimension used by public metrics projection.
522///
523
524#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
525#[remain::sorted]
526pub enum PlatformCallMetricReason {
527    CandidDecode,
528    CandidEncode,
529    HttpStatus,
530    Infra,
531    LedgerRejected,
532    Ok,
533}
534
535impl PlatformCallMetricReason {
536    /// Return the stable public metrics label for this reason.
537    #[must_use]
538    pub const fn metric_label(self) -> &'static str {
539        match self {
540            Self::CandidDecode => "candid_decode",
541            Self::CandidEncode => "candid_encode",
542            Self::HttpStatus => "http_status",
543            Self::Infra => "infra",
544            Self::LedgerRejected => "ledger_rejected",
545            Self::Ok => "ok",
546        }
547    }
548}