fluent-plugin-http 0.2.0 → 0.3.0

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: e6be21a1fe25c537139150f938f6dfdbef1fb7f5
4
- data.tar.gz: 3b45cfa458337d855d26b09d0314f0458364d453
3
+ metadata.gz: a05bb6dde35957eb0441bae8de152a7388a6b109
4
+ data.tar.gz: 64da30f0548d530bcdeca791bf3b7921931c7127
5
5
  SHA512:
6
- metadata.gz: cabba8b61a03f4750e180bd8c1acfb85af5fc6335e2229cc51ef6139c16b73aee531e0985e0aaa332b310ccf82478a7321e0b6eba7ca6e3c5ffab9a9b73f68dc
7
- data.tar.gz: 0d262e0ae06054e832797f3bbeab5a6f109f23c41b8ab03d0ad12cd2459457d8290d18c36296ccbd6d5d9c1dc406cb07b23fed9d9a770a02e8ac5f48148c42e1
6
+ metadata.gz: 6dc693aae20a9fc985b4d060ad7874e2043dc5be8f2dc0e46e041ee0477eded844f5ef530bbcc9662230b6d896437c593c0c6aee233e23976c5e486d7a8534fc
7
+ data.tar.gz: 4c27023f556ad1a1750b050c2afc8226e6e32ae7cc3b36741fbea09f9b83d0ede74f6732d98bd4dfb6cb13921c1499f6cdbb4463681041dd42abcbf59a6e612d
@@ -4,7 +4,7 @@ module Fluent
4
4
  # Unsuccessful response error
5
5
  ResponseError = Class.new(StandardError) do
6
6
  def self.error(request, response)
7
- new "Failed to POST event record to #{request.uri} because of " \
7
+ new "Failed to POST event records to #{request.uri} because of " \
8
8
  "unsuccessful response code: #{response.code.inspect} " \
9
9
  "#{response.body.inspect}"
10
10
  end
@@ -2,6 +2,7 @@
2
2
  require 'fluent/output'
3
3
  require 'uri'
4
4
  require 'net/http'
5
+ require 'json'
5
6
 
6
7
  # Fluentd
7
8
  module Fluent
@@ -61,32 +62,40 @@ module Fluent
61
62
  [tag, time, record].to_msgpack
62
63
  end
63
64
 
64
- USER_AGENT = 'FluentPluginHTTP'
65
- private_constant :USER_AGENT
66
-
67
65
  # Sends the event records
68
66
  #
69
67
  # @param chunk [#msgpack_each] buffer chunk that includes multiple
70
68
  # formatted events
71
69
  # @return void
72
70
  def write(chunk)
73
- chunk.msgpack_each do |_tag, _time, record|
74
- post_record = Net::HTTP::Post.new(url)
75
- post_record.set_form_data(record)
76
- post_record['User-Agent'] = USER_AGENT
71
+ records = []
72
+ chunk.msgpack_each { |_tag, _time, record| records << record }
77
73
 
78
- response = http.request(post_record)
74
+ post_records = post_records_request(records)
75
+ response = http.request(post_records)
79
76
 
80
- unless accept_status_code.include?(response.code)
81
- raise ResponseError.error(post_record, response)
82
- end
83
- end
77
+ return if accept_status_code.include?(response.code)
78
+ raise ResponseError.error(post_records, response)
84
79
  end
85
80
 
86
81
  private
87
82
 
88
83
  attr_reader :http
89
84
 
85
+ JSON_MIME_TYPE = 'application/json'
86
+ USER_AGENT = 'FluentPluginHTTP'
87
+ SERIALIZER = JSON
88
+
89
+ private_constant :USER_AGENT, :JSON_MIME_TYPE, :SERIALIZER
90
+
91
+ def post_records_request(records)
92
+ Net::HTTP::Post.new(url).tap do |request|
93
+ request.body = SERIALIZER.dump(records)
94
+ request.content_type = JSON_MIME_TYPE
95
+ request['User-Agent'] = USER_AGENT
96
+ end
97
+ end
98
+
90
99
  def validate_url(test_url)
91
100
  url = URI(test_url)
92
101
  return url if url.scheme == 'http' || url.scheme == 'https'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-14 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.6.6
139
+ rubygems_version: 2.6.8
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Fluentd output plugin that sends event records via HTTP