fluent-plugin-barito 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b35472a5c56fd8b341b8fe2c91b1baf8168c7d88078bf5e421a03f14b9c0165
4
- data.tar.gz: fddfbfea352eaa235c7599df2ac5920d346f47934aeb3fc14631a509195f3b0a
3
+ metadata.gz: dddd5d0082d68458cba7621f2f4c01d0ed7f1fed479de55af65acd9b1e5f40be
4
+ data.tar.gz: e117c347df66acd103f72bb850cb882b5ab35391f1fecf947d68734636f39597
5
5
  SHA512:
6
- metadata.gz: 409734aba8cc251c54a6cd0e2bb3f2989549f8880d9eb1f58eb2589f79073f989e86bda5f5880dbdd976c4d3fcd4eacd83b2f0c3c13721ca1b66573c88cab01c
7
- data.tar.gz: 9d6c49cb7ca58af3a45e0872e7bff01e38fc81002098dc4442ff57a79a1c4833463769554fc5d89769ab398311f5e812e3a9c45153acba470022c650210d267e
6
+ metadata.gz: ace5ec573a0aca28a58f06ebd1406050a6989d317219441a7cf0a962510e2d745dae06219e469f6adf5ad78a2c3da0ce6b80df44a15c3e89fd53f6e960cd61d5
7
+ data.tar.gz: 4dd29b131547cd237c28f57a5f4c87a0223cb296e5381965f88dd07b750c83e8eecff3e77337ba8e777649ad822f4db4d4fc7b73d8578d94b2b029be0ec7618a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ **0.3.2**
4
+
5
+ - Handle batch produce (from k8s)
6
+
3
7
  **0.3.1**
4
8
 
5
9
  - Revert nested parsing behaviour
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-barito"
6
- spec.version = "0.3.1"
6
+ spec.version = "0.3.2"
7
7
  spec.authors = ["BaritoLog"]
8
8
  spec.email = ["pushm0v.development@gmail.com", "iman.tung@gmail.com"]
9
9
 
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake", "~> 12.0"
25
25
  spec.add_development_dependency 'rspec', '~> 3.4'
26
26
  spec.add_development_dependency 'timecop', '~> 0.9.1'
27
- spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'simplecov', '~> 0'
28
28
  spec.add_development_dependency 'coveralls', '~> 0.8.21'
29
29
  spec.add_development_dependency 'test-unit', '~> 3.2'
30
30
 
@@ -0,0 +1,89 @@
1
+ require 'fluent/output'
2
+ require 'rest-client'
3
+ require_relative 'barito_timber'
4
+ require_relative 'barito_client_trail'
5
+
6
+ module Fluent
7
+ class BaritoBatchK8sOutput < BufferedOutput
8
+
9
+ PLUGIN_NAME = 'barito_batch_k8s'
10
+
11
+ Fluent::Plugin.register_output(PLUGIN_NAME, self)
12
+
13
+ config_param :application_secret, :string, :default => nil
14
+ config_param :application_group_secret, :string, :default => nil
15
+ config_param :application_name, :string, :default => nil
16
+ config_param :produce_url, :string, :default => ''
17
+
18
+ # Overide from BufferedOutput
19
+ def start
20
+ super
21
+ end
22
+
23
+ # Overide from BufferedOutput
24
+ def format(tag, time, record)
25
+ [tag, time, record].to_msgpack
26
+ end
27
+
28
+ # Overide from BufferedOutput
29
+ def write(chunk)
30
+ data = {
31
+ 'items' => []
32
+ }
33
+ chunk.msgpack_each do |tag, time, record|
34
+
35
+ # Kubernetes annotations
36
+ k8s_metadata = record['kubernetes']
37
+
38
+ record = clean_attribute(record)
39
+ trail = Fluent::Plugin::ClientTrail.new(true)
40
+ timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
41
+ new_timber = merge_log_attribute(timber)
42
+
43
+ # Add kubernetes information
44
+ new_timber['k8s_metadata'] = {
45
+ 'pod_name' => k8s_metadata['pod_name'],
46
+ 'namespace_name' => k8s_metadata['namespace_name'],
47
+ 'container_name' => k8s_metadata['container_name'],
48
+ 'host' => k8s_metadata['host']
49
+ }
50
+
51
+ data['items'] << new_timber
52
+ end
53
+
54
+ if @application_secret.nil? or @application_secret.empty?
55
+ return if @application_group_secret.nil? or @application_name.nil?
56
+ header = {
57
+ content_type: :json,
58
+ 'X-App-Group-Secret' => @application_group_secret,
59
+ 'X-App-Name' => @application_name
60
+ }
61
+ else
62
+ header = {content_type: :json, 'X-App-Secret' => @application_secret}
63
+ end
64
+
65
+ response = RestClient.post @produce_url, data.to_json, header
66
+ end
67
+
68
+ def clean_attribute(record)
69
+ # Delete kubernetes & docker field
70
+ record.delete('kubernetes')
71
+ record.delete('docker')
72
+ record
73
+ end
74
+
75
+ def merge_log_attribute(record)
76
+ message_log = nil
77
+ begin
78
+ message_log = JSON.parse(record['log'])
79
+ rescue
80
+ end
81
+
82
+ if !message_log.nil?
83
+ return record.merge(message_log)
84
+ end
85
+
86
+ record
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fluent::BaritoBatchK8sOutput' do
4
+ describe '.merge_log_attribute' do
5
+ it do
6
+ out = Fluent::BaritoBatchK8sOutput.new
7
+
8
+ record = {
9
+ "kubernetes" => {"some_attr" => "some_value"},
10
+ "docker" => "docker_value",
11
+ "log" => "{\"some_attr\": \"info\", \"other_attr\": \"other_value\"}"
12
+ }
13
+ new_record = out.merge_log_attribute(record)
14
+
15
+ expect(new_record['some_attr']).to eq("info")
16
+ expect(new_record['other_attr']).to eq("other_value")
17
+ end
18
+ end
19
+
20
+ describe '.clean_attribute' do
21
+ it do
22
+ out = Fluent::BaritoBatchK8sOutput.new
23
+
24
+ record = {
25
+ "kubernetes" => {"some_attr" => "some_value"},
26
+ "docker" => "docker_value",
27
+ "attr" => "some_value"
28
+ }
29
+ new_record = out.clean_attribute(record)
30
+
31
+ expect(new_record['kubernetes']).to be_nil
32
+ expect(new_record['docker']).to be_nil
33
+ expect(new_record['attr']).to eq("some_value")
34
+ end
35
+ end
36
+
37
+ end
@@ -55,6 +55,11 @@ describe 'Fluent::BaritoK8sOutput' do
55
55
  it do
