fluent-plugin-kubernetes 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c522ac244cb884a41b77a6042d25f223a52a4448
4
- data.tar.gz: 6a8bffaabeed107e17a5f7ad4f04d3fb04823e83
3
+ metadata.gz: e60aff3afc155348f6340256f4acd8d47786ea13
4
+ data.tar.gz: 5bbdcb6a7925a715069f7b9cfbc1893cc0ec4909
5
5
  SHA512:
6
- metadata.gz: a3edc748acc0b6c9cb8542bdf849f20ffbcbeed7a5e0ed3c045742e12268bc2f9d42b892e5eca11ef38d470d77b2910c2009a94ca42a89260f80e15b29aba89b
7
- data.tar.gz: d881fd0b70f7d9b2b91ac27c0bc0b90a06b221b546ebcb0fcbd294f58b099f20e53d64c23aa8d6f3f546ec0dca066bc2a8e5e03bf14408ce7fa1482894cccfe3
6
+ metadata.gz: 8b6eb7bf52dd7bf9d910b0687ddd4f1df291b29d50c7a76c22dc46905c2581f7adda7e449c9c745f30e86139e33d9dd9d031e86f21ff9bd7ba5b98c836faf0ef
7
+ data.tar.gz: 73293093eab47d7e2ed2fca5f97ff597f1fb6fefdd44ba6ad7675c96e28f1f80990d3239e04db4297f0540900e5460cc04f9520b4975332ba4924e1831aaeedc
data/README.md CHANGED
@@ -1,10 +1,5 @@
1
1
  # fluent-plugin-kubernetes, a plugin for [Fluentd](http://fluentd.org)
2
2
 
3
- ## Requirements
4
-
5
- Requires [fluent-plugin-docker-format](https://github.com/bwalex/fluent-plugin-docker-format)
6
- plugin.
7
-
8
3
  ## Installation
9
4
 
10
5
  gem install fluent-plugin-kubernetes
@@ -18,18 +13,15 @@ plugin.
18
13
  time_format %Y-%m-%dT%H:%M:%S
19
14
  tag docker.*
20
15
  format json
16
+ read_from_head true
21
17
  </source>
22
18
 
23
19
  <match docker.var.lib.docker.containers.*.*.log>
24
- type docker_format
20
+ type kubernetes
25
21
  container_id ${tag_parts[5]}
26
22
  tag docker.${name}
27
23
  </match>
28
24
 
29
- <match docker.**>
30
- type kubernetes
31
- </match>
32
-
33
25
  <match kubernetes>
34
26
  type stdout
35
27
  </match>
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fluent-plugin-kubernetes"
8
- spec.version = "0.1.0"
8
+ spec.version = "0.2.1"
9
9
  spec.authors = ["Jimmi Dyson"]
10
10
  spec.email = ["jimmidyson@gmail.com"]
11
11
  spec.description = %q{Output filter plugin to add Kubernetes metadata}
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "minitest", "~> 4.0"
24
24
  spec.add_runtime_dependency "fluentd"
25
+ spec.add_runtime_dependency "docker-api"
25
26
  end
@@ -3,7 +3,9 @@ require 'open3'
3
3
  class Fluent::KubernetesOutput < Fluent::Output
4
4
  Fluent::Plugin.register_output('kubernetes', self)
5
5
 
6
- K8S_CONTAINER_NAME_REGEX = '^[^_]+_([^\.]+)\.[^_]+_([^\.]+)\.([^\.]+)'
6
+ config_param :container_id, :string
7
+ config_param :tag, :string
8
+ config_param :kubernetes_pod_regex, :string, default: '^[^_]+_([^\.]+)\.[^_]+_([^\.]+)\.([^\.]+)'
7
9
 
8
10
  def initialize
9
11
  super
@@ -11,26 +13,46 @@ class Fluent::KubernetesOutput < Fluent::Output
11
13
 
12
14
  def configure(conf)
13
15
  super
16
+
17
+ require 'docker'
14
18
  end
15
19
 
16
20
  def emit(tag, es, chain)
17
21
  es.each do |time,record|
18
- Fluent::Engine.emit('kubernetes', time, enrich_record(record))
22
+ Fluent::Engine.emit('kubernetes', time, enrich_record(tag, record))
19
23
  end
20
24
 
21
25
  chain.next
22
26
  end
23
27
 
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
28
+ private
29
+
30
+ def interpolate(tag, str)
31
+ tag_parts = tag.split('.')
32
+
33
+ str.gsub(/\$\{tag_parts\[(\d+)\]\}/) { |m| tag_parts[$1.to_i] }
34
+ end
35
+
36
+ def enrich_record(tag, record)
37
+ if @container_id
38
+ id = interpolate(tag, @container_id)
39
+ record['container_id'] = id
40
+ puts id
41
+ container = Docker::Container.get(id)
42
+ if container
43
+ container_name = container.json['Name']
44
+ if container_name
45
+ record["container_name"] = container_name
46
+ regex = Regexp.new(@kubernetes_pod_regex)
47
+ match = container_name.match(regex)
48
+ if match
49
+ pod_container_name, pod_name, pod_namespace =
50
+ match.captures
51
+ record["pod_namespace"] = pod_namespace
52
+ record["pod"] = pod_name
53
+ record["pod_container"] = pod_container_name
54
+ end
55
+ end
34
56
  end
35
57
  end
36
58
  record
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.1.0
4
+ version: 0.2.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-06 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: docker-api
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Output filter plugin to add Kubernetes metadata
70
84
  email:
71
85
  - jimmidyson@gmail.com