fluent-plugin-barito 0.1.4 → 0.1.5

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: 2792af35a307f76fa10fa2c88468cfafc36c089d
4
- data.tar.gz: a0f36fe8a09d68e923060ea04bea248b4dfd9cbe
3
+ metadata.gz: f619871d3344d661cc8b0afc3e108b8300ee8ab1
4
+ data.tar.gz: 3baf519e4b5855bc58d31f976dfeb308540abcb6
5
5
  SHA512:
6
- metadata.gz: 9b2b40c21153642979d4fd92b9d99602f524a10158fe23013680800748cd01566f2c34faef0d78c151ce1925f3a7b649d90b5d0822e8a8077f1fadc88fecd6ae
7
- data.tar.gz: e9e29ece8edc7b26d3991ea66690e2a029f5750e54bf3e96ac25fcf0a553d51794b3fb231ee5090a6bdd16cce19ac913bfefc18d51d20211bfda5c44464f3604
6
+ metadata.gz: ec6259c713263775de741fa8426bc6c60ecc4f9e7f5882212cc428d0a5b9c89706f49b5445d463b2df9e0bd5ee1a5ed40979bbb0243e3e603363e06d0ec60de9
7
+ data.tar.gz: 1fcc5e7e5c3268afe6e658293aa9892d7f630315c0e7b60c3d30edb04626db8d5d4a875b49ea2eb85ff803c795b9a8702637a19efc1cf7673fac406fdfa732b3
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -17,4 +17,6 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  .idea/
20
- *.iml
20
+ *.iml
21
+ *.conf
22
+ coverage
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ dist: trusty
2
+ language: ruby rvm:
3
+ - 2.4.3
4
+ before_script:
5
+ - bundle exec rspec
@@ -3,9 +3,9 @@ $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.4"
6
+ spec.version = "0.1.5"
7
7
  spec.authors = ["BaritoLog"]
8
- spec.email = [""]
8
+ spec.email = ["pushm0v.development@gmail.com", "iman.tung@gmail.com"]
9
9
 
10
10
  spec.summary = %q{Fluentd output plugin for BaritoLog}
11
11
  spec.description = %q{This gem will forward output from fluentd to Barito-Flow}
@@ -22,7 +22,12 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.14"
24
24
  spec.add_development_dependency "rake", "~> 12.0"
25
- spec.add_development_dependency "test-unit", "~> 3.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "timecop"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "coveralls"
29
+ spec.add_development_dependency 'test-unit', '~> 3.2'
30
+
26
31
  spec.add_runtime_dependency "fluentd", "~> 0.12", ">= 0.12.0"
27
32
  spec.add_runtime_dependency "rest-client", "~> 2"
