Skip to main content

relay_core_lib/
metrics.rs

1use std::sync::atomic::{AtomicUsize, Ordering};
2
3/// Total number of flows dropped due to backpressure (channel full)
4pub static FLOWS_DROPPED_TOTAL: AtomicUsize = AtomicUsize::new(0);
5
6/// O4: Total number of bodies degraded (budget exceeded, rules skipped)
7pub static PROXY_BODY_DEGRADED_TOTAL: AtomicUsize = AtomicUsize::new(0);
8
9/// O4: Total number of HTTP requests processed through the streaming pipeline
10pub static PROXY_HTTP_REQUEST_TOTAL: AtomicUsize = AtomicUsize::new(0);
11
12/// O4: Total number of sandbox rejections
13pub static PROXY_SANDBOX_REJECT_TOTAL: AtomicUsize = AtomicUsize::new(0);
14
15/// O4: Total number of invalid method rejections (strict_http_semantics)
16pub static PROXY_INVALID_METHOD_TOTAL: AtomicUsize = AtomicUsize::new(0);
17
18/// O4: Total number of invalid status code rejections (strict_http_semantics)
19pub static PROXY_INVALID_STATUS_TOTAL: AtomicUsize = AtomicUsize::new(0);
20
21/// O4: Total number of idempotent request retries
22pub static PROXY_RETRY_TOTAL: AtomicUsize = AtomicUsize::new(0);
23
24/// O4: Total number of bodies processed in tap (streaming) mode
25pub static PROXY_STREAM_MODE_TAP_TOTAL: AtomicUsize = AtomicUsize::new(0);
26
27/// O4: Total number of bodies degraded from tap to pass-through
28pub static PROXY_STREAM_MODE_DEGRADE_TOTAL: AtomicUsize = AtomicUsize::new(0);
29
30/// Increment the dropped flows counter
31pub fn inc_flows_dropped() {
32    FLOWS_DROPPED_TOTAL.fetch_add(1, Ordering::Relaxed);
33}
34
35/// Get the current count of dropped flows
36pub fn get_flows_dropped() -> usize {
37    FLOWS_DROPPED_TOTAL.load(Ordering::Relaxed)
38}
39
40/// O4: Increment the body degraded counter
41pub fn inc_proxy_body_degraded() {
42    PROXY_BODY_DEGRADED_TOTAL.fetch_add(1, Ordering::Relaxed);
43}
44
45/// O4: Get the current count of degraded bodies
46pub fn get_proxy_body_degraded() -> usize {
47    PROXY_BODY_DEGRADED_TOTAL.load(Ordering::Relaxed)
48}
49
50/// O4: Increment the HTTP request counter
51pub fn inc_proxy_http_request() {
52    PROXY_HTTP_REQUEST_TOTAL.fetch_add(1, Ordering::Relaxed);
53}
54
55/// O4: Get the current count of HTTP requests
56pub fn get_proxy_http_request() -> usize {
57    PROXY_HTTP_REQUEST_TOTAL.load(Ordering::Relaxed)
58}
59
60/// O4: Increment the sandbox reject counter
61pub fn inc_proxy_sandbox_reject() {
62    PROXY_SANDBOX_REJECT_TOTAL.fetch_add(1, Ordering::Relaxed);
63}
64
65/// O4: Get the current count of sandbox rejections
66pub fn get_proxy_sandbox_reject() -> usize {
67    PROXY_SANDBOX_REJECT_TOTAL.load(Ordering::Relaxed)
68}
69
70/// O4: Increment the invalid method counter
71pub fn inc_proxy_invalid_method() {
72    PROXY_INVALID_METHOD_TOTAL.fetch_add(1, Ordering::Relaxed);
73}
74
75/// O4: Get the current count of invalid method rejections
76pub fn get_proxy_invalid_method() -> usize {
77    PROXY_INVALID_METHOD_TOTAL.load(Ordering::Relaxed)
78}
79
80/// O4: Increment the invalid status counter
81pub fn inc_proxy_invalid_status() {
82    PROXY_INVALID_STATUS_TOTAL.fetch_add(1, Ordering::Relaxed);
83}
84
85/// O4: Get the current count of invalid status rejections
86pub fn get_proxy_invalid_status() -> usize {
87    PROXY_INVALID_STATUS_TOTAL.load(Ordering::Relaxed)
88}
89
90/// O4: Increment the retry counter
91pub fn inc_proxy_retry() {
92    PROXY_RETRY_TOTAL.fetch_add(1, Ordering::Relaxed);
93}
94
95/// O4: Get the current count of retries
96pub fn get_proxy_retry() -> usize {
97    PROXY_RETRY_TOTAL.load(Ordering::Relaxed)
98}
99
100/// O4: Increment the stream mode tap counter
101pub fn inc_proxy_stream_mode_tap() {
102    PROXY_STREAM_MODE_TAP_TOTAL.fetch_add(1, Ordering::Relaxed);
103}
104
105/// O4: Get the current count of tap-mode streams
106pub fn get_proxy_stream_mode_tap() -> usize {
107    PROXY_STREAM_MODE_TAP_TOTAL.load(Ordering::Relaxed)
108}
109
110/// O4: Increment the stream mode degrade counter
111pub fn inc_proxy_stream_mode_degrade() {
112    PROXY_STREAM_MODE_DEGRADE_TOTAL.fetch_add(1, Ordering::Relaxed);
113}
114
115/// O4: Get the current count of degraded streams
116pub fn get_proxy_stream_mode_degrade() -> usize {
117    PROXY_STREAM_MODE_DEGRADE_TOTAL.load(Ordering::Relaxed)
118}