|
| 1 | +# Cardinality limit plugin |
| 2 | +Limits the cardinality of fields on events, drops events or just do nothing. |
| 3 | + |
| 4 | +## Examples |
| 5 | +Discarding events with high cardinality field: |
| 6 | +```yaml |
| 7 | +pipelines: |
| 8 | + example_pipeline: |
| 9 | + ... |
| 10 | + - type: cardinality |
| 11 | + limit: 2 |
| 12 | + action: discard |
| 13 | + ttl: 1m |
| 14 | + metric_prefix: service_client |
| 15 | + key: |
| 16 | + - service |
| 17 | + fields: |
| 18 | + - client_id |
| 19 | + ... |
| 20 | +``` |
| 21 | +Events: |
| 22 | +```json |
| 23 | +{"service": "registration", "client_id": "1"} |
| 24 | +{"service": "registration", "client_id": "1"} |
| 25 | +{"service": "registration", "client_id": "2"} |
| 26 | +{"service": "registration", "client_id": "3"} // will be discarded |
| 27 | +``` |
| 28 | +--- |
| 29 | + |
| 30 | +Remove high cardinality fields: |
| 31 | +```yaml |
| 32 | +pipelines: |
| 33 | + example_pipeline: |
| 34 | + ... |
| 35 | + - type: cardinality |
| 36 | + limit: 2 |
| 37 | + action: remove_fields |
| 38 | + ttl: 1m |
| 39 | + metric_prefix: service_client |
| 40 | + key: |
| 41 | + - service |
| 42 | + fields: |
| 43 | + - client_id |
| 44 | + ... |
| 45 | +``` |
| 46 | +The original events: |
| 47 | +```json |
| 48 | +{"service": "registration", "client_id": "1"} |
| 49 | +{"service": "registration", "client_id": "2"} |
| 50 | +{"service": "registration", "client_id": "3"} |
| 51 | +``` |
| 52 | +The resulting events: |
| 53 | +```json |
| 54 | +{"service": "registration", "client_id": "1"} |
| 55 | +{"service": "registration", "client_id": "2"} |
| 56 | +{"service": "registration"} |
| 57 | +``` |
| 58 | + |
| 59 | +## Config params |
| 60 | +**`key`** *`[]cfg.FieldSelector`* *`required`* |
| 61 | + |
| 62 | +Fields used to group events before calculating cardinality. |
| 63 | +Events with the same key values are aggregated together. |
| 64 | +Required for proper cardinality tracking per logical group. |
| 65 | + |
| 66 | +<br> |
| 67 | + |
| 68 | +**`fields`** *`[]cfg.FieldSelector`* *`required`* |
| 69 | + |
| 70 | +Target fields whose unique values are counted within each key group. |
| 71 | +The plugin monitors how many distinct values these fields contain. |
| 72 | +Required to define what constitutes high cardinality. |
| 73 | + |
| 74 | +<br> |
| 75 | + |
| 76 | +**`action`** *`string`* *`default=nothing`* *`options=discard|remove_fields|nothing`* |
| 77 | + |
| 78 | +Action to perform when cardinality limit is exceeded. |
| 79 | +Determines whether to discard events, remove fields, or just monitor. |
| 80 | +Choose based on whether you need to preserve other event data. |
| 81 | + |
| 82 | +<br> |
| 83 | + |
| 84 | +**`metric_prefix`** *`string`* |
| 85 | + |
| 86 | +Prefix added to metric names for better organization. |
| 87 | +Useful when running multiple instances to avoid metric name collisions. |
| 88 | +Leave empty for default metric naming. |
| 89 | + |
| 90 | +<br> |
| 91 | + |
| 92 | +**`limit`** *`int`* *`default=10000`* |
| 93 | + |
| 94 | +Maximum allowed number of unique values for monitored fields. |
| 95 | +When exceeded within a key group, the configured action triggers. |
| 96 | +Set based on expected diversity and system capacity. |
| 97 | + |
| 98 | +<br> |
| 99 | + |
| 100 | +**`ttl`** *`cfg.Duration`* *`default=1h`* |
| 101 | + |
| 102 | +Time-to-live for cardinality tracking cache entries. |
| 103 | +Prevents unbounded memory growth by forgetting old unique values. |
| 104 | +Should align with typical patterns of field value changes. |
| 105 | + |
| 106 | +<br> |
| 107 | + |
| 108 | + |
| 109 | +<br>*Generated using [__insane-doc__](https://github.com/vitkovskii/insane-doc)* |
0 commit comments