fluent-plugin-kubernetes_metadata_filter 2.5.2 → 2.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a683b622df5649113828c46b650d722a5042c4c92023de4ea3350c1a5057bf8c
4
- data.tar.gz: 86572e207c7aa2b595510922ac7b3946d3f2f1a4031d3f795d8356700c54d140
3
+ metadata.gz: 8eada7adb2f8305fc4f14d91c04a2f8d7293f4f622713b0e7d463d85b2ed15d3
4
+ data.tar.gz: 890266f08cda7757d459d99c728f7638c17f1c01ffa042c89c53d74da6c97c0e
5
5
  SHA512:
6
- metadata.gz: 77a3f4c2b33a0fe48e7b85636415d9b1d8d7aa1bba07af6c801290830a14f2c190c2dec76f9d48c7f0bc99131cb785dcf681217c5e42e90f3dfc9a24ad81f6e2
7
- data.tar.gz: 051563042ca5826bb5f07a00367672b63718aac7a49f4e32cd9b83ba1312493ebafeee5211c8846eb4f3b0d5ec07f22c52d6f24ae059c4c6560d707f8a60404a
6
+ metadata.gz: 5874033154af1f111f41e6197295134b66ab1ac94777fe2158e112880ae15343a69449fb78d2958cc0ad7a99e8db5249bd91e074fd17993d31fd48a859fe370d
7
+ data.tar.gz: 6dfc784c4f9696ec7618fffaf6b95e0fe797266ea8fe13e1bc0ee9fb0e51e48f1da77b6a0d1b7f0fd3e407608ac467f58bcc9081ddaf56daaccf8fb1eef572e0
@@ -14,21 +14,21 @@ missingdeps: &missingdeps
14
14
  sudo cp /tmp/sources.list /etc/apt/sources.list
15
15
  sudo apt-get update
16
16
  sudo apt-get install cmake libicu-dev libssl-dev
17
-
17
+
18
18
  test: &test
19
19
  name: Test bundle
20
20
  command: bundle exec rake test
21
21
 
22
22
  executors:
23
- ruby-2-4:
24
- docker:
25
- - image: circleci/ruby:2.4.6
26
23
  ruby-2-5:
27
24
  docker:
28
25
  - image: circleci/ruby:2.5.5
29
26
  ruby-2-6:
30
27
  docker:
31
28
  - image: circleci/ruby:2.6.3
29
+ ruby-2-7:
30
+ docker:
31
+ - image: circleci/ruby:2.7.1
32
32
  jobs:
33
33
  "ruby-test":
34
34
  parameters:
@@ -49,9 +49,9 @@ jobs:
49
49
  workflows:
50
50
  "test_multiple_ruby_versions":
51
51
  jobs:
52
- - ruby-test:
53
- ruby-version: ruby-2-4
54
52
  - ruby-test:
55
53
  ruby-version: ruby-2-5
56
54
  - ruby-test:
57
55
  ruby-version: ruby-2-6
56
+ - ruby-test:
57
+ ruby-version: ruby-2-7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-kubernetes_metadata_filter (2.5.2)
4
+ fluent-plugin-kubernetes_metadata_filter (2.5.3)
5
5
  fluentd (>= 0.14.0, < 1.12)
6
6
  kubeclient (< 5)
7
7
  lru_redux
@@ -16,8 +16,8 @@ GEM
16
16
  charlock_holmes (0.7.7)
17
17
  codeclimate-test-reporter (0.6.0)
18
18
  simplecov (>= 0.7.1, < 1.0.0)
19
- concurrent-ruby (1.1.6)
20
- cool.io (1.6.0)
19
+ concurrent-ruby (1.1.8)
20
+ cool.io (1.7.0)
21
21
  copyright-header (1.0.22)
22
22
  github-linguist
23
23
  crack (0.4.3)
@@ -26,15 +26,15 @@ GEM
26
26
  domain_name (0.5.20190701)
27
27
  unf (>= 0.0.5, < 1.0.0)
28
28
  escape_utils (1.2.1)
29
- ffi (1.13.1)
29
+ ffi (1.14.2)
30
30
  ffi-compiler (1.0.1)
31
31
  ffi (>= 1.0.0)
32
32
  rake
33
- fluentd (1.11.1)
33
+ fluentd (1.11.5)
34
34
  cool.io (>= 1.4.5, < 2.0.0)
35
35
  http_parser.rb (>= 0.5.1, < 0.7.0)
