logstash-output-qingstor 0.3.1 → 0.3.2

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: b634b7aee3754a9bfc4f88269a0ef6fc4135249d1143440ccae417c67852b47f
4
- data.tar.gz: 05c469d151a6647bb985b15a368dc3c607d69bf6eee496e6ba1d5841185b2b75
3
+ metadata.gz: 7cd73fbefc5156daf65ed1b5cbf65294847cafb9a36543ff2a33d2250ae8ee6c
4
+ data.tar.gz: 760d9f12c2facce1b5cf73eb309ff55a24c0857d110549d3166920477eef53a8
5
5
  SHA512:
6
- metadata.gz: 2579b496ce9f0da3c9831d4de53f70eb23c7f51febe23b7c82052df1cb2d99337c23724b34a3f8d66ddd385efe468e17f158bb8d786b4ceb5a6ee309ace88a2c
7
- data.tar.gz: 545228916a49aa445d47b8242ef062c1d78834590352c7d32f81fa6cb4f93acc7208c78d3bbed7b133f5a3fbee2abd46aa6ab2dc5e7912cacb2db303dc25005e
6
+ metadata.gz: '08b89f4023ca52c4db4a2ab24e973b139b4ca8dd23b63b8cf0b7e68f406ecb504c871176015c3da23fc8d5879552c49620908603ae8b6315d617fd5296c0956e'
7
+ data.tar.gz: 7140d939f04a284fd1c7e65d310a4e6e0ed25780e15c3843e74c02f7d857b6021f47e453b8532eeca5a131906c00c297f46e94bc38aa0440f1b53524b1182bb0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+
2
+
1
3
  ## 0.3.1
2
4
  - Refactor module: rotation policy
3
5
 
