relay_cardinality/
statsd.rs

1use relay_statsd::TimerMetric;
2#[cfg(feature = "redis")]
3use relay_statsd::{CounterMetric, HistogramMetric, SetMetric};
4
5/// Counter metrics for the Relay Cardinality Limiter.
6#[cfg(feature = "redis")]
7pub enum CardinalityLimiterCounters {
8    /// Incremented for every accepted item by the cardinality limiter.
9    ///
10    /// This metric is tagged with:
11    ///  - `id`: The scope of check operation.
12    ///  - `passive`: `true` if the enforced limit is passive.
13    #[cfg(feature = "redis")]
14    Accepted,
15    /// Incremented for every rejected item by the cardinality limiter.
16    ///
17    /// This metric is tagged with:
18    ///  - `id`: The scope of check operation.
19    ///  - `passive`: `true` if the enforced limit is passive.
20    #[cfg(feature = "redis")]
21    Rejected,
22    /// Incremented for every hash which was served from the in memory cache.
23    ///
24    /// This metric is tagged with:
25    ///  - `id`: The id of the enforced limit.
26    ///  - `passive`: `true` if the enforced limit is passive.
27    #[cfg(feature = "redis")]
28    RedisCacheHit,
29    /// Incremented for every hash which was not served from the in memory cache.
30    ///
31    /// This metric is tagged with:
32    ///  - `id`: The id of the enforced limit.
33    ///  - `passive`: `true` if the enforced limit is passive.
34    #[cfg(feature = "redis")]
35    RedisCacheMiss,
36    /// Amount of entries removed from the cache via periodic cleanups.
37    #[cfg(feature = "redis")]
38    RedisCacheVacuum,
39}
40
41#[cfg(feature = "redis")]
42impl CounterMetric for CardinalityLimiterCounters {
43    fn name(&self) -> &'static str {
44        match *self {
45            #[cfg(feature = "redis")]
46            Self::Accepted => "cardinality.limiter.accepted",
47            #[cfg(feature = "redis")]
48            Self::Rejected => "cardinality.limiter.rejected",
49            #[cfg(feature = "redis")]
50            Self::RedisCacheHit => "cardinality.limiter.redis.cache_hit",
51            #[cfg(feature = "redis")]
52            Self::RedisCacheMiss => "cardinality.limiter.redis.cache_miss",
53            #[cfg(feature = "redis")]
54            Self::RedisCacheVacuum => "cardinality.limiter.redis.cache_vacuum",
55        }
56    }
57}
58
59pub enum CardinalityLimiterTimers {
60    /// Timer for the entire process of checking cardinality limits.
61    CardinalityLimiter,
62    /// Timer for the duration of the Redis call.
63    ///
64    /// This metric is tagged with:
65    ///  - `id`: The id of the enforced limit.
66    ///  - `scopes`: The amount of scopes checked with a single Redis call.
67    #[cfg(feature = "redis")]
68    Redis,
69    /// Timer tracking the amount of time spent removing expired values
70    /// from the cardinality cache.
71    #[cfg(feature = "redis")]
72    CacheVacuum,
73}
74
75impl TimerMetric for CardinalityLimiterTimers {
76    fn name(&self) -> &'static str {
77        match self {
78            CardinalityLimiterTimers::CardinalityLimiter => "cardinality.limiter.duration",
79            #[cfg(feature = "redis")]
80            CardinalityLimiterTimers::Redis => "cardinality.limiter.redis.duration",
81            #[cfg(feature = "redis")]
82            CardinalityLimiterTimers::CacheVacuum => {
83                "cardinality.limiter.redis.cache_vacuum.duration"
84            }
85        }
86    }
87}
88
89#[cfg(feature = "redis")]
90pub enum CardinalityLimiterHistograms {
91    /// Amount of hashes sent to Redis to check the cardinality.
92    ///
93    /// This metric is tagged with:
94    ///  - `id`: The id of the enforced limit.
95    #[cfg(feature = "redis")]
96    RedisCheckHashes,
97    /// Redis stored set cardinality.
98    ///
99    /// This metric is tagged with:
100    ///  - `id`: The id of the enforced limit.
101    #[cfg(feature = "redis")]
102    RedisSetCardinality,
103}
104
105#[cfg(feature = "redis")]
106impl HistogramMetric for CardinalityLimiterHistograms {
107    fn name(&self) -> &'static str {
108        match *self {
109            #[cfg(feature = "redis")]
110            Self::RedisCheckHashes => "cardinality.limiter.redis.check_hashes",
111            #[cfg(feature = "redis")]
112            Self::RedisSetCardinality => "cardinality.limiter.redis.set_cardinality",
113        }
114    }
115}
116
117#[cfg(feature = "redis")]
118pub enum CardinalityLimiterSets {
119    /// Set containing all organizations which have had any metric sent through the cardinality
120    /// limiter.
121    ///
122    /// This metric is tagged with:
123    ///  - `id`: The id of the enforced limit.
124    ///  - `status`: Wether the organization was cardinality limited.
125    #[cfg(feature = "redis")]
126    Organizations,
127}
128
129#[cfg(feature = "redis")]
130impl SetMetric for CardinalityLimiterSets {
131    fn name(&self) -> &'static str {
132        match *self {
133            #[cfg(feature = "redis")]
134            Self::Organizations => "cardinality.limiter.organizations",
135        }
136    }
137}