Line data Source code
1 : use std::sync::{Arc, OnceLock};
2 :
3 : use lasso::ThreadedRodeo;
4 : use measured::label::{
5 : FixedCardinalitySet, LabelGroupSet, LabelName, LabelSet, LabelValue, StaticLabelSet,
6 : };
7 : use measured::metric::histogram::Thresholds;
8 : use measured::metric::name::MetricName;
9 : use measured::{
10 : Counter, CounterVec, FixedCardinalityLabel, Gauge, Histogram, HistogramVec, LabelGroup,
11 : MetricGroup,
12 : };
13 : use metrics::{CounterPairAssoc, CounterPairVec, HyperLogLog, HyperLogLogVec};
14 : use tokio::time::{self, Instant};
15 :
16 : use crate::control_plane::messages::ColdStartInfo;
17 : use crate::error::ErrorKind;
18 :
19 44 : #[derive(MetricGroup)]
20 : #[metric(new(thread_pool: Arc<ThreadPoolMetrics>))]
21 : pub struct Metrics {
22 : #[metric(namespace = "proxy")]
23 : #[metric(init = ProxyMetrics::new(thread_pool))]
24 : pub proxy: ProxyMetrics,
25 :
26 : #[metric(namespace = "wake_compute_lock")]
27 : pub wake_compute_lock: ApiLockMetrics,
28 : }
29 :
30 : static SELF: OnceLock<Metrics> = OnceLock::new();
31 : impl Metrics {
32 0 : pub fn install(thread_pool: Arc<ThreadPoolMetrics>) {
33 0 : let mut metrics = Metrics::new(thread_pool);
34 0 :
35 0 : metrics.proxy.errors_total.init_all_dense();
36 0 : metrics.proxy.redis_errors_total.init_all_dense();
37 0 : metrics.proxy.redis_events_count.init_all_dense();
38 0 : metrics.proxy.retries_metric.init_all_dense();
39 0 : metrics.proxy.invalid_endpoints_total.init_all_dense();
40 0 : metrics.proxy.connection_failures_total.init_all_dense();
41 0 :
42 0 : SELF.set(metrics)
43 0 : .ok()
44 0 : .expect("proxy metrics must not be installed more than once");
45 0 : }
46 :
47 143 : pub fn get() -> &'static Self {
48 143 : #[cfg(test)]
49 143 : return SELF.get_or_init(|| Metrics::new(Arc::new(ThreadPoolMetrics::new(0))));
50 143 :
51 143 : #[cfg(not(test))]
52 143 : SELF.get()
53 143 : .expect("proxy metrics must be installed by the main() function")
54 143 : }
55 : }
56 :
57 44 : #[derive(MetricGroup)]
58 : #[metric(new(thread_pool: Arc<ThreadPoolMetrics>))]
59 : pub struct ProxyMetrics {
60 : #[metric(flatten)]
61 : pub db_connections: CounterPairVec<NumDbConnectionsGauge>,
62 : #[metric(flatten)]
63 : pub client_connections: CounterPairVec<NumClientConnectionsGauge>,
64 : #[metric(flatten)]
65 : pub connection_requests: CounterPairVec<NumConnectionRequestsGauge>,
66 : #[metric(flatten)]
67 : pub http_endpoint_pools: HttpEndpointPools,
68 : #[metric(flatten)]
69 : pub cancel_channel_size: CounterPairVec<CancelChannelSizeGauge>,
70 :
71 : /// Time it took for proxy to establish a connection to the compute endpoint.
72 : // largest bucket = 2^16 * 0.5ms = 32s
73 : #[metric(metadata = Thresholds::exponential_buckets(0.0005, 2.0))]
74 : pub compute_connection_latency_seconds: HistogramVec<ComputeConnectionLatencySet, 16>,
75 :
76 : /// Time it took for proxy to receive a response from control plane.
77 : #[metric(
78 : // largest bucket = 2^16 * 0.2ms = 13s
79 : metadata = Thresholds::exponential_buckets(0.0002, 2.0),
80 : )]
81 : pub console_request_latency: HistogramVec<ConsoleRequestSet, 16>,
82 :
83 : /// Time it takes to acquire a token to call console plane.
84 : // largest bucket = 3^16 * 0.05ms = 2.15s
85 : #[metric(metadata = Thresholds::exponential_buckets(0.00005, 3.0))]
86 : pub control_plane_token_acquire_seconds: Histogram<16>,
87 :
88 : /// Size of the HTTP request body lengths.
89 : // smallest bucket = 16 bytes
90 : // largest bucket = 4^12 * 16 bytes = 256MB
91 : #[metric(metadata = Thresholds::exponential_buckets(16.0, 4.0))]
92 : pub http_conn_content_length_bytes: HistogramVec<StaticLabelSet<HttpDirection>, 12>,
93 :
94 : /// Time it takes to reclaim unused connection pools.
95 : #[metric(metadata = Thresholds::exponential_buckets(1e-6, 2.0))]
96 : pub http_pool_reclaimation_lag_seconds: Histogram<16>,
97 :
98 : /// Number of opened connections to a database.
99 : pub http_pool_opened_connections: Gauge,
100 :
101 : /// Number of cache hits/misses for allowed ips.
102 : pub allowed_ips_cache_misses: CounterVec<StaticLabelSet<CacheOutcome>>,
103 :
104 : /// Number of allowed ips
105 : #[metric(metadata = Thresholds::with_buckets([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 20.0, 50.0, 100.0]))]
106 : pub allowed_ips_number: Histogram<10>,
107 :
108 : /// Number of cache hits/misses for VPC endpoint IDs.
109 : pub vpc_endpoint_id_cache_stats: CounterVec<StaticLabelSet<CacheOutcome>>,
110 :
111 : /// Number of cache hits/misses for access blocker flags.
112 : pub access_blocker_flags_cache_stats: CounterVec<StaticLabelSet<CacheOutcome>>,
113 :
114 : /// Number of allowed VPC endpoints IDs
115 : #[metric(metadata = Thresholds::with_buckets([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 20.0, 50.0, 100.0]))]
116 : pub allowed_vpc_endpoint_ids: Histogram<10>,
117 :
118 : /// Number of connections (per sni).
119 : pub accepted_connections_by_sni: CounterVec<StaticLabelSet<SniKind>>,
120 :
121 : /// Number of connection failures (per kind).
122 : pub connection_failures_total: CounterVec<StaticLabelSet<ConnectionFailureKind>>,
123 :
124 : /// Number of wake-up failures (per kind).
125 : pub connection_failures_breakdown: CounterVec<ConnectionFailuresBreakdownSet>,
126 :
127 : /// Number of bytes sent/received between all clients and backends.
128 : pub io_bytes: CounterVec<StaticLabelSet<Direction>>,
129 :
130 : /// Number of errors by a given classification.
131 : pub errors_total: CounterVec<StaticLabelSet<crate::error::ErrorKind>>,
132 :
133 : /// Number of cancellation requests (per found/not_found).
134 : pub cancellation_requests_total: CounterVec<CancellationRequestSet>,
135 :
136 : /// Number of errors by a given classification
137 : pub redis_errors_total: CounterVec<RedisErrorsSet>,
138 :
139 : /// Number of TLS handshake failures
140 : pub tls_handshake_failures: Counter,
141 :
142 : /// Number of connection requests affected by authentication rate limits
143 : pub requests_auth_rate_limits_total: Counter,
144 :
145 : /// HLL approximate cardinality of endpoints that are connecting
146 : pub connecting_endpoints: HyperLogLogVec<StaticLabelSet<Protocol>, 32>,
147 :
148 : /// Number of endpoints affected by errors of a given classification
149 : pub endpoints_affected_by_errors: HyperLogLogVec<StaticLabelSet<crate::error::ErrorKind>, 32>,
150 :
151 : /// Number of endpoints affected by authentication rate limits
152 : pub endpoints_auth_rate_limits: HyperLogLog<32>,
153 :
154 : /// Number of invalid endpoints (per protocol, per rejected).
155 : pub invalid_endpoints_total: CounterVec<InvalidEndpointsSet>,
156 :
157 : /// Number of retries (per outcome, per retry_type).
158 : #[metric(metadata = Thresholds::with_buckets([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]))]
159 : pub retries_metric: HistogramVec<RetriesMetricSet, 9>,
160 :
161 : /// Number of events consumed from redis (per event type).
162 : pub redis_events_count: CounterVec<StaticLabelSet<RedisEventsCount>>,
163 :
164 : #[metric(namespace = "connect_compute_lock")]
165 : pub connect_compute_lock: ApiLockMetrics,
166 :
167 : #[metric(namespace = "scram_pool")]
168 : #[metric(init = thread_pool)]
169 : pub scram_pool: Arc<ThreadPoolMetrics>,
170 : }
171 :
172 88 : #[derive(MetricGroup)]
173 : #[metric(new())]
174 : pub struct ApiLockMetrics {
175 : /// Number of semaphores registered in this api lock
176 : pub semaphores_registered: Counter,
177 : /// Number of semaphores unregistered in this api lock
178 : pub semaphores_unregistered: Counter,
179 : /// Time it takes to reclaim unused semaphores in the api lock
180 : #[metric(metadata = Thresholds::exponential_buckets(1e-6, 2.0))]
181 : pub reclamation_lag_seconds: Histogram<16>,
182 : /// Time it takes to acquire a semaphore lock
183 : #[metric(metadata = Thresholds::exponential_buckets(1e-4, 2.0))]
184 : pub semaphore_acquire_seconds: Histogram<16>,
185 : }
186 :
187 : impl Default for ApiLockMetrics {
188 88 : fn default() -> Self {
189 88 : Self::new()
190 88 : }
191 : }
192 :
193 : #[derive(FixedCardinalityLabel, Copy, Clone)]
194 : #[label(singleton = "direction")]
195 : pub enum HttpDirection {
196 : Request,
197 : Response,
198 : }
199 :
200 : #[derive(FixedCardinalityLabel, Copy, Clone)]
201 : #[label(singleton = "direction")]
202 : pub enum Direction {
203 : Tx,
204 : Rx,
205 : }
206 :
207 : #[derive(FixedCardinalityLabel, Clone, Copy, Debug)]
208 : #[label(singleton = "protocol")]
209 : pub enum Protocol {
210 : Http,
211 : Ws,
212 : Tcp,
213 : SniRouter,
214 : }
215 :
216 : impl Protocol {
217 0 : pub fn as_str(self) -> &'static str {
218 0 : match self {
219 0 : Protocol::Http => "http",
220 0 : Protocol::Ws => "ws",
221 0 : Protocol::Tcp => "tcp",
222 0 : Protocol::SniRouter => "sni_router",
223 : }
224 0 : }
225 : }
226 :
227 : impl std::fmt::Display for Protocol {
228 0 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
229 0 : f.write_str(self.as_str())
230 0 : }
231 : }
232 :
233 : #[derive(FixedCardinalityLabel, Copy, Clone)]
234 : pub enum Bool {
235 : True,
236 : False,
237 : }
238 :
239 : #[derive(FixedCardinalityLabel, Copy, Clone)]
240 : #[label(singleton = "outcome")]
241 : pub enum Outcome {
242 : Success,
243 : Failed,
244 : }
245 :
246 : #[derive(FixedCardinalityLabel, Copy, Clone)]
247 : #[label(singleton = "outcome")]
248 : pub enum CacheOutcome {
249 : Hit,
250 : Miss,
251 : }
252 :
253 88 : #[derive(LabelGroup)]
254 : #[label(set = ConsoleRequestSet)]
255 : pub struct ConsoleRequest<'a> {
256 : #[label(dynamic_with = ThreadedRodeo, default)]
257 : pub request: &'a str,
258 : }
259 :
260 : #[derive(MetricGroup, Default)]
261 : pub struct HttpEndpointPools {
262 : /// Number of endpoints we have registered pools for
263 : pub http_pool_endpoints_registered_total: Counter,
264 : /// Number of endpoints we have unregistered pools for
265 : pub http_pool_endpoints_unregistered_total: Counter,
266 : }
267 :
268 : pub struct HttpEndpointPoolsGuard<'a> {
269 : dec: &'a Counter,
270 : }
271 :
272 : impl Drop for HttpEndpointPoolsGuard<'_> {
273 2 : fn drop(&mut self) {
274 2 : self.dec.inc();
275 2 : }
276 : }
277 :
278 : impl HttpEndpointPools {
279 2 : pub fn guard(&self) -> HttpEndpointPoolsGuard<'_> {
280 2 : self.http_pool_endpoints_registered_total.inc();
281 2 : HttpEndpointPoolsGuard {
282 2 : dec: &self.http_pool_endpoints_unregistered_total,
283 2 : }
284 2 : }
285 : }
286 : pub struct NumDbConnectionsGauge;
287 : impl CounterPairAssoc for NumDbConnectionsGauge {
288 : const INC_NAME: &'static MetricName = MetricName::from_str("opened_db_connections_total");
289 : const DEC_NAME: &'static MetricName = MetricName::from_str("closed_db_connections_total");
290 : const INC_HELP: &'static str = "Number of opened connections to a database.";
291 : const DEC_HELP: &'static str = "Number of closed connections to a database.";
292 : type LabelGroupSet = StaticLabelSet<Protocol>;
293 : }
294 : pub type NumDbConnectionsGuard<'a> = metrics::MeasuredCounterPairGuard<'a, NumDbConnectionsGauge>;
295 :
296 : pub struct NumClientConnectionsGauge;
297 : impl CounterPairAssoc for NumClientConnectionsGauge {
298 : const INC_NAME: &'static MetricName = MetricName::from_str("opened_client_connections_total");
299 : const DEC_NAME: &'static MetricName = MetricName::from_str("closed_client_connections_total");
300 : const INC_HELP: &'static str = "Number of opened connections from a client.";
301 : const DEC_HELP: &'static str = "Number of closed connections from a client.";
302 : type LabelGroupSet = StaticLabelSet<Protocol>;
303 : }
304 : pub type NumClientConnectionsGuard<'a> =
305 : metrics::MeasuredCounterPairGuard<'a, NumClientConnectionsGauge>;
306 :
307 : pub struct NumConnectionRequestsGauge;
308 : impl CounterPairAssoc for NumConnectionRequestsGauge {
309 : const INC_NAME: &'static MetricName = MetricName::from_str("accepted_connections_total");
310 : const DEC_NAME: &'static MetricName = MetricName::from_str("closed_connections_total");
311 : const INC_HELP: &'static str = "Number of client connections accepted.";
312 : const DEC_HELP: &'static str = "Number of client connections closed.";
313 : type LabelGroupSet = StaticLabelSet<Protocol>;
314 : }
315 : pub type NumConnectionRequestsGuard<'a> =
316 : metrics::MeasuredCounterPairGuard<'a, NumConnectionRequestsGauge>;
317 :
318 : pub struct CancelChannelSizeGauge;
319 : impl CounterPairAssoc for CancelChannelSizeGauge {
320 : const INC_NAME: &'static MetricName = MetricName::from_str("opened_msgs_cancel_channel_total");
321 : const DEC_NAME: &'static MetricName = MetricName::from_str("closed_msgs_cancel_channel_total");
322 : const INC_HELP: &'static str = "Number of processing messages in the cancellation channel.";
323 : const DEC_HELP: &'static str = "Number of closed messages in the cancellation channel.";
324 : type LabelGroupSet = StaticLabelSet<RedisMsgKind>;
325 : }
326 : pub type CancelChannelSizeGuard<'a> = metrics::MeasuredCounterPairGuard<'a, CancelChannelSizeGauge>;
327 :
328 264 : #[derive(LabelGroup)]
329 : #[label(set = ComputeConnectionLatencySet)]
330 : pub struct ComputeConnectionLatencyGroup {
331 : protocol: Protocol,
332 : cold_start_info: ColdStartInfo,
333 : outcome: ConnectOutcome,
334 : excluded: LatencyExclusions,
335 : }
336 :
337 : #[derive(FixedCardinalityLabel, Copy, Clone)]
338 : pub enum LatencyExclusions {
339 : Client,
340 : ClientAndCplane,
341 : ClientCplaneCompute,
342 : ClientCplaneComputeRetry,
343 : }
344 :
345 : #[derive(FixedCardinalityLabel, Copy, Clone)]
346 : #[label(singleton = "kind")]
347 : pub enum SniKind {
348 : Sni,
349 : NoSni,
350 : PasswordHack,
351 : }
352 :
353 : #[derive(FixedCardinalityLabel, Copy, Clone)]
354 : #[label(singleton = "kind")]
355 : pub enum ConnectionFailureKind {
356 : ComputeCached,
357 : ComputeUncached,
358 : }
359 :
360 176 : #[derive(LabelGroup)]
361 : #[label(set = ConnectionFailuresBreakdownSet)]
362 : pub struct ConnectionFailuresBreakdownGroup {
363 : pub kind: ErrorKind,
364 : pub retry: Bool,
365 : }
366 :
367 88 : #[derive(LabelGroup, Copy, Clone)]
368 : #[label(set = RedisErrorsSet)]
369 : pub struct RedisErrors<'a> {
370 : #[label(dynamic_with = ThreadedRodeo, default)]
371 : pub channel: &'a str,
372 : }
373 :
374 : #[derive(FixedCardinalityLabel, Copy, Clone)]
375 : pub enum CancellationOutcome {
376 : NotFound,
377 : Found,
378 : RateLimitExceeded,
379 : }
380 :
381 132 : #[derive(LabelGroup)]
382 : #[label(set = CancellationRequestSet)]
383 : pub struct CancellationRequest {
384 : pub kind: CancellationOutcome,
385 : }
386 :
387 : #[derive(Clone, Copy)]
388 : pub enum Waiting {
389 : Cplane,
390 : Client,
391 : Compute,
392 : RetryTimeout,
393 : }
394 :
395 : #[derive(FixedCardinalityLabel, Copy, Clone)]
396 : #[label(singleton = "kind")]
397 : #[allow(clippy::enum_variant_names)]
398 : pub enum RedisMsgKind {
399 : HSet,
400 : HSetMultiple,
401 : HGet,
402 : HGetAll,
403 : HDel,
404 : }
405 :
406 : #[derive(Default, Clone)]
407 : pub struct LatencyAccumulated {
408 : cplane: time::Duration,
409 : client: time::Duration,
410 : compute: time::Duration,
411 : retry: time::Duration,
412 : }
413 :
414 : impl std::fmt::Display for LatencyAccumulated {
415 0 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
416 0 : write!(
417 0 : f,
418 0 : "client: {}, cplane: {}, compute: {}, retry: {}",
419 0 : self.client.as_micros(),
420 0 : self.cplane.as_micros(),
421 0 : self.compute.as_micros(),
422 0 : self.retry.as_micros()
423 0 : )
424 0 : }
425 : }
426 :
427 : pub struct LatencyTimer {
428 : // time since the stopwatch was started
429 : start: time::Instant,
430 : // time since the stopwatch was stopped
431 : stop: Option<time::Instant>,
432 : // accumulated time on the stopwatch
433 : accumulated: LatencyAccumulated,
434 : // label data
435 : protocol: Protocol,
436 : cold_start_info: ColdStartInfo,
437 : outcome: ConnectOutcome,
438 :
439 : skip_reporting: bool,
440 : }
441 :
442 : impl LatencyTimer {
443 70 : pub fn new(protocol: Protocol) -> Self {
444 70 : Self {
445 70 : start: time::Instant::now(),
446 70 : stop: None,
447 70 : accumulated: LatencyAccumulated::default(),
448 70 : protocol,
449 70 : cold_start_info: ColdStartInfo::Unknown,
450 70 : // assume failed unless otherwise specified
451 70 : outcome: ConnectOutcome::Failed,
452 70 : skip_reporting: false,
453 70 : }
454 70 : }
455 :
456 0 : pub(crate) fn noop(protocol: Protocol) -> Self {
457 0 : Self {
458 0 : start: time::Instant::now(),
459 0 : stop: None,
460 0 : accumulated: LatencyAccumulated::default(),
461 0 : protocol,
462 0 : cold_start_info: ColdStartInfo::Unknown,
463 0 : // assume failed unless otherwise specified
464 0 : outcome: ConnectOutcome::Failed,
465 0 : skip_reporting: true,
466 0 : }
467 0 : }
468 :
469 28 : pub fn unpause(&mut self, start: Instant, waiting_for: Waiting) {
470 28 : let dur = start.elapsed();
471 28 : match waiting_for {
472 0 : Waiting::Cplane => self.accumulated.cplane += dur,
473 15 : Waiting::Client => self.accumulated.client += dur,
474 7 : Waiting::Compute => self.accumulated.compute += dur,
475 6 : Waiting::RetryTimeout => self.accumulated.retry += dur,
476 : }
477 28 : }
478 :
479 0 : pub fn cold_start_info(&mut self, cold_start_info: ColdStartInfo) {
480 0 : self.cold_start_info = cold_start_info;
481 0 : }
482 :
483 4 : pub fn success(&mut self) {
484 4 : // stop the stopwatch and record the time that we have accumulated
485 4 : self.stop = Some(time::Instant::now());
486 4 :
487 4 : // success
488 4 : self.outcome = ConnectOutcome::Success;
489 4 : }
490 :
491 0 : pub fn accumulated(&self) -> LatencyAccumulated {
492 0 : self.accumulated.clone()
493 0 : }
494 : }
495 :
496 : #[derive(FixedCardinalityLabel, Clone, Copy, Debug)]
497 : pub enum ConnectOutcome {
498 : Success,
499 : Failed,
500 : }
501 :
502 : impl Drop for LatencyTimer {
503 70 : fn drop(&mut self) {
504 70 : if self.skip_reporting {
505 0 : return;
506 70 : }
507 70 :
508 70 : let duration = self
509 70 : .stop
510 70 : .unwrap_or_else(time::Instant::now)
511 70 : .duration_since(self.start);
512 70 :
513 70 : let metric = &Metrics::get().proxy.compute_connection_latency_seconds;
514 70 :
515 70 : // Excluding client communication from the accumulated time.
516 70 : metric.observe(
517 70 : ComputeConnectionLatencyGroup {
518 70 : protocol: self.protocol,
519 70 : cold_start_info: self.cold_start_info,
520 70 : outcome: self.outcome,
521 70 : excluded: LatencyExclusions::Client,
522 70 : },
523 70 : duration
524 70 : .saturating_sub(self.accumulated.client)
525 70 : .as_secs_f64(),
526 70 : );
527 70 :
528 70 : // Exclude client and cplane communication from the accumulated time.
529 70 : let accumulated_total = self.accumulated.client + self.accumulated.cplane;
530 70 : metric.observe(
531 70 : ComputeConnectionLatencyGroup {
532 70 : protocol: self.protocol,
533 70 : cold_start_info: self.cold_start_info,
534 70 : outcome: self.outcome,
535 70 : excluded: LatencyExclusions::ClientAndCplane,
536 70 : },
537 70 : duration.saturating_sub(accumulated_total).as_secs_f64(),
538 70 : );
539 70 :
540 70 : // Exclude client, cplane, compute communication from the accumulated time.
541 70 : let accumulated_total =
542 70 : self.accumulated.client + self.accumulated.cplane + self.accumulated.compute;
543 70 : metric.observe(
544 70 : ComputeConnectionLatencyGroup {
545 70 : protocol: self.protocol,
546 70 : cold_start_info: self.cold_start_info,
547 70 : outcome: self.outcome,
548 70 : excluded: LatencyExclusions::ClientCplaneCompute,
549 70 : },
550 70 : duration.saturating_sub(accumulated_total).as_secs_f64(),
551 70 : );
552 70 :
553 70 : // Exclude client, cplane, compute, retry communication from the accumulated time.
554 70 : let accumulated_total = self.accumulated.client
555 70 : + self.accumulated.cplane
556 70 : + self.accumulated.compute
557 70 : + self.accumulated.retry;
558 70 : metric.observe(
559 70 : ComputeConnectionLatencyGroup {
560 70 : protocol: self.protocol,
561 70 : cold_start_info: self.cold_start_info,
562 70 : outcome: self.outcome,
563 70 : excluded: LatencyExclusions::ClientCplaneComputeRetry,
564 70 : },
565 70 : duration.saturating_sub(accumulated_total).as_secs_f64(),
566 70 : );
567 70 : }
568 : }
569 :
570 : impl From<bool> for Bool {
571 3 : fn from(value: bool) -> Self {
572 3 : if value { Bool::True } else { Bool::False }
573 3 : }
574 : }
575 :
576 220 : #[derive(LabelGroup)]
577 : #[label(set = InvalidEndpointsSet)]
578 : pub struct InvalidEndpointsGroup {
579 : pub protocol: Protocol,
580 : pub rejected: Bool,
581 : pub outcome: ConnectOutcome,
582 : }
583 :
584 176 : #[derive(LabelGroup)]
585 : #[label(set = RetriesMetricSet)]
586 : pub struct RetriesMetricGroup {
587 : pub outcome: ConnectOutcome,
588 : pub retry_type: RetryType,
589 : }
590 :
591 : #[derive(FixedCardinalityLabel, Clone, Copy, Debug)]
592 : pub enum RetryType {
593 : WakeCompute,
594 : ConnectToCompute,
595 : }
596 :
597 : #[derive(FixedCardinalityLabel, Clone, Copy, Debug)]
598 : #[label(singleton = "event")]
599 : pub enum RedisEventsCount {
600 : EndpointCreated,
601 : BranchCreated,
602 : ProjectCreated,
603 : CancelSession,
604 : PasswordUpdate,
605 : AllowedIpsUpdate,
606 : AllowedVpcEndpointIdsUpdateForProjects,
607 : AllowedVpcEndpointIdsUpdateForAllProjectsInOrg,
608 : BlockPublicOrVpcAccessUpdate,
609 : }
610 :
611 : pub struct ThreadPoolWorkers(usize);
612 : #[derive(Copy, Clone)]
613 : pub struct ThreadPoolWorkerId(pub usize);
614 :
615 : impl LabelValue for ThreadPoolWorkerId {
616 0 : fn visit<V: measured::label::LabelVisitor>(&self, v: V) -> V::Output {
617 0 : v.write_int(self.0 as i64)
618 0 : }
619 : }
620 :
621 : impl LabelGroup for ThreadPoolWorkerId {
622 0 : fn visit_values(&self, v: &mut impl measured::label::LabelGroupVisitor) {
623 0 : v.write_value(LabelName::from_str("worker"), self);
624 0 : }
625 : }
626 :
627 : impl LabelGroupSet for ThreadPoolWorkers {
628 : type Group<'a> = ThreadPoolWorkerId;
629 :
630 100 : fn cardinality(&self) -> Option<usize> {
631 100 : Some(self.0)
632 100 : }
633 :
634 7 : fn encode_dense(&self, value: Self::Unique) -> Option<usize> {
635 7 : Some(value)
636 7 : }
637 :
638 0 : fn decode_dense(&self, value: usize) -> Self::Group<'_> {
639 0 : ThreadPoolWorkerId(value)
640 0 : }
641 :
642 : type Unique = usize;
643 :
644 7 : fn encode(&self, value: Self::Group<'_>) -> Option<Self::Unique> {
645 7 : Some(value.0)
646 7 : }
647 :
648 0 : fn decode(&self, value: &Self::Unique) -> Self::Group<'_> {
649 0 : ThreadPoolWorkerId(*value)
650 0 : }
651 : }
652 :
653 : impl LabelSet for ThreadPoolWorkers {
654 : type Value<'a> = ThreadPoolWorkerId;
655 :
656 0 : fn dynamic_cardinality(&self) -> Option<usize> {
657 0 : Some(self.0)
658 0 : }
659 :
660 0 : fn encode(&self, value: Self::Value<'_>) -> Option<usize> {
661 0 : (value.0 < self.0).then_some(value.0)
662 0 : }
663 :
664 0 : fn decode(&self, value: usize) -> Self::Value<'_> {
665 0 : ThreadPoolWorkerId(value)
666 0 : }
667 : }
668 :
669 : impl FixedCardinalitySet for ThreadPoolWorkers {
670 0 : fn cardinality(&self) -> usize {
671 0 : self.0
672 0 : }
673 : }
674 :
675 50 : #[derive(MetricGroup)]
676 : #[metric(new(workers: usize))]
677 : pub struct ThreadPoolMetrics {
678 : #[metric(init = CounterVec::with_label_set(ThreadPoolWorkers(workers)))]
679 : pub worker_task_turns_total: CounterVec<ThreadPoolWorkers>,
680 : #[metric(init = CounterVec::with_label_set(ThreadPoolWorkers(workers)))]
681 : pub worker_task_skips_total: CounterVec<ThreadPoolWorkers>,
682 : }
|