36
36
  msgpack (>= 1.3.1, < 2.0.0)
37
- serverengine (>= 2.0.4, < 3.0.0)
37
+ serverengine (>= 2.2.2, < 3.0.0)
38
38
  sigdump (~> 0.2.2)
39
39
  strptime (>= 0.2.2, < 1.0.0)
40
40
  tzinfo (>= 1.0, < 3.0)
@@ -55,13 +55,12 @@ GEM
55
55
  http-cookie (1.0.3)
56
56
  domain_name (~> 0.5)
57
57
  http-form_data (2.3.0)
58
- http-parser (1.2.1)
58
+ http-parser (1.2.3)
59
59
  ffi-compiler (>= 1.0, < 2.0)
60
60
  http_parser.rb (0.6.0)
61
- jsonpath (1.0.5)
61
+ jsonpath (1.1.0)
62
62
  multi_json
63
- to_regexp (~> 0.2.1)
64
- kubeclient (4.8.0)
63
+ kubeclient (4.9.1)
65
64
  http (>= 3.0, < 5.0)
66
65
  jsonpath (~> 1.0)
67
66
  recursive-open-struct (~> 1.1, >= 1.1.1)
@@ -69,7 +68,7 @@ GEM
69
68
  lru_redux (1.1.0)
70
69
  mime-types (3.3.1)
71
70
  mime-types-data (~> 3.2015)
72
- mime-types-data (3.2020.0512)
71
+ mime-types-data (3.2020.1104)
73
72
  mini_mime (1.0.2)
74
73
  minitest (4.7.5)
75
74
  msgpack (1.3.3)
@@ -82,7 +81,7 @@ GEM
82
81
  public_suffix (4.0.5)
83
82
  rainbow (3.0.0)
84
83
  rake (13.0.1)
85
- recursive-open-struct (1.1.2)
84
+ recursive-open-struct (1.1.3)
86
85
  regexp_parser (1.7.1)
87
86
  rest-client (2.1.0)
88
87
  http-accept (>= 1.7.0, < 2.0)
@@ -105,23 +104,22 @@ GEM
105
104
  ruby-progressbar (1.10.1)
106
105
  rugged (1.0.1)
107
106
  safe_yaml (1.0.5)
108
- serverengine (2.2.1)
107
+ serverengine (2.2.2)
109
108
  sigdump (~> 0.2.2)
110
109
  sigdump (0.2.4)
111
110
  simplecov (0.18.5)
112
111
  docile (~> 1.1)
113
112
  simplecov-html (~> 0.11)
114
113
  simplecov-html (0.12.2)
115
- strptime (0.2.4)
114
+ strptime (0.2.5)
116
115
  test-unit (3.0.9)
117
116
  power_assert
118
117
  test-unit-rr (1.0.5)
119
118
  rr (>= 1.1.1)
120
119
  test-unit (>= 2.5.2)
121
- to_regexp (0.2.1)
122
- tzinfo (2.0.2)
120
+ tzinfo (2.0.4)
123
121
  concurrent-ruby (~> 1.0)
124
- tzinfo-data (1.2020.1)
122
+ tzinfo-data (1.2020.6)
125
123
  tzinfo (>= 1.0.0)
126
124
  unf (0.1.4)
127
125
  unf_ext
@@ -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.2"
7
+ gem.version = "2.5.3"
8
8
  gem.authors = ["Jimmi Dyson"]
9
9
  gem.email = ["jimmidyson@gmail.com"]
10
10
  gem.description = %q{Filter plugin to add Kubernetes metadata}
@@ -13,11 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.license = "Apache-2.0"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
16
 
20
- gem.required_ruby_version = '>= 2.1.0'
17
+ gem.required_ruby_version = '>= 2.5.0'
21
18
 
22
19
  gem.add_runtime_dependency 'fluentd', ['>= 0.14.0', '< 1.12']
23
20
  gem.add_runtime_dependency "lru_redux"
@@ -90,29 +90,15 @@ module Fluent::Plugin
90
90
 
91
91
  def fetch_pod_metadata(namespace_name, pod_name)
92
92
  log.trace("fetching pod metadata: #{namespace_name}/#{pod_name}") if log.trace?
93
- begin
94
- metadata = @client.get_pod(pod_name, namespace_name)
95
- unless metadata
96
- log.trace("no metadata returned for: #{namespace_name}/#{pod_name}") if log.trace?
97
- @stats.bump(:pod_cache_api_nil_not_found)
98
- else
99
- begin
100
- log.trace("raw metadata for #{namespace_name}/#{pod_name}: #{metadata}") if log.trace?
101
- metadata = parse_pod_metadata(metadata)
102
- @stats.bump(:pod_cache_api_updates)
103
- log.trace("parsed metadata for #{namespace_name}/#{pod_name}: #{metadata}") if log.trace?
104
- @cache[metadata['pod_id']] = metadata
105
- return metadata
106
- rescue Exception=>e
107
- log.debug(e)
108
- @stats.bump(:pod_cache_api_nil_bad_resp_payload)
109
- log.trace("returning empty metadata for #{namespace_name}/#{pod_name} due to error '#{e}'") if log.trace?
110
- end
111
- end
112
- rescue Exception=>e
113
- @stats.bump(:pod_cache_api_nil_error)
114
- log.debug "Exception '#{e}' encountered fetching pod metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
115
- end
93
+ pod_object = @client.get_pod(pod_name, namespace_name)
94
+ log.trace("raw metadata for #{namespace_name}/#{pod_name}: #{pod_object}") if log.trace?
95
+ metadata = parse_pod_metadata(pod_object)
96
+ @stats.bump(:pod_cache_api_updates)
97
+ log.trace("parsed metadata for #{namespace_name}/#{pod_name}: #{metadata}") if log.trace?
98
+ @cache[metadata['pod_id']] = metadata
99
+ rescue => e
100
+ @stats.bump(:pod_cache_api_nil_error)
101
+ log.debug "Exception '#{e}' encountered fetching pod metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
116
102
  {}
117
103
  end
118
104
 
@@ -132,29 +118,15 @@ module Fluent::Plugin
132
118
 
133
119
  def fetch_namespace_metadata(namespace_name)
134
120
  log.trace("fetching namespace metadata: #{namespace_name}") if log.trace?
135
- begin
136
- metadata = @client.get_namespace(namespace_name)
137
- unless metadata
138
- log.trace("no metadata returned for: #{namespace_name}") if log.trace?
139
- @stats.bump(:namespace_cache_api_nil_not_found)
140
- else
141
- begin
142
- log.trace("raw metadata for #{namespace_name}: #{metadata}") if log.trace?
143
- metadata = parse_namespace_metadata(metadata)
144
- @stats.bump(:namespace_cache_api_updates)
145
- log.trace("parsed metadata for #{namespace_name}: #{metadata}") if log.trace?
146
- @namespace_cache[metadata['namespace_id']] = metadata
147
- return metadata
148
- rescue Exception => e
149
- log.debug(e)
150
- @stats.bump(:namespace_cache_api_nil_bad_resp_payload)
151
- log.trace("returning empty metadata for #{namespace_name} due to error '#{e}'") if log.trace?
152
- end
153
- end
154
- rescue Exception => kube_error
155
- @stats.bump(:namespace_cache_api_nil_error)
156
- log.debug "Exception '#{kube_error}' encountered fetching namespace metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
157
- end
121
+ namespace_object = @client.get_namespace(namespace_name)
122
+ log.trace("raw metadata for #{namespace_name}: #{namespace_object}") if log.trace?
123
+ metadata = parse_namespace_metadata(namespace_object)
124
+ @stats.bump(:namespace_cache_api_updates)
125
+ log.trace("parsed metadata for #{namespace_name}: #{metadata}") if log.trace?
126
+ @namespace_cache[metadata['namespace_id']] = metadata
127
+ rescue => kube_error
128
+ @stats.bump(:namespace_cache_api_nil_error)
129
+ log.debug "Exception '#{kube_error}' encountered fetching namespace metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
158
130
  {}
159
131
  end
160
132
 
@@ -174,7 +146,7 @@ module Fluent::Plugin
174
146
  require 'lru_redux'
175
147
  @stats = KubernetesMetadata::Stats.new
176
148
 
177
- if @de_dot && (@de_dot_separator =~ /\./).present?
149
+ if @de_dot && @de_dot_separator.include?(".")
178
150
  raise Fluent::ConfigError, "Invalid de_dot_separator: cannot be or contain '.'"
179
151
  end
180
152
 
@@ -201,7 +173,7 @@ module Fluent::Plugin
201
173
 
202
174
  env_host = ENV['KUBERNETES_SERVICE_HOST']
203
175
  env_port = ENV['KUBERNETES_SERVICE_PORT']
