fluent-plugin-kubernetes 0.1.0
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +10 -0
- data/fluent-plugin-kubernetes.gemspec +25 -0
- data/lib/fluent/plugin/out_kubernetes.rb +39 -0
- data/test/helper.rb +30 -0
- data/test/plugin/test_out_kubernetes.rb +53 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c522ac244cb884a41b77a6042d25f223a52a4448
|
4
|
+
data.tar.gz: 6a8bffaabeed107e17a5f7ad4f04d3fb04823e83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3edc748acc0b6c9cb8542bdf849f20ffbcbeed7a5e0ed3c045742e12268bc2f9d42b892e5eca11ef38d470d77b2910c2009a94ca42a89260f80e15b29aba89b
|
7
|
+
data.tar.gz: d881fd0b70f7d9b2b91ac27c0bc0b90a06b221b546ebcb0fcbd294f58b099f20e53d64c23aa8d6f3f546ec0dca066bc2a8e5e03bf14408ce7fa1482894cccfe3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 yu-yamada
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# fluent-plugin-kubernetes, a plugin for [Fluentd](http://fluentd.org)
|
2
|
+
|
3
|
+
## Requirements
|
4
|
+
|
5
|
+
Requires [fluent-plugin-docker-format](https://github.com/bwalex/fluent-plugin-docker-format)
|
6
|
+
plugin.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
gem install fluent-plugin-kubernetes
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
```
|
14
|
+
<source>
|
15
|
+
type tail
|
16
|
+
path /var/lib/docker/containers/*/*-json.log
|
17
|
+
pos_file fluentd-docker.pos
|
18
|
+
time_format %Y-%m-%dT%H:%M:%S
|
19
|
+
tag docker.*
|
20
|
+
format json
|
21
|
+
</source>
|
22
|
+
|
23
|
+
<match docker.var.lib.docker.containers.*.*.log>
|
24
|
+
type docker_format
|
25
|
+
container_id ${tag_parts[5]}
|
26
|
+
tag docker.${name}
|
27
|
+
</match>
|
28
|
+
|
29
|
+
<match docker.**>
|
30
|
+
type kubernetes
|
31
|
+
</match>
|
32
|
+
|
33
|
+
<match kubernetes>
|
34
|
+
type stdout
|
35
|
+
</match>
|
36
|
+
```
|
37
|
+
|
38
|
+
### Assuming following inputs are coming:
|
39
|
+
test.aa: {"container_name":"k8s_CONTAINER.2f44475a_POD.NAMESPACE.api_ae0aeb72-c44f-11e4-a274-54ee7527188d_d442134f", "json":"dayo"}
|
40
|
+
### then output bocomes as belows
|
41
|
+
test.aa: {"container_name":"k8s_CONTAINER.2f44475a_POD.NAMESPACE.api_ae0aeb72-c44f-11e4-a274-54ee7527188d_d442134f", "pod":"POD", "pod_namespace":"NAMESPACE", "pod_container":"CONTAINER", "json":"dayo", "hoge":"moge","hogehoge":"mogemoge"}
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
50
|
+
|
51
|
+
## Copyright
|
52
|
+
Copyright (c) 2015 jimmidyson
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
# require 'fluent/plugin/add/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fluent-plugin-kubernetes"
|
8
|
+
spec.version = "0.1.0"
|
9
|
+
spec.authors = ["Jimmi Dyson"]
|
10
|
+
spec.email = ["jimmidyson@gmail.com"]
|
11
|
+
spec.description = %q{Output filter plugin to add Kubernetes metadata}
|
12
|
+
spec.summary = %q{Output filter plugin to add Kubernetes metadata}
|
13
|
+
spec.homepage = "https://github.com/jimmidyson/fluent-plugin-kubernetes"
|
14
|
+
spec.license = "ASL2"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest", "~> 4.0"
|
24
|
+
spec.add_runtime_dependency "fluentd"
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
class Fluent::KubernetesOutput < Fluent::Output
|
4
|
+
Fluent::Plugin.register_output('kubernetes', self)
|
5
|
+
|
6
|
+
K8S_CONTAINER_NAME_REGEX = '^[^_]+_([^\.]+)\.[^_]+_([^\.]+)\.([^\.]+)'
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure(conf)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def emit(tag, es, chain)
|
17
|
+
es.each do |time,record|
|
18
|
+
Fluent::Engine.emit('kubernetes', time, enrich_record(record))
|
19
|
+
end
|
20
|
+
|
21
|
+
chain.next
|
22
|
+
end
|
23
|
+
|
24
|
+
def enrich_record(record)
|
25
|
+
if record.has_key? "container_name"
|
26
|
+
regex = Regexp.new(K8S_CONTAINER_NAME_REGEX)
|
27
|
+
match = record["container_name"].match(regex)
|
28
|
+
if match
|
29
|
+
pod_container_name, pod_name, pod_namespace =
|
30
|
+
match.captures
|
31
|
+
record["pod_namespace"] = pod_namespace
|
32
|
+
record["pod"] = pod_name
|
33
|
+
record["pod_container"] = pod_container_name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
record
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'minitest/spec'
|
12
|
+
require 'minitest/autorun'
|
13
|
+
require 'minitest/benchmark'
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
require 'fluent/test'
|
17
|
+
unless ENV.has_key?('VERBOSE')
|
18
|
+
nulllogger = Object.new
|
19
|
+
nulllogger.instance_eval {|obj|
|
20
|
+
def method_missing(method, *args)
|
21
|
+
# pass
|
22
|
+
end
|
23
|
+
}
|
24
|
+
$log = nulllogger
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'fluent/plugin/out_kubernetes'
|
28
|
+
|
29
|
+
class Test::Unit::TestCase
|
30
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class KubernetesOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
]
|
10
|
+
|
11
|
+
def create_driver(conf = CONFIG, tag='test')
|
12
|
+
Fluent::Test::OutputTestDriver.new(Fluent::KubernetesOutput, tag).configure(conf)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_k8s_pod
|
16
|
+
d = create_driver
|
17
|
+
|
18
|
+
d.run do
|
19
|
+
d.emit("container_name" => "k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8")
|
20
|
+
end
|
21
|
+
mapped = {'pod' => 'POD', 'pod_namespace' => 'NAMESPACE', 'pod_container' => 'CONTAINER'}
|
22
|
+
assert_equal [
|
23
|
+
{"container_name" => "k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8"}.merge(mapped),
|
24
|
+
], d.records
|
25
|
+
|
26
|
+
d.run
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_non_k8s_container
|
30
|
+
d = create_driver
|
31
|
+
|
32
|
+
d.run do
|
33
|
+
d.emit("container_name" => "nonk8s")
|
34
|
+
end
|
35
|
+
assert_equal [
|
36
|
+
{"container_name" => "nonk8s"},
|
37
|
+
], d.records
|
38
|
+
|
39
|
+
d.run
|
40
|
+
end
|
41
|
+
|
42
|
+
def bench_k8s_pod
|
43
|
+
input = {"container_name" => "k8s_CONTAINER.ff8e9ce_POD.NAMESPACE.api_2b249189-c3e0-11e4-839d-54ee7527188d_c306d8a8"}
|
44
|
+
plugin = Fluent::KubernetesOutput.new
|
45
|
+
plugin.configure({})
|
46
|
+
assert_performance_linear do |n|
|
47
|
+
n.times do
|
48
|
+
plugin.enrich_record(input)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-kubernetes
|
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-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
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
|
+
description: Output filter plugin to add Kubernetes metadata
|
70
|
+
email:
|
71
|
+
- jimmidyson@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-kubernetes.gemspec
|
82
|
+
- lib/fluent/plugin/out_kubernetes.rb
|
83
|
+
- test/helper.rb
|
84
|
+
- test/plugin/test_out_kubernetes.rb
|
85
|
+
homepage: https://github.com/jimmidyson/fluent-plugin-kubernetes
|
86
|
+
licenses:
|
87
|
+
- ASL2
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.2.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Output filter plugin to add Kubernetes metadata
|
109
|
+
test_files:
|
110
|
+
- test/helper.rb
|
111
|
+
- test/plugin/test_out_kubernetes.rb
|