fluent-plugin-kubernetes_metadata_filter 2.5.0 → 2.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1991a6b8cd09f65728588401e697dda36954b94cf75b625789c6e7773d50ccf
4
- data.tar.gz: df46f28a113c17aa3e2174d3ad23edb0b5b93fb6d65d5f02787d6ac83ac129a2
3
+ metadata.gz: a683b622df5649113828c46b650d722a5042c4c92023de4ea3350c1a5057bf8c
4
+ data.tar.gz: 86572e207c7aa2b595510922ac7b3946d3f2f1a4031d3f795d8356700c54d140
5
5
  SHA512:
6
- metadata.gz: 1a41d498af8a2e92723c05679608294d07acf2cf7a87dfdf5921fe3a385df6369003eef939dd5aeabf970c67f31eb319ac1485d566ac110bcbe6b79f5acc392a
7
- data.tar.gz: e62c355dbdb0ac1e89e43534c5929c80e82b166f5c614b1967d6ff79658835881a9c6803d5072e85a41c83fbefc8db326ba95c6d2f1c5a20ca1b8a0f18ce3cf1
6
+ metadata.gz: 77a3f4c2b33a0fe48e7b85636415d9b1d8d7aa1bba07af6c801290830a14f2c190c2dec76f9d48c7f0bc99131cb785dcf681217c5e42e90f3dfc9a24ad81f6e2
7
+ data.tar.gz: 051563042ca5826bb5f07a00367672b63718aac7a49f4e32cd9b83ba1312493ebafeee5211c8846eb4f3b0d5ec07f22c52d6f24ae059c4c6560d707f8a60404a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-kubernetes_metadata_filter (2.5.0)
4
+ fluent-plugin-kubernetes_metadata_filter (2.5.2)
5
5
  fluentd (>= 0.14.0, < 1.12)
6
6
  kubeclient (< 5)
7
7
  lru_redux
@@ -58,8 +58,12 @@ GEM
58
58
  http-parser (1.2.1)
59
59
  ffi-compiler (>= 1.0, < 2.0)
60
60
  http_parser.rb (0.6.0)
61
- kubeclient (4.7.0)
61
+ jsonpath (1.0.5)
62
+ multi_json
63
+ to_regexp (~> 0.2.1)
64
+ kubeclient (4.8.0)
62
65
  http (>= 3.0, < 5.0)
66
+ jsonpath (~> 1.0)
63
67
  recursive-open-struct (~> 1.1, >= 1.1.1)
64
68
  rest-client (~> 2.0)
65
69
  lru_redux (1.1.0)
@@ -69,6 +73,7 @@ GEM
69
73
  mini_mime (1.0.2)
70
74
  minitest (4.7.5)
71
75
  msgpack (1.3.3)
76
+ multi_json (1.15.0)
72
77
  netrc (0.11.0)
73
78
  parallel (1.19.2)
74
79
  parser (2.7.1.4)
@@ -113,6 +118,7 @@ GEM
113
118
  test-unit-rr (1.0.5)
114
119
  rr (>= 1.1.1)
115
120
  test-unit (>= 2.5.2)
121
+ to_regexp (0.2.1)
116
122
  tzinfo (2.0.2)
117
123
  concurrent-ruby (~> 1.0)
118
124
  tzinfo-data (1.2020.1)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "fluent-plugin-kubernetes_metadata_filter"
7
- gem.version = "2.5.0"
7
+ gem.version = "2.5.2"
8
8
  gem.authors = ["Jimmi Dyson"]
9
9
  gem.email = ["jimmidyson@gmail.com"]
10
10
  gem.description = %q{Filter plugin to add Kubernetes metadata}
@@ -19,6 +19,12 @@
19
19
  module KubernetesMetadata
20
20
  module Common
21
21
 
22
+ class GoneError < StandardError
23
+ def initialize(msg="410 Gone")
24
+ super
25
+ end
26
+ end
27
+
22
28
  def match_annotations(annotations)
23
29
  result = {}
24
30
  @annotations_regexps.each do |regexp|
@@ -39,6 +39,12 @@ module KubernetesMetadata
39
39
  begin
40
40
  namespace_watcher ||= get_namespaces_and_start_watcher
41
41
  process_namespace_watcher_notices(namespace_watcher)
42
+ rescue GoneError => e
43
+ # Expected error. Quietly go back through the loop in order to
44
+ # start watching from the latest resource versions
45
+ @stats.bump(:namespace_watch_gone_errors)
46
+ log.info("410 Gone encountered. Restarting namespace watch to reset resource versions.", e)
47
+ namespace_watcher = nil
42
48
  rescue Exception => e
43
49
  @stats.bump(:namespace_watch_failures)
44
50
  if Thread.current[:namespace_watch_retry_count] < @watch_retry_max_times
@@ -123,9 +129,14 @@ module KubernetesMetadata
123
129
  # deleted but still processing logs
124
130
  @stats.bump(:namespace_cache_watch_deletes_ignored)
125
131
  when 'ERROR'
126
- @stats.bump(:namespace_watch_error_type_notices)
127
- message = notice['object']['message'] if notice['object'] && notice['object']['message']
128
- raise "Error while watching namespaces: #{message}"
132
+ if notice.object && notice.object['code'] == 410
133
+ @stats.bump(:namespace_watch_gone_notices)
134
+ raise GoneError
135
+ else
136
+ @stats.bump(:namespace_watch_error_type_notices)
137
+ message = notice['object']['message'] if notice['object'] && notice['object']['message']
138
+ raise "Error while watching namespaces: #{message}"
139
+ end
129
140
  else
130
141
  reset_namespace_watch_retry_stats
131
142
  # Don't pay attention to creations, since the created namespace may not
@@ -19,6 +19,7 @@
19
19
  require_relative 'kubernetes_metadata_common'
20
20
 
21
21
  module KubernetesMetadata
22
+
22
23
  module WatchPods
23
24
 
24
25
  include ::KubernetesMetadata::Common
@@ -39,6 +40,12 @@ module KubernetesMetadata
39
40
  begin
40
41
  pod_watcher ||= get_pods_and_start_watcher
41
42
  process_pod_watcher_notices(pod_watcher)
43
+ rescue GoneError => e
44
+ # Expected error. Quietly go back through the loop in order to
45
+ # start watching from the latest resource versions
46
+ @stats.bump(:pod_watch_gone_errors)
47
+ log.info("410 Gone encountered. Restarting pod watch to reset resource versions.", e)
48
+ pod_watcher = nil
42
49
  rescue Exception => e
43
50
  @stats.bump(:pod_watch_failures)
44
51
  if Thread.current[:pod_watch_retry_count] < @watch_retry_max_times
@@ -129,9 +136,14 @@ module KubernetesMetadata
129
136
  # deleted but still processing logs
130
137
  @stats.bump(:pod_cache_watch_delete_ignored)
131
138
  when 'ERROR'
132
- @stats.bump(:pod_watch_error_type_notices)
133
- message = notice['object']['message'] if notice['object'] && notice['object']['message']
134
- raise "Error while watching pods: #{message}"
139
+ if notice.object && notice.object['code'] == 410
140
+ @stats.bump(:pod_watch_gone_notices)
141
+ raise GoneError
142
+ else
143
+ @stats.bump(:pod_watch_error_type_notices)
144
+ message = notice['object']['message'] if notice['object'] && notice['object']['message']
145
+ raise "Error while watching pods: #{message}"
146
+ end
135
147
  else
136
148
  reset_pod_watch_retry_stats
137
149
  # Don't pay attention to creations, since the created pod may not
@@ -76,6 +76,20 @@ class WatchNamespacesTestTest < WatchTest
76
76
  'message' => 'some error message'
77
77
  }
78
78
  )
