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