fluent-plugin-label-router 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39bb31d6e0960885594803292fd8b7e6739191333aaa303d2db16809d2ddaf1c
4
- data.tar.gz: 46d5658ae6ed1159e4d55c6068f945ce5bb4719e6c373602cf88581323f60c46
3
+ metadata.gz: 84f4bafc4ac5d89f9c326c55c54e12f70b4315afe546aa6463492cc6ba69aa8e
4
+ data.tar.gz: 6c507a4af8eccfd37a5f70ea40e64f077ceefb4d34519ea3db1d284d90700a92
5
5
  SHA512:
6
- metadata.gz: cae3b60f07ff8bd9b411b7ae5ae766c59c95737484eb497e77b219e8d6d43f31943e4702313097cf8dd331b029a213389c3911ea0c1d937797dd6f18e7f19669
7
- data.tar.gz: bafd88bb200ca34795d206b7a4e24ab25e78de209c078282414f2de7b02de7e494e7835927c872f29c11e173ddd51056e8bea68a8642319a76519271d3ac524c
6
+ metadata.gz: 4db8ea9e6b6e0af1c491f9635c47dcf8e5eb8f4ac91cff15c46600717714e2e9784b2eb32a287ba83fdd96439c588e70a9b7e256c8b330998127976fd039d4ee
7
+ data.tar.gz: 8f112e80a1b562008ecbe69e02fe6292c93deed2afd53e9a54a6eb2f2fad56bfbdbb3994ab7fc4b1a2dbe942c25982a3858eed2c4f7f5aaf7813d2b4be8152bd
data/README.md CHANGED
@@ -35,7 +35,7 @@ $ bundle
35
35
  The configuration builds from `<route>` sections. Each `route` section
36
36
  can have several `<match>` statement. These statements computed in order and
37
37
  positive (or in case of *negate true* negative) results break the evaluation.
38
- We can say that the sections are coupled in a **lazy evaluation OR**.
38
+ We can say that the sections are coupled in a **lazy evaluation OR**.
39
39
 
40
40
  ```
41
41
  <match example.tag**>
@@ -78,6 +78,7 @@ Configuration reference
78
78
  |------------------|-------------------------------------------------------------------------------------------------------|----------|----------|
79
79
  | labels | Label definition to match record. Example: `app:nginx` | Hash | nil |
80
80
  | namespaces | Comma separated list of namespaces. Ignored if left empty. | []string | nil |
81
+ | namespaces_regex | Comma separated list of regex for namespaces match. Ignored if left empty. | []string | nil |
81
82
  | namespace_labels | Label definition of the namespace a record originates. Example: `kubernetes.io/metadata.name=default` | Hash | nil |
82
83
  | hosts | Comma separated list of hosts. Ignored if left empty. | []string | nil |
83
84
  | container_names | Comma separated list of container names. Ignored if left empty. | []string | nil |
@@ -145,7 +146,7 @@ Output
145
146
  @label = "@NGINX"; tag = "new_tag"; {"log" => "", "kubernetes" => { "namespace_name" => "default", "labels" => {"app" => "nginx" } } }
146
147
  nil
147
148
  ```
148
- ### 2. Both `labels` and `namespace` are optional
149
+ ### 3. Both `labels` and `namespace` are optional
149
150
  Only `labels`
150
151
  ```
151
152
  <match example.tag**>
@@ -183,10 +184,10 @@ Rewrite all
183
184
  </match>
184
185
  ```
185
186
 
186
- ### 3. One of `@label` ot `tag` configuration should be specified
187
+ ### 4. One of `@label` or `tag` configuration should be specified
187
188
  If you don't rewrite either of them fluent will **likely to crash** because it will reprocess the same messages again.
188
189
 
189
- ### 4. Default route/tag
190
+ ### 5. Default route/tag
190
191
 
191
192
  Use `default_label` and/or `default_tag` to route non matching records.