data/README_zh_CN.md CHANGED
@@ -58,11 +58,11 @@ output {
58
58
  # 默认: "size_and_time". 可选枚举值["size_and_time", "size", "time"].
59
59
  rotation_strategy => "size_and_time"
60
60
 
61
- # 配合"size_and_time", "size"的可选配置型, 单位byte
62
- # 默认: 1024*1024*5 (byte) = 5 (MB)
63
- size_file => 1024*1024*5
61
+ # 配合"size_and_time", "size"的可选配置型, 单位 MB(megabyte)
62
+ # 默认: 5 (MB)
63
+ size_file => 5
64
64
 
65
- # 配合"size_and_time", "time"的可选配置型, 单位minute
65
+ # 配合"size_and_time", "time"的可选配置型, 单位 minute
66
66
  # 默认: 15 (minutes)
67
67
  time_file => 15
68
68
 
@@ -73,7 +73,15 @@ module LogStash
73
73
  end
74
74
 
75
75
  def initialize(policy, file_size, file_time)
76
- @policy = Policy(policy, file_size, file_time)
76
+ @policy = Policy(policy, to_bytes(file_size), to_seconds(file_time))
77
+ end
78
+
79
+ def to_seconds(file_time)
80
+ file_time * 60
81
+ end
82
+
83
+ def to_bytes(file_size)
84
+ file_size * 1024 * 1024
77
85
  end
78
86
 
79
87
  def rotate?(file)
@@ -14,12 +14,12 @@ module LogStash
14
14
 
15
15
  def_delegators :@fd, :path, :write, :close, :fsync
16
16
 
17
- attr_reader :fd
17
+ attr_reader :fd, :dir_path
18
18
 
19
- def initialize(key, fd, tmp_path)
19
+ def initialize(key, fd, dir_path)
20
20
  @key = key
21
21
  @fd = fd
22
- @tmp_path = tmp_path
22
+ @dir_path = dir_path
23
23
  @created_at = Time.now
24
24
  end
25
25
 
@@ -27,8 +27,6 @@ module LogStash
27
27
  @created_at
28
28
  end
29
29
 
30
- attr_reader :tmp_path
31
-
32
30
  def size
33
31
  @fd.size
34
32
  rescue IOError
@@ -49,7 +47,7 @@ module LogStash
49
47
  rescue
50
48
  IOError
51
49
  end
52
- FileUtils.rm(path, :force => true)
50
+ FileUtils.rm_f(path)
53
51
  end
54
52
 
55
53
  def empty?
@@ -76,8 +76,8 @@ class LogStash::Outputs::Qingstor < LogStash::Outputs::Base
76
76
  config :rotation_strategy, :validate => %w[size_and_time size time],
77
77
  :default => 'size_and_time'
78
78
 
79
- # Define the size requirement for each file to upload to QingStor. In byte.
80
- config :file_size, :validate => :number, :default => 1024 * 1024 * 5
79
+ # Define the size requirement for each file to upload to QingStor. In megabyte(MB).
80
+ config :file_size, :validate => :number, :default => 5
81
81
 
82
82
  # Define the time interval for each file to upload to QingStor. In minutes.
83
83
  config :file_time, :validate => :number, :default => 15
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-qingstor'
3
- s.version = '0.3.1'
3
+ s.version = '0.3.2'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = 'logstash output plugin for qingstor'
6
6
  s.description = 'Collect the outputs of logstash and store into QingStor'
@@ -6,16 +6,19 @@ require 'fileutils'
6
6
  require 'tmpdir'
7
7
 
8
8
  describe LogStash::Outputs::Qingstor::TemporaryFile do
9
+ def file_path
10
+ File.join(Dir.tmpdir, 'foo.log')
11
+ end
12
+
9
13
  subject { described_class.new(key, io, Dir.tmpdir) }
10
14
 
11
15
  let(:key) { 'foo.log' }
12
16
  let(:content) { 'May the code be with you!' }
13
- let(:tmp_path) { File.join(Dir.tmpdir, key) }
14
17
  let(:file_mode) { 'w+' }
15
- let(:io) { ::File.open(tmp_path, file_mode) }
18
+ let(:io) { ::File.open(file_path, file_mode) }
16
19
 
17
20
  after(:all) do
18
- FileUtils.rm('/tmp/foo.log') if File.exist?('/tmp/foo.log')
21
+ FileUtils.rm(file_path) if File.exist?(file_path)
19
22
  end
20
23
 
21
24
  it 'return the key of the file' do
@@ -31,11 +34,11 @@ describe LogStash::Outputs::Qingstor::TemporaryFile do
31
34
  it 'can return the correct file size' do
32
35
  subject.write(content)
33
36
  subject.close
34
- expect(subject.size).to eq(File.size(tmp_path))
37
+ expect(subject.size).to eq(File.size(file_path))
35
38
  end
36
39
 
37
- it 'return the tmp_path of the file' do
38
- expect(File.join(subject.tmp_path, subject.key)).to eq(tmp_path)
40
+ it 'return the file_path of the file' do
41
+ expect(File.join(subject.dir_path, subject.key)).to eq(file_path)
39
42
  end
40
43
 
41
44
  it 'return the creation time' do
@@ -43,9 +46,9 @@ describe LogStash::Outputs::Qingstor::TemporaryFile do
43
46
  end
44
47
 
45
48
  it 'can delete file correctly' do
46
- expect(File.exist?(tmp_path)).to be_truthy
49
+ expect(File.exist?(file_path)).to be_truthy
47
50
  subject.delete!
48
- expect(File.exist?(tmp_path)).to be_falsey
51
+ expect(File.exist?(file_path)).to be_falsey
49
52
  end
50
53
 
51
54
  it 'return if the file is empty' do
@@ -5,7 +5,7 @@ require 'logstash/outputs/qingstor/uploader'
5
5
  require 'logstash/outputs/qingstor/temporary_file'
6
6
  require 'qingstor/sdk'
7
7
  require 'stud/temporary'
8
-
8
+ require 'fileutils'
9
9
  require_relative '../qs_access_helper'
10
10
 
11
11
  describe LogStash::Outputs::Qingstor::Uploader do
@@ -31,8 +31,13 @@ describe LogStash::Outputs::Qingstor::Uploader do
31
31
  f
32
32
  end
33
33
 
34
- after do
34
+ before(:all) do
35
+ clean_remote_files
36
+ end
37
+
38
+ after(:each) do
35
39
  delete_remote_file key
40
+ FileUtils.rm_r(tmp_file)
36
41
  end
37
42
 
38
43
  it 'upload file to the qingstor bucket' do
@@ -40,6 +45,12 @@ describe LogStash::Outputs::Qingstor::Uploader do
40
45
  expect(list_remote_file.size).to eq(1)
41
46
  end
42
47
 
48
+ it 'async upload file to qingstor' do
49
+ subject.upload_async(file)
50
+ sleep 2
51
+ expect(list_remote_file.size).to eq(1)
52
+ end
53
+
43
54
  it 'execute a callback when the upload is complete' do
44
55
  callback = proc { |f| }
45
56
  expect(callback).to receive(:call).with(file)
@@ -9,10 +9,15 @@ require_relative './qs_access_helper'
9
9
  require_relative './spec_helper'
10
10
 
11
11
  describe LogStash::Outputs::Qingstor do
12
+ def tmp_dir_path
13
+ File.join(Dir.tmpdir, 'lg_qs_spec')
14
+ end
15
+
12
16
  let(:prefix) { 'ss/%{server}' }
13
17
  let(:event) { LogStash::Event.new('server' => 'overwatch') }
14
18
  let(:event_encoded) { 'May the code be with you!' }
15
19
  let(:events_and_encoded) { { event => event_encoded } }
20
+ let(:tmpdir) { tmp_dir_path }
16
21
  let(:options) do
17
22
  {
18
23
  'access_key_id' => ENV['access_key_id'],
@@ -22,14 +27,17 @@ describe LogStash::Outputs::Qingstor do
22
27
  'prefix' => prefix
23
28
  }
24
29
  end
25
- let(:tmpdir) { File.join(Dir.tmpdir, 'logstash_restore_dir') }
30
+
31
+ before(:all) do
32
+ FileUtils.mkdir_p(tmp_dir_path) unless File.exist?(tmp_dir_path)
33
+ end
26
34
 
27
- after do
35
+ after(:each) do
28
36
  clean_remote_files
29
37
  end
30
38
 
31
- before do
32
- FileUtils.mkdir_p(tmpdir) unless File.exist?(tmpdir)
39
+ after(:all) do
40
+ FileUtils.rm_rf(tmp_dir_path)
33
41
  end
34
42
 
35
43
  it 'done work with minimal options' do
@@ -37,7 +45,7 @@ describe LogStash::Outputs::Qingstor do
37
45
  expect(list_remote_file.size).to eq(1)
38
46
  end
39
47
 
40
- it 'use aes256 to encrpytion in the server side' do
48
+ it 'use aes256 to encrpytion in the server side', :target => true do
41
49
  cipher = OpenSSL::Cipher::AES256.new(:CBC)
42
50
  cipher.encrypt
43
51
  key = cipher.random_key
@@ -48,6 +56,7 @@ describe LogStash::Outputs::Qingstor do
48
56
  end
49
57
 
50
58
  it 'upload existing file if turn on restore function' do
59
+ binding.pry
51
60
  non_empty_file = File.open(File.join(tmpdir, 'non-empty-file'), 'w')
52
61
  non_empty_file.write(event_encoded * 10)
53
62
  non_empty_file.close
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-qingstor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Zhao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement