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    CanisterStatus,
376    ClearChunkStore,
377    CreateCanister,
378    DeleteCanister,
379    DepositCycles,
380    EcdsaPublicKey,
381    GetCycles,
382    InstallChunkedCode,
383    InstallCode,
384    SignWithEcdsa,
385    StopCanister,
386    StoredChunks,
387    UninstallCode,
388    UpdateSettings,
389    UploadChunk,
390}
391
392///
393/// ManagementCallMetricOutcome
394///
395/// Management canister outcome dimension used by runtime metrics recording.
396///
397
398#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
399#[remain::sorted]
400pub enum ManagementCallMetricOutcome {
401    Completed,
402    Failed,
403    Started,
404}
405
406///
407/// ManagementCallMetricReason
408///
409/// Bounded management canister reason dimension used by runtime metrics recording.
410///
411
412#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
413#[remain::sorted]
414pub enum ManagementCallMetricReason {
415    Infra,
416    Ok,
417}
418
419///
420/// PlatformCallMetricSurface
421///
422/// Platform call surface dimension used by public metrics projection.
423///
424
425#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
426#[remain::sorted]
427pub enum PlatformCallMetricSurface {
428    Generic,
429    Management,
430}
431
432impl PlatformCallMetricSurface {
433    /// Return the stable public metrics label for this surface.
434    #[must_use]
435    pub const fn metric_label(self) -> &'static str {
436        match self {
437            Self::Generic => "generic",
438            Self::Management => "management",
439        }
440    }
441}
442
443///
444/// PlatformCallMetricMode
445///
446/// Platform call mode dimension used by public metrics projection.
447///
448
449#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
450#[remain::sorted]
451pub enum PlatformCallMetricMode {
452    BoundedWait,
453    UnboundedWait,
454    Update,
455}
456
457impl PlatformCallMetricMode {
458    /// Return the stable public metrics label for this mode.
459    #[must_use]
460    pub const fn metric_label(self) -> &'static str {
461        match self {
462            Self::BoundedWait => "bounded_wait",
463            Self::UnboundedWait => "unbounded_wait",
464            Self::Update => "update",
465        }
466    }
467}
468
469///
470/// PlatformCallMetricOutcome
471///
472/// Platform call outcome dimension used by public metrics projection.
473///
474
475#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
476#[remain::sorted]
477pub enum PlatformCallMetricOutcome {
478    Completed,
479    Failed,
480    Started,
481}
482
483impl PlatformCallMetricOutcome {
484    /// Return the stable public metrics label for this outcome.
485    #[must_use]
486    pub const fn metric_label(self) -> &'static str {
487        match self {
488            Self::Completed => "completed",
489            Self::Failed => "failed",
490            Self::Started => "started",
491        }
492    }
493}
494
495///
496/// PlatformCallMetricReason
497///
498/// Bounded platform call reason dimension used by public metrics projection.
499///
500
501#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
502#[remain::sorted]
503pub enum PlatformCallMetricReason {
504    CandidDecode,
505    CandidEncode,
506    Infra,
507    Ok,
508}
509
510impl PlatformCallMetricReason {
511    /// Return the stable public metrics label for this reason.
512    #[must_use]
513    pub const fn metric_label(self) -> &'static str {
514        match self {
515            Self::CandidDecode => "candid_decode",
516            Self::CandidEncode => "candid_encode",
517            Self::Infra => "infra",
518            Self::Ok => "ok",
519        }
520    }
521}