fluent-plugin-kubernetes_metadata_filter 2.4.6 → 2.5.3

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.
@@ -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,123 +24,141 @@ class DefaultPodWatchStrategyTest < WatchTest
25
24
  include KubernetesMetadata::WatchPods
26
25
 
27
26
  setup do
28
- @initial = Kubeclient::Common::EntityList.new(
29
- 'PodList',
30
- '123',
31
- [
32
- Kubeclient::Resource.new({
33
- 'metadata' => {
34
- 'name' => 'initial',
35
- 'namespace' => 'initial_ns',
36
- 'uid' => 'initial_uid',
37
- 'labels' => {},
38
- },
39
- 'spec' => {
40
- 'nodeName' => 'aNodeName',
41
- 'containers' => [{
42
- 'name' => 'foo',
43
- 'image' => 'bar',
44
- }, {
45
- 'name' => 'bar',
46
- 'image' => 'foo',
47
- }]
48
- }
49
- }),
50
- Kubeclient::Resource.new({
51
- 'metadata' => {
52
- 'name' => 'modified',
53
- 'namespace' => 'create',
54
- 'uid' => 'modified_uid',
55
- 'labels' => {},
56
- },
57
- 'spec' => {
58
- 'nodeName' => 'aNodeName',
59
- 'containers' => [{
60
- 'name' => 'foo',
61
- 'image' => 'bar',
62
- }, {
63
- 'name' => 'bar',
64
- 'image' => 'foo',
65
- }]
66
- }
67
- }),
68
- ])
69
- @created = OpenStruct.new(
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
- 'metadata' => {
73
- 'name' => 'created',
74
- 'namespace' => 'create',
75
- 'uid' => 'created_uid',
76
- 'labels' => {},
77
- },
78
- 'spec' => {
79
- 'nodeName' => 'aNodeName',
80
- 'containers' => [{
81
- 'name' => 'foo',
82
- 'image' => 'bar',
83
- }, {
84
- 'name' => 'bar',
85
- 'image' => 'foo',
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 = OpenStruct.new(
90
+ }
91
+ @modified = {
91
92
  type: 'MODIFIED',
92
93
  object: {
93
- 'metadata' => {
94
- 'name' => 'foo',
95
- 'namespace' => 'modified',
96
- 'uid' => 'modified_uid',
97
- 'labels' => {},
98
- },
99
- 'spec' => {
100
- 'nodeName' => 'aNodeName',
101
- 'containers' => [{
102
- 'name' => 'foo',
103
- 'image' => 'bar',
104
- }, {
105
- 'name' => 'bar',
106
- 'image' => 'foo',
107
- }]
108
- },
109
- 'status' => {
110
- 'containerStatuses' => [
111
- {
112
- 'name' => 'fabric8-console-container',
113
- 'state' => {
114
- 'running' => {
115
- 'startedAt' => '2015-05-08T09:22:44Z'
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 = OpenStruct.new(
130
+ }
131
+ @deleted = {
130
132
  type: 'DELETED',
131
133
  object: {
132
- 'metadata' => {
133
- 'name' => 'deleteme',
134
- 'namespace' => 'deleted',
135
- 'uid' => 'deleted_uid'
136
- }
134
+ metadata: {
135
+ name: 'deleteme',
136
+ namespace: 'deleted',
137
+ uid: 'deleted_uid',
138
+ resourceVersion: '124'
139
+ }
140
+ }
141
+ }
142
+ @error = {
143
+ type: 'ERROR',
144
+ object: {
145
+ message: 'some error message'
137
146
  }
138
- )
139
- @error = OpenStruct.new(
147
+ }
148
+ @gone = {
140
149
  type: 'ERROR',
141
150
  object: {
142
- 'message' => 'some error message'
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'
143
160
  }
144
- )
161
+ }
145
162
  end
146
163
 
147
164
  test 'pod list caches pods' do
@@ -167,6 +184,7 @@ class DefaultPodWatchStrategyTest < WatchTest
167
184
  end
168
185
  end
169
186
  ENV['K8S_NODE_NAME'] = orig_env_val
187
+ assert_equal('123', @last_seen_resource_version) # from @modified
170
188
  end
171
189
 
172
190
  test 'pod watch notice ignores CREATED' do
@@ -216,30 +234,53 @@ class DefaultPodWatchStrategyTest < WatchTest
216
234
  end
217
235
  end
218
236
 
219
- test 'pod watch retries when exceptions are encountered' do
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
220
254
  @client.stub :get_pods, @initial do
221
255
  @client.stub :watch_pods, [[@created, @exception_raised]] do
222
- assert_raise Fluent::UnrecoverableError do
223
- set_up_pod_thread
224
- end
225
- assert_equal(3, @stats[:pod_watch_failures])
226
- assert_equal(2, Thread.current[:pod_watch_retry_count])
227
- assert_equal(4, Thread.current[:pod_watch_retry_backoff_interval])
228
- assert_nil(@stats[:pod_watch_error_type_notices])
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)
229
266
  end
230
267
  end
231
268
  end
232
269
 
233
- test 'pod watch retries when error is received' do
270
+ test 'pod watch resets watch retry count when error is received and connection to k8s API server is re-established' do
234
271
  @client.stub :get_pods, @initial do
235
272
  @client.stub :watch_pods, [@error] do
236
- assert_raise Fluent::UnrecoverableError do
237
- set_up_pod_thread
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
238
279
  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_equal(3, @stats[:pod_watch_error_type_notices])
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)
243
284
  end
244
285
  end
245
286
  end
@@ -261,4 +302,32 @@ class DefaultPodWatchStrategyTest < WatchTest
261
302
  end
262
303
  end
263
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
264
333
  end
@@ -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
- self
46
+ {items: [], metadata: {resourceVersion: '12345'}}
51
47
  end
52
48
  def @client.get_pods(options = {})
53
- self
49
+ {items: [], metadata: {resourceVersion: '12345'}}
54
50
  end
55
51
 
56
- @exception_raised = OpenStruct.new
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.6
4
+ version: 2.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmi Dyson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
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.10'
22
+ version: '1.12'
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.10'
32
+ version: '1.12'
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.1.0
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.0.8
262
+ rubygems_version: 3.1.4
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: []