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    ManagedFleet,
275    Resolver,
276    Store,
277    TargetStore,
278}
279
280impl WasmStoreMetricSource {
281    /// Return the stable public metrics label for this source.
282    #[must_use]
283    pub const fn metric_label(self) -> &'static str {
284        match self {
285            Self::Bootstrap => "bootstrap",
286            Self::ManagedFleet => "managed_fleet",
287            Self::Resolver => "resolver",
288            Self::Store => "store",
289            Self::TargetStore => "target_store",
290        }
291    }
292}
293
294///
295/// WasmStoreMetricOutcome
296///
297/// Wasm-store outcome dimension used by public metrics projection.
298///
299
300#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
301#[remain::sorted]
302pub enum WasmStoreMetricOutcome {
303    Completed,
304    Failed,
305    Skipped,
306    Started,
307}
308
309impl WasmStoreMetricOutcome {
310    /// Return the stable public metrics label for this outcome.
311    #[must_use]
312    pub const fn metric_label(self) -> &'static str {
313        match self {
314            Self::Completed => "completed",
315            Self::Failed => "failed",
316            Self::Skipped => "skipped",
317            Self::Started => "started",
318        }
319    }
320}
321
322///
323/// WasmStoreMetricReason
324///
325/// Bounded wasm-store reason dimension used by public metrics projection.
326///
327
328#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
329#[remain::sorted]
330pub enum WasmStoreMetricReason {
331    CacheHit,
332    CacheMiss,
333    Capacity,
334    HashMismatch,
335    InvalidState,
336    ManagementCall,
337    MissingChunk,
338    MissingManifest,
339    Ok,
340    StoreCall,
341    UnsupportedInline,
342}
343
344impl WasmStoreMetricReason {
345    /// Return the stable public metrics label for this reason.
346    #[must_use]
347    pub const fn metric_label(self) -> &'static str {
348        match self {
349            Self::CacheHit => "cache_hit",
350            Self::CacheMiss => "cache_miss",
351            Self::Capacity => "capacity",
352            Self::HashMismatch => "hash_mismatch",
353            Self::InvalidState => "invalid_state",
354            Self::ManagementCall => "management_call",
355            Self::MissingChunk => "missing_chunk",
356            Self::MissingManifest => "missing_manifest",
357            Self::Ok => "ok",
358            Self::StoreCall => "store_call",
359            Self::UnsupportedInline => "unsupported_inline",
360        }
361    }
362}
363
364///
365/// ManagementCallMetricOperation
366///
367/// Management canister operation dimension used by runtime metrics recording.
368///
369
370#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
371#[remain::sorted]
372pub enum ManagementCallMetricOperation {
373    CanisterInfo,
374    CanisterStatus,
375    ClearChunkStore,
376    DeleteCanister,
377    DepositCycles,
378    EcdsaPublicKey,
379    GetCycles,
380    InstallChunkedCode,
381    InstallCode,
382    SignWithEcdsa,
383    StopCanister,
384    StoredChunks,
385    UninstallCode,
386    UpdateSettings,
387    UploadChunk,
388}
389
390///
391/// ManagementCallMetricOutcome
392///
393/// Management canister outcome dimension used by runtime metrics recording.
394///
395
396#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
397#[remain::sorted]
398pub enum ManagementCallMetricOutcome {
399    Completed,
400    Failed,
401    Started,
402}
403
404///
405/// ManagementCallMetricReason
406///
407/// Bounded management canister reason dimension used by runtime metrics recording.
408///
409
410#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
411#[remain::sorted]
412pub enum ManagementCallMetricReason {
413    Infra,
414    Ok,
415}
416
417///
418/// PlatformCallMetricSurface
419///
420/// Platform call surface dimension used by public metrics projection.
421///
422
423#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
424#[remain::sorted]
425pub enum PlatformCallMetricSurface {
426    Generic,
427    Management,
428}
429
430impl PlatformCallMetricSurface {
431    /// Return the stable public metrics label for this surface.
432    #[must_use]
433    pub const fn metric_label(self) -> &'static str {
434        match self {
435            Self::Generic => "generic",
436            Self::Management => "management",
437        }
438    }
439}
440
441///
442/// PlatformCallMetricMode
443///
444/// Platform call mode dimension used by public metrics projection.
445///
446
447#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
448#[remain::sorted]
449pub enum PlatformCallMetricMode {
450    BoundedWait,
451    UnboundedWait,
452    Update,
453}
454
455impl PlatformCallMetricMode {
456    /// Return the stable public metrics label for this mode.
457    #[must_use]
458    pub const fn metric_label(self) -> &'static str {
459        match self {
460            Self::BoundedWait => "bounded_wait",
461            Self::UnboundedWait => "unbounded_wait",
462            Self::Update => "update",
463        }
464    }
465}
466
467///
468/// PlatformCallMetricOutcome
469///
470/// Platform call outcome dimension used by public metrics projection.
471///
472
473#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
474#[remain::sorted]
475pub enum PlatformCallMetricOutcome {
476    Completed,
477    Failed,
478    Started,
479}
480
481impl PlatformCallMetricOutcome {
482    /// Return the stable public metrics label for this outcome.
483    #[must_use]
484    pub const fn metric_label(self) -> &'static str {
485        match self {
486            Self::Completed => "completed",
487            Self::Failed => "failed",
488            Self::Started => "started",
489        }
490    }
491}
492
493///
494/// PlatformCallMetricReason
495///
496/// Bounded platform call reason dimension used by public metrics projection.
497///
498
499#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
500#[remain::sorted]
501pub enum PlatformCallMetricReason {
502    CandidDecode,
503    CandidEncode,
504    Infra,
505    Ok,
506}
507
508impl PlatformCallMetricReason {
509    /// Return the stable public metrics label for this reason.
510    #[must_use]
511    pub const fn metric_label(self) -> &'static str {
512        match self {
513            Self::CandidDecode => "candid_decode",
514            Self::CandidEncode => "candid_encode",
515            Self::Infra => "infra",
516            Self::Ok => "ok",
517        }
518    }
519}