204
- if env_host.present? && env_port.present?
176
+ if present?(env_host) && present?(env_port)
205
177
  if env_host =~ Resolv::IPv6::Regex
206
178
  # Brackets are needed around IPv6 addresses
207
179
  env_host = "[#{env_host}]"
@@ -219,22 +191,21 @@ module Fluent::Plugin
219
191
  ca_cert = File.join(@secret_dir, K8_POD_CA_CERT)
220
192
  pod_token = File.join(@secret_dir, K8_POD_TOKEN)
221
193
 
222
- if !@ca_file.present? and File.exist?(ca_cert)
194
+ if !present?(@ca_file) and File.exist?(ca_cert)
223
195
  log.debug "Found CA certificate: #{ca_cert}"
224
196
  @ca_file = ca_cert
225
197
  end
226
198
 
227
- if !@bearer_token_file.present? and File.exist?(pod_token)
199
+ if !present?(@bearer_token_file) and File.exist?(pod_token)
228
200
  log.debug "Found pod token: #{pod_token}"
229
201
  @bearer_token_file = pod_token
230
202
  end
231
203
  end
232
204
 
233
- if @kubernetes_url.present?
234
-
205
+ if present?(@kubernetes_url)
235
206
  ssl_options = {
236
- client_cert: @client_cert.present? ? OpenSSL::X509::Certificate.new(File.read(@client_cert)) : nil,
237
- client_key: @client_key.present? ? OpenSSL::PKey::RSA.new(File.read(@client_key)) : nil,
207
+ client_cert: present?(@client_cert) ? OpenSSL::X509::Certificate.new(File.read(@client_cert)) : nil,
208
+ client_key: present?(@client_key) ? OpenSSL::PKey::RSA.new(File.read(@client_key)) : nil,
238
209
  ca_file: @ca_file,
239
210
  verify_ssl: @verify_ssl ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
240
211
  }
@@ -256,15 +227,19 @@ module Fluent::Plugin
256
227
 
257
228
  auth_options = {}
258
229
 
259
- if @bearer_token_file.present?
230
+ if present?(@bearer_token_file)
260
231
  bearer_token = File.read(@bearer_token_file)
261
232
  auth_options[:bearer_token] = bearer_token
262
233
  end
263
234
 
264
235
  log.debug "Creating K8S client"
265
- @client = Kubeclient::Client.new @kubernetes_url, @apiVersion,
266
- ssl_options: ssl_options,
267
- auth_options: auth_options
236
+ @client = Kubeclient::Client.new(
237
+ @kubernetes_url,
238
+ @apiVersion,
239
+ ssl_options: ssl_options,
240
+ auth_options: auth_options,
241
+ as: :parsed_symbolized
242
+ )
268
243
 
269
244
  begin
270
245
  @client.api_valid?
@@ -305,7 +280,7 @@ module Fluent::Plugin
305
280
  'pod_name' => pod_name
306
281
  }
307
282
  }
308
- if @kubernetes_url.present?
283
+ if present?(@kubernetes_url)
309
284
  pod_metadata = get_pod_metadata(container_id, namespace_name, pod_name, create_time, batch_miss_cache)
310
285
 
311
286
  if (pod_metadata.include? 'containers') && (pod_metadata['containers'].include? container_id) && !@skip_container_metadata
@@ -396,5 +371,9 @@ module Fluent::Plugin
396
371
  end
397
372
  end
398
373
 
374
+ # copied from activesupport
375
+ def present?(object)
376
+ object.respond_to?(:empty?) ? !object.empty? : !!object
377
+ end
399
378
  end
400
379
  end
@@ -39,65 +39,65 @@ module KubernetesMetadata
39
39
 
40
40
  def parse_namespace_metadata(namespace_object)
41
41
  labels = String.new
42
- labels = syms_to_strs(namespace_object['metadata']['labels'].to_h) unless @skip_labels
42
+ labels = syms_to_strs(namespace_object[:metadata][:labels].to_h) unless @skip_labels
43
43
 
44
- annotations = match_annotations(syms_to_strs(namespace_object['metadata']['annotations'].to_h))
44
+ annotations = match_annotations(syms_to_strs(namespace_object[:metadata][:annotations].to_h))
45
45
  if @de_dot
46
46
  self.de_dot!(labels) unless @skip_labels
47
47
  self.de_dot!(annotations)
48
48
  end
