relay_cardinality/
statsd.rs

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