@@ -41,7 +41,7 @@ type Plugin struct {
4141 fields []string
4242 logger * zap.Logger
4343
44- cardinalityDiscardCounter * prometheus.CounterVec
44+ cardinalityApplyCounter * prometheus.CounterVec
4545}
4646
4747const (
@@ -82,6 +82,11 @@ type Config struct {
8282 // > Leave empty for default metric naming.
8383 MetricPrefix string `json:"metric_prefix" default:""` // *
8484
85+ // > @3@4@5@6
86+ // >
87+ // > Value assigned to the metric label when cardinality limit is exceeded.
88+ MetricLabelValue string `json:"metric_label_value" default:"unknown"` // *
89+
8590 // > @3@4@5@6
8691 // >
8792 // > Maximum allowed number of unique values for monitored fields.
@@ -134,13 +139,13 @@ func (p *Plugin) makeMetric(ctl *metric.Ctl, name, help string, labels ...string
134139func (p * Plugin ) registerMetrics (ctl * metric.Ctl , prefix string ) {
135140 var metricName string
136141 if prefix == "" {
137- metricName = "cardinality_discard_total "
142+ metricName = "cardinality_applied_total "
138143 } else {
139- metricName = fmt .Sprintf (`cardinality_discard_ %s_total` , prefix )
144+ metricName = fmt .Sprintf (`cardinality_applied_ %s_total` , prefix )
140145 }
141- p .cardinalityDiscardCounter = p .makeMetric (ctl ,
146+ p .cardinalityApplyCounter = p .makeMetric (ctl ,
142147 metricName ,
143- "Total number of events discarded due to cardinality limits" ,
148+ "Total number of events applied due to cardinality limits" ,
144149 p .keys ... ,
145150 )
146151}
@@ -149,11 +154,7 @@ func (p *Plugin) Start(config pipeline.AnyConfig, params *pipeline.ActionPluginP
149154 p .config = config .(* Config )
150155 p .logger = params .Logger .Desugar ()
151156
152- var err error
153- p .cache , err = NewCache (p .config .TTL_ )
154- if err != nil {
155- panic (err )
156- }
157+ p .cache = NewCache (p .config .TTL_ )
157158
158159 p .keys = make ([]string , 0 , len (p .config .KeyFields ))
159160 for _ , fs := range p .config .KeyFields {
@@ -198,16 +199,16 @@ func (p *Plugin) Do(event *pipeline.Event) pipeline.ActionResult {
198199 value := mapToStringSorted (cacheKey , cacheValue )
199200 keysCount := p .cache .CountPrefix (key )
200201
201- if p .config .Limit > 0 && keysCount >= p .config .Limit {
202+ if p .config .Limit >= 0 && keysCount >= p .config .Limit {
202203 labelsValues := make ([]string , 0 , len (p .keys ))
203204 for _ , key := range p .keys {
204205 if val , exists := cacheKey [key ]; exists {
205206 labelsValues = append (labelsValues , val )
206207 } else {
207- labelsValues = append (labelsValues , "unknown" )
208+ labelsValues = append (labelsValues , p . config . MetricLabelValue )
208209 }
209210 }
210- p .cardinalityDiscardCounter .WithLabelValues (labelsValues ... ).Inc ()
211+ p .cardinalityApplyCounter .WithLabelValues (labelsValues ... ).Inc ()
211212 switch p .config .Action {
212213 case actionDiscard :
213214 return pipeline .ActionDiscard
0 commit comments