192
193
 
@@ -200,6 +201,22 @@ Use `default_label` and/or `default_tag` to route non matching records.
200
201
  </match>
201
202
  ```
202
203
 
204
+ ### 6. Use of namespaces_regex
205
+
206
+ Configuration to re-tag and re-label all logs from namespaces_regex which match regex .*-system$
207
+
208
+ ```
209
+ <match example.tag**>
210
+ @type label_router
211
+ <route>
212
+ @label SYSTEM_NAMESPACE
213
+ tag new_tag
214
+ <match>
215
+ namespaces_regex .*-system$
216
+ </match>
217
+ </route>
218
+ </match>
219
+ ```
203
220
 
204
221
  ## Copyright
205
222
 
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-label-router"
6
- spec.version = "0.4.0"
6
+ spec.version = "0.5.0"
7
7
  spec.authors = ["Banzai Cloud"]
8
8
  spec.email = ["info@banzaicloud.com"]
9
9
 
@@ -54,6 +54,8 @@ module Fluent
54
54
  config_param :labels, :hash, :default => {}
55
55
  desc "List of namespace definition to filter the record. Ignored if left empty."
56
56
  config_param :namespaces, :array, :default => [], value_type: :string
57
+ desc "List of regex for namespace definition to filter the record. Ignored if left empty."
58
+ config_param :namespaces_regex, :array, :default => [], value_type: :string
57
59
  desc "List of namespace labels to filter the record based on where it came from. Ignored if left empty."
58
60
  config_param :namespace_labels, :hash, :default => {}
59
61
  desc "List of hosts definition to filter the record. Ignored if left empty."
@@ -117,6 +119,10 @@ module Fluent
117
119
  unless match.namespaces.empty? || match.namespaces.include?(metadata[:namespace])
118
120
  return false
119
121
  end
122
+ # Break if list of namespaces is not empty and does not contain any entry that match actual namespace
123
+ unless match.namespaces_regex.empty? || match.namespaces_regex.any? { |pattern| Regexp.new(pattern).match?(metadata[:namespace]) }
124
+ return false
125
+ end
120
126
  # Break if list of namespace_labels is not empty and does not match actual namespace labels
121
127
  if !match.namespace_labels.empty? && !match_labels(metadata[:namespace_labels], match.namespace_labels)
122
128
  return false
@@ -59,6 +59,12 @@ class LabelRouterOutputTest < Test::Unit::TestCase
59
59
  </match>
60
60
  tag new_app_tag
61
61
  </route>
62
+ <route>
63
+ <match>
64
+ labels app:app3
65
+ namespaces_regex .*-system$,^kube-.*
66
+ </match>
67
+ </route>
62
68
  <route>
63
69
  <match>
64
70
  labels app:nginx
@@ -98,23 +104,42 @@ class LabelRouterOutputTest < Test::Unit::TestCase
98
104
  assert_equal(false, r2.match?(labels: { 'app3' => 'app' }, namespace: 'system'))
99
105
 
100
106
  r3 = Fluent::Plugin::LabelRouterOutput::Route.new(d.instance.routes[2], nil,nil)
101
- assert_equal(true, r3.match?(labels: { 'app' => 'nginx' }, namespace: 'dev'))
102
- assert_equal(true, r3.match?(labels: { 'app' => 'nginx' }, namespace: 'sandbox'))
103
- assert_equal(false, r3.match?(labels: { 'app' => 'nginx2' }, namespace: 'sandbox'))
107
+ # Match selector and namespace: GO
108
+ assert_equal(true, r3.match?(labels: { 'app' => 'app3' }, namespace: 'logging-system'))
109
+ # Nothing matched: NO GO
110
+ assert_equal(false, r3.match?(labels: { 'app' => 'app3' }, namespace: 'logging-system1'))
111
+ # Nothing matched: NO GO
112
+ assert_equal(false, r3.match?(labels: { 'app' => 'app3' }, namespace: 'system'))
113
+ # Nothing matched: NO GO
114
+ assert_equal(false, r3.match?(labels: { 'app' => 'app3' }, namespace: '1system'))
115
+ # Match selector and namespace: GO
116
+ assert_equal(true, r3.match?(labels: { 'app' => 'app3' }, namespace: 'kube-ns'))
117
+ # Nothing matched: NO GO
118
+ assert_equal(false, r3.match?(labels: { 'app' => 'app3' }, namespace: '1kube-ns'))
119
+ # Nothing matched: NO GO
120
+ assert_equal(false, r3.match?(labels: { 'app' => 'app3' }, namespace: 'kube'))
121
+ # Nothing matched: NO GO
122
+ assert_equal(false, r3.match?(labels: { 'app' => 'app3' }, namespace: 'kube1'))
123
+
104
124
 
105
125
  r4 = Fluent::Plugin::LabelRouterOutput::Route.new(d.instance.routes[3], nil,nil)
126
+ assert_equal(true, r4.match?(labels: { 'app' => 'nginx' }, namespace: 'dev'))
127
+ assert_equal(true, r4.match?(labels: { 'app' => 'nginx' }, namespace: 'sandbox'))
128
+ assert_equal(false, r4.match?(labels: { 'app' => 'nginx2' }, namespace: 'sandbox'))
129
+
130
+ r5 = Fluent::Plugin::LabelRouterOutput::Route.new(d.instance.routes[4], nil,nil)
106
131
  # Matching container name
107
- assert_equal(true, r4.match?(labels: { 'app' => 'nginx' }, namespace: 'dev', container: 'mycontainer'))
132
+ assert_equal(true, r5.match?(labels: { 'app' => 'nginx' }, namespace: 'dev', container: 'mycontainer'))
108
133
  # Missing container name is equal to wrong container
109
- assert_equal(false, r4.match?(labels: { 'app' => 'nginx' }, namespace: 'sandbox'))
134
+ assert_equal(false, r5.match?(labels: { 'app' => 'nginx' }, namespace: 'sandbox'))
110
135
  # Wrong container name
111
- assert_equal(false, r4.match?(labels: { 'app' => 'nginx' }, namespace: 'dev', container: 'mycontainer2'))
136
+ assert_equal(false, r5.match?(labels: { 'app' => 'nginx' }, namespace: 'dev', container: 'mycontainer2'))
112
137
  # Wrong label but good namespace and container_name
113
- assert_equal(false, r4.match?(labels: { 'app' => 'nginx2' }, namespace: 'sandbox', container_name: 'mycontainer2'))
138
+ assert_equal(false, r5.match?(labels: { 'app' => 'nginx2' }, namespace: 'sandbox', container_name: 'mycontainer2'))
114
139
 
115
- r4 = Fluent::Plugin::LabelRouterOutput::Route.new(d.instance.routes[4], nil,nil)
140
+ r6 = Fluent::Plugin::LabelRouterOutput::Route.new(d.instance.routes[5], nil,nil)
116
141
  # Matching namespaces_labels
117
- assert_equal(true, r4.match?(namespaces_labels: { 'name' => 'default' }))
142
+ assert_equal(true, r6.match?(namespaces_labels: { 'name' => 'default' }))
118
143
  end
119
144
  end
120
145
 
@@ -224,6 +249,7 @@ default_tag "new_tag"
224
249
  <match>
225
250
  labels
226
251
  namespaces
252
+ namespaces_regex
227
253
  </match>
228
254
  </route>
229
255
  ]
@@ -254,6 +280,7 @@ default_tag "new_tag"
254
280
  <match>
255
281
  labels
256
282
  namespaces
283
+ namespaces_regex
257
284
  </match>
258
285
  </route>
259
286
  ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-label-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Banzai Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-02 00:00:00.000000000 Z
11
+ date: 2025-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake