fluent-plugin-barito 0.3.2 → 0.3.3

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
  SHA256:
3
- metadata.gz: dddd5d0082d68458cba7621f2f4c01d0ed7f1fed479de55af65acd9b1e5f40be
4
- data.tar.gz: e117c347df66acd103f72bb850cb882b5ab35391f1fecf947d68734636f39597
3
+ metadata.gz: ecf8a3646e7930f83602324b333be4399b4995455f061fa92c4a059b7e054c1d
4
+ data.tar.gz: f0abcd3652ba0ddbe029f59ed24332a87102bb2971a017577332418df60a9ffd
5
5
  SHA512:
6
- metadata.gz: ace5ec573a0aca28a58f06ebd1406050a6989d317219441a7cf0a962510e2d745dae06219e469f6adf5ad78a2c3da0ce6b80df44a15c3e89fd53f6e960cd61d5
7
- data.tar.gz: 4dd29b131547cd237c28f57a5f4c87a0223cb296e5381965f88dd07b750c83e8eecff3e77337ba8e777649ad822f4db4d4fc7b73d8578d94b2b029be0ec7618a
6
+ metadata.gz: cb971966ecb6feff749865a6cea6c5bdc812bb104fe2a6fa8a99aebf0711dae35268dd9066ffe1206794322484611351a47989b022a88e54648d1c84e947448c
7
+ data.tar.gz: a54188a399d3958707511c178b0555b24102965f181e39e0d421f8498532a2ff3ff39cfd76a101a6f7c6245725fdffaecf1317d50393af5374953c349ae0c95e
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ **0.3.3**
4
+
5
+ - Print verbose error on logs when receiving failed response from the server
6
+
3
7
  **0.3.2**
4
8
 
5
9
  - Handle batch produce (from k8s)
@@ -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.2"
6
+ spec.version = "0.3.3"
7
7
  spec.authors = ["BaritoLog"]
8
8
  spec.email = ["pushm0v.development@gmail.com", "iman.tung@gmail.com"]
9
9
 
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
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
+ spec.add_development_dependency 'webmock', '~> 3.4'
30
31
 
31
32
  spec.add_runtime_dependency "fluentd", "~> 0.12", ">= 0.12.0"
32
33
  spec.add_runtime_dependency "rest-client", "~> 2"
@@ -0,0 +1,20 @@
1
+ require 'rest-client'
2
+
3
+ class Fluent::Plugin::BaritoTransport
4
+
5
+ attr_accessor :produce_url, :logger
6
+
7
+ def initialize(produce_url, logger)
8
+ @produce_url = produce_url
9
+ @logger = logger
10
+ end
11
+
12
+ def send(timber, header)
13
+ begin
14
+ RestClient.post @produce_url, timber.to_json, header
15
+ rescue Exception => e
16
+ @logger.error [e.message, e.response, header].join(', ')
17
+ end
18
+ end
19
+
20
+ end
@@ -1,7 +1,7 @@
1
1
  require 'fluent/output'
2
- require 'rest-client'
3
2
  require_relative 'barito_timber'
4
3
  require_relative 'barito_client_trail'
4
+ require_relative 'barito_transport'
5
5
 
6
6
  module Fluent
7
7
  class BaritoBatchK8sOutput < BufferedOutput
@@ -30,6 +30,8 @@ module Fluent
30
30
  data = {
31
31
  'items' => []
32
32
  }
33
+
34
+ transport = Fluent::Plugin::BaritoTransport.new(@produce_url, log)
33
35
  chunk.msgpack_each do |tag, time, record|
34
36
 
35
37
  # Kubernetes annotations
@@ -62,7 +64,7 @@ module Fluent
62
64
  header = {content_type: :json, 'X-App-Secret' => @application_secret}
63
65
  end
64
66
 
65
- response = RestClient.post @produce_url, data.to_json, header
67
+ transport.send(data, header)
66
68
  end
67
69
 
68
70
  def clean_attribute(record)
@@ -1,7 +1,7 @@
1
1
  require 'fluent/output'
2
- require 'rest-client'
3
2
  require_relative 'barito_timber'
4
3
  require_relative 'barito_client_trail'
4
+ require_relative 'barito_transport'
5
5
 
6
6
  module Fluent
7
7
  class BaritoBatchVMOutput < BufferedOutput
@@ -30,6 +30,7 @@ module Fluent
30
30
  data = {
31
31
  'items' => []
32
32
  }
33
+ transport = Fluent::Plugin::BaritoTransport.new(@produce_url, log)
33
34
  chunk.msgpack_each do |tag, time, record|
34
35
  trail = Fluent::Plugin::ClientTrail.new(false)
35
36
  timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
@@ -48,7 +49,7 @@ module Fluent
48
49
  header = {content_type: :json, 'X-App-Secret' => @application_secret}
49
50
  end
50
51
 
51
- response = RestClient.post @produce_url, data.to_json, header
52
+ transport.send(data, header)
52
53
  end
53
54
  end
54
55
  end
@@ -1,7 +1,7 @@
1
1
  require 'fluent/output'
2
- require 'rest-client'
3
2
  require_relative 'barito_timber'