56
56
  out = Fluent::BaritoK8sOutput.new
57
57
 
58
+ record = {
59
+ "kubernetes" => {"some_attr" => "some_value"},
60
+ "docker" => "docker_value",
61
+ "log" => "{\"some_attr\": \"info\", \"other_attr\": \"other_value\"}"
62
+ }
58
63
  new_record = out.merge_log_attribute(record)
59
64
 
60
65
  expect(new_record['some_attr']).to eq("info")
data/spec/spec_helper.rb CHANGED
@@ -114,6 +114,7 @@ RSpec.configure do |config|
114
114
  require 'fluent/test/driver/output'
115
115
  require 'fluent/plugin/out_barito_vm'
116
116
  require 'fluent/plugin/out_barito_k8s'
117
+ require 'fluent/plugin/out_barito_batch_k8s'
117
118
  require 'fluent/plugin/barito_client_trail'
118
119
  require 'fluent/plugin/barito_timber'
119
120
  require 'timecop'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-barito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - BaritoLog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-31 00:00:00.000000000 Z
11
+ date: 2018-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
@@ -162,10 +162,12 @@ files:
162
162
  - fluent-plugin-barito.gemspec
163
163
  - lib/fluent/plugin/barito_client_trail.rb
164
164
  - lib/fluent/plugin/barito_timber.rb
165
+ - lib/fluent/plugin/out_barito_batch_k8s.rb
165
166
  - lib/fluent/plugin/out_barito_batch_vm.rb
166
167
  - lib/fluent/plugin/out_barito_k8s.rb
167
168
  - lib/fluent/plugin/out_barito_vm.rb
168
169
  - spec/lib/fluent/plugin/barito_timber_spec.rb
170
+ - spec/lib/fluent/plugin/out_barito_batch_k8s_spec.rb
169
171
  - spec/lib/fluent/plugin/out_barito_k8s_spec.rb
170
172
  - spec/spec_helper.rb
171
173
  homepage: https://github.com/BaritoLog/Barito-Fluent-Plugin
@@ -194,5 +196,6 @@ specification_version: 4
194
196
  summary: Fluentd output plugin for BaritoLog
195
197
  test_files:
196
198
  - spec/lib/fluent/plugin/barito_timber_spec.rb
199
+ - spec/lib/fluent/plugin/out_barito_batch_k8s_spec.rb
197
200
  - spec/lib/fluent/plugin/out_barito_k8s_spec.rb
198
201
  - spec/spec_helper.rb