28
- end
33
+ end
@@ -0,0 +1,20 @@
1
+ class Fluent::Plugin::ClientTrail
2
+
3
+ attr_accessor :is_k8s, :sent_at, :hints
4
+
5
+ def initialize(is_k8s)
6
+ @is_k8s = is_k8s
7
+ @sent_at = Time.now.utc
8
+ @hints = []
9
+
10
+ end
11
+
12
+ def to_hash
13
+ {
14
+ 'is_k8s' => @is_k8s,
15
+ 'sent_at' => @sent_at,
16
+ 'hints' => @hints
17
+ }
18
+ end
19
+
20
+ end
@@ -0,0 +1,44 @@
1
+ class Fluent::Plugin::Timber
2
+ MESSAGE_KEY = "message"
3
+
4
+ HINTS_NO_TIMESTAMP = "no timestamp".freeze
5
+ HINTS_NO_MESSAGE = "no #{MESSAGE_KEY}".freeze
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
+ def self.create_timber(tag, time, record, trail)
24
+
25
+ timber = Fluent::Plugin::Timber.new
26
+ timber.tag = tag
27
+ timber.timestamp = time
28
+ timber.message = record[MESSAGE_KEY] if record.is_a?(Hash) and record.has_key?(MESSAGE_KEY)
29
+ timber.client_trail = trail
30
+
31
+ if timber.timestamp.nil?
32
+ timber.timestamp = Time.now.utc
33
+ trail.hints << HINTS_NO_TIMESTAMP
34
+ end
35
+
36
+ if timber.message.nil? or timber.message.empty?
37
+ timber.message = record.to_str
38
+ trail.hints << HINTS_NO_MESSAGE
39
+ end
40
+
41
+ timber
42
+
43
+ end
44
+ end
@@ -0,0 +1,76 @@
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 BaritoK8sOutput < BufferedOutput
8
+
9
+ PLUGIN_NAME = 'barito_k8s'
10
+
11
+ LABEL_APP_SECRET = 'baritoApplicationSecret'
12
+ LABEL_STREAM_ID = 'baritoStreamId'
13
+ LABEL_PRODUCE_HOST = 'baritoProduceHost'
14
+ LABEL_PRODUCE_PORT = 'baritoProducePort'
15
+ LABEL_PRODUCE_TOPIC = 'baritoProduceTopic'
16
+ LABEL_STORE_ID = 'baritoStoreId'
17
+ LABEL_FORWARD_ID = 'baritoForwarderId'
18
+ LABEL_CLIENT_ID = 'baritoClientId'
19
+
20
+
21
+ Fluent::Plugin.register_output(PLUGIN_NAME, self)
22
+
23
+ config_param :use_https, :bool, :default => false
24
+
25
+
26
+ # Overide from BufferedOutput
27
+ def start
28
+ super
29
+ end
30
+
31
+ # Overide from BufferedOutput
32
+ def format(tag, time, record)
33
+ [tag, time, record].to_msgpack
34
+ end
35
+
36
+ # Overide from BufferedOutput
37
+ def write(chunk)
38
+
39
+ chunk.msgpack_each do |tag, time, record|
40
+ labels = record['kubernetes']['labels']
41
+ url = produce_url(labels)
42
+ secret = application_secret(labels)
43
+
44
+ trail = Fluent::Plugin::ClientTrail.new(true)
45
+
46
+ timber = Fluent::Plugin::Timber::create_timber(tag, time, record, trail)
47
+ header = {content_type: :json, application_secret: secret}
48
+
49
+ RestClient.post url, timber.to_json, header
50
+ end
51
+ end
52
+
53
+ def produce_url(labels)
54
+ stream_id = labels[LABEL_STREAM_ID]
55
+ produce_host = labels[LABEL_PRODUCE_HOST]
56
+ produce_port = labels[LABEL_PRODUCE_PORT]
57
+ 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
+
62
+ protocol = @use_https? 'https' : 'http'
63
+
64
+ produce_url = "#{protocol}://#{produce_host}:#{produce_port}/str/#{stream_id}/st/#{store_id}/fw/#{forwarder_id}/cl/#{client_id}/produce/#{produce_topic}"
65
+ produce_url
66
+ end
67
+
68
+ def application_secret(labels)
69
+ labels[LABEL_APP_SECRET]
70
+ end
71
+
72
+
73
+ end
74
+
75
+
76
+ end
@@ -0,0 +1,42 @@
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 BaritoVMOutput < BufferedOutput
8
+
9
+ PLUGIN_NAME = "barito_vm"
10
+
11
+ Fluent::Plugin.register_output(PLUGIN_NAME, self)
12
+
13
+ config_param :application_secret, :string, :default => nil
14
+ config_param :produce_url, :string, :default => ''
15
+
16
+ # Overide from BufferedOutput
17
+ def start
18
+ super
19
+ end
20
+
21
+ # Overide from BufferedOutput
22
+ def format(tag, time, record)
23
+ [tag, time, record].to_msgpack
24
+ end
25
+
26
+ # Overide from BufferedOutput
27
+ def write(chunk)
28
+
29
+ chunk.msgpack_each do |tag, time, record|
30
+ trail = Fluent::Plugin::ClientTrail.new(false)
31
+
32
+ timber = Fluent::Plugin::Timber::create_timber(tag, time, record, trail)
33
+ header = {content_type: :json, application_secret: @application_secret}
34
+
35
+ RestClient.post @produce_url, timber.to_json, header
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+
42
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fluent::Plugin::Timber' do
4
+
5
+ describe 'create_timber' do
6
+
7
+ it 'is valid parameter' do
8
+ trail = Fluent::Plugin::ClientTrail.new(true)
9
+
10
+ tag = "some_tag"
11
+ time = Time.parse('2018-01-31 12:22:26')
12
+ record = {"message" => "some_message"}
13
+
14
+ timber = Fluent::Plugin::Timber::create_timber(tag, time, record, trail)
15
+ expect(timber.tag).to eq(tag)
16
+ expect(timber.timestamp).to eq(time)
17
+ expect(timber.message).to eq("some_message")
18
+ expect(timber.client_trail).to eq(trail)
19
+
20
+ end
21
+
22
+ it 'using current timestamp if timber.timestamp nil' do
23
+ time = Time.parse('2018-01-31 12:22:26')
24
+
25
+ Timecop.freeze(time) do
26
+ trail = Fluent::Plugin::ClientTrail.new(true)
27
+
28
+ record = {"message" => "some_message"}
29
+ timber = Fluent::Plugin::Timber::create_timber("some_tag", nil, record, trail)
30
+
31
+ expect(timber.timestamp).to eq(time)
32
+ expect(timber.client_trail.hints).to include(Fluent::Plugin::Timber::HINTS_NO_TIMESTAMP)
33
+ end
34
+ end
35
+
36
+ it 'using whole record if record[MESSAGE_KEY] emtpy' do
37
+ trail = Fluent::Plugin::ClientTrail.new(true)
38
+
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
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fluent::BaritoK8sOutput' do
4
+
5
+ describe '.produce_url' do
6
+ it do
7
+ k8s_labels = {
8
+ Fluent::BaritoK8sOutput::LABEL_PRODUCE_HOST => 'localhost',
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
+ Fluent::BaritoK8sOutput::LABEL_PRODUCE_TOPIC => 'sometopic'
15
+ }
16
+
17
+ out1 = Fluent::BaritoK8sOutput.new
18
+ out1.use_https = true
19
+ url = out1.produce_url(k8s_labels)
20
+ expect(url).to eq 'https://localhost:5000/str/1/st/2/fw/3/cl/4/produce/sometopic'
21
+
22
+ out2 = Fluent::BaritoK8sOutput.new
23
+ out2.use_https = false
24
+ url = out2.produce_url(k8s_labels)
25
+ expect(url).to eq 'http://localhost:5000/str/1/st/2/fw/3/cl/4/produce/sometopic'
26
+ end
27
+
28
+ end
29
+
30
+ describe '.application_secret' do
31
+ it do
32
+ out = Fluent::BaritoK8sOutput.new
33
+
34
+ k8s_labels = {
35
+ Fluent::BaritoK8sOutput::LABEL_APP_SECRET => 'some_secret'
36
+ }
37
+ secret = out.application_secret(k8s_labels)
38
+ expect(secret).to eq 'some_secret'
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,120 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ require 'simplecov'
17
+ require 'coveralls'
18
+
19
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
20
+ SimpleCov::Formatter::HTMLFormatter,
21
+ Coveralls::SimpleCov::Formatter
22
+ ]
23
+ SimpleCov.start do
24
+ add_filter do |src|
25
+ !(src.filename =~ /^#{SimpleCov.root}\/lib/)
26
+ end
27
+ end
28
+
29
+ RSpec.configure do |config|
30
+ # rspec-expectations config goes here. You can use an alternate
31
+ # assertion/expectation library such as wrong or the stdlib/minitest
32
+ # assertions if you prefer.
33
+ config.expect_with :rspec do |expectations|
34
+ # This option will default to `true` in RSpec 4. It makes the `description`
35
+ # and `failure_message` of custom matchers include text for helper methods
36
+ # defined using `chain`, e.g.:
37
+ # be_bigger_than(2).and_smaller_than(4).description
38
+ # # => "be bigger than 2 and smaller than 4"
39
+ # ...rather than:
40
+ # # => "be bigger than 2"
41
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
42
+ end
43
+
44
+ # rspec-mocks config goes here. You can use an alternate test double
45
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
46
+ config.mock_with :rspec do |mocks|
47
+ # Prevents you from mocking or stubbing a method that does not exist on
48
+ # a real object. This is generally recommended, and will default to
49
+ # `true` in RSpec 4.
50
+ mocks.verify_partial_doubles = true
51
+ end
52
+
53
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
54
+ # have no way to turn it off -- the option exists only for backwards
55
+ # compatibility in RSpec 3). It causes shared context metadata to be
56
+ # inherited by the metadata hash of host groups and examples, rather than
57
+ # triggering implicit auto-inclusion in groups with matching metadata.
58
+ config.shared_context_metadata_behavior = :apply_to_host_groups
59
+
60
+ # The settings below are suggested to provide a good initial experience
61
+ # with RSpec, but feel free to customize to your heart's content.
62
+ =begin
63
+ # This allows you to limit a spec run to individual examples or groups
64
+ # you care about by tagging them with `:focus` metadata. When nothing
65
+ # is tagged with `:focus`, all examples get run. RSpec also provides
66
+ # aliases for `it`, `describe`, and `context` that include `:focus`
67
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
68
+ config.filter_run_when_matching :focus
69
+
70
+ # Allows RSpec to persist some state between runs in order to support
71
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
72
+ # you configure your source control system to ignore this file.
73
+ config.example_status_persistence_file_path = "spec/examples.txt"
74
+
75
+ # Limits the available syntax to the non-monkey patched syntax that is
76
+ # recommended. For more details, see:
77
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
78
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
79
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
80
+ config.disable_monkey_patching!
81
+
82
+ # This setting enables warnings. It's recommended, but in some cases may
83
+ # be too noisy due to issues in dependencies.
84
+ config.warnings = true
85
+
86
+ # Many RSpec users commonly either run the entire suite or an individual
87
+ # file, and it's useful to allow more verbose output when running an
88
+ # individual spec file.
89
+ if config.files_to_run.one?
90
+ # Use the documentation formatter for detailed output,
91
+ # unless a formatter has already been configured
92
+ # (e.g. via a command-line flag).
93
+ config.default_formatter = "doc"
94
+ end
95
+
96
+ # Print the 10 slowest examples and example groups at the
97
+ # end of the spec run, to help surface which specs are running
98
+ # particularly slow.
99
+ config.profile_examples = 10
100
+
101
+ # Run specs in random order to surface order dependencies. If you find an
102
+ # order dependency and want to debug it, you can fix the order by providing
103
+ # the seed, which is printed after each run.
104
+ # --seed 1234
105
+ config.order = :random
106
+
107
+ # Seed global randomization in this process using the `--seed` CLI option.
108
+ # Setting this allows you to use `--seed` to deterministically reproduce
109
+ # test failures related to randomization by passing the same `--seed` value
110
+ # as the one that triggered the failure.
111
+ Kernel.srand config.seed
112
+ =end
113
+ require 'fluent/test'
114
+ require 'fluent/test/driver/output'
115
+ require 'fluent/plugin/out_barito_vm'
116
+ require 'fluent/plugin/out_barito_k8s'
117
+ require 'fluent/plugin/barito_client_trail'
118
+ require 'fluent/plugin/barito_timber'
119
+ require 'timecop'
120
+ 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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - BaritoLog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-26 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,76 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
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: coveralls
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'
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: test-unit
43
99
  requirement: !ruby/object:Gem::Requirement
44
100
  requirements:
45
101
  - - "~>"
46
102
  - !ruby/object:Gem::Version
47
- version: '3.0'
103
+ version: '3.2'
48
104
  type: :development
49
105
  prerelease: false
50
106
  version_requirements: !ruby/object:Gem::Requirement
51
107
  requirements:
52
108
  - - "~>"
53
109
  - !ruby/object:Gem::Version
54
- version: '3.0'
110
+ version: '3.2'
55
111
  - !ruby/object:Gem::Dependency
56
112
  name: fluentd
57
113
  requirement: !ruby/object:Gem::Requirement
@@ -88,20 +144,28 @@ dependencies:
88
144
  version: '2'
89
145
  description: This gem will forward output from fluentd to Barito-Flow
90
146
  email:
91
- - ''
147
+ - pushm0v.development@gmail.com
148
+ - iman.tung@gmail.com
92
149
  executables: []
93
150
  extensions: []
94
151
  extra_rdoc_files: []
95
152
  files:
153
+ - ".coveralls.yml"
96
154
  - ".gitignore"
155
+ - ".rspec"
156
+ - ".travis.yml"
97
157
  - Gemfile
98
158
  - LICENSE
99
159
  - README.md
100
160
  - Rakefile
101
161
  - fluent-plugin-barito.gemspec
102
- - lib/fluent/plugin/out_barito.rb
103
- - test/helper.rb
104
- - test/plugin/test_out_barito.rb
162
+ - lib/fluent/plugin/barito_client_trail.rb
163
+ - lib/fluent/plugin/barito_timber.rb
164
+ - lib/fluent/plugin/out_barito_k8s.rb
165
+ - lib/fluent/plugin/out_barito_vm.rb
166
+ - spec/lib/fluent/plugin/barito_timber_spec.rb
167
+ - spec/lib/fluent/plugin/out_barito_k8s_spec.rb
168
+ - spec/spec_helper.rb
105
169
  homepage: https://github.com/BaritoLog/Barito-Fluent-Plugin
106
170
  licenses:
107
171
  - Apache-2.0
@@ -122,10 +186,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
186
  version: '0'
123
187
  requirements: []
124
188
  rubyforge_project:
125
- rubygems_version: 2.5.2
189
+ rubygems_version: 2.6.14
126
190
  signing_key:
127
191
  specification_version: 4
128
192
  summary: Fluentd output plugin for BaritoLog
129
193
  test_files:
130
- - test/helper.rb
131
- - test/plugin/test_out_barito.rb
194
+ - spec/lib/fluent/plugin/barito_timber_spec.rb
195
+ - spec/lib/fluent/plugin/out_barito_k8s_spec.rb
196
+ - spec/spec_helper.rb
@@ -1,108 +0,0 @@
1
- require 'fluent/output'
2
- require 'rest-client'
3
-
4
- module Fluent
5
- class BaritoOutput < BufferedOutput
6
-
7
- TIMESTAMP_FIELD = "@timestamp"
8
-
9
- Fluent::Plugin.register_output("barito", self)
10
-
11
- config_param :use_https, :bool, :default => false
12
- config_param :use_kubernetes, :bool, :default => false
13
-
14
- config_param :application_secret, :string, :default => nil
15
- config_param :stream_id, :string, :default => ''
16
- config_param :store_id, :string, :default => ''
17
- config_param :client_id, :string, :default => ''
18
- config_param :forwarder_id, :string, :default => ''
19
- config_param :produce_host, :string, :default => ''
20
- config_param :produce_port, :string, :default => ''
21
- config_param :produce_topic, :string, :default => ''
22
-
23
- config_param :barito_market_url, :string, :default => nil
24
- config_param :produce_url, :string, :default => ''
25
-
26
- def start
27
- super
28
- @protocol = 'http'
29
- get_config
30
- end
31
-
32
- def get_config
33
- @barito_market_url ||= ENV['BARITO_MARKET_URL']
34
- @application_secret ||= ENV['BARITO_MARKET_APPLICATION_SECRET']
35
- response = RestClient.get @barito_market_url, {content_type: :json, application_secret: @application_secret}
36
- body = response.body
37
- unless body.nil?
38
- client = JSON.parse(body)
39
- @produce_url = client["client"]["produce_url"]
40
- if @produce_url.nil?
41
- log.error("Produce URL from BaritoMarket is nil")
42
- else
43
- log.info("Start with Produce URL : #{@produce_url}")
44
- end
45
- end
46
- end
47
-
48
- def send_message(url, message)
49
- RestClient.post url, message, {content_type: :json, application_secret: @application_secret}
50
- end
51
-
52
- def format(tag, time, record)
53
- [tag, time, record].to_msgpack
54
- end
55
-
56
- def generate_produce_url
57
- unless @produce_url.nil? || @produce_url == ''
58
- return @produce_url
59
- end
60
-
61
- if @use_https
62
- @protocol = 'https'
63
- end
64
-
65
- return "#{@protocol}://#{@produce_host}:#{@produce_port}/str/#{@stream_id}/st/#{@store_id}/fw/#{@forwarder_id}/cl/#{@client_id}/produce/#{@produce_topic}"
66
- end
67
-
68
- def configure_params_k8(params)
69
- @application_secret = params['baritoApplicationSecret']
70
- @stream_id = params['baritoStreamId']
71
- @produce_host = params['baritoProduceHost']
72
- @produce_port = params['baritoProducePort']
73
- @produce_topic = params['baritoProduceTopic']
74
- @store_id = params['baritoStoreId']
75
- @forwarder_id = params['baritoForwarderId']
76
- @client_id = params['baritoClientId']
77
- end
78
-
79
- def write(chunk)
80
- chunk.msgpack_each {|(tag, time, record)|
81
- next unless record.is_a? Hash
82
-
83
- if @use_kubernetes
84
- next unless not record['kubernetes']['labels'].nil?
85
- params = record['kubernetes']['labels']
86
- configure_params_k8(params)
87
-
88
- next unless not @stream_id.nil? and @stream_id != ''
89
- end
90
-
91
- unless record.has_key?(TIMESTAMP_FIELD)
92
- t = Time.now.utc
93
- unless time.nil?
94
- if time.is_a?(Integer)
95
- t = Time.at(time)
96
- end
97
- end
98
- record[TIMESTAMP_FIELD] = t.strftime('%Y-%m-%dT%H:%M:%S.%L%z')
99
- end
100
-
101
- message = record.to_json
102
- url = generate_produce_url
103
-
104
- send_message(url, message)
105
- }
106
- end
107
- end
108
- end
@@ -1,8 +0,0 @@
1
- $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
- require "test-unit"
3
- require "fluent/test"
4
- require "fluent/test/driver/output"
5
- require "fluent/test/helpers"
6
-
7
- Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
- Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -1,18 +0,0 @@
1
- require "helper"
2
- require "fluent/plugin/out_barito.rb"
3
-
4
- class BaritoOutputTest < Test::Unit::TestCase
5
- setup do
6
- Fluent::Test.setup
7
- end
8
-
9
- test "failure" do
10
- flunk
11
- end
12
-
13
- private
14
-
15
- def create_driver(conf)
16
- Fluent::Test::Driver::Output.new(Fluent::Plugin::BaritoOutput).configure(conf)
17
- end
18
- end