Skip to main content

autopush_common/
metric_name.rs

1//! Defines standard metric names used across the application.
2//!
3//! This module provides a type-safe way to refer to metrics by replacing
4//! string literals with enum variants, ensuring consistency and discoverability.
5
6use strum::{AsRefStr, Display, EnumString};
7use strum_macros::IntoStaticStr;
8
9/// Represents all metric names used in the application.
10#[derive(Debug, Clone, IntoStaticStr, AsRefStr, Display, EnumString)]
11#[strum(serialize_all = "snake_case")]
12pub enum MetricName {
13    //
14    // User agent metrics
15    //
16    /// User agent is already connected
17    #[strum(serialize = "ua.already_connected")]
18    UaAlreadyConnected,
19
20    /// User agent hello command
21    #[strum(serialize = "ua.command.hello")]
22    UaCommandHello,
23
24    /// User agent register command
25    #[strum(serialize = "ua.command.register")]
26    UaCommandRegister,
27
28    /// User agent unregister command
29    #[strum(serialize = "ua.command.unregister")]
30    UaCommandUnregister,
31
32    /// User agent ack command
33    #[strum(serialize = "ua.command.ack")]
34    UaCommandAck,
35
36    /// User agent nack command
37    #[strum(serialize = "ua.command.nack")]
38    UaCommandNack,
39
40    /// User agent connection check
41    #[strum(serialize = "ua.connection.check")]
42    UaConnectionCheck,
43
44    /// User agent connection channel count
45    #[strum(serialize = "ua.connection.channel_count")]
46    UaConnectionChannelCount,
47
48    /// User agent notification sent
49    #[strum(serialize = "ua.notification.sent")]
50    UaNotificationSent,
51
52    /// User agent expiration
53    #[strum(serialize = "ua.expiration")]
54    UaExpiration,
55
56    //
57    // Notification metrics
58    //
59    #[strum(serialize = "notification.received")]
60    NotificationReceived,
61
62    /// Notification authentication
63    #[strum(serialize = "notification.auth")]
64    NotificationAuth,
65
66    /// Notification authentication bad VAPID JSON
67    #[strum(serialize = "notification.auth.bad_vapid.json")]
68    NotificationAuthBadVapidJson,
69
70    /// Notification authentication bad VAPID other
71    #[strum(serialize = "notification.auth.bad_vapid.other")]
72    NotificationAuthBadVapidOther,
73
74    /// Authentication success
75    #[strum(serialize = "notification.auth.ok")]
76    NotificationAuthOk,
77
78    /// Authentication error
79    #[strum(serialize = "notification.auth.error")]
80    NotificationAuthError,
81
82    /// Notification message expired
83    /// Notification had TTL=0 and was undeliverable
84    /// (i.e. no live client) so it was discarded
85    #[strum(serialize = "notification.message.expired")]
86    NotificationMessageExpired,
87
88    /// Bridge error in notification routing
89    #[strum(serialize = "notification.bridge.error")]
90    NotificationBridgeError,
91
92    /// Bridge successfully sent notification
93    #[strum(serialize = "notification.bridge.sent")]
94    NotificationBridgeSent,
95
96    /// Notification total request time
97    #[strum(serialize = "notification.total_request_time")]
98    NotificationTotalRequestTime,
99
100    /// Notification message data
101    #[strum(serialize = "notification.message_data")]
102    NotificationMessageData,
103
104    /// Notifcation message stored
105    #[strum(serialize = "notification.message.stored")]
106    NotificationMessageStored,
107
108    /// Notifcation message deleted
109    #[strum(serialize = "notification.message.deleted")]
110    NotificationMessageDeleted,
111
112    /// Time a message spent in storage before being sent to a (re)connected
113    /// client, in milliseconds. Emitted at retrieval time (where the client's
114    /// user agent is known) and tagged with a low-cardinality `os`.
115    #[strum(serialize = "notification.storage.time")]
116    NotificationStorageTime,
117
118    //
119    // Error metrics
120    //
121    /// Node timeout error
122    #[strum(serialize = "error.node.timeout")]
123    ErrorNodeTimeout,
124
125    /// Node connection error
126    #[strum(serialize = "error.node.connect")]
127    ErrorNodeConnect,
128
129    /// A stale `node_id` could not be cleared: the `remove_node_id` predicate
130    /// didn't match, so the next notification for this user will attempt direct
131    /// delivery to the same dead node and pay the connect timeout again.
132    #[strum(serialize = "error.node.stale")]
133    ErrorNodeStale,
134
135    /// Disconnect semaphore full, unacked direct notifications dropped
136    #[strum(serialize = "error.disconnect.semaphore_full")]
137    ErrorDisconnectSemaphoreFull,
138
139    //
140    // Update metrics
141    //
142    /// Updates drop user
143    #[strum(serialize = "updates.drop_user")]
144    UpdatesDropUser,
145
146    /// VAPID version updates
147    #[strum(serialize = "updates.vapid.draft")]
148    UpdatesVapidDraft,
149
150    /// Client host is gone
151    #[strum(serialize = "updates.client.host_gone")]
152    UpdatesClientHostGone,
153
154    /// VAPID update
155    #[strum(serialize = "updates.vapid")]
156    UpdatesVapid,
157
158    //
159    // Megaphone metrics
160    //
161    /// Megaphone updater successful
162    #[strum(serialize = "megaphone.updater.ok")]
163    MegaphoneUpdaterOk,
164
165    /// Megaphone updater error
166    #[strum(serialize = "megaphone.updater.error")]
167    MegaphoneUpdaterError,
168
169    //
170    // Reliability metrics
171    //
172    /// Reliability error with Redis unavailable
173    #[strum(serialize = "reliability.error.redis_unavailable")]
174    ReliabilityErrorRedisUnavailable,
175
176    //
177    // Redis metrics
178    //
179    #[strum(serialize = "error.redis.unavailable")]
180    ErrorRedisUnavailable,
181
182    //
183    // Database metrics
184    //
185    // Database metric for retrying the connection
186    #[strum(serialize = "database.retry")]
187    DatabaseRetry,
188
189    // Database metric for dropping user
190    #[strum(serialize = "database.drop_user")]
191    DatabaseDropUser,
192
193    /// A router record was read whose TTL had passed. It is still served: this
194    /// counts what a `max_age` GC policy on the router family would have
195    /// hidden. Tagged by `router_type` and `app_id`
196    #[strum(serialize = "database.expired_user")]
197    DatabaseExpiredUser,
198
199    /// Channels read from a router record whose TTL had passed. As with
200    /// [MetricName::DatabaseExpiredUser] they are still served; channel cells
201    /// expire independently of the record that holds them
202    #[strum(serialize = "database.expired_channels")]
203    DatabaseExpiredChannels,
204
205    //
206    // Reliability metrics
207    //
208    // Reliability gc
209    #[strum(serialize = "reliability.gc")]
210    ReliabilityGc,
211
212    //
213    // Performance / pool metrics
214    //
215    /// Gauge of in-flight HTTP requests to autoconnect nodes
216    #[strum(serialize = "request.in_flight")]
217    InFlightNodeRequests,
218
219    /// Timer for the full notification routing path
220    #[strum(serialize = "notification.route_time")]
221    NotificationRouteTime,
222
223    /// Timer for db.save_message calls
224    #[strum(serialize = "notification.storage.save_time")]
225    StorageSaveTime,
226
227    /// Timer for the send_notification HTTP call to a node
228    #[strum(serialize = "notification.direct.delivery_time")]
229    DirectDeliveryTime,
230
231    /// Counter tagged with response status for direct delivery
232    #[strum(serialize = "notification.direct.delivery_status")]
233    DirectDeliveryStatus,
234}