fluent-plugin-kubernetes_metadata_filter 2.1.4 → 2.9.4

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +57 -0
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +57 -0
  5. data/Gemfile +4 -2
  6. data/Gemfile.lock +158 -0
  7. data/README.md +48 -28
  8. data/Rakefile +15 -11
  9. data/fluent-plugin-kubernetes_metadata_filter.gemspec +25 -28
  10. data/lib/fluent/plugin/filter_kubernetes_metadata.rb +185 -131
  11. data/lib/fluent/plugin/kubernetes_metadata_cache_strategy.rb +27 -20
  12. data/lib/fluent/plugin/kubernetes_metadata_common.rb +59 -33
  13. data/lib/fluent/plugin/kubernetes_metadata_stats.rb +6 -6
  14. data/lib/fluent/plugin/kubernetes_metadata_test_api_adapter.rb +68 -0
  15. data/lib/fluent/plugin/kubernetes_metadata_util.rb +53 -0
  16. data/lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb +121 -27
  17. data/lib/fluent/plugin/kubernetes_metadata_watch_pods.rb +138 -29
  18. data/release_notes.md +42 -0
  19. data/test/cassettes/kubernetes_docker_metadata_annotations.yml +0 -34
  20. data/test/cassettes/{kubernetes_docker_metadata_dotted_labels.yml → kubernetes_docker_metadata_dotted_slashed_labels.yml} +0 -34
  21. data/test/cassettes/kubernetes_get_api_v1.yml +193 -0
  22. data/test/cassettes/kubernetes_get_api_v1_using_token.yml +195 -0
  23. data/test/cassettes/kubernetes_get_namespace_default.yml +69 -0
  24. data/test/cassettes/kubernetes_get_namespace_default_using_token.yml +71 -0
  25. data/test/cassettes/{kubernetes_docker_metadata.yml → kubernetes_get_pod.yml} +0 -82
  26. data/test/cassettes/{metadata_with_namespace_id.yml → kubernetes_get_pod_container_init.yml} +3 -134
  27. data/test/cassettes/{kubernetes_docker_metadata_using_bearer_token.yml → kubernetes_get_pod_using_token.yml} +5 -105
  28. data/test/cassettes/metadata_from_tag_and_journald_fields.yml +0 -255
  29. data/test/cassettes/metadata_from_tag_journald_and_kubernetes_fields.yml +0 -255
  30. data/test/cassettes/{non_kubernetes_docker_metadata.yml → valid_kubernetes_api_server_using_token.yml} +4 -44
  31. data/test/helper.rb +20 -2
  32. data/test/plugin/test_cache_stats.rb +10 -13
  33. data/test/plugin/test_cache_strategy.rb +158 -160
  34. data/test/plugin/test_filter_kubernetes_metadata.rb +480 -320
  35. data/test/plugin/test_utils.rb +56 -0
  36. data/test/plugin/test_watch_namespaces.rb +209 -55
  37. data/test/plugin/test_watch_pods.rb +302 -103
  38. data/test/plugin/watch_test.rb +52 -33
  39. metadata +69 -72
  40. data/circle.yml +0 -17
@@ -18,261 +18,6 @@
18
18
  #
19
19
  ---
20
20
  http_interactions:
