Skip to content

Commit 1689365

Browse files
committed
enable force-decoding with decode_gzip => force
1 parent f3d7899 commit 1689365

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.5.0
2+
- Added ability to force gzip-decoding regardless of filename with `decode_gzip => force`
3+
14
## 3.4.1
25
- Fixed link formatting for input type (documentation)
36

docs/index.asciidoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ The name of the S3 bucket.
140140

141141
Whether to delete processed files from the original bucket.
142142

143+
[id="plugins-{type}s-{plugin}-decode_gzip"]
144+
==== `decode_gzip`
145+
146+
* Value type is <<string,string>>
147+
* Acceptable values are `detect` and `force`
148+
* Default value is `detect`
149+
150+
Controls behaviour for performing gzip-decoding on files.
151+
152+
* `detect` will perform gzip-decoding on files with matching extensions (`.gz` and `.gzip`)
153+
* `force` will perform gzip-decoding on all files, regardless of extension or contents.
154+
143155
[id="plugins-{type}s-{plugin}-endpoint"]
144156
===== `endpoint`
145157

lib/logstash/inputs/s3.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base
7979
# be present.
8080
config :include_object_properties, :validate => :boolean, :default => false
8181

82+
# Controls which files are handled as gzip.
83+
config :decode_gzip, :validate => %w(detect force), :default => 'detect'
84+
8285
public
8386
def register
8487
require "fileutils"
@@ -109,6 +112,12 @@ def register
109112
if !@watch_for_new_files && original_params.include?('interval')
110113
logger.warn("`watch_for_new_files` has been disabled; `interval` directive will be ignored.")
111114
end
115+
116+
@gzip_detector = case @decode_gzip
117+
when "force" then -> (_) { true }
118+
when "detect" then -> (filename) { filename.end_with?('.gz','.gzip') }
119+
else fail(LogStah::ConfigurationError, "unsupported value `#{@decode_gzip}` for decode_gzip")
120+
end
112121
end
113122

114123
public
@@ -315,7 +324,7 @@ def read_gzip_file(filename, block)
315324

316325
private
317326
def gzip?(filename)
318-
filename.end_with?('.gz','.gzip')
327+
@gzip_detector.call(filename)
319328
end
320329

321330
private

logstash-input-s3.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-input-s3'
4-
s.version = '3.4.1'
4+
s.version = '3.5.0'
55
s.licenses = ['Apache-2.0']
66
s.summary = "Streams events from files in a S3 bucket"
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

spec/inputs/s3_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@
428428
include_examples "generated events"
429429
end
430430

431+
context 'force gzip decoding' do
432+
let(:config) { super().merge('decode_gzip' => 'force') }
433+
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'compressed.log.gz') }
434+
435+
include_examples "generated events"
436+
end
437+
431438
context 'compressed with gzip extension' do
432439
let(:log) { double(:key => 'log.gz', :last_modified => Time.now - 2 * day, :content_length => 5, :storage_class => 'STANDARD') }
433440
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'compressed.log.gzip') }

0 commit comments

Comments
 (0)