fluent-plugin-label-router 0.2.10 → 0.3.2
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +58 -0
- data/README.md +8 -7
- data/fluent-plugin-label-router.gemspec +2 -1
- data/lib/fluent/plugin/out_label_router.rb +16 -10
- data/test/plugin/test_out_label_router.rb +34 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0188ed80bdd96932a8d4942585a4cba52843b2e32c0492718aa1706b73ae29e4'
|
4
|
+
data.tar.gz: 8d9fd20daf7e0a2d171185e752bbd4310fb52575747cc73442492839d51056a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 687f7dfb1523caf6ac12c7d5574b7fbab1a7f2a70f4b350a53a1d81aa1c69b24d365546c95d490af4f992b2174b0ad3c6a8793f56e07656f9988f96bf093ad5b
|
7
|
+
data.tar.gz: 38ce993e367fc24bc974da84a96579ba4ce311cf3891f0afe268bea9ee24b05ddb164e7d7fc1214172128a8fa6d9a9ac42d8ddfe974b8a487e86e7b38817d713
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.idea
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-label-router (0.3.0)
|
5
|
+
fluentd (>= 0.14.10, < 2)
|
6
|
+
prometheus-client (>= 2.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
base64 (0.2.0)
|
12
|
+
concurrent-ruby (1.3.1)
|
13
|
+
cool.io (1.8.1)
|
14
|
+
csv (3.3.0)
|
15
|
+
drb (2.2.1)
|
16
|
+
fluentd (1.17.0)
|
17
|
+
base64 (~> 0.2)
|
18
|
+
bundler
|
19
|
+
cool.io (>= 1.4.5, < 2.0.0)
|
20
|
+
csv (~> 3.2)
|
21
|
+
drb (~> 2.2)
|
22
|
+
http_parser.rb (>= 0.5.1, < 0.9.0)
|
23
|
+
msgpack (>= 1.3.1, < 2.0.0)
|
24
|
+
serverengine (>= 2.3.2, < 3.0.0)
|
25
|
+
sigdump (~> 0.2.5)
|
26
|
+
strptime (>= 0.2.4, < 1.0.0)
|
27
|
+
tzinfo (>= 1.0, < 3.0)
|
28
|
+
tzinfo-data (~> 1.0)
|
29
|
+
webrick (~> 1.4)
|
30
|
+
yajl-ruby (~> 1.0)
|
31
|
+
http_parser.rb (0.8.0)
|
32
|
+
msgpack (1.7.2)
|
33
|
+
power_assert (2.0.3)
|
34
|
+
prometheus-client (4.2.2)
|
35
|
+
rake (12.3.3)
|
36
|
+
serverengine (2.3.2)
|
37
|
+
sigdump (~> 0.2.2)
|
38
|
+
sigdump (0.2.5)
|
39
|
+
strptime (0.2.5)
|
40
|
+
test-unit (3.6.2)
|
41
|
+
power_assert
|
42
|
+
tzinfo (2.0.6)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
tzinfo-data (1.2024.1)
|
45
|
+
tzinfo (>= 1.0.0)
|
46
|
+
webrick (1.8.2)
|
47
|
+
yajl-ruby (1.4.3)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
fluent-plugin-label-router!
|
54
|
+
rake (~> 12.0)
|
55
|
+
test-unit (~> 3.0)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.1.4
|
data/README.md
CHANGED
@@ -74,13 +74,14 @@ Configuration reference
|
|
74
74
|
|
75
75
|
|
76
76
|
#### \<match\>
|
77
|
-
| Parameter
|
78
|
-
|
79
|
-
| labels
|
80
|
-
| namespaces
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
| Parameter | Description | Type | Default |
|
78
|
+
|------------------|-------------------------------------------------------------------------------------------------------|----------|----------|
|
79
|
+
| labels | Label definition to match record. Example: `app:nginx` | Hash | nil |
|
80
|
+
| namespaces | Comma separated list of namespaces. Ignored if left empty. | []string | nil |
|
81
|
+
| namespace_labels | Label definition of the namespace a record originates. Example: `kubernetes.io/metadata.name=default` | Hash | nil |
|
82
|
+
| hosts | Comma separated list of hosts. Ignored if left empty. | []string | nil |
|
83
|
+
| container_names | Comma separated list of container names. Ignored if left empty. | []string | nil |
|
84
|
+
| negate | Negate the selector meaning to exclude matches | bool | false |
|
84
85
|
|
85
86
|
## Rules of thumb
|
86
87
|
|
@@ -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.2
|
6
|
+
spec.version = "0.3.2"
|
7
7
|
spec.authors = ["Banzai Cloud"]
|
8
8
|
spec.email = ["info@banzaicloud.com"]
|
9
9
|
|
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake", "~> 12.0"
|
24
24
|
spec.add_development_dependency "test-unit", "~> 3.0"
|
25
25
|
spec.add_dependency "prometheus-client", ">= 2.1.0"
|
26
|
+
spec.add_dependency "concurrent-ruby"
|
26
27
|
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
27
28
|
end
|
@@ -15,6 +15,7 @@
|
|
15
15
|
|
16
16
|
require "fluent/plugin/output"
|
17
17
|
require 'prometheus/client'
|
18
|
+
require 'concurrent'
|
18
19
|
|
19
20
|
|
20
21
|
module Fluent
|
@@ -53,6 +54,8 @@ module Fluent
|
|
53
54
|
config_param :labels, :hash, :default => {}
|
54
55
|
desc "List of namespace definition to filter the record. Ignored if left empty."
|
55
56
|
config_param :namespaces, :array, :default => [], value_type: :string
|
57
|
+
desc "List of namespace labels to filter the record based on where it came from. Ignored if left empty."
|
58
|
+
config_param :namespace_labels, :hash, :default => {}
|
56
59
|
desc "List of hosts definition to filter the record. Ignored if left empty."
|
57
60
|
config_param :hosts, :array, :default => [], value_type: :string
|
58
61
|
desc "List of container names definition to filter the record. Ignored if left empty."
|
@@ -93,11 +96,8 @@ module Fluent
|
|
93
96
|
# There is no match at all -> return false
|
94
97
|
def match?(metadata)
|
95
98
|
@matches.each do |match|
|
96
|
-
if filter_select(match, metadata)
|
97
|
-
return
|
98
|
-
end
|
99
|
-
if filter_select(match, metadata) and match.negate
|
100
|
-
return false
|
99
|
+
if filter_select(match, metadata)
|
100
|
+
return !match.negate
|
101
101
|
end
|
102
102
|
end
|
103
103
|
false
|
@@ -117,6 +117,10 @@ module Fluent
|
|
117
117
|
unless match.namespaces.empty? || match.namespaces.include?(metadata[:namespace])
|
118
118
|
return false
|
119
119
|
end
|
120
|
+
# Break if list of namespace_labels is not empty and does not match actual namespace labels
|
121
|
+
if !match.namespace_labels.empty? && !match_labels(metadata[:namespace_labels], match.namespace_labels)
|
122
|
+
return false
|
123
|
+
end
|
120
124
|
|
121
125
|
match_labels(metadata[:labels], match.labels)
|
122
126
|
end
|
@@ -147,7 +151,7 @@ module Fluent
|
|
147
151
|
|
148
152
|
def process(tag, es)
|
149
153
|
if @sticky_tags
|
150
|
-
@
|
154
|
+
@rwlock.with_read_lock {
|
151
155
|
if @route_map.has_key?(tag)
|
152
156
|
# We already matched with this tag send events to the routers
|
153
157
|
@route_map[tag].each do |r|
|
@@ -161,6 +165,7 @@ module Fluent
|
|
161
165
|
es.each do |time, record|
|
162
166
|
input_metadata = { labels: @access_to_labels.call(record).to_h,
|
163
167
|
namespace: @access_to_namespace.call(record).to_s,
|
168
|
+
namespace_labels: @access_to_namespace_labels.call(record).to_h,
|
164
169
|
container: @access_to_container_name.call(record).to_s,
|
165
170
|
host: @access_to_host.call(record).to_s}
|
166
171
|
orphan_record = true
|
@@ -168,7 +173,7 @@ module Fluent
|
|
168
173
|
if r.match?(input_metadata)
|
169
174
|
orphan_record = false
|
170
175
|
if @sticky_tags
|
171
|
-
@
|
176
|
+
@rwlock.with_write_lock {
|
172
177
|
@route_map[tag].add(r)
|
173
178
|
}
|
174
179
|
end
|
@@ -181,7 +186,7 @@ module Fluent
|
|
181
186
|
end
|
182
187
|
if !@default_router.nil? && orphan_record
|
183
188
|
if @sticky_tags
|
184
|
-
@
|
189
|
+
@rwlock.with_write_lock {
|
185
190
|
@route_map[tag].add(@default_router)
|
186
191
|
}
|
187
192
|
end
|
@@ -203,7 +208,7 @@ module Fluent
|
|
203
208
|
super
|
204
209
|
@registry = (::Prometheus::Client.registry if @metrics)
|
205
210
|
@route_map = Hash.new { |h, k| h[k] = Set.new }
|
206
|
-
@
|
211
|
+
@rwlock = Concurrent::ReadWriteLock.new
|
207
212
|
@routers = []
|
208
213
|
@default_router = nil
|
209
214
|
@routes.each do |rule|
|
@@ -217,6 +222,7 @@ module Fluent
|
|
217
222
|
end
|
218
223
|
|
219
224
|
@access_to_labels = record_accessor_create("$.kubernetes.labels")
|
225
|
+
@access_to_namespace_labels = record_accessor_create("$.kubernetes.namespace_labels")
|
220
226
|
@access_to_namespace = record_accessor_create("$.kubernetes.namespace_name")
|
221
227
|
@access_to_host = record_accessor_create("$.kubernetes.host")
|
222
228
|
@access_to_container_name = record_accessor_create("$.kubernetes.container_name")
|
@@ -225,4 +231,4 @@ module Fluent
|
|
225
231
|
end
|
226
232
|
end
|
227
233
|
end
|
228
|
-
end
|
234
|
+
end
|
@@ -72,6 +72,11 @@ class LabelRouterOutputTest < Test::Unit::TestCase
|
|
72
72
|
container_names mycontainer
|
73
73
|
</match>
|
74
74
|
</route>
|
75
|
+
<route>
|
76
|
+
<match>
|
77
|
+
namespaces_labels name:default
|
78
|
+
</match>
|
79
|
+
</route>
|
75
80
|
)
|
76
81
|
d = Fluent::Test::Driver::BaseOwner.new(Fluent::Plugin::LabelRouterOutput)
|
77
82
|
d.configure(routing_conf)
|
@@ -106,6 +111,10 @@ class LabelRouterOutputTest < Test::Unit::TestCase
|
|
106
111
|
assert_equal(false, r4.match?(labels: { 'app' => 'nginx' }, namespace: 'dev', container: 'mycontainer2'))
|
107
112
|
# Wrong label but good namespace and container_name
|
108
113
|
assert_equal(false, r4.match?(labels: { 'app' => 'nginx2' }, namespace: 'sandbox', container_name: 'mycontainer2'))
|
114
|
+
|
115
|
+
r4 = Fluent::Plugin::LabelRouterOutput::Route.new(d.instance.routes[4], nil,nil)
|
116
|
+
# Matching namespaces_labels
|
117
|
+
assert_equal(true, r4.match?(namespaces_labels: { 'name' => 'default' }))
|
109
118
|
end
|
110
119
|
end
|
111
120
|
|
@@ -134,6 +143,31 @@ class LabelRouterOutputTest < Test::Unit::TestCase
|
|
134
143
|
end
|
135
144
|
end
|
136
145
|
|
146
|
+
sub_test_case 'test_namespaces_labels' do
|
147
|
+
test 'normal' do
|
148
|
+
CONFIG = %[
|
149
|
+
<route>
|
150
|
+
<match>
|
151
|
+
namespace_labels matching:yes
|
152
|
+
</match>
|
153
|
+
tag matching
|
154
|
+
</route>
|
155
|
+
]
|
156
|
+
event_time = event_time("2019-07-17 11:11:11 UTC")
|
157
|
+
d = create_driver(CONFIG)
|
158
|
+
d.run(default_tag: 'test') do
|
159
|
+
d.feed(event_time, {"kubernetes" => {"namespace_labels" => {"matching" => "no"} } } )
|
160
|
+
end
|
161
|
+
d.run(default_tag: 'test2') do
|
162
|
+
d.feed(event_time, {"kubernetes" => {"namespace_labels" => {"matching" => "yes"} } } )
|
163
|
+
end
|
164
|
+
events = d.events
|
165
|
+
|
166
|
+
assert_equal(1, events.size)
|
167
|
+
assert_equal ["matching", event_time, {"kubernetes" => {"namespace_labels" => {"matching" => "yes"} } }], events[0]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
137
171
|
|
138
172
|
sub_test_case 'test_multiple_events_batched' do
|
139
173
|
test 'normal' do
|
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.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Banzai Cloud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: concurrent-ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: fluentd
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +94,9 @@ executables: []
|
|
80
94
|
extensions: []
|
81
95
|
extra_rdoc_files: []
|
82
96
|
files:
|
97
|
+
- ".gitignore"
|
83
98
|
- Gemfile
|
99
|
+
- Gemfile.lock
|
84
100
|
- LICENSE
|
85
101
|
- README.md
|
86
102
|
- Rakefile
|
@@ -107,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
123
|
- !ruby/object:Gem::Version
|
108
124
|
version: '0'
|
109
125
|
requirements: []
|
110
|
-
rubygems_version: 3.0.3
|
126
|
+
rubygems_version: 3.0.3.1
|
111
127
|
signing_key:
|
112
128
|
specification_version: 4
|
113
129
|
summary: Routing records based on Kubernetes labels.
|