21
- - request:
22
- method: get
23
- uri: https://localhost:8443/api
24
- body:
25
- encoding: US-ASCII
26
- string: ''
27
- headers:
28
- Accept:
29
- - "*/*; q=0.5, application/xml"
30
- Accept-Encoding:
31
- - gzip, deflate
32
- User-Agent:
33
- - Ruby
34
- response:
35
- status:
36
- code: 200
37
- message: OK
38
- headers:
39
- Content-Type:
40
- - application/json
41
- Date:
42
- - Fri, 08 May 2015 10:35:37 GMT
43
- Content-Length:
44
- - '67'
45
- body:
46
- encoding: UTF-8
47
- string: |-
48
- {
49
- "versions": [
50
- "v1"
51
- ]
52
- }
53
- http_version:
54
- recorded_at: Fri, 08 May 2015 10:35:37 GMT
55
- - request:
56
- method: get
57
- uri: https://localhost:8443/api/v1/namespaces/default/pods/fabric8-console-controller-98rqc
58
- body:
59
- encoding: US-ASCII
60
- string: ''
61
- headers:
62
- Accept:
63
- - "*/*; q=0.5, application/xml"
64
- Accept-Encoding:
65
- - gzip, deflate
66
- User-Agent:
67
- - Ruby
68
- response:
69
- status:
70
- code: 200
71
- message: OK
72
- headers:
73
- Content-Type:
74
- - application/json
75
- Date:
76
- - Fri, 08 May 2015 10:35:37 GMT
77
- Transfer-Encoding:
78
- - chunked
79
- body:
80
- encoding: UTF-8
81
- string: |-
82
- {
83
- "kind": "Pod",
84
- "apiVersion": "v1",
85
- "metadata": {
86
- "name": "fabric8-console-controller-98rqc",
87
- "generateName": "fabric8-console-controller-",
88
- "namespace": "default",
89
- "selfLink": "/api/v1/namespaces/default/pods/fabric8-console-controller-98rqc",
90
- "uid": "c76927af-f563-11e4-b32d-54ee7527188d",
91
- "resourceVersion": "122",
92
- "creationTimestamp": "2015-05-08T09:22:42Z",
93
- "labels": {
94
- "component": "fabric8Console"
95
- }
96
- },
97
- "spec": {
98
- "volumes": [
99
- {
100
- "name": "openshift-cert-secrets",
101
- "hostPath": null,
102
- "emptyDir": null,
103
- "gcePersistentDisk": null,
104
- "gitRepo": null,
105
- "secret": {
106
- "secretName": "openshift-cert-secrets"
107
- },
108
- "nfs": null,
109
- "iscsi": null,
110
- "glusterfs": null
111
- }
112
- ],
113
- "containers": [
114
- {
115
- "name": "fabric8-console-container",
116
- "image": "fabric8/hawtio-kubernetes:latest",
117
- "ports": [
118
- {
119
- "containerPort": 9090,
120
- "protocol": "TCP"
121
- }
122
- ],
123
- "env": [
124
- {
125
- "name": "OAUTH_CLIENT_ID",
126
- "value": "fabric8-console"
127
- },
128
- {
129
- "name": "OAUTH_AUTHORIZE_URI",
130
- "value": "https://localhost:8443/oauth/authorize"
131
- }
132
- ],
133
- "resources": {},
134
- "volumeMounts": [
135
- {
136
- "name": "openshift-cert-secrets",
137
- "readOnly": true,
138
- "mountPath": "/etc/secret-volume"
139
- }
140
- ],
141
- "terminationMessagePath": "/dev/termination-log",
142
- "imagePullPolicy": "IfNotPresent",
143
- "capabilities": {}
144
- }
145
- ],
146
- "restartPolicy": "Always",
147
- "dnsPolicy": "ClusterFirst",
148
- "nodeName": "jimmi-redhat.localnet"
149
- },
150
- "status": {
151
- "phase": "Running",
152
- "Condition": [
153
- {
154
- "type": "Ready",
155
- "status": "True"
156
- }
157
- ],
158
- "hostIP": "172.17.42.1",
159
- "podIP": "172.17.0.8",
160
- "containerStatuses": [
161
- {
162
- "name": "fabric8-console-container",
163
- "state": {
164
- "running": {
165
- "startedAt": "2015-05-08T09:22:44Z"
166
- }
167
- },
168
- "lastState": {},
169
- "ready": true,
170
- "restartCount": 0,
171
- "image": "fabric8/hawtio-kubernetes:latest",
172
- "imageID": "docker://b2bd1a24a68356b2f30128e6e28e672c1ef92df0d9ec01ec0c7faea5d77d2303",
173
- "containerID": "docker://49095a2894da899d3b327c5fde1e056a81376cc9a8f8b09a195f2a92bceed459"
174
- }
175
- ]
176
- }
177
- }
178
- http_version:
179
- recorded_at: Fri, 08 May 2015 10:35:37 GMT
180
- - request:
181
- method: get
182
- uri: https://localhost:8443/api/v1/namespaces/default
183
- body:
184
- encoding: US-ASCII
185
- string: ''
186
- headers:
187
- Accept:
188
- - "*/*; q=0.5, application/xml"
189
- Accept-Encoding:
190
- - gzip, deflate
191
- User-Agent:
192
- - Ruby
193
- response:
194
- status:
195
- code: 200
196
- message: OK
197
- headers:
198
- Content-Type:
199
- - application/json
200
- Date:
201
- - Fri, 08 May 2015 10:35:37 GMT
202
- Transfer-Encoding:
203
- - chunked
204
- body:
205
- encoding: UTF-8
206
- string: |-
207
- {
208
- "kind": "Namespace",
209
- "apiVersion": "v1",
210
- "metadata": {
211
- "name": "default",
212
- "selfLink": "/api/v1/namespaces/default",
213
- "uid": "898268c8-4a36-11e5-9d81-42010af0194c",
214
- "resourceVersion": "6",
215
- "creationTimestamp": "2015-05-08T09:22:01Z"
216
- },
217
- "spec": {
218
- "finalizers": [
219
- "kubernetes"
220
- ]
221
- },
222
- "status": {
223
- "phase": "Active"
224
- }
225
- }
226
- http_version:
227
- recorded_at: Fri, 08 May 2015 10:35:37 GMT
228
- - request:
229
- method: get
230
- uri: https://localhost:8443/api/v1/namespaces/default
231
- body:
232
- encoding: US-ASCII
233
- string: ''
234
- headers:
235
- Accept:
236
- - "*/*; q=0.5, application/xml"
237
- Accept-Encoding:
238
- - gzip, deflate
239
- User-Agent:
240
- - Ruby
241
- response:
242
- status:
243
- code: 200
244
- message: OK
245
- headers:
246
- Content-Type:
247
- - application/json
248
- Date:
249
- - Fri, 08 May 2015 10:35:37 GMT
250
- Transfer-Encoding:
251
- - chunked
252
- body:
253
- encoding: UTF-8
254
- string: |-
255
- {
256
- "kind": "Namespace",
257
- "apiVersion": "v1",
258
- "metadata": {
259
- "name": "default",
260
- "selfLink": "/api/v1/namespaces/default",
261
- "uid": "898268c8-4a36-11e5-9d81-42010af0194c",
262
- "resourceVersion": "6",
263
- "creationTimestamp": "2015-05-08T09:22:01Z"
264
- },
265
- "spec": {
266
- "finalizers": [
267
- "kubernetes"
268
- ]
269
- },
270
- "status": {
271
- "phase": "Active"
272
- }
273
- }
274
- http_version:
275
- recorded_at: Fri, 08 May 2015 10:35:37 GMT
276
21
  - request:
277
22
  method: get
278
23
  uri: https://localhost:8443/api/v1/namespaces/journald-namespace-name/pods/journald-pod-name
@@ -31,6 +31,8 @@ http_interactions:
31
31
  - gzip, deflate
32
32
  User-Agent:
33
33
  - Ruby
34
+ Authorization:
35
+ - Bearer YzYyYzFlODMtODdhNS00ZTMyLWIzMmItNmY4NDc4OTI1ZWFh
34
36
  response:
35
37
  status:
36
38
  code: 200
@@ -39,7 +41,7 @@ http_interactions:
39
41
  Content-Type:
40
42
  - application/json
41
43
  Date:
42
- - Fri, 08 May 2015 10:35:37 GMT
44
+ - Fri, 08 May 2015 10:13:54 GMT
43
45
  Content-Length:
44
46
  - '67'
45
47
  body:
@@ -51,47 +53,5 @@ http_interactions:
51
53
  ]
52
54
  }
53
55
  http_version:
54
- recorded_at: Fri, 08 May 2015 10:35:37 GMT
55
- - request:
56
- method: get
57
- uri: https://localhost:8443/api/v1/namespaces/default/pods/fabric8-forge-controller-ymkew
58
- body:
59
- encoding: US-ASCII
60
- string: ''
61
- headers:
62
- Accept:
63
- - "*/*; q=0.5, application/xml"
64
- Accept-Encoding:
65
- - gzip, deflate
66
- User-Agent:
67
- - Ruby
68
- response:
69
- status:
70
- code: 404
71
- message: Not Found
72
- headers:
73
- Content-Type:
74
- - application/json
75
- Date:
76
- - Fri, 08 May 2015 10:35:37 GMT
77
- Content-Length:
78
- - '278'
79
- body:
80
- encoding: UTF-8
81
- string: |-
82
- {
83
- "kind": "Status",
84
- "apiVersion": "v1",
85
- "metadata": {},
86
- "status": "Failure",
87
- "message": "pods \"fabric8-forge-controller-ymkew\" not found",
88
- "reason": "NotFound",
89
- "details": {
90
- "id": "fabric8-forge-controller-ymkew",
91
- "kind": "pods"
92
- },
93
- "code": 404
94
- }
95
- http_version:
96
- recorded_at: Fri, 08 May 2015 10:35:37 GMT
56
+ recorded_at: Fri, 08 May 2015 10:13:54 GMT
97
57
  recorded_with: VCR 2.9.3
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
3
5
  # Kubernetes metadata