49
49
  kubernetes_metadata = {
50
- 'namespace_id' => namespace_object['metadata']['uid'],
51
- 'creation_timestamp' => namespace_object['metadata']['creationTimestamp']
50
+ 'namespace_id' => namespace_object[:metadata][:uid],
51
+ 'creation_timestamp' => namespace_object[:metadata][:creationTimestamp]
52
52
  }
53
53
  kubernetes_metadata['namespace_labels'] = labels unless labels.empty?
54
54
  kubernetes_metadata['namespace_annotations'] = annotations unless annotations.empty?
55
- return kubernetes_metadata
55
+ kubernetes_metadata
56
56
  end
57
57
 
58
58
  def parse_pod_metadata(pod_object)
59
59
  labels = String.new
60
- labels = syms_to_strs(pod_object['metadata']['labels'].to_h) unless @skip_labels
60
+ labels = syms_to_strs(pod_object[:metadata][:labels].to_h) unless @skip_labels
61
61
 
62
- annotations = match_annotations(syms_to_strs(pod_object['metadata']['annotations'].to_h))
62
+ annotations = match_annotations(syms_to_strs(pod_object[:metadata][:annotations].to_h))
63
63
  if @de_dot
64
64
  self.de_dot!(labels) unless @skip_labels
65
65
  self.de_dot!(annotations)
66
66
  end
67
67
 
68
- # collect container informations
68
+ # collect container information
69
69
  container_meta = {}
70
70
  begin
71
- pod_object['status']['containerStatuses'].each do|container_status|
71
+ pod_object[:status][:containerStatuses].each do|container_status|
72
72
  # get plain container id (eg. docker://hash -> hash)
73
- container_id = container_status['containerID'].sub /^[-_a-zA-Z0-9]+:\/\//, ''
73
+ container_id = container_status[:containerID].sub /^[-_a-zA-Z0-9]+:\/\//, ''
74
74
  unless @skip_container_metadata
75
75
  container_meta[container_id] = {
76
- 'name' => container_status['name'],
77
- 'image' => container_status['image'],
78
- 'image_id' => container_status['imageID']
76
+ 'name' => container_status[:name],
77
+ 'image' => container_status[:image],
78
+ 'image_id' => container_status[:imageID]
79
79
  }
80
80
  else
81
81
  container_meta[container_id] = {
82
- 'name' => container_status['name']
82
+ 'name' => container_status[:name]
83
83
  }
84
84
  end
85
85
  end
86
86
  rescue
87
- log.debug("parsing container meta information failed for: #{pod_object['metadata']['namespace']}/#{pod_object['metadata']['name']} ")
87
+ log.debug("parsing container meta information failed for: #{pod_object[:metadata][:namespace]}/#{pod_object[:metadata][:name]} ")
88
88
  end
89
89
 
90
90
  kubernetes_metadata = {
91
- 'namespace_name' => pod_object['metadata']['namespace'],
92
- 'pod_id' => pod_object['metadata']['uid'],
93
- 'pod_name' => pod_object['metadata']['name'],
91
+ 'namespace_name' => pod_object[:metadata][:namespace],
92
+ 'pod_id' => pod_object[:metadata][:uid],
93
+ 'pod_name' => pod_object[:metadata][:name],
94
94
  'containers' => syms_to_strs(container_meta),
95
- 'host' => pod_object['spec']['nodeName']
95
+ 'host' => pod_object[:spec][:nodeName]
96
96
  }
97
97
  kubernetes_metadata['annotations'] = annotations unless annotations.empty?
98
98
  kubernetes_metadata['labels'] = labels unless labels.empty?
99
99
  kubernetes_metadata['master_url'] = @kubernetes_url unless @skip_master_url
100
- return kubernetes_metadata
100
+ kubernetes_metadata
101
101
  end
102
102
 
103
103
  def syms_to_strs(hsh)
@@ -117,29 +117,3 @@ module KubernetesMetadata
117
117
 
118
118
  end
119
119
  end
120
-
121
- # copied from activesupport
122
- class Object
123
- # An object is blank if it's false, empty, or a whitespace string.
124
- # For example, +nil+, '', ' ', [], {}, and +false+ are all blank.
125
- #
126
- # This simplifies
127
- #
128
- # !address || address.empty?
129
- #
130
- # to
131
- #
132
- # address.blank?
133
- #
134
- # @return [true, false]
135
- def blank?
136
- respond_to?(:empty?) ? !!empty? : !self
137
- end
138
-
139
- # An object is present if it's not blank.
140
- #
141
- # @return [true, false]
142
- def present?
143
- !blank?
144
- end
145
- end