Skip to main content

canic_core/dto/
metrics.rs

1use crate::dto::prelude::*;
2
3//
4// Metrics DTOs
5//
6
7//
8// MetricsKind
9//
10// Metric family selector.
11//
12
13#[derive(CandidType, Clone, Copy, Deserialize)]
14#[remain::sorted]
15pub enum MetricsKind {
16    Access,
17    Auth,
18    CanisterOps,
19    Cascade,
20    CyclesFunding,
21    CyclesTopup,
22    DelegatedAuth,
23    Directory,
24    Http,
25    Intent,
26    InterCanisterCall,
27    Lifecycle,
28    ManagementCall,
29    Perf,
30    PlatformCall,
31    Pool,
32    Provisioning,
33    Replay,
34    RootCapability,
35    Scaling,
36    #[cfg(feature = "sharding")]
37    Sharding,
38    System,
39    Timer,
40    WasmStore,
41}
42
43//
44// MetricEntry
45//
46// Unified metrics row.
47//
48
49#[derive(CandidType, Deserialize)]
50pub struct MetricEntry {
51    // Ordered labels.
52    pub labels: Vec<String>,
53
54    // Optional principal dimension.
55    pub principal: Option<Principal>,
56
57    // Metric payload.
58    pub value: MetricValue,
59}
60
61//
62// MetricValue
63//
64
65#[derive(CandidType, Deserialize)]
66pub enum MetricValue {
67    Count(u64),
68    CountAndU64 { count: u64, value_u64: u64 },
69    U128(u128),
70}
71
72//
73// QueryPerfSample
74//
75// Same-call query performance sample.
76//
77
78#[derive(CandidType, Deserialize)]
79pub struct QueryPerfSample<T> {
80    // Query result returned by the probe.
81    pub value: T,
82
83    // Local instruction counter observed in the same query call context.
84    pub local_instructions: u64,
85}