@@ -16,6 +18,7 @@
16
18
  # See the License for the specific language governing permissions and
17
19
  # limitations under the License.
18
20
  #
21
+ require 'bundler/setup'
19
22
  require 'codeclimate-test-reporter'
20
23
  SimpleCov.start do
21
24
  formatter SimpleCov::Formatter::MultiFormatter.new [
@@ -31,8 +34,14 @@ require 'fileutils'
31
34
  require 'fluent/log'
32
35
  require 'fluent/test'
33
36
  require 'minitest/autorun'
34
- require 'webmock/test_unit'
35
37
  require 'vcr'
38
+ require 'ostruct'
39
+ require 'fluent/plugin/filter_kubernetes_metadata'
40
+ require 'fluent/test/driver/filter'
41
+ require 'kubeclient'
42
+
43
+ require 'webmock/test_unit'
44
+ WebMock.disable_net_connect!
36
45
 
37
46
  VCR.configure do |config|
38
47
  config.cassette_library_dir = 'test/cassettes'
@@ -58,7 +67,16 @@ def ipv6_enabled?
58
67
  begin
59
68
  TCPServer.open('::1', 0)
60
69
  true
61
- rescue
70
+ rescue StandardError
62
71
  false
63
72
  end
64
73
  end
74
+
75
+ # TEST_NAME='foo' ruby test_file.rb to run a single test case
76
+ if ENV['TEST_NAME']
77
+ (class << Test::Unit::TestCase; self; end).prepend(Module.new do
78
+ def test(name)
79
+ super if name == ENV['TEST_NAME']
80
+ end
81
+ end)
82
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
3
5
  # Kubernetes metadata
@@ -17,20 +19,15 @@
17
19
  # limitations under the License.
18
20
  #
19
21
  require_relative '../helper'
20
- require 'fluent/plugin/kubernetes_metadata_stats'
21
- require 'webmock/test_unit'
22
- WebMock.disable_net_connect!
23
22
 
24
23
  class KubernetesMetadataCacheStatsTest < Test::Unit::TestCase
25
-
26
- test 'watch stats' do
27
- require 'lru_redux'
28
- stats = KubernetesMetadata::Stats.new
29
- stats.bump(:missed)
30
- stats.bump(:deleted)
31
- stats.bump(:deleted)
24
+ test 'watch stats' do
25
+ require 'lru_redux'
26
+ stats = KubernetesMetadata::Stats.new
27
+ stats.bump(:missed)
28
+ stats.bump(:deleted)
29
+ stats.bump(:deleted)
32
30
 
33
- assert_equal("stats - deleted: 2, missed: 1", stats.to_s)
34
- end
35
-
31
+ assert_equal('stats - deleted: 2, missed: 1', stats.to_s)
32
+ end
36
33
  end