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