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