From 10c587a2bf01e30ea960dfd44662942324779368 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 25 Nov 2020 12:45:45 +0500 Subject: [PATCH 1/4] Gzip compression added --- lib/fluent/plugin/out_lm.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/out_lm.rb b/lib/fluent/plugin/out_lm.rb index 18f015a..66faacf 100644 --- a/lib/fluent/plugin/out_lm.rb +++ b/lib/fluent/plugin/out_lm.rb @@ -8,6 +8,7 @@ require 'base64' require 'net/http' require 'net/https' +require('zlib') module Fluent @@ -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. @@ -116,8 +119,17 @@ 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 + log.info "Gzipped json #{request.body}" + else + request.body = body + end resp = http.request(request) if @debug || (!resp.kind_of? Net::HTTPSuccess) From ab237cd11ec264a779961feaa8e99e6cdef83891 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 25 Nov 2020 13:09:47 +0500 Subject: [PATCH 2/4] Log removed --- lib/fluent/plugin/out_lm.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/fluent/plugin/out_lm.rb b/lib/fluent/plugin/out_lm.rb index 66faacf..cf307ff 100644 --- a/lib/fluent/plugin/out_lm.rb +++ b/lib/fluent/plugin/out_lm.rb @@ -126,7 +126,6 @@ def send_batch(events) gzip = Zlib::GzipWriter.new(StringIO.new) gzip << body request.body = gzip.close.string - log.info "Gzipped json #{request.body}" else request.body = body end From 6b26c2763c513398a289ebc2a8e9cafcca086024 Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 25 Nov 2020 13:21:34 +0500 Subject: [PATCH 3/4] Unit test fix --- test/plugin/test_out_lm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugin/test_out_lm.rb b/test/plugin/test_out_lm.rb index 7d8ebeb..9e9b4b3 100644 --- a/test/plugin/test_out_lm.rb +++ b/test/plugin/test_out_lm.rb @@ -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) From bc865c2faee5b7eaf2658631e0eb0913b458fb8b Mon Sep 17 00:00:00 2001 From: Ahsan Date: Wed, 25 Nov 2020 14:11:24 +0500 Subject: [PATCH 4/4] Gem version updated for release --- fluent-plugin-lm-logs.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-plugin-lm-logs.gemspec b/fluent-plugin-lm-logs.gemspec index e0c121e..08d2abb 100644 --- a/fluent-plugin-lm-logs.gemspec +++ b/fluent-plugin-lm-logs.gemspec @@ -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"