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
use metrics::counter;
use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL};

pub struct TagCardinalityLimitRejectingEvent<'a> {
    pub metric_name: &'a str,
    pub tag_key: &'a str,
    pub tag_value: &'a str,
}

impl<'a> InternalEvent for TagCardinalityLimitRejectingEvent<'a> {
    fn emit(self) {
        debug!(
            message = "Event containing tag with new value after hitting configured 'value_limit'; discarding event.",
            metric_name = self.metric_name,
            tag_key = self.tag_key,
            tag_value = self.tag_value,
            internal_log_rate_limit = true,
        );
        counter!("tag_value_limit_exceeded_total").increment(1);

        emit!(ComponentEventsDropped::<INTENTIONAL> {
            count: 1,
            reason: "Tag value limit exceeded."
        })
    }
}

pub struct TagCardinalityLimitRejectingTag<'a> {
    pub metric_name: &'a str,
    pub tag_key: &'a str,
    pub tag_value: &'a str,
}

impl<'a> InternalEvent for TagCardinalityLimitRejectingTag<'a> {
    fn emit(self) {
        debug!(
            message = "Rejecting tag after hitting configured 'value_limit'.",
            metric_name = self.metric_name,
            tag_key = self.tag_key,
            tag_value = self.tag_value,
            internal_log_rate_limit = true,
        );
        counter!("tag_value_limit_exceeded_total").increment(1);
    }
}

pub struct TagCardinalityValueLimitReached<'a> {
    pub key: &'a str,
}

impl<'a> InternalEvent for TagCardinalityValueLimitReached<'a> {
    fn emit(self) {
        debug!(
            message = "Value_limit reached for key. New values for this key will be rejected.",
            key = %self.key,
        );
        counter!("value_limit_reached_total").increment(1);
    }
}