fluent-plugin-azure-storage-append-blob-lts 0.6.3 → 0.7.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
  SHA256:
3
- metadata.gz: f9e6de27ebbf624d51968e415d502111523d3fd670d2345558381b03895934d6
4
- data.tar.gz: 80fbe42cee9d82adb02afbaf2cfed1fd92b0d4fbbbfb1e67b50e328795d90b23
3
+ metadata.gz: 4e900def94ba82e3cb4e29b5ce37beed5b3801b951e5f68b1a1bc1e5a84ebfc1
4
+ data.tar.gz: 64780e024de8bb93023c7c42c5aff1d26ae461f51a769aae3ef74697fb607264
5
5
  SHA512:
6
- metadata.gz: d3c2e0296f88ae875f19043e322678aa9a7ea3a26e9bb41f9f4292991ff09a6a50022d03c1da48b36e0c724c2e9e83f70ef431e1b9a3fc628507774a8de32943
7
- data.tar.gz: a86038ca1acc515dd05df9f86d014cef337c5cc8a70847a15dd94b8f86fe2233c5b0a49be988f26a3da86f298d1aa27465aab4fb904ddd8eeef9e16535291d99
6
+ metadata.gz: d7da2a55760e6221520198ccb54632892bfc3293d68bd78f0b088260f2d6ca2ff49b014caaff7427fa99de6731a52f642167be9df96e930323ffce7eb54d70e0
7
+ data.tar.gz: bc0cacd9e1bc4fb6a2e425a0556d8c9737fc2f35cd4530399bb3e95f62fa1b55804b118f4ec7550dadc549e29a3c7767eb2c61a3f7d84fca1bb24969084ea3dd
@@ -1,29 +1,28 @@
1
+ ---
2
+ jobs:
3
+ build:
4
+ name: Build + Publish
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v3
8
+ - name: Set up Ruby
9
+ uses: actions/setup-ruby@v1
10
+ with:
11
+ ruby-version: "3.1"
12
+ - env:
13
+ RUBYGEMS_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
14
+ name: Publish to RubyGems
15
+ run: |
16
+ mkdir -p $HOME/.gem
17
+ touch $HOME/.gem/credentials
18
+ chmod 0600 $HOME/.gem/credentials
19
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
20
+ gem build *.gemspec
21
+ gem push *.gem --otp ${{ github.event.inputs.otp }}
1
22
  name: Publish Ruby Gem
2
-
3
23
  on:
4
24
  workflow_dispatch:
5
25
  inputs:
6
26
  otp:
7
- description: 'One Time Password'
27
+ description: "One Time Password"
8
28
  required: true
9
-
10
- jobs:
11
- build:
12
- name: Build + Publish
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v2
16
- - name: Set up Ruby 2.6
17
- uses: actions/setup-ruby@v1
18
- with:
19
- ruby-version: 2.6.x
20
- - name: Publish to RubyGems
21
- run: |
22
- mkdir -p $HOME/.gem
23
- touch $HOME/.gem/credentials
24
- chmod 0600 $HOME/.gem/credentials
25
- printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
26
- gem build *.gemspec
27
- gem push *.gem --otp ${{ github.event.inputs.otp }}
28
- env:
29
- RUBYGEMS_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -1,21 +1,20 @@
1
- name: Test
2
-
3
- on:
4
- push:
5
- branches: [ master ]
6
- pull_request:
7
- branches: [ master ]
8
-
1
+ ---
9
2
  jobs:
10
3
  test:
11
4
  runs-on: ubuntu-latest
12
5
  steps:
13
- - uses: actions/checkout@v2
14
- - name: Set up Ruby
15
- uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: 2.6
18
- - name: Install dependencies
19
- run: bundle install
20
- - name: Run tests
21
- run: bundle exec rake test
6
+ - uses: actions/checkout@v3
7
+ - name: Set up Ruby
8
+ uses: ruby/setup-ruby@v1
9
+ with:
10
+ ruby-version: "3.1"
11
+ - name: Install dependencies
12
+ run: bundle install
13
+ - name: Run tests
14
+ run: bundle exec rake test
15
+ name: Test
16
+ on:
17
+ pull_request:
18
+ branches: [master]
19
+ push:
20
+ branches: [master]
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.7
1
+ FROM ruby:3.1.4
2
2
 
3
3
  WORKDIR /plugin
4
4
 
data/README.md CHANGED
@@ -42,6 +42,7 @@ And then execute:
42
42
  path logs/
43
43
  azure_object_key_format %{path}%{time_slice}_%{index}.log
44
44
  time_slice_format %Y%m%d-%H
45
+ compress false
45
46
  compute_checksums true
