fluent-plugin-kubernetes_metadata_filter 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/fluent-plugin-kubernetes_metadata_filter.gemspec +1 -1
- data/lib/fluent/plugin/filter_kubernetes_metadata.rb +6 -6
- data/lib/fluent/plugin/kubernetes_metadata_cache_strategy.rb +0 -1
- data/lib/fluent/plugin/kubernetes_metadata_watch_pods.rb +3 -0
- data/test/plugin/test_filter_kubernetes_metadata.rb +27 -6
- data/test/plugin/test_watch_pods.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51343e9798a88739c3959e9cf6e350ec1b213ac3
|
4
|
+
data.tar.gz: d361fbbaa5f7f43832f4ae261746c5715c2e3aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4307c9fc6195ed933cca79e12dbedb6698266943632814c9f25ad669cb909ebab2957317694ce764cc5abed0eabd4366622f2446e0e45f68566ad15f4f3082ce
|
7
|
+
data.tar.gz: 62f89e376091e5d4f856d034a8f47f0b15839e346912840cd3fafa2e7654e91bb4aa990030b22d87cc9056496b9c2aa4f893cbebbf8379993d9616d9aecb634a
|
data/README.md
CHANGED
@@ -104,6 +104,22 @@ Reading from the systemd journal (requires the fluentd `fluent-plugin-systemd` a
|
|
104
104
|
</match>
|
105
105
|
```
|
106
106
|
|
107
|
+
## Environment variables for Kubernetes
|
108
|
+
|
109
|
+
If the name of the Kubernetes node the plugin is running on is set as
|
110
|
+
an environment variable with the name `K8S_NODE_NAME`, it will reduce cache
|
111
|
+
misses and needless calls to the Kubernetes API.
|
112
|
+
|
113
|
+
In the Kubernetes container definition, this is easily accomplished by:
|
114
|
+
|
115
|
+
```yaml
|
116
|
+
env:
|
117
|
+
- name: K8S_NODE_NAME
|
118
|
+
valueFrom:
|
119
|
+
fieldRef:
|
120
|
+
fieldPath: spec.nodeName
|
121
|
+
```
|
122
|
+
|
107
123
|
## Example input/output
|
108
124
|
|
109
125
|
Kubernetes creates symlinks to Docker log files in `/var/log/containers/*.log`. Docker logs in JSON format.
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "fluent-plugin-kubernetes_metadata_filter"
|
7
|
-
gem.version = "1.0.
|
7
|
+
gem.version = "1.0.3"
|
8
8
|
gem.authors = ["Jimmi Dyson"]
|
9
9
|
gem.email = ["jimmidyson@gmail.com"]
|
10
10
|
gem.description = %q{Filter plugin to add Kubernetes metadata}
|
@@ -90,12 +90,12 @@ module Fluent
|
|
90
90
|
rescue Exception=>e
|
91
91
|
log.debug(e)
|
92
92
|
@stats.bump(:pod_cache_api_nil_bad_resp_payload)
|
93
|
-
log.trace("returning empty metadata for #{namespace_name}/#{pod_name} due to error") if log.trace?
|
93
|
+
log.trace("returning empty metadata for #{namespace_name}/#{pod_name} due to error '#{e}'") if log.trace?
|
94
94
|
end
|
95
95
|
end
|
96
|
-
rescue
|
96
|
+
rescue Exception=>e
|
97
97
|
@stats.bump(:pod_cache_api_nil_error)
|
98
|
-
log.debug "Exception encountered fetching pod metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}
|
98
|
+
log.debug "Exception '#{e}' encountered fetching pod metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
|
99
99
|
end
|
100
100
|
{}
|
101
101
|
end
|
@@ -132,12 +132,12 @@ module Fluent
|
|
132
132
|
rescue Exception => e
|
133
133
|
log.debug(e)
|
134
134
|
@stats.bump(:namespace_cache_api_nil_bad_resp_payload)
|
135
|
-
log.trace("returning empty metadata for #{namespace_name} due to error") if log.trace?
|
135
|
+
log.trace("returning empty metadata for #{namespace_name} due to error '#{e}'") if log.trace?
|
136
136
|
end
|
137
137
|
end
|
138
|
-
rescue
|
138
|
+
rescue Exception => kube_error
|
139
139
|
@stats.bump(:namespace_cache_api_nil_error)
|
140
|
-
log.debug "Exception encountered fetching namespace metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}
|
140
|
+
log.debug "Exception '#{kube_error}' encountered fetching namespace metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
|
141
141
|
end
|
142
142
|
{}
|
143
143
|
end
|
@@ -42,6 +42,9 @@ module KubernetesMetadata
|
|
42
42
|
if cached
|
43
43
|
@cache[cache_key] = parse_pod_metadata(notice.object)
|
44
44
|
@stats.bump(:pod_cache_watch_updates)
|
45
|
+
elsif ENV['K8S_NODE_NAME'] == notice.object['spec']['nodeName'] then
|
46
|
+
@cache[cache_key] = parse_pod_metadata(notice.object)
|
47
|
+
@stats.bump(:pod_cache_host_updates)
|
45
48
|
else
|
46
49
|
@stats.bump(:pod_cache_watch_misses)
|
47
50
|
end
|
@@ -137,12 +137,6 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
|
|
137
137
|
cache_size 1
|
138
138
|
', d: nil)
|
139
139
|
d = create_driver(config) if d.nil?
|
140
|
-
if ENV['LOGLEVEL']
|
141
|
-
logger = Logger.new(STDOUT)
|
142
|
-
logger.level = eval("Logger::#{ENV['LOGLEVEL'].upcase}")
|
143
|
-
instance = d.instance
|
144
|
-
instance.instance_variable_set(:@log,logger)
|
145
|
-
end
|
146
140
|
d.run {
|
147
141
|
d.emit(msg, @time)
|
148
142
|
}.filtered
|
@@ -159,6 +153,33 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
|
|
159
153
|
}.filtered
|
160
154
|
end
|
161
155
|
|
156
|
+
test 'inability to connect to the api server handles exception and doensnt block pipeline' do
|
157
|
+
VCR.use_cassette('kubernetes_docker_metadata') do
|
158
|
+
driver = create_driver('
|
159
|
+
kubernetes_url https://localhost:8443
|
160
|
+
watch false
|
161
|
+
cache_size 1
|
162
|
+
')
|
163
|
+
stub_request(:any, 'https://localhost:8443/api/v1/namespaces/default/pods/fabric8-console-controller-98rqc').to_raise(SocketError.new('error from pod fetch'))
|
164
|
+
stub_request(:any, 'https://localhost:8443/api/v1/namespaces/default').to_raise(SocketError.new('socket error from namespace fetch'))
|
165
|
+
es = emit({'time'=>'2015-05-08T09:22:01Z'}, '', :d => driver)
|
166
|
+
expected_kube_metadata = {
|
167
|
+
'time'=>'2015-05-08T09:22:01Z',
|
168
|
+
'docker' => {
|
169
|
+
'container_id' => '49095a2894da899d3b327c5fde1e056a81376cc9a8f8b09a195f2a92bceed459'
|
170
|
+
},
|
171
|
+
'kubernetes' => {
|
172
|
+
'pod_name' => 'fabric8-console-controller-98rqc',
|
173
|
+
'container_name' => 'fabric8-console-container',
|
174
|
+
"namespace_id"=>"orphaned",
|
175
|
+
'namespace_name' => '.orphaned',
|
176
|
+
"orphaned_namespace"=>"default"
|
177
|
+
}
|
178
|
+
}
|
179
|
+
assert_equal(expected_kube_metadata, es.instance_variable_get(:@record_array)[0])
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
162
183
|
test 'with docker & kubernetes metadata where id cache hit and metadata miss' do
|
163
184
|
VCR.use_cassette('kubernetes_docker_metadata') do
|
164
185
|
driver = create_driver('
|
@@ -81,6 +81,17 @@ class DefaultPodWatchStrategyTest < WatchTest
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
test 'pod MODIFIED cached when hostname matches' do
|
85
|
+
orig_env_val = ENV['K8S_NODE_NAME']
|
86
|
+
ENV['K8S_NODE_NAME'] = 'aNodeName'
|
87
|
+
@client.stub :watch_pods, [@modified] do
|
88
|
+
start_pod_watch
|
89
|
+
assert_equal(true, @cache.key?('modified_uid'))
|
90
|
+
assert_equal(1, @stats[:pod_cache_host_updates])
|
91
|
+
end
|
92
|
+
ENV['K8S_NODE_NAME'] = orig_env_val
|
93
|
+
end
|
94
|
+
|
84
95
|
test 'pod watch notice is updated when MODIFIED is received' do
|
85
96
|
@cache['modified_uid'] = {}
|
86
97
|
@client.stub :watch_pods, [@modified] do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-kubernetes_metadata_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmi Dyson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|