fluent-plugin-barito 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -17
- data/fluent-plugin-barito.gemspec +2 -2
- data/lib/fluent/plugin/barito_timber.rb +22 -27
- data/lib/fluent/plugin/out_barito_k8s.rb +3 -11
- data/lib/fluent/plugin/out_barito_vm.rb +4 -2
- data/spec/lib/fluent/plugin/barito_timber_spec.rb +34 -28
- data/spec/lib/fluent/plugin/out_barito_k8s_spec.rb +2 -6
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 753ba672b958cc160d38fc62eb418f8ab2919310
|
4
|
+
data.tar.gz: 95dfa553c16d8074452695552a2553e99a33a86c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79794a905fef7c4bb895d8e8f5348afce598e5f6c67d74ce2875a117c0fadc21590c821806b8489f67789d5792af30b8815d0536ceb6def5ac816343e02054d9
|
7
|
+
data.tar.gz: 6a36ee02fdfee7782bb49374816c9da298de13f9301b3b083521be09b026632d44fafab146dc69c34a90eb475df3de22226649535a677de4b01a8e62a90ca8ae
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# fluent-plugin-barito
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/BaritoLog/Barito-Fluent-Plugin.svg?branch=master)](https://travis-ci.org/BaritoLog/Barito-Fluent-Plugin)
|
4
|
+
|
3
5
|
[Fluentd](https://fluentd.org/) output plugin for [BaritoLog](https://github.com/BaritoLog).
|
4
6
|
|
5
7
|
## Installation
|
@@ -15,7 +17,7 @@ $ gem install fluent-plugin-barito
|
|
15
17
|
Add following line to your Gemfile:
|
16
18
|
|
17
19
|
```ruby
|
18
|
-
gem
|
20
|
+
gem 'fluent-plugin-barito'
|
19
21
|
```
|
20
22
|
|
21
23
|
And then execute:
|
@@ -38,18 +40,21 @@ You can copy and paste generated documents here.
|
|
38
40
|
|
39
41
|
## Without Kubernetes
|
40
42
|
|
43
|
+
Use type `barito_vm` for deployment without kubernetes
|
44
|
+
|
41
45
|
```conf
|
42
46
|
<source>
|
43
47
|
@type tail
|
44
48
|
tag "barito"
|
45
49
|
path /path/to/file.log
|
50
|
+
<parse>
|
51
|
+
@type none
|
52
|
+
</parse>
|
46
53
|
</source>
|
47
54
|
|
48
55
|
<match barito>
|
49
|
-
@type
|
56
|
+
@type barito_vm
|
50
57
|
|
51
|
-
use_https false
|
52
|
-
use_kubernetes false
|
53
58
|
application_secret "ABCDE1234"
|
54
59
|
produce_url "http://receiver-host:receiver-port/str/1/st/2/fw/3/cl/4/produce/some-topic"
|
55
60
|
<buffer>
|
@@ -59,27 +64,17 @@ You can copy and paste generated documents here.
|
|
59
64
|
```
|
60
65
|
|
61
66
|
## With Kubernetes
|
62
|
-
|
67
|
+
Change type to `barito_k8s`.
|
63
68
|
|
64
69
|
```
|
65
70
|
<match barito>
|
66
|
-
@type
|
71
|
+
@type barito_k8s
|
67
72
|
|
68
73
|
use_https false
|
69
|
-
use_kubernetes true
|
70
|
-
|
71
|
-
application_secret "ABCDE1234"
|
72
|
-
stream_id "1"
|
73
|
-
store_id "2"
|
74
|
-
client_id "3"
|
75
|
-
forwarder_id "4"
|
76
|
-
produce_host "receiver-host"
|
77
|
-
produce_port "receiver-port"
|
78
|
-
produce_topic "some-topic"
|
79
74
|
</match>
|
80
75
|
```
|
81
76
|
|
82
|
-
|
77
|
+
and set `kubernetes labels` in YAML :
|
83
78
|
|
84
79
|
```
|
85
80
|
labels:
|
@@ -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.1.
|
6
|
+
spec.version = "0.1.7"
|
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'
|
28
28
|
spec.add_development_dependency 'coveralls', '~> 0.8.21'
|
29
29
|
spec.add_development_dependency 'test-unit', '~> 3.2'
|
30
30
|
|
@@ -1,43 +1,38 @@
|
|
1
|
-
class Fluent::Plugin::
|
1
|
+
class Fluent::Plugin::TimberFactory
|
2
2
|
MESSAGE_KEY = "message"
|
3
3
|
|
4
4
|
HINTS_NO_TIMESTAMP = "no timestamp".freeze
|
5
5
|
HINTS_NO_MESSAGE = "no #{MESSAGE_KEY}".freeze
|
6
6
|
|
7
|
-
attr_accessor :location, :tag, :message, :timestamp, :client_trail
|
8
|
-
|
9
|
-
def to_hash
|
10
|
-
{
|
11
|
-
'location' => @location,
|
12
|
-
'tag' => @tag,
|
13
|
-
'@message' => @message,
|
14
|
-
'@timestamp' => @timestamp,
|
15
|
-
'client_trail' => @client_trail.to_hash
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_json
|
20
|
-
to_hash.to_json
|
21
|
-
end
|
22
|
-
|
23
7
|
def self.create_timber(tag, time, record, trail)
|
24
8
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
timber.client_trail = trail
|
9
|
+
begin
|
10
|
+
timber = JSON.parse(record['message'])
|
11
|
+
rescue
|
12
|
+
end
|
30
13
|
|
31
|
-
|
32
|
-
timber
|
33
|
-
trail.hints << HINTS_NO_TIMESTAMP
|
14
|
+
unless timber.is_a?(Hash) then
|
15
|
+
timber = Hash.new
|
34
16
|
end
|
35
17
|
|
36
|
-
|
37
|
-
|
18
|
+
|
19
|
+
message = record[MESSAGE_KEY] if record.is_a?(Hash) and record.has_key?(MESSAGE_KEY)
|
20
|
+
client_trail = trail
|
21
|
+
|
22
|
+
|
23
|
+
timestamp = Time.now.utc.strftime('%FT%TZ')
|
24
|
+
|
25
|
+
|
26
|
+
if message.nil? or message.empty?
|
27
|
+
message = record.to_str
|
38
28
|
trail.hints << HINTS_NO_MESSAGE
|
39
29
|
end
|
40
30
|
|
31
|
+
timber['tag'] = tag
|
32
|
+
timber['@message'] = message
|
33
|
+
timber['@timestamp'] = timestamp
|
34
|
+
timber['client_trail'] = client_trail.to_hash
|
35
|
+
|
41
36
|
timber
|
42
37
|
|
43
38
|
end
|
@@ -9,13 +9,9 @@ module Fluent
|
|
9
9
|
PLUGIN_NAME = 'barito_k8s'
|
10
10
|
|
11
11
|
LABEL_APP_SECRET = 'baritoApplicationSecret'
|
12
|
-
LABEL_STREAM_ID = 'baritoStreamId'
|
13
12
|
LABEL_PRODUCE_HOST = 'baritoProduceHost'
|
14
13
|
LABEL_PRODUCE_PORT = 'baritoProducePort'
|
15
14
|
LABEL_PRODUCE_TOPIC = 'baritoProduceTopic'
|
16
|
-
LABEL_STORE_ID = 'baritoStoreId'
|
17
|
-
LABEL_FORWARD_ID = 'baritoForwarderId'
|
18
|
-
LABEL_CLIENT_ID = 'baritoClientId'
|
19
15
|
|
20
16
|
|
21
17
|
Fluent::Plugin.register_output(PLUGIN_NAME, self)
|
@@ -43,25 +39,21 @@ module Fluent
|
|
43
39
|
|
44
40
|
trail = Fluent::Plugin::ClientTrail.new(true)
|
45
41
|
|
46
|
-
timber = Fluent::Plugin::
|
47
|
-
header = {content_type: :json,
|
42
|
+
timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
|
43
|
+
header = {content_type: :json, 'X-App-Secret' => secret}
|
48
44
|
|
49
45
|
RestClient.post url, timber.to_json, header
|
50
46
|
end
|
51
47
|
end
|
52
48
|
|
53
49
|
def produce_url(labels)
|
54
|
-
stream_id = labels[LABEL_STREAM_ID]
|
55
50
|
produce_host = labels[LABEL_PRODUCE_HOST]
|
56
51
|
produce_port = labels[LABEL_PRODUCE_PORT]
|
57
52
|
produce_topic = labels[LABEL_PRODUCE_TOPIC]
|
58
|
-
store_id = labels[LABEL_STORE_ID]
|
59
|
-
forwarder_id = labels[LABEL_FORWARD_ID]
|
60
|
-
client_id = labels[LABEL_CLIENT_ID]
|
61
53
|
|
62
54
|
protocol = @use_https? 'https' : 'http'
|
63
55
|
|
64
|
-
produce_url = "#{protocol}://#{produce_host}:#{produce_port}/
|
56
|
+
produce_url = "#{protocol}://#{produce_host}:#{produce_port}/produce/#{produce_topic}"
|
65
57
|
produce_url
|
66
58
|
end
|
67
59
|
|
@@ -26,11 +26,13 @@ module Fluent
|
|
26
26
|
# Overide from BufferedOutput
|
27
27
|
def write(chunk)
|
28
28
|
|
29
|
+
# logger = Logger.new(STDOUT)
|
30
|
+
|
29
31
|
chunk.msgpack_each do |tag, time, record|
|
30
32
|
trail = Fluent::Plugin::ClientTrail.new(false)
|
31
33
|
|
32
|
-
timber = Fluent::Plugin::
|
33
|
-
header = {content_type: :json,
|
34
|
+
timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
|
35
|
+
header = {content_type: :json, 'X-App-Secret' => @application_secret}
|
34
36
|
|
35
37
|
RestClient.post @produce_url, timber.to_json, header
|
36
38
|
end
|
@@ -1,45 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Fluent::Plugin::
|
3
|
+
describe 'Fluent::Plugin::TimberFactory' do
|
4
4
|
|
5
5
|
describe 'create_timber' do
|
6
6
|
|
7
|
-
|
8
|
-
trail = Fluent::Plugin::ClientTrail.new(true)
|
7
|
+
context 'message' do
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
it 'is json' do
|
10
|
+
trail = Fluent::Plugin::ClientTrail.new(true)
|
11
|
+
tag = "some_tag"
|
12
|
+
record = {'message' => '{"booking_id":1234,"foo":"bar"}'}
|
13
|
+
|
14
|
+
timber = Fluent::Plugin::TimberFactory::create_timber(tag, nil, record, trail)
|
15
|
+
expect(timber['booking_id']).to eq(1234)
|
16
|
+
expect(timber['foo']).to eq('bar')
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
it 'is quoted string' do
|
20
|
+
trail = Fluent::Plugin::ClientTrail.new(true)
|
21
|
+
tag = "some_tag"
|
22
|
+
record = {'message' => '"something"'}
|
23
|
+
timber = Fluent::Plugin::TimberFactory::create_timber(tag, nil, record, trail)
|
24
|
+
expect(timber['@message']).to eq('"something"')
|
25
|
+
end
|
24
26
|
|
25
|
-
|
27
|
+
it 'is not json' do
|
26
28
|
trail = Fluent::Plugin::ClientTrail.new(true)
|
27
|
-
|
29
|
+
tag = "some_tag"
|
28
30
|
record = {"message" => "some_message"}
|
29
|
-
timber = Fluent::Plugin::Timber::create_timber("some_tag", nil, record, trail)
|
30
31
|
|
31
|
-
|
32
|
-
expect(timber
|
32
|
+
timber = Fluent::Plugin::TimberFactory::create_timber(tag, nil, record, trail)
|
33
|
+
expect(timber['tag']).to eq(tag)
|
34
|
+
expect(timber['@message']).to eq("some_message")
|
35
|
+
expect(timber['client_trail']).to eq(trail.to_hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'has no message' do
|
39
|
+
trail = Fluent::Plugin::ClientTrail.new(true)
|
40
|
+
timber = Fluent::Plugin::TimberFactory::create_timber("some_tag", nil, "invalid_message", trail)
|
41
|
+
expect(timber['@message']).to eq("invalid_message")
|
42
|
+
expect(timber['client_trail']['hints']).to include(Fluent::Plugin::TimberFactory::HINTS_NO_MESSAGE)
|
33
43
|
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'using whole record if record[MESSAGE_KEY] emtpy' do
|
37
|
-
trail = Fluent::Plugin::ClientTrail.new(true)
|
38
44
|
|
39
|
-
timber = Fluent::Plugin::Timber::create_timber("some_tag", nil, "invalid_message", trail)
|
40
|
-
expect(timber.message).to eq("invalid_message")
|
41
|
-
expect(timber.client_trail.hints).to include(Fluent::Plugin::Timber::HINTS_NO_MESSAGE)
|
42
45
|
end
|
46
|
+
|
47
|
+
|
48
|
+
|
43
49
|
end
|
44
50
|
|
45
51
|
end
|
@@ -7,22 +7,18 @@ describe 'Fluent::BaritoK8sOutput' do
|
|
7
7
|
k8s_labels = {
|
8
8
|
Fluent::BaritoK8sOutput::LABEL_PRODUCE_HOST => 'localhost',
|
9
9
|
Fluent::BaritoK8sOutput::LABEL_PRODUCE_PORT => '5000',
|
10
|
-
Fluent::BaritoK8sOutput::LABEL_STREAM_ID => '1',
|
11
|
-
Fluent::BaritoK8sOutput::LABEL_STORE_ID => '2',
|
12
|
-
Fluent::BaritoK8sOutput::LABEL_FORWARD_ID => '3',
|
13
|
-
Fluent::BaritoK8sOutput::LABEL_CLIENT_ID => '4',
|
14
10
|
Fluent::BaritoK8sOutput::LABEL_PRODUCE_TOPIC => 'sometopic'
|
15
11
|
}
|
16
12
|
|
17
13
|
out1 = Fluent::BaritoK8sOutput.new
|
18
14
|
out1.use_https = true
|
19
15
|
url = out1.produce_url(k8s_labels)
|
20
|
-
expect(url).to eq 'https://localhost:5000/
|
16
|
+
expect(url).to eq 'https://localhost:5000/produce/sometopic'
|
21
17
|
|
22
18
|
out2 = Fluent::BaritoK8sOutput.new
|
23
19
|
out2.use_https = false
|
24
20
|
url = out2.produce_url(k8s_labels)
|
25
|
-
expect(url).to eq 'http://localhost:5000/
|
21
|
+
expect(url).to eq 'http://localhost:5000/produce/sometopic'
|
26
22
|
end
|
27
23
|
|
28
24
|
end
|
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.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BaritoLog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
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
|
-
version: 0
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: coveralls
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|