Skip to content

Commit

Permalink
Merge pull request #32 from logicmonitor/ahsan/gzip-compression
Browse files Browse the repository at this point in the history
gzip compression
  • Loading branch information
ahsan13jan authored Nov 25, 2020
2 parents 806ab9c + bc865c2 commit 1b92014
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fluent-plugin-lm-logs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |spec|
spec.name = "fluent-plugin-lm-logs"
spec.version = '0.0.11'
spec.version = '0.0.12'
spec.authors = ["LogicMonitor"]
spec.email = "rubygems@logicmonitor.com"
spec.summary = "LogicMonitor logs fluentd output plugin"
Expand Down
15 changes: 13 additions & 2 deletions lib/fluent/plugin/out_lm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'base64'
require 'net/http'
require 'net/https'
require('zlib')


module Fluent
Expand All @@ -28,6 +29,8 @@ class LmOutput < BufferedOutput

config_param :force_encoding, :string, :default => ""

config_param :compression, :string, :default => ""

# This method is called before starting.
# 'conf' is a Hash that includes configuration parameters.
# If the configuration is invalid, raise Fluent::ConfigError.
Expand Down Expand Up @@ -116,8 +119,16 @@ def send_batch(events)

request = Net::HTTP::Post.new(uri.request_uri)
request['authorization'] = generate_token(events)
request['Content-type'] = "application/json"
request.body = body
request['Content-type'] = "application/json"

if @compression == "gzip"
request['Content-Encoding'] = "gzip"
gzip = Zlib::GzipWriter.new(StringIO.new)
gzip << body
request.body = gzip.close.string
else
request.body = body
end

resp = http.request(request)
if @debug || (!resp.kind_of? Net::HTTPSuccess)
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_out_lm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_valid_subject

tag = "lm.test"
time = Time.parse("2020-08-23T00:53:15+00:00").to_i
record = {"message" => "Hello from test", "timestamp2" => "2020-10-30T00:29:08.629701504Z" ,"a" => { "b" => "lm_property_value" } }
record = {"message" => "Hello from test", "timestamp" => "2020-10-30T00:29:08.629701504Z" ,"a" => { "b" => "lm_property_value" } }

result = plugin.process_record(tag, time, record)

Expand Down

0 comments on commit 1b92014

Please sign in to comment.