Skip to content

Commit ad7e535

Browse files
authored
Feat: Add gzip_pattern config option (#168)
1 parent 1da02a0 commit ad7e535

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 3.5.0
22
- Added support for including objects restored from Glacier or Glacier Deep [#199](https://github.com/logstash-plugins/logstash-input-s3/issues/199)
3+
- Added `gzip_pattern` option, enabling more flexible determination of whether a file is gzipped [#165](https://github.com/logstash-plugins/logstash-input-s3/issues/165)
34

45
## 3.4.1
56
- Fixed link formatting for input type (documentation)

docs/index.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
4646
| <<plugins-{type}s-{plugin}-delete>> |<<boolean,boolean>>|No
4747
| <<plugins-{type}s-{plugin}-endpoint>> |<<string,string>>|No
4848
| <<plugins-{type}s-{plugin}-exclude_pattern>> |<<string,string>>|No
49+
| <<plugins-{type}s-{plugin}-gzip_pattern>> |<<string,string>>|No
4950
| <<plugins-{type}s-{plugin}-include_object_properties>> |<<boolean,boolean>>|No
5051
| <<plugins-{type}s-{plugin}-interval>> |<<number,number>>|No
5152
| <<plugins-{type}s-{plugin}-prefix>> |<<string,string>>|No
@@ -158,6 +159,14 @@ guaranteed to work correctly with the AWS SDK.
158159

159160
Ruby style regexp of keys to exclude from the bucket
160161

162+
[id="plugins-{type}s-{plugin}-gzip_pattern"]
163+
===== `gzip_pattern`
164+
165+
* Value type is <<string,string>>
166+
* Default value is `"\.gz(ip)?$"`
167+
168+
Regular expression used to determine whether an input file is in gzip format.
169+
161170
[id="plugins-{type}s-{plugin}-additional_settings"]
162171
===== `additional_settings`
163172

lib/logstash/inputs/s3.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class LogStash::Inputs::S3 < LogStash::Inputs::Base
8282
# be present.
8383
config :include_object_properties, :validate => :boolean, :default => false
8484

85+
# Regular expression used to determine whether an input file is in gzip format.
86+
# default to an expression that matches *.gz and *.gzip file extensions
87+
config :gzip_pattern, :validate => :string, :default => "\.gz(ip)?$"
88+
8589
public
8690
def register
8791
require "fileutils"
@@ -318,7 +322,7 @@ def read_gzip_file(filename, block)
318322

319323
private
320324
def gzip?(filename)
321-
filename.end_with?('.gz','.gzip')
325+
Regexp.new(@gzip_pattern).match(filename)
322326
end
323327

324328
private
303 Bytes
Binary file not shown.

spec/inputs/s3_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,20 @@
443443
include_examples "generated events"
444444
end
445445

446-
context 'compressed with gzip extension' do
446+
context 'compressed with gzip extension and using default gzip_pattern option' do
447447
let(:log) { double(:key => 'log.gz', :last_modified => Time.now - 2 * day, :content_length => 5, :storage_class => 'STANDARD') }
448448
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'compressed.log.gzip') }
449449

450450
include_examples "generated events"
451451
end
452452

453+
context 'compressed with gzip extension and using custom gzip_pattern option' do
454+
let(:config) { super.merge({ "gzip_pattern" => "gee.zip$" }) }
455+
let(:log) { double(:key => 'log.gee.zip', :last_modified => Time.now - 2 * day, :content_length => 5, :storage_class => 'STANDARD') }
456+
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'compressed.log.gee.zip') }
457+
include_examples "generated events"
458+
end
459+
453460
context 'plain text' do
454461
let(:log_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'uncompressed.log') }
455462

0 commit comments

Comments
 (0)