fluent-plugin-kubernetes_metadata_filter 2.4.7 → 2.6.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/.circleci/config.yml +6 -6
- data/Gemfile.lock +47 -44
- data/README.md +1 -0
- data/fluent-plugin-kubernetes_metadata_filter.gemspec +3 -6
- data/lib/fluent/plugin/filter_kubernetes_metadata.rb +38 -59
- data/lib/fluent/plugin/kubernetes_metadata_common.rb +26 -46
- data/lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb +29 -13
- data/lib/fluent/plugin/kubernetes_metadata_watch_pods.rb +36 -24
- data/test/helper.rb +17 -1
- data/test/plugin/test_cache_stats.rb +2 -5
- data/test/plugin/test_cache_strategy.rb +5 -8
- data/test/plugin/test_filter_kubernetes_metadata.rb +11 -10
- data/test/plugin/test_watch_namespaces.rb +116 -54
- data/test/plugin/test_watch_pods.rb +188 -143
- data/test/plugin/watch_test.rb +3 -10
- metadata +6 -27
@@ -17,7 +17,6 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
require_relative '../helper'
|
20
|
-
require 'ostruct'
|
21
20
|
require_relative 'watch_test'
|
22
21
|
|
23
22
|
class DefaultPodWatchStrategyTest < WatchTest
|
@@ -25,137 +24,141 @@ class DefaultPodWatchStrategyTest < WatchTest
|
|
25
24
|
include KubernetesMetadata::WatchPods
|
26
25
|
|
27
26
|
setup do
|
28
|
-
@initial =
|
29
|
-
'PodList',
|
30
|
-
'123',
|
31
|
-
[
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
]
|
69
|
-
|
27
|
+
@initial = {
|
28
|
+
kind: 'PodList',
|
29
|
+
metadata: {resourceVersion: '123'},
|
30
|
+
items: [
|
31
|
+
{
|
32
|
+
metadata: {
|
33
|
+
name: 'initial',
|
34
|
+
namespace: 'initial_ns',
|
35
|
+
uid: 'initial_uid',
|
36
|
+
labels: {},
|
37
|
+
},
|
38
|
+
spec: {
|
39
|
+
nodeName: 'aNodeName',
|
40
|
+
containers: [{
|
41
|
+
name: 'foo',
|
42
|
+
image: 'bar',
|
43
|
+
}, {
|
44
|
+
name: 'bar',
|
45
|
+
image: 'foo',
|
46
|
+
}]
|
47
|
+
}
|
48
|
+
},
|
49
|
+
{
|
50
|
+
metadata: {
|
51
|
+
name: 'modified',
|
52
|
+
namespace: 'create',
|
53
|
+
uid: 'modified_uid',
|
54
|
+
labels: {},
|
55
|
+
},
|
56
|
+
spec: {
|
57
|
+
nodeName: 'aNodeName',
|
58
|
+
containers: [{
|
59
|
+
name: 'foo',
|
60
|
+
image: 'bar',
|
61
|
+
}, {
|
62
|
+
name: 'bar',
|
63
|
+
image: 'foo',
|
64
|
+
}]
|
65
|
+
}
|
66
|
+
}
|
67
|
+
]
|
68
|
+
}
|
69
|
+
@created = {
|
70
70
|
type: 'CREATED',
|
71
71
|
object: {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
72
|
+
metadata: {
|
73
|
+
name: 'created',
|
74
|
+
namespace: 'create',
|
75
|
+
uid: 'created_uid',
|
76
|
+
resourceVersion: '122',
|
77
|
+
labels: {},
|
78
|
+
},
|
79
|
+
spec: {
|
80
|
+
nodeName: 'aNodeName',
|
81
|
+
containers: [{
|
82
|
+
name: 'foo',
|
83
|
+
image: 'bar',
|
84
|
+
}, {
|
85
|
+
name: 'bar',
|
86
|
+
image: 'foo',
|
87
|
+
}]
|
88
|
+
}
|
88
89
|
}
|
89
|
-
|
90
|
-
@modified =
|
90
|
+
}
|
91
|
+
@modified = {
|
91
92
|
type: 'MODIFIED',
|
92
93
|
object: {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
},
|
118
|
-
'lastState' => {},
|
119
|
-
'ready' => true,
|
120
|
-
'restartCount' => 0,
|
121
|
-
'image' => 'fabric8/hawtio-kubernetes:latest',
|
122
|
-
'imageID' => 'docker://b2bd1a24a68356b2f30128e6e28e672c1ef92df0d9ec01ec0c7faea5d77d2303',
|
123
|
-
'containerID' => 'docker://49095a2894da899d3b327c5fde1e056a81376cc9a8f8b09a195f2a92bceed459'
|
94
|
+
metadata: {
|
95
|
+
name: 'foo',
|
96
|
+
namespace: 'modified',
|
97
|
+
uid: 'modified_uid',
|
98
|
+
resourceVersion: '123',
|
99
|
+
labels: {},
|
100
|
+
},
|
101
|
+
spec: {
|
102
|
+
nodeName: 'aNodeName',
|
103
|
+
containers: [{
|
104
|
+
name: 'foo',
|
105
|
+
image: 'bar',
|
106
|
+
}, {
|
107
|
+
name: 'bar',
|
108
|
+
image: 'foo',
|
109
|
+
}]
|
110
|
+
},
|
111
|
+
status: {
|
112
|
+
containerStatuses: [
|
113
|
+
{
|
114
|
+
name: 'fabric8-console-container',
|
115
|
+
state: {
|
116
|
+
running: {
|
117
|
+
startedAt: '2015-05-08T09:22:44Z'
|
124
118
|
}
|
125
|
-
|
119
|
+
},
|
120
|
+
lastState: {},
|
121
|
+
ready: true,
|
122
|
+
restartCount: 0,
|
123
|
+
image: 'fabric8/hawtio-kubernetes:latest',
|
124
|
+
imageID: 'docker://b2bd1a24a68356b2f30128e6e28e672c1ef92df0d9ec01ec0c7faea5d77d2303',
|
125
|
+
containerID: 'docker://49095a2894da899d3b327c5fde1e056a81376cc9a8f8b09a195f2a92bceed459'
|
126
|
+
}
|
127
|
+
]
|
126
128
|
}
|
127
129
|
}
|
128
|
-
|
129
|
-
@deleted =
|
130
|
+
}
|
131
|
+
@deleted = {
|
130
132
|
type: 'DELETED',
|
131
133
|
object: {
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
metadata: {
|
135
|
+
name: 'deleteme',
|
136
|
+
namespace: 'deleted',
|
137
|
+
uid: 'deleted_uid',
|
138
|
+
resourceVersion: '124'
|
139
|
+
}
|
137
140
|
}
|
138
|
-
|
139
|
-
@error =
|
141
|
+
}
|
142
|
+
@error = {
|
140
143
|
type: 'ERROR',
|
141
144
|
object: {
|
142
|
-
|
145
|
+
message: 'some error message'
|
143
146
|
}
|
144
|
-
|
145
|
-
@gone =
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
147
|
+
}
|
148
|
+
@gone = {
|
149
|
+
type: 'ERROR',
|
150
|
+
object: {
|
151
|
+
code: 410,
|
152
|
+
kind: 'Status',
|
153
|
+
message: 'too old resource version: 123 (391079)',
|
154
|
+
metadata: {
|
155
|
+
name: 'gone',
|
156
|
+
namespace: 'gone',
|
157
|
+
uid: 'gone_uid'
|
158
|
+
},
|
159
|
+
reason: 'Gone'
|
160
|
+
}
|
161
|
+
}
|
159
162
|
end
|
160
163
|
|
161
164
|
test 'pod list caches pods' do
|
@@ -181,6 +184,7 @@ class DefaultPodWatchStrategyTest < WatchTest
|
|
181
184
|
end
|
182
185
|
end
|
183
186
|
ENV['K8S_NODE_NAME'] = orig_env_val
|
187
|
+
assert_equal('123', @last_seen_resource_version) # from @modified
|
184
188
|
end
|
185
189
|
|
186
190
|
test 'pod watch notice ignores CREATED' do
|
@@ -230,40 +234,53 @@ class DefaultPodWatchStrategyTest < WatchTest
|
|
230
234
|
end
|
231
235
|
end
|
232
236
|
|
233
|
-
test 'pod watch
|
237
|
+
test 'pod watch raises Fluent::UnrecoverableError when cannot re-establish connection to k8s API server' do
|
238
|
+
# Stub start_pod_watch to simulate initial successful connection to API server
|
239
|
+
stub(self).start_pod_watch
|
240
|
+
# Stub watch_pods to simluate not being able to set up watch connection to API server
|
241
|
+
stub(@client).watch_pods { raise }
|
234
242
|
@client.stub :get_pods, @initial do
|
235
|
-
|
236
|
-
|
237
|
-
set_up_pod_thread
|
238
|
-
end
|
239
|
-
assert_equal(3, @stats[:pod_watch_failures])
|
240
|
-
assert_equal(2, Thread.current[:pod_watch_retry_count])
|
241
|
-
assert_equal(4, Thread.current[:pod_watch_retry_backoff_interval])
|
242
|
-
assert_nil(@stats[:pod_watch_error_type_notices])
|
243
|
+
assert_raise Fluent::UnrecoverableError do
|
244
|
+
set_up_pod_thread
|
243
245
|
end
|
244
246
|
end
|
247
|
+
assert_equal(3, @stats[:pod_watch_failures])
|
248
|
+
assert_equal(2, Thread.current[:pod_watch_retry_count])
|
249
|
+
assert_equal(4, Thread.current[:pod_watch_retry_backoff_interval])
|
250
|
+
assert_nil(@stats[:pod_watch_error_type_notices])
|
245
251
|
end
|
246
252
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
253
|
+
test 'pod watch resets watch retry count when exceptions are encountered and connection to k8s API server is re-established' do
|
254
|
+
@client.stub :get_pods, @initial do
|
255
|
+
@client.stub :watch_pods, [[@created, @exception_raised]] do
|
256
|
+
# Force the infinite watch loop to exit after 3 seconds. Verifies that
|
257
|
+
# no unrecoverable error was thrown during this period of time.
|
258
|
+
assert_raise Timeout::Error.new('execution expired') do
|
259
|
+
Timeout.timeout(3) do
|
260
|
+
set_up_pod_thread
|
261
|
+
end
|
262
|
+
end
|
263
|
+
assert_operator(@stats[:pod_watch_failures], :>=, 3)
|
264
|
+
assert_operator(Thread.current[:pod_watch_retry_count], :<=, 1)
|
265
|
+
assert_operator(Thread.current[:pod_watch_retry_backoff_interval], :<=, 1)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
256
269
|
|
257
|
-
test 'pod watch
|
270
|
+
test 'pod watch resets watch retry count when error is received and connection to k8s API server is re-established' do
|
258
271
|
@client.stub :get_pods, @initial do
|
259
272
|
@client.stub :watch_pods, [@error] do
|
260
|
-
|
261
|
-
|
273
|
+
# Force the infinite watch loop to exit after 3 seconds. Verifies that
|
274
|
+
# no unrecoverable error was thrown during this period of time.
|
275
|
+
assert_raise Timeout::Error.new('execution expired') do
|
276
|
+
Timeout.timeout(3) do
|
277
|
+
set_up_pod_thread
|
278
|
+
end
|
262
279
|
end
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
280
|
+
assert_operator(@stats[:pod_watch_failures], :>=, 3)
|
281
|
+
assert_operator(Thread.current[:pod_watch_retry_count], :<=, 1)
|
282
|
+
assert_operator(Thread.current[:pod_watch_retry_backoff_interval], :<=, 1)
|
283
|
+
assert_operator(@stats[:pod_watch_error_type_notices], :>=, 3)
|
267
284
|
end
|
268
285
|
end
|
269
286
|
end
|
@@ -285,4 +302,32 @@ class DefaultPodWatchStrategyTest < WatchTest
|
|
285
302
|
end
|
286
303
|
end
|
287
304
|
end
|
305
|
+
|
306
|
+
test 'pod watch raises a GoneError when a 410 Gone error is received' do
|
307
|
+
@cache['gone_uid'] = {}
|
308
|
+
@client.stub :watch_pods, [@gone] do
|
309
|
+
@last_seen_resource_version = '100'
|
310
|
+
assert_raise KubernetesMetadata::Common::GoneError do
|
311
|
+
process_pod_watcher_notices(start_pod_watch)
|
312
|
+
end
|
313
|
+
assert_equal(1, @stats[:pod_watch_gone_notices])
|
314
|
+
assert_nil @last_seen_resource_version # forced restart
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
test 'pod watch retries when 410 Gone errors are encountered' do
|
319
|
+
@client.stub :get_pods, @initial do
|
320
|
+
@client.stub :watch_pods, [@created, @gone, @modified] do
|
321
|
+
# Force the infinite watch loop to exit after 3 seconds because the code sleeps 3 times.
|
322
|
+
# Verifies that no unrecoverable error was thrown during this period of time.
|
323
|
+
assert_raise Timeout::Error.new('execution expired') do
|
324
|
+
Timeout.timeout(3) do
|
325
|
+
set_up_pod_thread
|
326
|
+
end
|
327
|
+
end
|
328
|
+
assert_operator(@stats[:pod_watch_gone_errors], :>=, 3)
|
329
|
+
assert_operator(@stats[:pod_watch_gone_notices], :>=, 3)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
288
333
|
end
|
data/test/plugin/watch_test.rb
CHANGED
@@ -17,7 +17,6 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
require_relative '../helper'
|
20
|
-
require 'ostruct'
|
21
20
|
|
22
21
|
class WatchTest < Test::Unit::TestCase
|
23
22
|
|
@@ -37,9 +36,6 @@ class WatchTest < Test::Unit::TestCase
|
|
37
36
|
Thread.current[:namespace_watch_retry_count] = 0
|
38
37
|
|
39
38
|
@client = OpenStruct.new
|
40
|
-
def @client.resourceVersion
|
41
|
-
'12345'
|
42
|
-
end
|
43
39
|
def @client.watch_pods(options = {})
|
44
40
|
[]
|
45
41
|
end
|
@@ -47,16 +43,13 @@ class WatchTest < Test::Unit::TestCase
|
|
47
43
|
[]
|
48
44
|
end
|
49
45
|
def @client.get_namespaces(options = {})
|
50
|
-
|
46
|
+
{items: [], metadata: {resourceVersion: '12345'}}
|
51
47
|
end
|
52
48
|
def @client.get_pods(options = {})
|
53
|
-
|
49
|
+
{items: [], metadata: {resourceVersion: '12345'}}
|
54
50
|
end
|
55
51
|
|
56
|
-
@exception_raised =
|
57
|
-
def @exception_raised.each
|
58
|
-
raise Exception
|
59
|
-
end
|
52
|
+
@exception_raised = :blow_up_when_used
|
60
53
|
end
|
61
54
|
|
62
55
|
def watcher=(value)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-kubernetes_metadata_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmi Dyson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 0.14.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '1.
|
22
|
+
version: '1.13'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 0.14.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '1.
|
32
|
+
version: '1.13'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: lru_redux
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -252,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
252
252
|
requirements:
|
253
253
|
- - ">="
|
254
254
|
- !ruby/object:Gem::Version
|
255
|
-
version: 2.
|
255
|
+
version: 2.5.0
|
256
256
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
257
|
requirements:
|
258
258
|
- - ">="
|
@@ -263,25 +263,4 @@ rubygems_version: 3.1.2
|
|
263
263
|
signing_key:
|
264
264
|
specification_version: 4
|
265
265
|
summary: Fluentd filter plugin to add Kubernetes metadata
|
266
|
-
test_files:
|
267
|
-
- test/cassettes/invalid_api_server_config.yml
|
268
|
-
- test/cassettes/kubernetes_docker_metadata_annotations.yml
|
269
|
-
- test/cassettes/kubernetes_docker_metadata_dotted_labels.yml
|
270
|
-
- test/cassettes/kubernetes_get_api_v1.yml
|
271
|
-
- test/cassettes/kubernetes_get_api_v1_using_token.yml
|
272
|
-
- test/cassettes/kubernetes_get_namespace_default.yml
|
273
|
-
- test/cassettes/kubernetes_get_namespace_default_using_token.yml
|
274
|
-
- test/cassettes/kubernetes_get_pod.yml
|
275
|
-
- test/cassettes/kubernetes_get_pod_using_token.yml
|
276
|
-
- test/cassettes/metadata_from_tag_and_journald_fields.yml
|
277
|
-
- test/cassettes/metadata_from_tag_journald_and_kubernetes_fields.yml
|
278
|
-
- test/cassettes/valid_kubernetes_api_server.yml
|
279
|
-
- test/cassettes/valid_kubernetes_api_server_using_token.yml
|
280
|
-
- test/helper.rb
|
281
|
-
- test/plugin/test.token
|
282
|
-
- test/plugin/test_cache_stats.rb
|
283
|
-
- test/plugin/test_cache_strategy.rb
|
284
|
-
- test/plugin/test_filter_kubernetes_metadata.rb
|
285
|
-
- test/plugin/test_watch_namespaces.rb
|
286
|
-
- test/plugin/test_watch_pods.rb
|
287
|
-
- test/plugin/watch_test.rb
|
266
|
+
test_files: []
|