4
3
  require_relative 'barito_client_trail'
4
+ require_relative 'barito_transport'
5
5
 
6
6
  module Fluent
7
7
  class BaritoK8sOutput < BufferedOutput
@@ -53,6 +53,7 @@ module Fluent
53
53
  end
54
54
 
55
55
  record = clean_attribute(record)
56
+ transport = Fluent::Plugin::BaritoTransport.new(url, log)
56
57
  trail = Fluent::Plugin::ClientTrail.new(true)
57
58
  timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
58
59
  new_timber = merge_log_attribute(timber)
@@ -65,7 +66,7 @@ module Fluent
65
66
  'host' => k8s_metadata['host']
66
67
  }
67
68
 
68
- RestClient.post url, new_timber.to_json, header
69
+ transport.send(new_timber, header)
69
70
  end
70
71
  end
71
72
 
@@ -1,7 +1,7 @@
1
1
  require 'fluent/output'
2
- require 'rest-client'
3
2
  require_relative 'barito_timber'
4
3
  require_relative 'barito_client_trail'
4
+ require_relative 'barito_transport'
5
5
 
6
6
  module Fluent
7
7
  class BaritoVMOutput < BufferedOutput
@@ -28,6 +28,7 @@ module Fluent
28
28
  # Overide from BufferedOutput
29
29
  def write(chunk)
30
30
  chunk.msgpack_each do |tag, time, record|
31
+ transport = Fluent::Plugin::BaritoTransport.new(@produce_url, log)
31
32
  trail = Fluent::Plugin::ClientTrail.new(false)
32
33
  timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
33
34
 
@@ -41,8 +42,7 @@ module Fluent
41
42
  else
42
43
  header = {content_type: :json, 'X-App-Secret' => @application_secret}
43
44
  end
44
-
45
- RestClient.post @produce_url, timber.to_json, header
45
+ transport.send(timber, header)
46
46
  end
47
47
  end
48
48
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'fluent/engine'
3
+ require 'fluent/log'
4
+
5
+ describe 'Fluent::Plugin::BaritoTransport' do
6
+ describe 'send' do
7
+ context 'exception' do
8
+ let(:user_agent) { 'Barito' }
9
+ let(:log) { Fluent::Test::DummyLogDevice.new }
10
+ let(:logger) { ServerEngine::DaemonLogger.new(log) }
11
+
12
+ it 'produce log' do
13
+ mock_host = 'localhost-not-exist'
14
+ uri_string = "http://#{mock_host}/"
15
+ stub_request(:post, uri_string).
16
+ with(
17
+ headers: {
18
+ 'Accept'=> '*/*',
19
+ 'Host'=> mock_host,
20
+ 'User-Agent'=>user_agent
21
+ }).
22
+ to_return(status: 404, body: "not-exist", headers: {'User-Agent': user_agent })
23
+
24
+ transport = Fluent::Plugin::BaritoTransport.new(uri_string, logger)
25
+ expect(logger).to receive(:error).with("404 Not Found, not-exist, {:\"User-Agent\"=>\"#{user_agent}\"}")
26
+ transport.send({},{'User-Agent': user_agent})
27
+ end
28
+ end
29
+ end
30
+ end
@@ -117,5 +117,7 @@ RSpec.configure do |config|
117
117
  require 'fluent/plugin/out_barito_batch_k8s'
118
118
  require 'fluent/plugin/barito_client_trail'
119
119
  require 'fluent/plugin/barito_timber'
120
+ require 'fluent/plugin/barito_transport'
120
121
  require 'timecop'
122
+ require 'webmock/rspec'
121
123
  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.3.2
4
+ version: 0.3.3
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-11 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.4'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: fluentd
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -162,11 +176,13 @@ files:
162
176
  - fluent-plugin-barito.gemspec
163
177
  - lib/fluent/plugin/barito_client_trail.rb
164
178
  - lib/fluent/plugin/barito_timber.rb
179
+ - lib/fluent/plugin/barito_transport.rb
165
180
  - lib/fluent/plugin/out_barito_batch_k8s.rb
166
181
  - lib/fluent/plugin/out_barito_batch_vm.rb
167
182
  - lib/fluent/plugin/out_barito_k8s.rb
168
183
  - lib/fluent/plugin/out_barito_vm.rb
169
184
  - spec/lib/fluent/plugin/barito_timber_spec.rb
185
+ - spec/lib/fluent/plugin/barito_transport_spec.rb
170
186
  - spec/lib/fluent/plugin/out_barito_batch_k8s_spec.rb
171
187
  - spec/lib/fluent/plugin/out_barito_k8s_spec.rb
172
188
  - spec/spec_helper.rb
@@ -196,6 +212,7 @@ specification_version: 4
196
212
  summary: Fluentd output plugin for BaritoLog
197
213
  test_files:
198
214
  - spec/lib/fluent/plugin/barito_timber_spec.rb
215
+ - spec/lib/fluent/plugin/barito_transport_spec.rb
199
216
  - spec/lib/fluent/plugin/out_barito_batch_k8s_spec.rb
200
217
  - spec/lib/fluent/plugin/out_barito_k8s_spec.rb
201
218
  - spec/spec_helper.rb