46
47
  # if you want to use %{tag} or %Y/%m/%d/ like syntax in path / azure_blob_name_format,
47
48
  # need to specify tag for %{tag} and time for %Y/%m/%d in <buffer> argument.
@@ -147,6 +148,20 @@ The [fluent-mixin-config-placeholders](https://github.com/tagomoris/fluent-mixin
147
148
 
148
149
  Format of the time used in the file name. Default is '%Y%m%d'. Use '%Y%m%d%H' to split files hourly.
149
150
 
151
+ ### `compress`
152
+
153
+ Default: `false`
154
+
155
+ If `true`, compress (gzip) the file prior to uploading it.
156
+
157
+ Note: If desired, set `.gz` suffix via `azure_object_key_format`.
158
+
159
+ Example:
160
+
161
+ ```
162
+ azure_object_key_format %{path}%{time_slice}-%{index}.log.gz
163
+ ```
164
+
150
165
  ### `compute_checksums`
151
166
 
152
167
  Default: `true`
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'fluent-plugin-azure-storage-append-blob-lts'
6
- spec.version = '0.6.3'
6
+ spec.version = '0.7.0'
7
7
  spec.authors = ['Jonas-Taha El Sesiy']
8
8
  spec.email = ['github@elsesiy.com']
9
9
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
20
20
  spec.test_files = test_files
21
21
  spec.require_paths = ['lib']
22
- spec.required_ruby_version = '>= 2.6'
22
+ spec.required_ruby_version = '>= 3.1'
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 2.0'
25
25
  spec.add_development_dependency 'rake', '~> 13.0'
@@ -8,6 +8,7 @@ require 'azure/storage/blob'
8
8
  require 'faraday'
9
9
  require 'fluent/plugin/output'
10
10
  require 'json'
11
+ require 'zlib'
11
12
 
12
13
  module Fluent
13
14
  module Plugin
@@ -46,6 +47,7 @@ module Fluent
46
47
  config_param :azure_object_key_format, :string, default: '%{path}%{time_slice}-%{index}.log'
47
48
  config_param :auto_create_container, :bool, default: true
48
49
  config_param :compute_checksums, :bool, default: true
50
+ config_param :compress, :bool, default: false
49
51
  config_param :format, :string, default: DEFAULT_FORMAT_TYPE
50
52
  config_param :time_slice_format, :string, default: '%Y%m%d'
51
53
  config_param :localtime, :bool, default: false
@@ -124,7 +126,9 @@ module Fluent
124
126
 
125
127
  def start
126
128
  super
127
- if @use_msi
129
+ if @bs
130
+ # nop
131
+ elsif @use_msi
128
132
  token_credential = Azure::Storage::Common::Core::TokenCredential.new get_access_token
129
133
  token_signer = Azure::Storage::Common::Core::Auth::TokenSigner.new token_credential
130
134
  @bs = Azure::Storage::Blob::BlobService.new(
@@ -171,10 +175,49 @@ module Fluent
171
175
  @formatter.format(tag, time, r)
172
176
  end
173
177
 
178
+ def write_compress(chunk, tmp)
179
+ tmp.binmode
180
+ write_compress_helper(chunk, tmp)
181
+ tmp.rewind
182
+ end
183
+
184
+ # ref: https://github.com/fluent/fluent-plugin-s3/blob/master/lib/fluent/plugin/s3_compressor_gzip_command.rb
185
+ def write_compress_helper(chunk, tmp)
186
+ chunk_is_file = @buffer_type == 'file'
187
+ path = if chunk_is_file
188
+ chunk.path
189
+ else
190
+ w = Tempfile.new("chunk-gzip-tmp")
191
+ w.binmode
192
+ chunk.write_to(w)
193
+ w.close
194
+ w.path
195
+ end
196
+
197
+ res = system "gzip -c #{path} > #{tmp.path}"
198
+ unless res
199
+ log.warn "failed to execute gzip command. Fallback to GzipWriter. status = #{$?}"
200
+ begin
201
+ tmp.truncate(0)
202
+ gw = Zlib::GzipWriter.new(tmp)
203
+ chunk.write_to(gw)
204
+ gw.close
205
+ ensure
206
+ gw.close rescue nil
207
+ end
208
+ end
209
+ ensure
210
+ w.close(true) rescue nil
211
+ end
212
+
174
213
  def write(chunk)
175
214
  tmp = Tempfile.new('azure-')
176
215
  begin
177
- chunk.write_to(tmp)
216
+ if @compress
217
+ write_compress(chunk, tmp)
218
+ else
219
+ chunk.write_to(tmp)
220
+ end
178
221
 
179
222
  generate_log_name(chunk, @current_index)
180
223
  if @last_azure_storage_path != @azure_storage_path
@@ -2,6 +2,8 @@ require 'helper'
2
2
  require 'fluent/plugin/out_azure-storage-append-blob.rb'
3
3
  require 'azure/core/http/http_response'
4
4
  require 'azure/core/http/http_error'
5
+ require 'stringio'
6
+ require 'zlib'
5
7
 
6
8
  include Fluent::Test::Helpers
7
9
 
@@ -140,6 +142,18 @@ class AzureStorageAppendBlobOutTest < Test::Unit::TestCase
140
142
  end
141
143
  end
142
144
 
145
+ sub_test_case 'compress options' do
146
+ test 'compress default value' do
147
+ d = create_driver
148
+ assert_equal false, d.instance.instance_variable_get(:@compress)
149
+ end
150
+ test 'compress set true' do
151
+ config = CONFIG.clone + "\ncompress true\n"
152
+ d = create_driver conf: config
153
+ assert_equal true, d.instance.instance_variable_get(:@compress)
154
+ end
155
+ end
156
+
143
157
  # This class is used to create an Azure::Core::Http::HTTPError. HTTPError parses
144
158
  # a response object when it is created.
145
159
  class FakeResponse
@@ -152,6 +166,70 @@ class AzureStorageAppendBlobOutTest < Test::Unit::TestCase
152
166
  attr_reader :status, :body, :headers
153
167
  end
154
168
 
169
+ def uncompress_blocks(blocks)
170
+ gzip_data = blocks.join
171
+ uncompressed_data = ""
172
+ while gzip_data do
173
+ Zlib::GzipReader.wrap(StringIO.new(gzip_data.b)) do |gz|
174
+ uncompressed_data << gz.read
175
+ gzip_data = gz.unused
176
+ end
177
+ end
178
+ uncompressed_data
179
+ end
180
+
181
+ sub_test_case 'test append blob for compress' do
182
+ test 'compress 2 events 1 chunk' do
183
+ config = CONFIG.clone + %(
184
+ compress true
185
+ <buffer time>
186
+ timekey 5
187
+ timekey_wait 0
188
+ </buffer>
189
+ )
190
+
191
+ svc = FakeBlobService.new(200)
192
+ d = create_driver conf:config, service: svc
193
+
194
+ d.run(default_tag: 'test') do
195
+ d.feed(event_time("2011-01-02 13:14:15 UTC"), { :a => 1 })
196
+ d.feed(event_time("2011-01-02 13:14:15 UTC"), { :a => 2 })
197
+ end
198
+
199
+ uncompressed_data = uncompress_blocks(svc.blocks)
200
+
201
+ expected = "2011-01-02T13:14:15+00:00\ttest\t{\"a\":1}\n" +
202
+ "2011-01-02T13:14:15+00:00\ttest\t{\"a\":2}\n"
203
+ assert_equal(expected, uncompressed_data)
204
+ assert_equal(10, svc.blocks.size)
205
+ end
206
+
207
+ test 'compress 2 events 2 chunk' do
208
+ config = CONFIG.clone + %(
209
+ compress true
210
+ <buffer time>
211
+ timekey 5
212
+ timekey_wait 0
213
+ </buffer>
214
+ )
215
+
216
+ svc = FakeBlobService.new(200)
217
+ d = create_driver conf:config, service: svc
218
+
219
+ d.run(default_tag: 'test') do
220
+ d.feed(event_time("2011-01-02 13:14:00 UTC"), { :a => 1 })
221
+ d.feed(event_time("2011-01-02 13:14:15 UTC"), { :a => 2 }) # after 15 sec
222
+ end
223
+
224
+ uncompressed_data = uncompress_blocks(svc.blocks)
225
+
226
+ expected = "2011-01-02T13:14:00+00:00\ttest\t{\"a\":1}\n" +
227
+ "2011-01-02T13:14:15+00:00\ttest\t{\"a\":2}\n"
228
+ assert_equal(expected, uncompressed_data)
229
+ assert_equal(20, svc.blocks.size)
230
+ end
231
+ end
232
+
155
233
  # This class is used to test plugin functions which interact with the blob service
156
234
  class FakeBlobService
157
235
  def initialize(status)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-azure-storage-append-blob-lts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas-Taha El Sesiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-03 00:00:00.000000000 Z
11
+ date: 2023-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,14 +120,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="
122
122
  - !ruby/object:Gem::Version
123
- version: '2.6'
123
+ version: '3.1'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - ">="
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []
130
- rubygems_version: 3.0.3
130
+ rubygems_version: 3.3.26
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Azure Storage Append Blob output plugin for Fluentd event collector