fluent-plugin-kubernetes_metadata_filter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +201 -0
- data/README.md +99 -0
- data/Rakefile +37 -0
- data/circle.yml +3 -0
- data/fluent-plugin-kubernetes_metadata_filter.gemspec +37 -0
- data/lib/fluent/plugin/filter_kubernetes_metadata.rb +107 -0
- data/test/cassettes/kubernetes_docker_metadata.yml +182 -0
- data/test/cassettes/non_kubernetes_docker_metadata.yml +99 -0
- data/test/cassettes/valid_kubernetes_api_server.yml +57 -0
- data/test/helper.rb +65 -0
- data/test/plugin/test_filter_kubernetes_metadata.rb +124 -0
- metadata +245 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b09f5217a8e64acff136a114d222513bc0dbc6e9
|
4
|
+
data.tar.gz: 2d5d1e8cc206a9290f74e3428c3aa01f2c2fd46c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1e354e6e49a5c3461a9b038992d6f3a74cd961405672974f8127387aa00ab22d2cefa0d82722bc7245eb3a7f17a8729224b8af8581895e4556a58ac3a323f5a
|
7
|
+
data.tar.gz: 8b8845065dc989f610e31e72f4daaad7c0806d4163a2c257564bda38f96ce2edcaedfc1204877732da0a6e38e340d25015671fc1edcda5be8910cd9204e67d0f
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# fluent-plugin-kubernetes_metadata_filter, a plugin for [Fluentd](http://fluentd.org)
|
2
|
+
[![Circle CI](https://circleci.com/gh/fabric8io/fluent-plugin-kubernetes_metadata_filter.svg?style=svg)](https://circleci.com/gh/fabric8io/fluent-plugin-kubernetes_metadata_filter)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/fabric8io/fluent-plugin-kubernetes_metadata_filter/badges/gpa.svg)](https://codeclimate.com/github/fabric8io/fluent-plugin-kubernetes_metadata_filter)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/fabric8io/fluent-plugin-kubernetes_metadata_filter/badges/coverage.svg)](https://codeclimate.com/github/fabric8io/fluent-plugin-kubernetes_metadata_filter)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install fluent-plugin-kubernetes_metadata_filter
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
Configuration options are:
|
13
|
+
|
14
|
+
* `kubernetes_url` - URL to the API server. *This is required*
|
15
|
+
* `apiVersion` - API version to use (default: `v1beta3`)
|
16
|
+
* `client_cert` - path to a client cert file to authenticate to the API server
|
17
|
+
* `client_key` - path to a client key file to authenticate to the API server
|
18
|
+
* `ca_file` - path to CA file for Kubernetes server certificate validation
|
19
|
+
* `verify_ssl` - validate SSL certificates (default: true)
|
20
|
+
* `container_name_to_kubernetes_name_regexp` - the regular expression used to extract kubernetes metadata (pod name, container name, namespace) from the Docker container name. This must used named capture groups for `pod_container_name`, `pod_name` & `namespace` (default: `'\/?[^_]+_(?<pod_container_name>[^\.]+)[^_]+_(?<pod_name>[^_]+)_(?<namespace>[^_]+)'`)
|
21
|
+
* `cache_size` - size of the cache of Kubernetes metadata to reduce requests to the API server (default: `1000`)
|
22
|
+
|
23
|
+
```
|
24
|
+
<source>
|
25
|
+
type tail
|
26
|
+
path /var/lib/docker/containers/*/*-json.log
|
27
|
+
pos_file fluentd-docker.pos
|
28
|
+
time_format %Y-%m-%dT%H:%M:%S
|
29
|
+
tag docker.*
|
30
|
+
format json
|
31
|
+
read_from_head true
|
32
|
+
</source>
|
33
|
+
|
34
|
+
<filter docker.var.lib.docker.containers.*.*.log>
|
35
|
+
type docker_metadata
|
36
|
+
</filter>
|
37
|
+
|
38
|
+
<filter docker.var.lib.docker.containers.*.*.log>
|
39
|
+
type kubernetes_metadata
|
40
|
+
kubernetes_url https://localhost:8443
|
41
|
+
</filter>
|
42
|
+
|
43
|
+
<match **>
|
44
|
+
type stdout
|
45
|
+
</match>
|
46
|
+
```
|
47
|
+
|
48
|
+
## Example input/output
|
49
|
+
|
50
|
+
Docker logs in JSON format. Log files are normally in
|
51
|
+
`/var/lib/docker/containers/*/*-json.log`, depending on what your Docker
|
52
|
+
data directory is.
|
53
|
+
|
54
|
+
Assuming following inputs are coming from a log file:
|
55
|
+
df14e0d5ae4c07284fa636d739c8fc2e6b52bc344658de7d3f08c36a2e804115-json.log:
|
56
|
+
```
|
57
|
+
{
|
58
|
+
"log": "2015/05/05 19:54:41 \n",
|
59
|
+
"stream": "stderr",
|
60
|
+
"time": "2015-05-05T19:54:41.240447294Z"
|
61
|
+
}
|
62
|
+
```
|
63
|
+
|
64
|
+
Then output becomes as belows
|
65
|
+
```
|
66
|
+
{
|
67
|
+
"log": "2015/05/05 19:54:41 \n",
|
68
|
+
"stream": "stderr",
|
69
|
+
"docker": {
|
70
|
+
"id": "df14e0d5ae4c07284fa636d739c8fc2e6b52bc344658de7d3f08c36a2e804115",
|
71
|
+
"name": "/k8s_fabric8-console-container.efbd6e64_fabric8-console-controller-9knhj_default_8ae2f621-f360-11e4-8d12-54ee7527188d_7ec9aa3e",
|
72
|
+
"container_hostname": "fabric8-console-controller-9knhj",
|
73
|
+
"image": "fabric8/hawtio-kubernetes:latest",
|
74
|
+
"image_id": "b2bd1a24a68356b2f30128e6e28e672c1ef92df0d9ec01ec0c7faea5d77d2303",
|
75
|
+
"labels": {}
|
76
|
+
}
|
77
|
+
"kubernetes": {
|
78
|
+
"host": "jimmi-redhat.localnet",
|
79
|
+
"pod_name":"fabric8-console-controller-98rqc",
|
80
|
+
"container_name": "fabric8-console-container",
|
81
|
+
"namespace": "default",
|
82
|
+
"uid": "c76927af-f563-11e4-b32d-54ee7527188d",
|
83
|
+
"labels": {
|
84
|
+
"component": "fabric8Console"
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork it
|
93
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
95
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
96
|
+
5. Create new Pull Request
|
97
|
+
|
98
|
+
## Copyright
|
99
|
+
Copyright (c) 2015 jimmidyson
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "bump/tasks"
|
4
|
+
|
5
|
+
task :test => [:base_test]
|
6
|
+
|
7
|
+
task :default => [:test, :build]
|
8
|
+
|
9
|
+
desc 'Run test_unit based test'
|
10
|
+
Rake::TestTask.new(:base_test) do |t|
|
11
|
+
# To run test for only one file (or file path pattern)
|
12
|
+
# $ bundle exec rake base_test TEST=test/test_specified_path.rb
|
13
|
+
# $ bundle exec rake base_test TEST=test/test_*.rb
|
14
|
+
t.libs << "test"
|
15
|
+
t.test_files = Dir["test/**/test_*.rb"].sort
|
16
|
+
t.verbose = true
|
17
|
+
#t.warning = true
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Add copyright headers"
|
21
|
+
task :headers do
|
22
|
+
require 'rubygems'
|
23
|
+
require 'copyright_header'
|
24
|
+
|
25
|
+
args = {
|
26
|
+
:license => 'ASL2',
|
27
|
+
:copyright_software => 'Fluentd Kubernetes Metadata Filter Plugin',
|
28
|
+
:copyright_software_description => "Enrich Fluentd events with Kubernetes metadata",
|
29
|
+
:copyright_holders => ['Red Hat, Inc.'],
|
30
|
+
:copyright_years => ['2015'],
|
31
|
+
:add_path => 'lib:test',
|
32
|
+
:output_dir => '.'
|
33
|
+
}
|
34
|
+
|
35
|
+
command_line = CopyrightHeader::CommandLine.new( args )
|
36
|
+
command_line.execute
|
37
|
+
end
|
data/circle.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "fluent-plugin-kubernetes_metadata_filter"
|
7
|
+
gem.version = "0.1.0"
|
8
|
+
gem.authors = ["Jimmi Dyson"]
|
9
|
+
gem.email = ["jimmidyson@gmail.com"]
|
10
|
+
gem.description = %q{Filter plugin to add Kubernetes metadata}
|
11
|
+
gem.summary = %q{Filter plugin to add Kubernetes metadata}
|
12
|
+
gem.homepage = "https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter"
|
13
|
+
gem.license = "ASL2"
|
14
|
+
|
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
|
+
gem.has_rdoc = false
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 2.0.0'
|
22
|
+
|
23
|
+
gem.add_runtime_dependency "fluentd"
|
24
|
+
gem.add_runtime_dependency "lru_redux"
|
25
|
+
gem.add_runtime_dependency "kubeclient"
|
26
|
+
gem.add_runtime_dependency "fluent-plugin-docker_metadata_filter"
|
27
|
+
|
28
|
+
gem.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
gem.add_development_dependency "rake"
|
30
|
+
gem.add_development_dependency "minitest", "~> 4.0"
|
31
|
+
gem.add_development_dependency "test-unit", "~> 3.0.2"
|
32
|
+
gem.add_development_dependency "test-unit-rr", "~> 1.0.3"
|
33
|
+
gem.add_development_dependency "copyright-header"
|
34
|
+
gem.add_development_dependency "webmock"
|
35
|
+
gem.add_development_dependency "vcr"
|
36
|
+
gem.add_development_dependency "bump"
|
37
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
|
3
|
+
# Kubernetes metadata
|
4
|
+
#
|
5
|
+
# Copyright 2015 Red Hat, Inc.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
module Fluent
|
20
|
+
class KubernetesMetadataFilter < Fluent::Filter
|
21
|
+
Fluent::Plugin.register_filter('kubernetes_metadata', self)
|
22
|
+
|
23
|
+
config_param :cache_size, :integer, :default => 1000
|
24
|
+
config_param :kubernetes_url, :string
|
25
|
+
config_param :apiVersion, :string, :default => 'v1beta3'
|
26
|
+
config_param :client_cert, :string, :default => ''
|
27
|
+
config_param :client_key, :string, :default => ''
|
28
|
+
config_param :ca_file, :string, :default => ''
|
29
|
+
config_param :verify_ssl, :bool, :default => true
|
30
|
+
config_param :container_name_to_kubernetes_name_regexp,
|
31
|
+
:string,
|
32
|
+
:default => '\/?[^_]+_(?<pod_container_name>[^\.]+)[^_]+_(?<pod_name>[^_]+)_(?<namespace>[^_]+)'
|
33
|
+
|
34
|
+
def self.get_metadata(pod_name, container_name, namespace)
|
35
|
+
begin
|
36
|
+
metadata = @@client.get_pod(pod_name, namespace)
|
37
|
+
if metadata
|
38
|
+
return {
|
39
|
+
:uid => metadata['metadata']['uid'],
|
40
|
+
:namespace => metadata['metadata']['namespace'],
|
41
|
+
:pod_name => metadata['metadata']['name'],
|
42
|
+
:container_name => container_name,
|
43
|
+
:labels => metadata['metadata']['labels'].to_h,
|
44
|
+
:host => metadata['spec']['host']
|
45
|
+
}
|
46
|
+
end
|
47
|
+
rescue KubeException
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
def configure(conf)
|
57
|
+
super
|
58
|
+
|
59
|
+
require 'kubeclient'
|
60
|
+
require 'active_support/core_ext/object/blank'
|
61
|
+
require 'lru_redux'
|
62
|
+
|
63
|
+
@@client = Kubeclient::Client.new @kubernetes_url, @apiVersion
|
64
|
+
|
65
|
+
if @client_cert.present? && @client_key.present? && @ca_file.present?
|
66
|
+
|
67
|
+
@@client.ssl_options(
|
68
|
+
client_cert: OpenSSL::X509::Certificate.new(File.read(@client_cert)),
|
69
|
+
client_key: OpenSSL::PKey::RSA.new(File.read(@client_key)),
|
70
|
+
ca_file: @ca_file,
|
71
|
+
verify_ssl: @verify_ssl ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
raise Fluent::ConfigError, 'Invalid Kubernetes API endpoint' unless @@client.api_valid?
|
76
|
+
|
77
|
+
@cache = LruRedux::ThreadSafeCache.new(@cache_size)
|
78
|
+
@container_name_to_kubernetes_name_regexp_compiled = Regexp.compile(@container_name_to_kubernetes_name_regexp)
|
79
|
+
end
|
80
|
+
|
81
|
+
def filter_stream(tag, es)
|
82
|
+
new_es = MultiEventStream.new
|
83
|
+
|
84
|
+
es.each {|time, record|
|
85
|
+
if record.has_key?(:docker) && record[:docker].has_key?(:name)
|
86
|
+
metadata = @cache.getset(record[:docker][:name]){
|
87
|
+
match_data = record[:docker][:name].match(@container_name_to_kubernetes_name_regexp_compiled)
|
88
|
+
if match_data
|
89
|
+
KubernetesMetadataFilter.get_metadata(
|
90
|
+
match_data[:pod_name],
|
91
|
+
match_data[:pod_container_name],
|
92
|
+
match_data[:namespace]
|
93
|
+
)
|
94
|
+
end
|
95
|
+
}
|
96
|
+
|
97
|
+
record[:kubernetes] = metadata if metadata
|
98
|
+
end
|
99
|
+
|
100
|
+
new_es.add(time, record)
|
101
|
+
}
|
102
|
+
|
103
|
+
new_es
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
|
3
|
+
# Kubernetes metadata
|
4
|
+
#
|
5
|
+
# Copyright 2015 Red Hat, Inc.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
---
|
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
|
+
"v1beta1",
|
51
|
+
"v1beta2",
|
52
|
+
"v1beta3"
|
53
|
+
]
|
54
|
+
}
|
55
|
+
http_version:
|
56
|
+
recorded_at: Fri, 08 May 2015 10:35:37 GMT
|
57
|
+
- request:
|
58
|
+
method: get
|
59
|
+
uri: https://localhost:8443/api/v1beta3/namespaces/default/pods/fabric8-console-controller-98rqc
|
60
|
+
body:
|
61
|
+
encoding: US-ASCII
|
62
|
+
string: ''
|
63
|
+
headers:
|
64
|
+
Accept:
|
65
|
+
- "*/*; q=0.5, application/xml"
|
66
|
+
Accept-Encoding:
|
67
|
+
- gzip, deflate
|
68
|
+
User-Agent:
|
69
|
+
- Ruby
|
70
|
+
response:
|
71
|
+
status:
|
72
|
+
code: 200
|
73
|
+
message: OK
|
74
|
+
headers:
|
75
|
+
Content-Type:
|
76
|
+
- application/json
|
77
|
+
Date:
|
78
|
+
- Fri, 08 May 2015 10:35:37 GMT
|
79
|
+
Transfer-Encoding:
|
80
|
+
- chunked
|
81
|
+
body:
|
82
|
+
encoding: UTF-8
|
83
|
+
string: |-
|
84
|
+
{
|
85
|
+
"kind": "Pod",
|
86
|
+
"apiVersion": "v1beta3",
|
87
|
+
"metadata": {
|
88
|
+
"name": "fabric8-console-controller-98rqc",
|
89
|
+
"generateName": "fabric8-console-controller-",
|
90
|
+
"namespace": "default",
|
91
|
+
"selfLink": "/api/v1beta3/namespaces/default/pods/fabric8-console-controller-98rqc",
|
92
|
+
"uid": "c76927af-f563-11e4-b32d-54ee7527188d",
|
93
|
+
"resourceVersion": "122",
|
94
|
+
"creationTimestamp": "2015-05-08T09:22:42Z",
|
95
|
+
"labels": {
|
96
|
+
"component": "fabric8Console"
|
97
|
+
}
|
98
|
+
},
|
99
|
+
"spec": {
|
100
|
+
"volumes": [
|
101
|
+
{
|
102
|
+
"name": "openshift-cert-secrets",
|
103
|
+
"hostPath": null,
|
104
|
+
"emptyDir": null,
|
105
|
+
"gcePersistentDisk": null,
|
106
|
+
"gitRepo": null,
|
107
|
+
"secret": {
|
108
|
+
"secretName": "openshift-cert-secrets"
|
109
|
+
},
|
110
|
+
"nfs": null,
|
111
|
+
"iscsi": null,
|
112
|
+
"glusterfs": null
|
113
|
+
}
|
114
|
+
],
|
115
|
+
"containers": [
|
116
|
+
{
|
117
|
+
"name": "fabric8-console-container",
|
118
|
+
"image": "fabric8/hawtio-kubernetes:latest",
|
119
|
+
"ports": [
|
120
|
+
{
|
121
|
+
"containerPort": 9090,
|
122
|
+
"protocol": "TCP"
|
123
|
+
}
|
124
|
+
],
|
125
|
+
"env": [
|
126
|
+
{
|
127
|
+
"name": "OAUTH_CLIENT_ID",
|
128
|
+
"value": "fabric8-console"
|
129
|
+
},
|
130
|
+
{
|
131
|
+
"name": "OAUTH_AUTHORIZE_URI",
|
132
|
+
"value": "https://localhost:8443/oauth/authorize"
|
133
|
+
}
|
134
|
+
],
|
135
|
+
"resources": {},
|
136
|
+
"volumeMounts": [
|
137
|
+
{
|
138
|
+
"name": "openshift-cert-secrets",
|
139
|
+
"readOnly": true,
|
140
|
+
"mountPath": "/etc/secret-volume"
|
141
|
+
}
|
142
|
+
],
|
143
|
+
"terminationMessagePath": "/dev/termination-log",
|
144
|
+
"imagePullPolicy": "IfNotPresent",
|
145
|
+
"capabilities": {}
|
146
|
+
}
|
147
|
+
],
|
148
|
+
"restartPolicy": "Always",
|
149
|
+
"dnsPolicy": "ClusterFirst",
|
150
|
+
"host": "jimmi-redhat.localnet"
|
151
|
+
},
|
152
|
+
"status": {
|
153
|
+
"phase": "Running",
|
154
|
+
"Condition": [
|
155
|
+
{
|
156
|
+
"type": "Ready",
|
157
|
+
"status": "True"
|
158
|
+
}
|
159
|
+
],
|
160
|
+
"hostIP": "172.17.42.1",
|
161
|
+
"podIP": "172.17.0.8",
|
162
|
+
"containerStatuses": [
|
163
|
+
{
|
164
|
+
"name": "fabric8-console-container",
|
165
|
+
"state": {
|
166
|
+
"running": {
|
167
|
+
"startedAt": "2015-05-08T09:22:44Z"
|
168
|
+
}
|
169
|
+
},
|
170
|
+
"lastState": {},
|
171
|
+
"ready": true,
|
172
|
+
"restartCount": 0,
|
173
|
+
"image": "fabric8/hawtio-kubernetes:latest",
|
174
|
+
"imageID": "docker://b2bd1a24a68356b2f30128e6e28e672c1ef92df0d9ec01ec0c7faea5d77d2303",
|
175
|
+
"containerID": "docker://49095a2894da899d3b327c5fde1e056a81376cc9a8f8b09a195f2a92bceed459"
|
176
|
+
}
|
177
|
+
]
|
178
|
+
}
|
179
|
+
}
|
180
|
+
http_version:
|
181
|
+
recorded_at: Fri, 08 May 2015 10:35:37 GMT
|
182
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
|
3
|
+
# Kubernetes metadata
|
4
|
+
#
|
5
|
+
# Copyright 2015 Red Hat, Inc.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
---
|
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
|
+
"v1beta1",
|
51
|
+
"v1beta2",
|
52
|
+
"v1beta3"
|
53
|
+
]
|
54
|
+
}
|
55
|
+
http_version:
|
56
|
+
recorded_at: Fri, 08 May 2015 10:35:37 GMT
|
57
|
+
- request:
|
58
|
+
method: get
|
59
|
+
uri: https://localhost:8443/api/v1beta3/namespaces/default/pods/fabric8-forge-controller-ymkew
|
60
|
+
body:
|
61
|
+
encoding: US-ASCII
|
62
|
+
string: ''
|
63
|
+
headers:
|
64
|
+
Accept:
|
65
|
+
- "*/*; q=0.5, application/xml"
|
66
|
+
Accept-Encoding:
|
67
|
+
- gzip, deflate
|
68
|
+
User-Agent:
|
69
|
+
- Ruby
|
70
|
+
response:
|
71
|
+
status:
|
72
|
+
code: 404
|
73
|
+
message: Not Found
|
74
|
+
headers:
|
75
|
+
Content-Type:
|
76
|
+
- application/json
|
77
|
+
Date:
|
78
|
+
- Fri, 08 May 2015 10:35:37 GMT
|
79
|
+
Content-Length:
|
80
|
+
- '278'
|
81
|
+
body:
|
82
|
+
encoding: UTF-8
|
83
|
+
string: |-
|
84
|
+
{
|
85
|
+
"kind": "Status",
|
86
|
+
"apiVersion": "v1beta3",
|
87
|
+
"metadata": {},
|
88
|
+
"status": "Failure",
|
89
|
+
"message": "pods \"fabric8-forge-controller-ymkew\" not found",
|
90
|
+
"reason": "NotFound",
|
91
|
+
"details": {
|
92
|
+
"id": "fabric8-forge-controller-ymkew",
|
93
|
+
"kind": "pods"
|
94
|
+
},
|
95
|
+
"code": 404
|
96
|
+
}
|
97
|
+
http_version:
|
98
|
+
recorded_at: Fri, 08 May 2015 10:35:37 GMT
|
99
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
|
3
|
+
# Kubernetes metadata
|
4
|
+
#
|
5
|
+
# Copyright 2015 Red Hat, Inc.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
---
|
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:13:54 GMT
|
43
|
+
Content-Length:
|
44
|
+
- '67'
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: |-
|
48
|
+
{
|
49
|
+
"versions": [
|
50
|
+
"v1beta1",
|
51
|
+
"v1beta2",
|
52
|
+
"v1beta3"
|
53
|
+
]
|
54
|
+
}
|
55
|
+
http_version:
|
56
|
+
recorded_at: Fri, 08 May 2015 10:13:54 GMT
|
57
|
+
recorded_with: VCR 2.9.3
|
data/test/helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
|
3
|
+
# Kubernetes metadata
|
4
|
+
#
|
5
|
+
# Copyright 2015 Red Hat, Inc.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
require "codeclimate-test-reporter"
|
20
|
+
SimpleCov.start do
|
21
|
+
formatter SimpleCov::Formatter::MultiFormatter[
|
22
|
+
SimpleCov::Formatter::HTMLFormatter,
|
23
|
+
CodeClimate::TestReporter::Formatter
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rr'
|
28
|
+
require 'test/unit'
|
29
|
+
require 'test/unit/rr'
|
30
|
+
require 'fileutils'
|
31
|
+
require 'fluent/log'
|
32
|
+
require 'fluent/test'
|
33
|
+
require 'webmock/test_unit'
|
34
|
+
require 'vcr'
|
35
|
+
|
36
|
+
VCR.configure do |config|
|
37
|
+
config.cassette_library_dir = "test/cassettes"
|
38
|
+
config.hook_into :webmock # or :fakeweb
|
39
|
+
config.ignore_hosts 'codeclimate.com'
|
40
|
+
end
|
41
|
+
|
42
|
+
unless defined?(Test::Unit::AssertionFailedError)
|
43
|
+
class Test::Unit::AssertionFailedError < StandardError
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def unused_port
|
48
|
+
s = TCPServer.open(0)
|
49
|
+
port = s.addr[1]
|
50
|
+
s.close
|
51
|
+
port
|
52
|
+
end
|
53
|
+
|
54
|
+
def ipv6_enabled?
|
55
|
+
require 'socket'
|
56
|
+
|
57
|
+
begin
|
58
|
+
TCPServer.open("::1", 0)
|
59
|
+
true
|
60
|
+
rescue
|
61
|
+
false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
$log = Fluent::Log.new(Fluent::Test::DummyLogDevice.new, Fluent::Log::LEVEL_WARN)
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Metadata Filter Plugin - Enrich Fluentd events with
|
3
|
+
# Kubernetes metadata
|
4
|
+
#
|
5
|
+
# Copyright 2015 Red Hat, Inc.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
require_relative '../helper'
|
20
|
+
require 'fluent/plugin/filter_kubernetes_metadata'
|
21
|
+
|
22
|
+
require 'webmock/test_unit'
|
23
|
+
WebMock.disable_net_connect!
|
24
|
+
|
25
|
+
class KubernetesMetadataFilterTest < Test::Unit::TestCase
|
26
|
+
include Fluent
|
27
|
+
|
28
|
+
setup do
|
29
|
+
Fluent::Test.setup
|
30
|
+
@time = Fluent::Engine.now
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_driver(conf = '')
|
34
|
+
Test::FilterTestDriver.new(KubernetesMetadataFilter).configure(conf, true)
|
35
|
+
end
|
36
|
+
|
37
|
+
sub_test_case 'configure' do
|
38
|
+
test 'check default' do
|
39
|
+
assert_raise Fluent::ConfigError do
|
40
|
+
create_driver
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'kubernetes url' do
|
45
|
+
VCR.use_cassette('valid_kubernetes_api_server') do
|
46
|
+
d = create_driver(%[
|
47
|
+
kubernetes_url https://localhost:8443
|
48
|
+
])
|
49
|
+
assert_equal('https://localhost:8443', d.instance.kubernetes_url)
|
50
|
+
assert_equal(1000, d.instance.cache_size)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'cache size' do
|
55
|
+
VCR.use_cassette('valid_kubernetes_api_server') do
|
56
|
+
d = create_driver(%[
|
57
|
+
kubernetes_url https://localhost:8443
|
58
|
+
cache_size 1
|
59
|
+
])
|
60
|
+
assert_equal('https://localhost:8443', d.instance.kubernetes_url)
|
61
|
+
assert_equal(1, d.instance.cache_size)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
sub_test_case 'filter_stream' do
|
67
|
+
|
68
|
+
def emit(msg, config=%[
|
69
|
+
kubernetes_url https://localhost:8443
|
70
|
+
cache_size 1
|
71
|
+
])
|
72
|
+
d = create_driver(config)
|
73
|
+
d.run {
|
74
|
+
d.emit(msg, @time)
|
75
|
+
}.filtered
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'with docker & kubernetes metadata' do
|
79
|
+
VCR.use_cassette('kubernetes_docker_metadata') do
|
80
|
+
msg = {
|
81
|
+
:docker => {
|
82
|
+
:name => '/k8s_fabric8-console-container.efbd6e64_fabric8-console-controller-98rqc_default_c76927af-f563-11e4-b32d-54ee7527188d_42cbc279'
|
83
|
+
}
|
84
|
+
}
|
85
|
+
es = emit(msg)
|
86
|
+
expected_kube_metadata = {
|
87
|
+
:kubernetes => {
|
88
|
+
:host => "jimmi-redhat.localnet",
|
89
|
+
:pod_name =>"fabric8-console-controller-98rqc",
|
90
|
+
:container_name => "fabric8-console-container",
|
91
|
+
:namespace => "default",
|
92
|
+
:uid => "c76927af-f563-11e4-b32d-54ee7527188d",
|
93
|
+
:labels => {
|
94
|
+
:component => "fabric8Console"
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
assert_equal(msg.merge(expected_kube_metadata), es.instance_variable_get(:@record_array)[0])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
test 'with docker metadata, non-kubernetes' do
|
103
|
+
VCR.use_cassette('non_kubernetes_docker_metadata') do
|
104
|
+
msg = {
|
105
|
+
:docker => {
|
106
|
+
:name => '/k8s_POD.c0b903ca_fabric8-forge-controller-ymkew_default_bcde9961-f4b7-11e4-bdbf-54ee7527188d_e1f00705'
|
107
|
+
}
|
108
|
+
}
|
109
|
+
es = emit(msg)
|
110
|
+
assert_equal(msg, es.instance_variable_get(:@record_array)[0])
|
111
|
+
assert_false(es.instance_variable_get(:@record_array)[0].has_key?(:kubernetes))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
test 'without docker metadata' do
|
116
|
+
VCR.use_cassette('valid_kubernetes_api_server') do
|
117
|
+
msg = {'foo' => 'bar'}
|
118
|
+
es = emit(msg)
|
119
|
+
assert_equal(msg, es.instance_variable_get(:@record_array)[0])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
metadata
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-kubernetes_metadata_filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jimmi Dyson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: lru_redux
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: kubeclient
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluent-plugin-docker_metadata_filter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: test-unit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.0.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.0.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: test-unit-rr
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.0.3
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.0.3
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: copyright-header
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: vcr
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: bump
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: Filter plugin to add Kubernetes metadata
|
196
|
+
email:
|
197
|
+
- jimmidyson@gmail.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- ".gitignore"
|
203
|
+
- ".ruby-version"
|
204
|
+
- Gemfile
|
205
|
+
- LICENSE.txt
|
206
|
+
- README.md
|
207
|
+
- Rakefile
|
208
|
+
- circle.yml
|
209
|
+
- fluent-plugin-kubernetes_metadata_filter.gemspec
|
210
|
+
- lib/fluent/plugin/filter_kubernetes_metadata.rb
|
211
|
+
- test/cassettes/kubernetes_docker_metadata.yml
|
212
|
+
- test/cassettes/non_kubernetes_docker_metadata.yml
|
213
|
+
- test/cassettes/valid_kubernetes_api_server.yml
|
214
|
+
- test/helper.rb
|
215
|
+
- test/plugin/test_filter_kubernetes_metadata.rb
|
216
|
+
homepage: https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
|
217
|
+
licenses:
|
218
|
+
- ASL2
|
219
|
+
metadata: {}
|
220
|
+
post_install_message:
|
221
|
+
rdoc_options: []
|
222
|
+
require_paths:
|
223
|
+
- lib
|
224
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: 2.0.0
|
229
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
230
|
+
requirements:
|
231
|
+
- - ">="
|
232
|
+
- !ruby/object:Gem::Version
|
233
|
+
version: '0'
|
234
|
+
requirements: []
|
235
|
+
rubyforge_project:
|
236
|
+
rubygems_version: 2.2.2
|
237
|
+
signing_key:
|
238
|
+
specification_version: 4
|
239
|
+
summary: Filter plugin to add Kubernetes metadata
|
240
|
+
test_files:
|
241
|
+
- test/cassettes/kubernetes_docker_metadata.yml
|
242
|
+
- test/cassettes/non_kubernetes_docker_metadata.yml
|
243
|
+
- test/cassettes/valid_kubernetes_api_server.yml
|
244
|
+
- test/helper.rb
|
245
|
+
- test/plugin/test_filter_kubernetes_metadata.rb
|