fluent-plugin-label-router 0.2.9 → 0.3.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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +58 -0
- data/README.md +10 -9
- data/fluent-plugin-label-router.gemspec +1 -1
- data/lib/fluent/plugin/out_label_router.rb +15 -6
- data/test/plugin/test_out_label_router.rb +34 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd979b17d11338356a4aba41b453da815b59abac9169b4df7ec6aba97f60adf0
|
4
|
+
data.tar.gz: ed8c5dd1a8129582eaafb2ac8e93afc9b0be487b9b89a4dc44d8b90bc0bf0402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4031c23b18c50f72953be1d20264c19bd62feea1de49c55bdb479e180f72814bfc064756156b1b4a5d10e2ebe1e1e72339f103e423874d82a01c089da44e1cff
|
7
|
+
data.tar.gz: 0fa73c96e20e9ffb0da8442f2deafb27853434b78c665437a47f42646df2b3c5ba92c406792012d3cdfb41216916198728c45a46d0fca87b3f236ebbda18a74a
|
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.1)
|
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
@@ -13,7 +13,7 @@ $ gem install fluent-plugin-label-router
|
|
13
13
|
### Specific install
|
14
14
|
|
15
15
|
```
|
16
|
-
$ gem install specific_install &&
|
16
|
+
$ gem install specific_install && gem specific_install -l https://github.com/banzaicloud/fluent-plugin-label-router.git
|
17
17
|
```
|
18
18
|
|
19
19
|
### Bundler
|
@@ -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
|
|
@@ -114,7 +115,7 @@ Configuration to re-tag and re-label all logs from `default` namespace with labe
|
|
114
115
|
```
|
115
116
|
|
116
117
|
### 2. Exclude specific `labels` and `namespaces`
|
117
|
-
Configuration to re-tag and re-label all logs that **not** from `default` namespace **and not** have labels `
|
118
|
+
Configuration to re-tag and re-label all logs that **not** from `default` namespace **and not** have labels `app=nginx` and `env=dev`
|
118
119
|
```
|
119
120
|
<match example.tag**>
|
120
121
|
@type label_router
|
@@ -33,6 +33,8 @@ module Fluent
|
|
33
33
|
config_param :sticky_tags, :bool, default: true
|
34
34
|
desc "Default label to drain unmatched patterns"
|
35
35
|
config_param :default_route, :string, :default => ""
|
36
|
+
desc "Metrics labels for the default_route"
|
37
|
+
config_param :default_metrics_labels, :hash, :default => {}
|
36
38
|
desc "Default tag to drain unmatched patterns"
|
37
39
|
config_param :default_tag, :string, :default => ""
|
38
40
|
desc "Enable metrics for the router"
|
@@ -51,6 +53,8 @@ module Fluent
|
|
51
53
|
config_param :labels, :hash, :default => {}
|
52
54
|
desc "List of namespace definition to filter the record. Ignored if left empty."
|
53
55
|
config_param :namespaces, :array, :default => [], value_type: :string
|
56
|
+
desc "List of namespace labels to filter the record based on where it came from. Ignored if left empty."
|
57
|
+
config_param :namespace_labels, :hash, :default => {}
|
54
58
|
desc "List of hosts definition to filter the record. Ignored if left empty."
|
55
59
|
config_param :hosts, :array, :default => [], value_type: :string
|
56
60
|
desc "List of container names definition to filter the record. Ignored if left empty."
|
@@ -72,15 +76,14 @@ module Fluent
|
|
72
76
|
if registry.exist?(:fluentd_router_records_total)
|
73
77
|
@counter = registry.get(:fluentd_router_records_total)
|
74
78
|
else
|
75
|
-
@counter = registry.counter(:fluentd_router_records_total, docstring: "Total number of events
|
79
|
+
@counter = registry.counter(:fluentd_router_records_total, docstring: "Total number of events routed for the flow", labels: [:flow, :id])
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
80
84
|
def get_labels
|
81
|
-
|
82
|
-
|
83
|
-
labels
|
85
|
+
labels = { 'flow': @label, 'id': "default" }
|
86
|
+
!@metrics_labels.nil? ? labels.merge(@metrics_labels) : labels
|
84
87
|
end
|
85
88
|
|
86
89
|
# Evaluate selectors
|
@@ -116,6 +119,10 @@ module Fluent
|
|
116
119
|
unless match.namespaces.empty? || match.namespaces.include?(metadata[:namespace])
|
117
120
|
return false
|
118
121
|
end
|
122
|
+
# Break if list of namespace_labels is not empty and does not match actual namespace labels
|
123
|
+
if !match.namespace_labels.empty? && !match_labels(metadata[:namespace_labels], match.namespace_labels)
|
124
|
+
return false
|
125
|
+
end
|
119
126
|
|
120
127
|
match_labels(metadata[:labels], match.labels)
|
121
128
|
end
|
@@ -160,6 +167,7 @@ module Fluent
|
|
160
167
|
es.each do |time, record|
|
161
168
|
input_metadata = { labels: @access_to_labels.call(record).to_h,
|
162
169
|
namespace: @access_to_namespace.call(record).to_s,
|
170
|
+
namespace_labels: @access_to_namespace_labels.call(record).to_h,
|
163
171
|
container: @access_to_container_name.call(record).to_s,
|
164
172
|
host: @access_to_host.call(record).to_s}
|
165
173
|
orphan_record = true
|
@@ -211,11 +219,12 @@ module Fluent
|
|
211
219
|
end
|
212
220
|
|
213
221
|
if @default_route != '' or @default_tag != ''
|
214
|
-
default_rule = { 'matches' => nil, 'tag' => @default_tag, '@label' => @default_route}
|
222
|
+
default_rule = { 'matches' => nil, 'tag' => @default_tag, '@label' => @default_route, 'metrics_labels' => @default_metrics_labels }
|
215
223
|
@default_router = Route.new(default_rule, event_emitter_router(@default_route), @registry)
|
216
224
|
end
|
217
225
|
|
218
226
|
@access_to_labels = record_accessor_create("$.kubernetes.labels")
|
227
|
+
@access_to_namespace_labels = record_accessor_create("$.kubernetes.namespace_labels")
|
219
228
|
@access_to_namespace = record_accessor_create("$.kubernetes.namespace_name")
|
220
229
|
@access_to_host = record_accessor_create("$.kubernetes.host")
|
221
230
|
@access_to_container_name = record_accessor_create("$.kubernetes.container_name")
|
@@ -224,4 +233,4 @@ module Fluent
|
|
224
233
|
end
|
225
234
|
end
|
226
235
|
end
|
227
|
-
end
|
236
|
+
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.
|
4
|
+
version: 0.3.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:
|
11
|
+
date: 2024-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,7 +80,9 @@ executables: []
|
|
80
80
|
extensions: []
|
81
81
|
extra_rdoc_files: []
|
82
82
|
files:
|
83
|
+
- ".gitignore"
|
83
84
|
- Gemfile
|
85
|
+
- Gemfile.lock
|
84
86
|
- LICENSE
|
85
87
|
- README.md
|
86
88
|
- Rakefile
|
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
- !ruby/object:Gem::Version
|
108
110
|
version: '0'
|
109
111
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.5.9
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
115
|
summary: Routing records based on Kubernetes labels.
|