fluent-plugin-kubernetes_metadata_filter 2.5.2 → 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 +43 -43
- 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 +20 -46
- data/lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb +17 -12
- data/lib/fluent/plugin/kubernetes_metadata_watch_pods.rb +33 -16
- 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 +90 -68
- data/test/plugin/test_watch_pods.rb +164 -135
- data/test/plugin/watch_test.rb +3 -10
- metadata +7 -28
@@ -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,30 +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 }
|
242
|
+
@client.stub :get_pods, @initial do
|
243
|
+
assert_raise Fluent::UnrecoverableError do
|
244
|
+
set_up_pod_thread
|
245
|
+
end
|
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])
|
251
|
+
end
|
252
|
+
|
253
|
+
test 'pod watch resets watch retry count when exceptions are encountered and connection to k8s API server is re-established' do
|
234
254
|
@client.stub :get_pods, @initial do
|
235
255
|
@client.stub :watch_pods, [[@created, @exception_raised]] do
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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)
|
243
266
|
end
|
244
267
|
end
|
245
268
|
end
|
246
269
|
|
247
|
-
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
|
248
271
|
@client.stub :get_pods, @initial do
|
249
272
|
@client.stub :watch_pods, [@error] do
|
250
|
-
|
251
|
-
|
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
|
252
279
|
end
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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)
|
257
284
|
end
|
258
285
|
end
|
259
286
|
end
|
@@ -279,18 +306,20 @@ class DefaultPodWatchStrategyTest < WatchTest
|
|
279
306
|
test 'pod watch raises a GoneError when a 410 Gone error is received' do
|
280
307
|
@cache['gone_uid'] = {}
|
281
308
|
@client.stub :watch_pods, [@gone] do
|
309
|
+
@last_seen_resource_version = '100'
|
282
310
|
assert_raise KubernetesMetadata::Common::GoneError do
|
283
311
|
process_pod_watcher_notices(start_pod_watch)
|
284
312
|
end
|
285
313
|
assert_equal(1, @stats[:pod_watch_gone_notices])
|
314
|
+
assert_nil @last_seen_resource_version # forced restart
|
286
315
|
end
|
287
316
|
end
|
288
317
|
|
289
318
|
test 'pod watch retries when 410 Gone errors are encountered' do
|
290
319
|
@client.stub :get_pods, @initial do
|
291
320
|
@client.stub :watch_pods, [@created, @gone, @modified] do
|
292
|
-
# Force the infinite watch loop to exit after 3 seconds
|
293
|
-
# no unrecoverable error was thrown during this period of time.
|
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.
|
294
323
|
assert_raise Timeout::Error.new('execution expired') do
|
295
324
|
Timeout.timeout(3) do
|
296
325
|
set_up_pod_thread
|
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,36 +252,15 @@ 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
|
- - ">="
|
259
259
|
- !ruby/object:Gem::Version
|
260
260
|
version: '0'
|
261
261
|
requirements: []
|
262
|
-
rubygems_version: 3.
|
262
|
+
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: []
|