79
+ @gone = OpenStruct.new(
80
+ type: 'ERROR',
81
+ object: {
82
+ 'code' => 410,
83
+ 'kind' => 'Status',
84
+ 'message' => 'too old resource version: 123 (391079)',
85
+ 'metadata' => {
86
+ 'name' => 'gone',
87
+ 'namespace' => 'gone',
88
+ 'uid' => 'gone_uid'
89
+ },
90
+ 'reason' => 'Gone'
91
+ }
92
+ )
79
93
  end
80
94
 
81
95
  test 'namespace list caches namespaces' do
@@ -179,4 +193,30 @@ class WatchNamespacesTestTest < WatchTest
179
193
  end
180
194
  end
181
195
  end
196
+
197
+ test 'namespace watch raises a GoneError when a 410 Gone error is received' do
198
+ @cache['gone_uid'] = {}
199
+ @client.stub :watch_namespaces, [@gone] do
200
+ assert_raise KubernetesMetadata::Common::GoneError do
201
+ process_namespace_watcher_notices(start_namespace_watch)
202
+ end
203
+ assert_equal(1, @stats[:namespace_watch_gone_notices])
204
+ end
205
+ end
206
+
207
+ test 'namespace watch retries when 410 Gone errors are encountered' do
208
+ @client.stub :get_namespaces, @initial do
209
+ @client.stub :watch_namespaces, [@created, @gone, @modified] do
210
+ # Force the infinite watch loop to exit after 3 seconds. Verifies that
211
+ # no unrecoverable error was thrown during this period of time.
212
+ assert_raise Timeout::Error.new('execution expired') do
213
+ Timeout.timeout(3) do
214
+ set_up_namespace_thread
215
+ end
216
+ end
217
+ assert_operator(@stats[:namespace_watch_gone_errors], :>=, 3)
218
+ assert_operator(@stats[:namespace_watch_gone_notices], :>=, 3)
219
+ end
220
+ end
221
+ end
182
222
  end
@@ -142,6 +142,20 @@ class DefaultPodWatchStrategyTest < WatchTest
142
142
  'message' => 'some error message'
143
143
  }
144
144
  )
145
+ @gone = OpenStruct.new(
146
+ type: 'ERROR',
147
+ object: {
148
+ 'code' => 410,
149
+ 'kind' => 'Status',
150
+ 'message' => 'too old resource version: 123 (391079)',
151
+ 'metadata' => {
152
+ 'name' => 'gone',
153
+ 'namespace' => 'gone',
154
+ 'uid' => 'gone_uid'
155
+ },
156
+ 'reason' => 'Gone'
157
+ }
158
+ )
145
159
  end
146
160
 
147
161
  test 'pod list caches pods' do
@@ -261,4 +275,30 @@ class DefaultPodWatchStrategyTest < WatchTest
261
275
  end
262
276
  end
263
277
  end
278
+
279
+ test 'pod watch raises a GoneError when a 410 Gone error is received' do
280
+ @cache['gone_uid'] = {}
281
+ @client.stub :watch_pods, [@gone] do
282
+ assert_raise KubernetesMetadata::Common::GoneError do
283
+ process_pod_watcher_notices(start_pod_watch)
284
+ end
285
+ assert_equal(1, @stats[:pod_watch_gone_notices])
286
+ end
287
+ end
288
+
289
+ test 'pod watch retries when 410 Gone errors are encountered' do
290
+ @client.stub :get_pods, @initial do
291
+ @client.stub :watch_pods, [@created, @gone, @modified] do
292
+ # Force the infinite watch loop to exit after 3 seconds. Verifies that
293
+ # no unrecoverable error was thrown during this period of time.
294
+ assert_raise Timeout::Error.new('execution expired') do
295
+ Timeout.timeout(3) do
296
+ set_up_pod_thread
297
+ end
298
+ end
299
+ assert_operator(@stats[:pod_watch_gone_errors], :>=, 3)
300
+ assert_operator(@stats[:pod_watch_gone_notices], :>=, 3)
301
+ end
302
+ end
303
+ end
264
304
  end
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.5.0
4
+ version: 2.5.2
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-07-01 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd