relay_cardinality/
statsd.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use relay_statsd::{CounterMetric, HistogramMetric, SetMetric, TimerMetric};

/// Counter metrics for the Relay Cardinality Limiter.
pub enum CardinalityLimiterCounters {
    /// Incremented for every accepted item by the cardinality limiter.
    ///
    /// This metric is tagged with:
    ///  - `id`: The scope of check operation.
    ///  - `passive`: `true` if the enforced limit is passive.
    #[cfg(feature = "redis")]
    Accepted,
    /// Incremented for every rejected item by the cardinality limiter.
    ///
    /// This metric is tagged with:
    ///  - `id`: The scope of check operation.
    ///  - `passive`: `true` if the enforced limit is passive.
    #[cfg(feature = "redis")]
    Rejected,
    /// Incremented for every hash which was served from the in memory cache.
    ///
    /// This metric is tagged with:
    ///  - `id`: The id of the enforced limit.
    ///  - `passive`: `true` if the enforced limit is passive.
    #[cfg(feature = "redis")]
    RedisCacheHit,
    /// Incremented for every hash which was not served from the in memory cache.
    ///
    /// This metric is tagged with:
    ///  - `id`: The id of the enforced limit.
    ///  - `passive`: `true` if the enforced limit is passive.
    #[cfg(feature = "redis")]
    RedisCacheMiss,
    /// Amount of entries removed from the cache via periodic cleanups.
    #[cfg(feature = "redis")]
    RedisCacheVacuum,
}

impl CounterMetric for CardinalityLimiterCounters {
    fn name(&self) -> &'static str {
        match *self {
            #[cfg(feature = "redis")]
            Self::Accepted => "cardinality.limiter.accepted",
            #[cfg(feature = "redis")]
            Self::Rejected => "cardinality.limiter.rejected",
            #[cfg(feature = "redis")]
            Self::RedisCacheHit => "cardinality.limiter.redis.cache_hit",
            #[cfg(feature = "redis")]
            Self::RedisCacheMiss => "cardinality.limiter.redis.cache_miss",
            #[cfg(feature = "redis")]
            Self::RedisCacheVacuum => "cardinality.limiter.redis.cache_vacuum",
        }
    }
}

pub enum CardinalityLimiterTimers {
    /// Timer for the entire process of checking cardinality limits.
    CardinalityLimiter,
    /// Timer for the duration of the Redis call.
    ///
    /// This metric is tagged with:
    ///  - `id`: The id of the enforced limit.
    ///  - `scopes`: The amount of scopes checked with a single Redis call.
    #[cfg(feature = "redis")]
    Redis,
    /// Timer tracking the amount of time spent removing expired values
    /// from the cardinality cache.
    #[cfg(feature = "redis")]
    CacheVacuum,
}

impl TimerMetric for CardinalityLimiterTimers {
    fn name(&self) -> &'static str {
        match self {
            CardinalityLimiterTimers::CardinalityLimiter => "cardinality.limiter.duration",
            #[cfg(feature = "redis")]
            CardinalityLimiterTimers::Redis => "cardinality.limiter.redis.duration",
            #[cfg(feature = "redis")]
            CardinalityLimiterTimers::CacheVacuum => {
                "cardinality.limiter.redis.cache_vacuum.duration"
            }
        }
    }
}

pub enum CardinalityLimiterHistograms {
    /// Amount of hashes sent to Redis to check the cardinality.
    ///
    /// This metric is tagged with:
    ///  - `id`: The id of the enforced limit.
    #[cfg(feature = "redis")]
    RedisCheckHashes,
    /// Redis stored set cardinality.
    ///
    /// This metric is tagged with:
    ///  - `id`: The id of the enforced limit.
    #[cfg(feature = "redis")]
    RedisSetCardinality,
}

impl HistogramMetric for CardinalityLimiterHistograms {
    fn name(&self) -> &'static str {
        match *self {
            #[cfg(feature = "redis")]
            Self::RedisCheckHashes => "cardinality.limiter.redis.check_hashes",
            #[cfg(feature = "redis")]
            Self::RedisSetCardinality => "cardinality.limiter.redis.set_cardinality",
        }
    }
}

pub enum CardinalityLimiterSets {
    /// Set containing all organizations which have had any metric sent through the cardinality
    /// limiter.
    ///
    /// This metric is tagged with:
    ///  - `id`: The id of the enforced limit.
    ///  - `status`: Wether the organization was cardinality limited.
    #[cfg(feature = "redis")]
    Organizations,
}

impl SetMetric for CardinalityLimiterSets {
    fn name(&self) -> &'static str {
        match *self {
            #[cfg(feature = "redis")]
            Self::Organizations => "cardinality.limiter.organizations",
        }
    }
}