fluent-plugin-wh-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/.circleci/config.yml +53 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +57 -0
- data/Gemfile +9 -0
- data/LICENSE +201 -0
- data/README.md +179 -0
- data/Rakefile +41 -0
- data/fluent-plugin-wh-kubernetes_metadata_filter.gemspec +33 -0
- data/lib/fluent/plugin/filter_kubernetes_metadata.rb +381 -0
- data/lib/fluent/plugin/kubernetes_metadata_cache_strategy.rb +100 -0
- data/lib/fluent/plugin/kubernetes_metadata_common.rb +130 -0
- data/lib/fluent/plugin/kubernetes_metadata_stats.rb +62 -0
- data/lib/fluent/plugin/kubernetes_metadata_test_api_adapter.rb +68 -0
- data/lib/fluent/plugin/kubernetes_metadata_util.rb +33 -0
- data/lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb +187 -0
- data/lib/fluent/plugin/kubernetes_metadata_watch_pods.rb +205 -0
- data/test/cassettes/invalid_api_server_config.yml +53 -0
- data/test/cassettes/kubernetes_docker_metadata_annotations.yml +205 -0
- data/test/cassettes/kubernetes_docker_metadata_dotted_slashed_labels.yml +197 -0
- data/test/cassettes/kubernetes_get_api_v1.yml +193 -0
- data/test/cassettes/kubernetes_get_api_v1_using_token.yml +195 -0
- data/test/cassettes/kubernetes_get_namespace_default.yml +72 -0
- data/test/cassettes/kubernetes_get_namespace_default_using_token.yml +71 -0
- data/test/cassettes/kubernetes_get_pod.yml +146 -0
- data/test/cassettes/kubernetes_get_pod_container_init.yml +145 -0
- data/test/cassettes/kubernetes_get_pod_using_token.yml +148 -0
- data/test/cassettes/metadata_from_tag_and_journald_fields.yml +153 -0
- data/test/cassettes/metadata_from_tag_journald_and_kubernetes_fields.yml +285 -0
- data/test/cassettes/valid_kubernetes_api_server.yml +55 -0
- data/test/cassettes/valid_kubernetes_api_server_using_token.yml +57 -0
- data/test/helper.rb +82 -0
- data/test/plugin/test.token +1 -0
- data/test/plugin/test_cache_stats.rb +33 -0
- data/test/plugin/test_cache_strategy.rb +194 -0
- data/test/plugin/test_filter_kubernetes_metadata.rb +810 -0
- data/test/plugin/test_watch_namespaces.rb +245 -0
- data/test/plugin/test_watch_pods.rb +344 -0
- data/test/plugin/watch_test.rb +76 -0
- metadata +276 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 567eb9e3769d52d720fdd3dbba267a8fd2ae1e01d8ec90f475314f4268077de7
|
4
|
+
data.tar.gz: 7b86839e8c7b1e4dd6951ae5dbf98a7ae0bb0ae8dcc9c979cb1067ac56db0008
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a6a3dbe0665ff01aa874c475e9181ed12b272117c0590ad8cb283a7ee31b23b2d0b39c84f9da2cda3ec509cd0598a0b8de5f97c1fa23771403899cdd3bc4224
|
7
|
+
data.tar.gz: 79cbde67398551f0128e3a113eee7ecd8a181d313dfe3dc4f0ad242509bc0bfceb9169d17e9a74c518f9a1a7550889e1d56c9fe2fff8da6d5acaca1167dec0b4
|
@@ -0,0 +1,53 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
install: &install
|
4
|
+
name: Install bundle
|
5
|
+
command: |
|
6
|
+
gem install bundler
|
7
|
+
bundle config set --local path vendor/bundle
|
8
|
+
bundle install
|
9
|
+
|
10
|
+
missingdeps: &missingdeps
|
11
|
+
name: Install missing dependecies
|
12
|
+
command: |
|
13
|
+
cat /etc/os-release
|
14
|
+
printf "deb http://deb.debian.org/debian buster main\ndeb http://security.debian.org buster/updates main\ndeb-src http://security.debian.org buster/updates main" > /tmp/sources.list
|
15
|
+
sudo cp /tmp/sources.list /etc/apt/sources.list
|
16
|
+
sudo apt-get --allow-releaseinfo-change update
|
17
|
+
sudo apt-get install cmake libicu-dev libssl-dev
|
18
|
+
|
19
|
+
test: &test
|
20
|
+
name: Test bundle
|
21
|
+
command: bundle exec rake test --trace
|
22
|
+
|
23
|
+
executors:
|
24
|
+
ruby-2-6:
|
25
|
+
docker:
|
26
|
+
- image: circleci/ruby:2.6.3
|
27
|
+
ruby-2-7:
|
28
|
+
docker:
|
29
|
+
- image: circleci/ruby:2.7.1
|
30
|
+
jobs:
|
31
|
+
"ruby-test":
|
32
|
+
parameters:
|
33
|
+
ruby-version:
|
34
|
+
type: executor
|
35
|
+
executor: << parameters.ruby-version >>
|
36
|
+
working_directory: ~/fluent-plugin-wh-kubernetes_metadata_filter
|
37
|
+
steps:
|
38
|
+
- run: *missingdeps
|
39
|
+
- checkout
|
40
|
+
- run: *install
|
41
|
+
- run: *test
|
42
|
+
- store_test_results:
|
43
|
+
path: coverage
|
44
|
+
- store_artifacts:
|
45
|
+
path: coverage
|
46
|
+
|
47
|
+
workflows:
|
48
|
+
"test_multiple_ruby_versions":
|
49
|
+
jobs:
|
50
|
+
- ruby-test:
|
51
|
+
ruby-version: ruby-2-6
|
52
|
+
- ruby-test:
|
53
|
+
ruby-version: ruby-2-7
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5 # keep in sync with .circleci/config.yml and gemspec
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/EmptyMethod:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Metrics:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
# not safe ... needs require 'English'
|
12
|
+
Style/SpecialGlobalVars:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Layout/LineLength:
|
16
|
+
Max: 205 # TODO: lower
|
17
|
+
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Naming/AccessorMethodName:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Naming/MethodParameterName:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/IfInsideElse:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/GuardClause:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Lint/NestedMethodDefinition:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# TODO: fix
|
37
|
+
Style/StringConcatenation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/NumericPredicate:
|
41
|
+
EnforcedStyle: comparison
|
42
|
+
|
43
|
+
Style/IfUnlessModifier:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/ClassAndModuleChildren:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
# TODO: enable ... somehow breaks tests
|
50
|
+
Style/HashEachMethods:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Style/WordArray:
|
54
|
+
EnforcedStyle: brackets
|
55
|
+
|
56
|
+
Style/SymbolArray:
|
57
|
+
EnforcedStyle: brackets
|
data/Gemfile
ADDED
data/LICENSE
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,179 @@
|
|
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
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
|
6
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
|
7
|
+
|
8
|
+
The Kubernetes metadata plugin filter enriches container log records with pod and namespace metadata.
|
9
|
+
|
10
|
+
This plugin derives basic metadata about the container that emitted a given log record using the source of the log record. Records from kubernetes containers encode metadata about the container in the file name. The initial metadata derived from the source is used
|
11
|
+
to lookup additional metadata about the container's associated pod and namespace (e.g. UUIDs, labels, annotations) when the kubernetes_url is configured. If the plugin cannot
|
12
|
+
authoritatively determine the namespace of the container emitting a log record, it will use an 'orphan' namespace ID in the metadata. This behaviors supports multi-tenant systems
|
13
|
+
that rely on the authenticity of the namespace for proper log isolation.
|
14
|
+
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
| fluent-plugin-kubernetes_metadata_filter | fluentd | ruby |
|
18
|
+
|-------------------|---------|------|
|
19
|
+
| >= 2.10.0 | >= v1.10.0 | >= 2.6 |
|
20
|
+
| >= 2.5.0 | >= v1.10.0 | >= 2.5 |
|
21
|
+
| >= 2.0.0 | >= v0.14.20 | >= 2.1 |
|
22
|
+
| < 2.0.0 | >= v0.12.0 | >= 1.9 |
|
23
|
+
|
24
|
+
NOTE: For v0.12 version, you should use 1.x.y version. Please send patch into v0.12 branch if you encountered 1.x version's bug.
|
25
|
+
|
26
|
+
NOTE: This documentation is for fluent-plugin-kubernetes_metadata_filter-plugin-elasticsearch 2.x or later. For 1.x documentation, please see [v0.12 branch](https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter/tree/v0.12).
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
gem install fluent-plugin-kubernetes_metadata_filter
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
|
34
|
+
Configuration options for fluent.conf are:
|
35
|
+
|
36
|
+
* `kubernetes_url` - URL to the API server. Set this to retrieve further kubernetes metadata for logs from kubernetes API server. If not specified, environment variables `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` will be used if both are present which is typically true when running fluentd in a pod.
|
37
|
+
* `apiVersion` - API version to use (default: `v1`)
|
38
|
+
* `ca_file` - path to CA file for Kubernetes server certificate validation
|
39
|
+
* `verify_ssl` - validate SSL certificates (default: `true`)
|
40
|
+
* `client_cert` - path to a client cert file to authenticate to the API server
|
41
|
+
* `client_key` - path to a client key file to authenticate to the API server
|
42
|
+
* `bearer_token_file` - path to a file containing the bearer token to use for authentication
|
43
|
+
* `tag_to_kubernetes_name_regexp` - the regular expression used to extract kubernetes metadata (pod name, container name, namespace) from the current fluentd tag.
|
44
|
+
This must use named capture groups for `container_name`, `pod_name`, `namespace`, and either `pod_uuid (/var/log/pods)` or `docker_id (/var/log/containers)`
|
45
|
+
* `cache_size` - size of the cache of Kubernetes metadata to reduce requests to the API server (default: `1000`)
|
46
|
+
* `cache_ttl` - TTL in seconds of each cached element. Set to negative value to disable TTL eviction (default: `3600` - 1 hour)
|
47
|
+
* `watch` - set up a watch on pods on the API server for updates to metadata (default: `true`)
|
48
|
+
* `annotation_match` - Array of regular expressions matching annotation field names. Matched annotations are added to a log record.
|
49
|
+
* `allow_orphans` - Modify the namespace and namespace id to the values of `orphaned_namespace_name` and `orphaned_namespace_id`
|
50
|
+
when true (default: `true`)
|
51
|
+
* `orphaned_namespace_name` - The namespace to associate with records where the namespace can not be determined (default: `.orphaned`)
|
52
|
+
* `orphaned_namespace_id` - The namespace id to associate with records where the namespace can not be determined (default: `orphaned`)
|
53
|
+
* `lookup_from_k8s_field` - If the field `kubernetes` is present, lookup the metadata from the given subfields such as `kubernetes.namespace_name`, `kubernetes.pod_name`, etc. This allows you to avoid having to pass in metadata to lookup in an explicitly formatted tag name or in an explicitly formatted `CONTAINER_NAME` value. For example, set `kubernetes.namespace_name`, `kubernetes.pod_name`, `kubernetes.container_name`, and `docker.id` in the record, and the filter will fill in the rest. (default: `true`)
|
54
|
+
* `ssl_partial_chain` - if `ca_file` is for an intermediate CA, or otherwise we do not have the root CA and want
|
55
|
+
to trust the intermediate CA certs we do have, set this to `true` - this corresponds to
|
56
|
+
the `openssl s_client -partial_chain` flag and `X509_V_FLAG_PARTIAL_CHAIN` (default: `false`)
|
57
|
+
* `skip_labels` - Skip all label fields from the metadata.
|
58
|
+
* `skip_pod_labels` - Skip only pod label fields from the metadata.
|
59
|
+
* `skip_namespace_labels` - Skip only namespace label fields from the metadata.
|
60
|
+
* `skip_container_metadata` - Skip some of the container data of the metadata. The metadata will not contain the container_image and container_image_id fields.
|
61
|
+
* `skip_master_url` - Skip the master_url field from the metadata.
|
62
|
+
* `skip_namespace_metadata` - Skip the namespace_id field from the metadata. The fetch_namespace_metadata function will be skipped. The plugin will be faster and cpu consumption will be less.
|
63
|
+
* `stats_interval` - The interval to display cache stats (default: 30s). Set to 0 to disable stats collection and logging
|
64
|
+
* `watch_retry_interval` - The time interval in seconds for retry backoffs when watch connections fail. (default: `10`)
|
65
|
+
* `open_timeout` - The time in seconds to wait for a connection to kubernetes service. (default: `3`)
|
66
|
+
* `read_timeout` - The time in seconds to wait for a read from kubernetes service. (default: `10`)
|
67
|
+
|
68
|
+
|
69
|
+
Reading from a JSON formatted log files with `in_tail` and wildcard filenames while respecting the CRI-o log format with the same config you need the fluent-plugin "multi-format-parser":
|
70
|
+
|
71
|
+
```
|
72
|
+
fluent-gem install fluent-plugin-multi-format-parser
|
73
|
+
```
|
74
|
+
|
75
|
+
The config block could look like this:
|
76
|
+
```
|
77
|
+
<source>
|
78
|
+
@type tail
|
79
|
+
path /var/log/containers/*.log
|
80
|
+
pos_file fluentd-docker.pos
|
81
|
+
read_from_head true
|
82
|
+
tag kubernetes.*
|
83
|
+
<parse>
|
84
|
+
@type multi_format
|
85
|
+
<pattern>
|
86
|
+
format json
|
87
|
+
time_key time
|
88
|
+
time_type string
|
89
|
+
time_format "%Y-%m-%dT%H:%M:%S.%NZ"
|
90
|
+
keep_time_key false
|
91
|
+
</pattern>
|
92
|
+
<pattern>
|
93
|
+
format regexp
|
94
|
+
expression /^(?<time>.+) (?<stream>stdout|stderr)( (?<logtag>.))? (?<log>.*)$/
|
95
|
+
time_format '%Y-%m-%dT%H:%M:%S.%N%:z'
|
96
|
+
keep_time_key false
|
97
|
+
</pattern>
|
98
|
+
</parse>
|
99
|
+
</source>
|
100
|
+
|
101
|
+
<filter kubernetes.var.log.containers.**.log>
|
102
|
+
@type kubernetes_metadata
|
103
|
+
</filter>
|
104
|
+
|
105
|
+
<match **>
|
106
|
+
@type stdout
|
107
|
+
</match>
|
108
|
+
```
|
109
|
+
|
110
|
+
## Environment variables for Kubernetes
|
111
|
+
|
112
|
+
If the name of the Kubernetes node the plugin is running on is set as
|
113
|
+
an environment variable with the name `K8S_NODE_NAME`, it will reduce cache
|
114
|
+
misses and needless calls to the Kubernetes API.
|
115
|
+
|
116
|
+
In the Kubernetes container definition, this is easily accomplished by:
|
117
|
+
|
118
|
+
```yaml
|
119
|
+
env:
|
120
|
+
- name: K8S_NODE_NAME
|
121
|
+
valueFrom:
|
122
|
+
fieldRef:
|
123
|
+
fieldPath: spec.nodeName
|
124
|
+
```
|
125
|
+
|
126
|
+
## Example input/output
|
127
|
+
|
128
|
+
Kubernetes creates symlinks to Docker log files in `/var/log/containers/*.log`. Docker logs in JSON format.
|
129
|
+
|
130
|
+
Assuming following inputs are coming from a log file named `/var/log/containers/fabric8-console-controller-98rqc_default_fabric8-console-container-df14e0d5ae4c07284fa636d739c8fc2e6b52bc344658de7d3f08c36a2e804115.log`:
|
131
|
+
|
132
|
+
```
|
133
|
+
{
|
134
|
+
"log": "2015/05/05 19:54:41 \n",
|
135
|
+
"stream": "stderr",
|
136
|
+
"time": "2015-05-05T19:54:41.240447294Z"
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
Then output becomes as belows
|
141
|
+
```
|
142
|
+
{
|
143
|
+
"log": "2015/05/05 19:54:41 \n",
|
144
|
+
"stream": "stderr",
|
145
|
+
"docker": {
|
146
|
+
"id": "df14e0d5ae4c07284fa636d739c8fc2e6b52bc344658de7d3f08c36a2e804115",
|
147
|
+
}
|
148
|
+
"kubernetes": {
|
149
|
+
"host": "jimmi-redhat.localnet",
|
150
|
+
"pod_name":"fabric8-console-controller-98rqc",
|
151
|
+
"pod_id": "c76927af-f563-11e4-b32d-54ee7527188d",
|
152
|
+
"pod_ip": "172.17.0.8",
|
153
|
+
"container_name": "fabric8-console-container",
|
154
|
+
"namespace_name": "default",
|
155
|
+
"namespace_id": "23437884-8e08-4d95-850b-e94378c9b2fd",
|
156
|
+
"namespace_annotations": {
|
157
|
+
"fabric8.io/git-commit": "5e1116f63df0bac2a80bdae2ebdc563577bbdf3c"
|
158
|
+
},
|
159
|
+
"namespace_labels": {
|
160
|
+
"product_version": "v1.0.0"
|
161
|
+
},
|
162
|
+
"labels": {
|
163
|
+
"component": "fabric8Console"
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
```
|
168
|
+
|
169
|
+
## Contributing
|
170
|
+
|
171
|
+
1. Fork it
|
172
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
173
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
174
|
+
4. Test it (`GEM_HOME=vendor bundle install; GEM_HOME=vendor bundle exec rake test`)
|
175
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
176
|
+
6. Create new Pull Request
|
177
|
+
|
178
|
+
## Copyright
|
179
|
+
Copyright (c) 2015 jimmidyson
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'bump/tasks'
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
|
9
|
+
task test: [:base_test]
|
10
|
+
task default: [:test, :build, :rubocop]
|
11
|
+
|
12
|
+
RuboCop::RakeTask.new
|
13
|
+
|
14
|
+
desc 'Run test_unit based test'
|
15
|
+
Rake::TestTask.new(:base_test) do |t|
|
16
|
+
# To run test for only one file (or file path pattern)
|
17
|
+
# $ bundle exec rake base_test TEST=test/test_specified_path.rb
|
18
|
+
# $ bundle exec rake base_test TEST=test/test_*.rb
|
19
|
+
t.libs << 'test'
|
20
|
+
t.test_files = Dir['test/**/test_*.rb'].sort
|
21
|
+
t.warning = false
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Add copyright headers'
|
25
|
+
task :headers do
|
26
|
+
require 'rubygems'
|
27
|
+
require 'copyright_header'
|
28
|
+
|
29
|
+
args = {
|
30
|
+
license: 'Apache-2.0',
|
31
|
+
copyright_software: 'Fluentd Kubernetes Metadata Filter Plugin',
|
32
|
+
copyright_software_description: 'Enrich Fluentd events with Kubernetes metadata',
|
33
|
+
copyright_holders: ['Red Hat, Inc.'],
|
34
|
+
copyright_years: ['2015-2021'],
|
35
|
+
add_path: 'lib:test',
|
36
|
+
output_dir: '.'
|
37
|
+
}
|
38
|
+
|
39
|
+
command_line = CopyrightHeader::CommandLine.new(args)
|
40
|
+
command_line.execute
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'fluent-plugin-wh-kubernetes_metadata_filter'
|
5
|
+
gem.version = '0.1.0'
|
6
|
+
gem.authors = ['Jimmi Dyson','October']
|
7
|
+
gem.email = ['hyperistio@gmail.com']
|
8
|
+
|
9
|
+
gem.description = 'Filter plugin to add Kubernetes metadata'
|
10
|
+
gem.summary = 'Fluentd filter plugin to add Kubernetes metadata'
|
11
|
+
gem.homepage = 'https://github.com/raingallery/fluent-plugin-wh-kubernetes_metadata_filter'
|
12
|
+
gem.license = 'Apache-2.0'
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
|
17
|
+
gem.required_ruby_version = '>= 2.6.0'
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'fluentd', ['>= 0.14.0', '< 1.17']
|
20
|
+
gem.add_runtime_dependency 'kubeclient', ['>= 4.0.0', '< 5.0.0']
|
21
|
+
gem.add_runtime_dependency 'lru_redux'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'bump'
|
24
|
+
gem.add_development_dependency 'bundler', '~> 2.0'
|
25
|
+
gem.add_development_dependency 'copyright-header'
|
26
|
+
gem.add_development_dependency 'minitest', '~> 4.0'
|
27
|
+
gem.add_development_dependency 'rake'
|
28
|
+
gem.add_development_dependency 'test-unit', '~> 3.5.5'
|
29
|
+
gem.add_development_dependency 'test-unit-rr', '~> 1.0.3'
|
30
|
+
gem.add_development_dependency 'vcr'
|
31
|
+
gem.add_development_dependency 'webmock'
|
32
|
+
gem.add_development_dependency 'yajl-ruby'
|
33
|
+
end
|