fluent-plugin-kubernetes 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +67 -5
- data/circle.yml +3 -0
- data/fluent-plugin-kubernetes.gemspec +3 -2
- data/lib/fluent/plugin/out_kubernetes.rb +31 -21
- data/test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/container_name_not_starting_with_slash/uses_full_container_name.yml +73 -0
- data/test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/json_log_data/merges_json_log_data.yml +73 -0
- data/test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/kubernetes_container/enriches_with_correct_kubernets_metadata.yml +73 -0
- data/test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/non-kubernetes_container/leaves_event_untouched.yml +73 -0
- data/test/helper.rb +38 -4
- data/test/plugin/test_out_kubernetes.rb +54 -37
- metadata +39 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5d5f6b5708cabfe5acb67a6ca8887b4527a0159
|
4
|
+
data.tar.gz: ae3b534361d548138b2a8629fc22723c0d004957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2924405f00af9e58a592ce103c5638c2fbadf0f959a7a722c9be8298bfc14c4104bc41d160e410f60af9a694d7ae95bd6dc1472d47598f0f2387f8f5be8cc0fd
|
7
|
+
data.tar.gz: 5451e026ff16df9e148def5bfbb9c93580f449f9dcb95940837b2137706155bf51d8c21fd0a74424b34052d333a7d2b653aa6cae25bdf6965ee1bd31ba941289
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# fluent-plugin-kubernetes, a plugin for [Fluentd](http://fluentd.org)
|
1
|
+
# fluent-plugin-kubernetes, a plugin for [Fluentd](http://fluentd.org)
|
2
|
+
[](https://circleci.com/gh/fabric8io/fluent-plugin-kubernetes)
|
3
|
+
[](https://codeclimate.com/github/fabric8io/fluent-plugin-kubernetes)
|
4
|
+
[](https://codeclimate.com/github/fabric8io/fluent-plugin-kubernetes)
|
2
5
|
|
3
6
|
## Installation
|
4
7
|
|
@@ -27,10 +30,69 @@
|
|
27
30
|
</match>
|
28
31
|
```
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
Docker logs in JSON format. Log files are normally in
|
34
|
+
`/var/lib/docker/containers/*/*-json.log`, depending on what your Docker
|
35
|
+
data directory is.
|
36
|
+
|
37
|
+
Assuming following inputs are coming from a log file:
|
38
|
+
0bbc558cca13c5a92cc59f33626db0aaa2afea24742d2fbe549e3a30faf7ab09-json.log:
|
39
|
+
```
|
40
|
+
{
|
41
|
+
"log": "Something happened\n",
|
42
|
+
"stream": "stdout",
|
43
|
+
"time": "2015-03-07T20:04:17.604503223Z"
|
44
|
+
}
|
45
|
+
```
|
46
|
+
|
47
|
+
Then output becomes as belows
|
48
|
+
```
|
49
|
+
{
|
50
|
+
"log": "Something happened\n",
|
51
|
+
"stream": "stdout",
|
52
|
+
"time": "2015-03-07T20:04:17.604503223Z"
|
53
|
+
"container_id": "0bbc558cca13c5a92cc59f33626db0aaa2afea24742d2fbe549e3a30faf7ab09",
|
54
|
+
"container_name": "k8s_CONTAINER.2f44475a_POD.NAMESPACE.api_ae0aeb72-c44f-11e4-a274-54ee7527188d_d442134f",
|
55
|
+
"pod": "POD",
|
56
|
+
"pod_namespace": "NAMESPACE",
|
57
|
+
"pod_container": "CONTAINER"
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
## JSON logging
|
62
|
+
|
63
|
+
Logging requires context to be really useful. Context can either be derived
|
64
|
+
from log lines from known formats, but this is error prone & requires
|
65
|
+
processing power. The logging application is the best place to add
|
66
|
+
context.
|
67
|
+
|
68
|
+
If you use JSON for your application logs you can add context to your logs
|
69
|
+
as you go. This plugin will parse your log lines & if it sees that they are
|
70
|
+
JSON it will merge it in to the top level record so your contextual logging
|
71
|
+
will be nicely searchable.
|
72
|
+
|
73
|
+
Something like this:
|
74
|
+
|
75
|
+
```
|
76
|
+
{
|
77
|
+
"log": "{\"context\":\"something\"}",
|
78
|
+
"stream": "stdout",
|
79
|
+
"time": "2015-03-07T20:04:17.604503223Z"
|
80
|
+
}
|
81
|
+
```
|
82
|
+
|
83
|
+
Then output becomes as belows
|
84
|
+
```
|
85
|
+
{
|
86
|
+
"context": "something",
|
87
|
+
"stream": "stdout",
|
88
|
+
"time": "2015-03-07T20:04:17.604503223Z"
|
89
|
+
"container_id": "0bbc558cca13c5a92cc59f33626db0aaa2afea24742d2fbe549e3a30faf7ab09",
|
90
|
+
"container_name": "k8s_CONTAINER.2f44475a_POD.NAMESPACE.api_ae0aeb72-c44f-11e4-a274-54ee7527188d_d442134f",
|
91
|
+
"pod": "POD",
|
92
|
+
"pod_namespace": "NAMESPACE",
|
93
|
+
"pod_container": "CONTAINER"
|
94
|
+
}
|
95
|
+
```
|
34
96
|
|
35
97
|
## Contributing
|
36
98
|
|
data/circle.yml
ADDED
@@ -1,11 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
# require 'fluent/plugin/add/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "fluent-plugin-kubernetes"
|
8
|
-
spec.version = "0.3.
|
7
|
+
spec.version = "0.3.1"
|
9
8
|
spec.authors = ["Jimmi Dyson"]
|
10
9
|
spec.email = ["jimmidyson@gmail.com"]
|
11
10
|
spec.description = %q{Output filter plugin to add Kubernetes metadata}
|
@@ -22,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
22
21
|
spec.add_development_dependency "rake"
|
23
22
|
spec.add_development_dependency "minitest", "~> 4.0"
|
24
23
|
spec.add_development_dependency "copyright-header"
|
24
|
+
spec.add_development_dependency "minitest-vcr"
|
25
|
+
spec.add_development_dependency "webmock"
|
25
26
|
spec.add_runtime_dependency "fluentd"
|
26
27
|
spec.add_runtime_dependency "docker-api"
|
27
28
|
end
|
@@ -16,8 +16,6 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
|
-
require 'open3'
|
20
|
-
|
21
19
|
class Fluent::KubernetesOutput < Fluent::Output
|
22
20
|
Fluent::Plugin.register_output('kubernetes', self)
|
23
21
|
|
@@ -55,7 +53,37 @@ class Fluent::KubernetesOutput < Fluent::Output
|
|
55
53
|
end
|
56
54
|
|
57
55
|
def enrich_record(tag, record)
|
58
|
-
|
56
|
+
id = interpolate(tag, @container_id)
|
57
|
+
if !id.empty?
|
58
|
+
record['container_id'] = id
|
59
|
+
record = enrich_container_data(id, record)
|
60
|
+
record = merge_json_log(record)
|
61
|
+
end
|
62
|
+
record
|
63
|
+
end
|
64
|
+
|
65
|
+
def enrich_container_data(id, record)
|
66
|
+
container = Docker::Container.get(id)
|
67
|
+
if container
|
68
|
+
container_name = container.json['Name']
|
69
|
+
if container_name
|
70
|
+
record["container_name"] = container_name[1..-1] if container_name[0] == '/'
|
71
|
+
regex = Regexp.new(@kubernetes_pod_regex)
|
72
|
+
match = container_name.match(regex)
|
73
|
+
if match
|
74
|
+
pod_container_name, pod_name, pod_namespace =
|
75
|
+
match.captures
|
76
|
+
record["pod_namespace"] = pod_namespace
|
77
|
+
record["pod"] = pod_name
|
78
|
+
record["pod_container"] = pod_container_name
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
record
|
83
|
+
end
|
84
|
+
|
85
|
+
def merge_json_log(record)
|
86
|
+
if record.has_key?('log')
|
59
87
|
log = record['log'].strip
|
60
88
|
if log[0].eql?('{') && log[-1].eql?('}')
|
61
89
|
begin
|
@@ -67,24 +95,6 @@ class Fluent::KubernetesOutput < Fluent::Output
|
|
67
95
|
rescue JSON::ParserError
|
68
96
|
end
|
69
97
|
end
|
70
|
-
id = interpolate(tag, @container_id)
|
71
|
-
record['container_id'] = id
|
72
|
-
container = Docker::Container.get(id)
|
73
|
-
if container
|
74
|
-
container_name = container.json['Name']
|
75
|
-
if container_name
|
76
|
-
record["container_name"] = container_name[1..-1]
|
77
|
-
regex = Regexp.new(@kubernetes_pod_regex)
|
78
|
-
match = container_name.match(regex)
|
79
|
-
if match
|
80
|
-
pod_container_name, pod_name, pod_namespace =
|
81
|
-
match.captures
|
82
|
-
record["pod_namespace"] = pod_namespace
|
83
|
-
record["pod"] = pod_name
|
84
|
-
record["pod_container"] = pod_container_name
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
98
|
end
|
89
99
|
record
|
90
100
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Output Plugin - Enrich Fluentd events with Kubernetes
|
3
|
+
# 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: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
24
|
+
body:
|
25
|
+
encoding: US-ASCII
|
26
|
+
string: ''
|
27
|
+
headers:
|
28
|
+
User-Agent:
|
29
|
+
- Swipely/Docker-API 1.20.0
|
30
|
+
Content-Type:
|
31
|
+
- text/plain
|
32
|
+
response:
|
33
|
+
status:
|
34
|
+
code: 200
|
35
|
+
message:
|
36
|
+
headers:
|
37
|
+
Content-Type:
|
38
|
+
- application/json
|
39
|
+
Date:
|
40
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: |
|
44
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"no-leading-slash"}
|
45
|
+
http_version:
|
46
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
47
|
+
- request:
|
48
|
+
method: get
|
49
|
+
uri: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
50
|
+
body:
|
51
|
+
encoding: US-ASCII
|
52
|
+
string: ''
|
53
|
+
headers:
|
54
|
+
User-Agent:
|
55
|
+
- Swipely/Docker-API 1.20.0
|
56
|
+
Content-Type:
|
57
|
+
- text/plain
|
58
|
+
response:
|
59
|
+
status:
|
60
|
+
code: 200
|
61
|
+
message:
|
62
|
+
headers:
|
63
|
+
Content-Type:
|
64
|
+
- application/json
|
65
|
+
Date:
|
66
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
67
|
+
body:
|
68
|
+
encoding: UTF-8
|
69
|
+
string: |
|
70
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"no-leading-slash"}
|
71
|
+
http_version:
|
72
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
73
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Output Plugin - Enrich Fluentd events with Kubernetes
|
3
|
+
# 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: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
24
|
+
body:
|
25
|
+
encoding: US-ASCII
|
26
|
+
string: ''
|
27
|
+
headers:
|
28
|
+
User-Agent:
|
29
|
+
- Swipely/Docker-API 1.20.0
|
30
|
+
Content-Type:
|
31
|
+
- text/plain
|
32
|
+
response:
|
33
|
+
status:
|
34
|
+
code: 200
|
35
|
+
message:
|
36
|
+
headers:
|
37
|
+
Content-Type:
|
38
|
+
- application/json
|
39
|
+
Date:
|
40
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: |
|
44
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"/non-kubernetes"}
|
45
|
+
http_version:
|
46
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
47
|
+
- request:
|
48
|
+
method: get
|
49
|
+
uri: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
50
|
+
body:
|
51
|
+
encoding: US-ASCII
|
52
|
+
string: ''
|
53
|
+
headers:
|
54
|
+
User-Agent:
|
55
|
+
- Swipely/Docker-API 1.20.0
|
56
|
+
Content-Type:
|
57
|
+
- text/plain
|
58
|
+
response:
|
59
|
+
status:
|
60
|
+
code: 200
|
61
|
+
message:
|
62
|
+
headers:
|
63
|
+
Content-Type:
|
64
|
+
- application/json
|
65
|
+
Date:
|
66
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
67
|
+
body:
|
68
|
+
encoding: UTF-8
|
69
|
+
string: |
|
70
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"/non-kubernetes"}
|
71
|
+
http_version:
|
72
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
73
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Output Plugin - Enrich Fluentd events with Kubernetes
|
3
|
+
# 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: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
24
|
+
body:
|
25
|
+
encoding: US-ASCII
|
26
|
+
string: ''
|
27
|
+
headers:
|
28
|
+
User-Agent:
|
29
|
+
- Swipely/Docker-API 1.20.0
|
30
|
+
Content-Type:
|
31
|
+
- text/plain
|
32
|
+
response:
|
33
|
+
status:
|
34
|
+
code: 200
|
35
|
+
message:
|
36
|
+
headers:
|
37
|
+
Content-Type:
|
38
|
+
- application/json
|
39
|
+
Date:
|
40
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: |
|
44
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"/k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8"}
|
45
|
+
http_version:
|
46
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
47
|
+
- request:
|
48
|
+
method: get
|
49
|
+
uri: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
50
|
+
body:
|
51
|
+
encoding: US-ASCII
|
52
|
+
string: ''
|
53
|
+
headers:
|
54
|
+
User-Agent:
|
55
|
+
- Swipely/Docker-API 1.20.0
|
56
|
+
Content-Type:
|
57
|
+
- text/plain
|
58
|
+
response:
|
59
|
+
status:
|
60
|
+
code: 200
|
61
|
+
message:
|
62
|
+
headers:
|
63
|
+
Content-Type:
|
64
|
+
- application/json
|
65
|
+
Date:
|
66
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
67
|
+
body:
|
68
|
+
encoding: UTF-8
|
69
|
+
string: |
|
70
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"/k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8"}
|
71
|
+
http_version:
|
72
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
73
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Fluentd Kubernetes Output Plugin - Enrich Fluentd events with Kubernetes
|
3
|
+
# 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: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
24
|
+
body:
|
25
|
+
encoding: US-ASCII
|
26
|
+
string: ''
|
27
|
+
headers:
|
28
|
+
User-Agent:
|
29
|
+
- Swipely/Docker-API 1.20.0
|
30
|
+
Content-Type:
|
31
|
+
- text/plain
|
32
|
+
response:
|
33
|
+
status:
|
34
|
+
code: 200
|
35
|
+
message:
|
36
|
+
headers:
|
37
|
+
Content-Type:
|
38
|
+
- application/json
|
39
|
+
Date:
|
40
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: |
|
44
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"/non-kubernetes"}
|
45
|
+
http_version:
|
46
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
47
|
+
- request:
|
48
|
+
method: get
|
49
|
+
uri: "<DOCKER_HOST>/v1.16/containers/9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7/json"
|
50
|
+
body:
|
51
|
+
encoding: US-ASCII
|
52
|
+
string: ''
|
53
|
+
headers:
|
54
|
+
User-Agent:
|
55
|
+
- Swipely/Docker-API 1.20.0
|
56
|
+
Content-Type:
|
57
|
+
- text/plain
|
58
|
+
response:
|
59
|
+
status:
|
60
|
+
code: 200
|
61
|
+
message:
|
62
|
+
headers:
|
63
|
+
Content-Type:
|
64
|
+
- application/json
|
65
|
+
Date:
|
66
|
+
- Mon, 09 Mar 2015 11:43:55 GMT
|
67
|
+
body:
|
68
|
+
encoding: UTF-8
|
69
|
+
string: |
|
70
|
+
{"Id": "9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7","Name":"/non-kubernetes"}
|
71
|
+
http_version:
|
72
|
+
recorded_at: Mon, 09 Mar 2015 11:43:55 GMT
|
73
|
+
recorded_with: VCR 2.9.3
|
data/test/helper.rb
CHANGED
@@ -16,8 +16,30 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
|
-
require
|
20
|
-
require
|
19
|
+
require "simplecov"
|
20
|
+
require "codeclimate-test-reporter"
|
21
|
+
if ENV['CIRCLE_ARTIFACTS']
|
22
|
+
dir = File.join("..", "..", "..", ENV['CIRCLE_ARTIFACTS'], "coverage")
|
23
|
+
SimpleCov.coverage_dir(dir)
|
24
|
+
end
|
25
|
+
|
26
|
+
SimpleCov.add_filter 'vendor'
|
27
|
+
|
28
|
+
SimpleCov.start do
|
29
|
+
formatter SimpleCov::Formatter::MultiFormatter[
|
30
|
+
SimpleCov::Formatter::HTMLFormatter,
|
31
|
+
CodeClimate::TestReporter::Formatter
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require "bundler"
|
37
|
+
rescue LoadError => e
|
38
|
+
STDERR.puts e.message
|
39
|
+
STDERR.puts "Run `gem install bundler` to install Bundler."
|
40
|
+
exit e.status_code
|
41
|
+
end
|
42
|
+
|
21
43
|
begin
|
22
44
|
Bundler.setup(:default, :development)
|
23
45
|
rescue Bundler::BundlerError => e
|
@@ -42,7 +64,19 @@ unless ENV.has_key?('VERBOSE')
|
|
42
64
|
$log = nulllogger
|
43
65
|
end
|
44
66
|
|
67
|
+
require "minispec-metadata"
|
68
|
+
require "vcr"
|
69
|
+
require "minitest-vcr"
|
70
|
+
require "webmock"
|
71
|
+
|
72
|
+
VCR.configure do |c|
|
73
|
+
c.cassette_library_dir = 'test/cassettes'
|
74
|
+
c.hook_into :excon, :webmock
|
75
|
+
c.filter_sensitive_data('<DOCKER_HOST>') { Docker.url.sub(/tcp\:/, 'https:') }
|
76
|
+
c.ignore_hosts 'codeclimate.com'
|
77
|
+
end
|
78
|
+
|
79
|
+
MinitestVcr::Spec.configure!
|
80
|
+
|
45
81
|
require 'fluent/plugin/out_kubernetes'
|
46
82
|
|
47
|
-
class Test::Unit::TestCase
|
48
|
-
end
|
@@ -18,54 +18,71 @@
|
|
18
18
|
#
|
19
19
|
require 'helper'
|
20
20
|
|
21
|
-
|
22
|
-
def setup
|
23
|
-
Fluent::Test.setup
|
24
|
-
end
|
21
|
+
describe 'Fluentd Kubernetes Output Plugin' do
|
25
22
|
|
26
|
-
CONFIG = %
|
27
|
-
|
23
|
+
CONFIG = %{
|
24
|
+
container_id ${tag_parts[5]}
|
25
|
+
tag docker.${name}
|
26
|
+
}
|
28
27
|
|
29
|
-
|
30
|
-
Fluent::Test
|
28
|
+
before do
|
29
|
+
Fluent::Test.setup
|
30
|
+
@fluentd_driver = Fluent::Test::OutputTestDriver.new(
|
31
|
+
Fluent::KubernetesOutput,
|
32
|
+
'docker.var.lib.docker.containers.9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7')
|
33
|
+
.configure(CONFIG)
|
31
34
|
end
|
32
35
|
|
33
|
-
|
34
|
-
|
36
|
+
describe 'add kubernetes metadata', vcr: {record: :once} do
|
37
|
+
describe 'kubernetes container' do
|
38
|
+
it 'enriches with correct kubernets metadata' do
|
39
|
+
@fluentd_driver.run do
|
40
|
+
@fluentd_driver.emit("container_name" => "k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8")
|
41
|
+
end
|
42
|
+
mapped = {'container_id' => '9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7', 'pod' => 'POD', 'pod_namespace' => 'NAMESPACE', 'pod_container' => 'CONTAINER'}
|
43
|
+
assert_equal [
|
44
|
+
{"container_name" => "k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8"}.merge(mapped),
|
45
|
+
], @fluentd_driver.records
|
35
46
|
|
36
|
-
|
37
|
-
|
47
|
+
@fluentd_driver.run
|
48
|
+
end
|
38
49
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
describe 'non-kubernetes container' do
|
51
|
+
it 'leaves event untouched' do
|
52
|
+
@fluentd_driver.run do
|
53
|
+
@fluentd_driver.emit("container_name" => "/non-kubernetes")
|
54
|
+
end
|
55
|
+
assert_equal [
|
56
|
+
{'container_id' => '9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7', "container_name" => "non-kubernetes"},
|
57
|
+
], @fluentd_driver.records
|
46
58
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
d.run do
|
51
|
-
d.emit("container_name" => "nonk8s")
|
59
|
+
@fluentd_driver.run
|
60
|
+
end
|
52
61
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
62
|
+
describe 'container name not starting with slash' do
|
63
|
+
it 'uses full container name' do
|
64
|
+
@fluentd_driver.run do
|
65
|
+
@fluentd_driver.emit("container_name" => "no-leading-slash")
|
66
|
+
end
|
67
|
+
assert_equal [
|
68
|
+
{'container_id' => '9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7', "container_name" => "no-leading-slash"},
|
69
|
+
], @fluentd_driver.records
|
56
70
|
|
57
|
-
|
58
|
-
|
71
|
+
@fluentd_driver.run
|
72
|
+
end
|
73
|
+
end
|
74
|
+
describe 'json log data' do
|
75
|
+
it 'merges json log data' do
|
76
|
+
@fluentd_driver.run do
|
77
|
+
@fluentd_driver.emit({"container_name" => "non-kubernetes", "log" => "{\"this\":\"rocks\"}"})
|
78
|
+
end
|
79
|
+
assert_equal [
|
80
|
+
{'container_id' => '9b26b527e73550b1fb217d0d643b15aa2ec6607593a6b477cda82a9c72cb82a7', "container_name" => "non-kubernetes", "this" => "rocks"},
|
81
|
+
], @fluentd_driver.records
|
59
82
|
|
60
|
-
|
61
|
-
input = {"container_name" => "k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8"}
|
62
|
-
plugin = Fluent::KubernetesOutput.new
|
63
|
-
plugin.configure({})
|
64
|
-
assert_performance_linear do |n|
|
65
|
-
n.times do
|
66
|
-
plugin.enrich_record(input)
|
83
|
+
@fluentd_driver.run
|
67
84
|
end
|
68
85
|
end
|
69
86
|
end
|
70
87
|
|
71
|
-
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-kubernetes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmi Dyson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
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'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: fluentd
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,8 +134,13 @@ files:
|
|
106
134
|
- LICENSE.txt
|
107
135
|
- README.md
|
108
136
|
- Rakefile
|
137
|
+
- circle.yml
|
109
138
|
- fluent-plugin-kubernetes.gemspec
|
110
139
|
- lib/fluent/plugin/out_kubernetes.rb
|
140
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/container_name_not_starting_with_slash/uses_full_container_name.yml
|
141
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/json_log_data/merges_json_log_data.yml
|
142
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/kubernetes_container/enriches_with_correct_kubernets_metadata.yml
|
143
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/non-kubernetes_container/leaves_event_untouched.yml
|
111
144
|
- test/helper.rb
|
112
145
|
- test/plugin/test_out_kubernetes.rb
|
113
146
|
homepage: https://github.com/fabric8io/fluent-plugin-kubernetes
|
@@ -135,5 +168,9 @@ signing_key:
|
|
135
168
|
specification_version: 4
|
136
169
|
summary: Output filter plugin to add Kubernetes metadata
|
137
170
|
test_files:
|
171
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/container_name_not_starting_with_slash/uses_full_container_name.yml
|
172
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/json_log_data/merges_json_log_data.yml
|
173
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/kubernetes_container/enriches_with_correct_kubernets_metadata.yml
|
174
|
+
- test/cassettes/Fluentd_Kubernetes_Output_Plugin/add_kubernetes_metadata/non-kubernetes_container/leaves_event_untouched.yml
|
138
175
|
- test/helper.rb
|
139
176
|
- test/plugin/test_out_kubernetes.rb
|