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