logstash-output-qingstor 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37cd55d01157b2c5608f05cdbcb180bf4481f211
4
- data.tar.gz: b2a6a86bde35c314a081d2fbe5c2e7659441727c
3
+ metadata.gz: a2ac88521a301ed4c893e420a8d445a66abd4df8
4
+ data.tar.gz: cd922893c84aedfee1654f4e689bf3402f0fa034
5
5
  SHA512:
6
- metadata.gz: 808e7a27ec343e15a36733cfa59c77377f19e1948f126b5299f492fdcdc0715cba6d7050529868d5d8349c2a7991a73e95a9f4826107c50c8fa43857de02d5a6
7
- data.tar.gz: 3b7c31af1054c5c267d9e1eb4a555eb342e84d0cc3eb6cc42265a6c17f71167dc63522e5e69a9cebac0d1f9e2fd85a884aacee678ba2c9336804c641b4dd79ab
6
+ metadata.gz: c20dfb1dcc93ec3342bcdc1664638bcdd4abf4f73e343f33333eedf12a510d52b7062ad527cd002d508d9c83eaea1d21ee8d51be19fc3f5debacfd0258153874
7
+ data.tar.gz: 9dba748ec32b6d7567f253a1d945df6d9262ddb961b939cbc41dcd45a6aced67f9893fcf77a4467cebf7efa11afecbc1f6fd9018f294a4ae7355c6f4f734873f
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ module Outputs
4
+ class Qingstor
5
+ class RotationPolicy
6
+
7
+ def initialize(policy, file_size, file_time)
8
+ @policy = policy
9
+ case policy
10
+ when "time"
11
+ init_time(file_time)
12
+ when "size"
13
+ init_size(file_size)
14
+ when "size_and_time"
15
+ init_size(file_size)
16
+ init_time(file_time)
17
+ end
18
+ end
19
+
20
+ def init_size(file_size)
21
+ if file_size <= 0
22
+ raise LogStash::ConfigurationError, "'file_size' need to be greater than 0"
23
+ end
24
+ @file_size = file_size
25
+ end
26
+
27
+ def init_time(file_time)
28
+ if file_time <= 0
29
+ raise LogStash::ConfigurationError, "'file_time' need to be greater than 0"
30
+ end
31
+ @file_time = file_time
32
+ end
33
+
34
+ def rotate?(file)
35
+ case @policy
36
+ when "time"
37
+ time_rotate?(file)
38
+ when "size"
39
+ size_rotate?(file)
40
+ when "size_and_time"
41
+ size_and_time_rotate?(file)
42
+ end
43
+ end
44
+
45
+ def size_and_time_rotate?(file)
46
+ size_rotate?(file) || time_rotate?(file)
47
+ end
48
+
49
+ def size_rotate?(file)
50
+ file.size >= @file_size
51
+ end
52
+
53
+ def time_rotate?(file)
54
+ file.size > 0 && (Time.now - file.ctime) >= @file_time
55
+ end
56
+
57
+ def needs_periodic?
58
+ case @policy
59
+ when "time" then
60
+ true
61
+ when "size_and_time" then
62
+ true
63
+ else
64
+ false
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+ end
71
+ end
@@ -10,9 +10,7 @@ class LogStash::Outputs::Qingstor < LogStash::Outputs::Base
10
10
  require "logstash/outputs/qingstor/temporary_file"
11
11
  require "logstash/outputs/qingstor/temporary_file_factory"
12
12
  require "logstash/outputs/qingstor/file_repository"
13
- require "logstash/outputs/qingstor/size_rotation_policy"
14
- require "logstash/outputs/qingstor/time_rotation_policy"
15
- require "logstash/outputs/qingstor/size_and_time_rotation_policy"
13
+ require "logstash/outputs/qingstor/rotation_policy"
16
14
  require "logstash/outputs/qingstor/uploader"
17
15
  require "logstash/outputs/qingstor/qingstor_validator"
18
16
 
@@ -101,7 +99,7 @@ class LogStash::Outputs::Qingstor < LogStash::Outputs::Base
101
99
 
102
100
  @file_repository = FileRepository.new(@tags, @encoding, @tmpdir)
103
101
 
104
- @rotation = rotation_strategy
102
+ @rotation = RotationPolicy.new(@rotation_strategy, @file_size, @file_time)
105
103
 
106
104
  executor = Concurrent::ThreadPoolExecutor.new({
107
105
  :min_threads => 1,
@@ -141,16 +139,6 @@ class LogStash::Outputs::Qingstor < LogStash::Outputs::Base
141
139
  rotate_if_needed(prefix_written_to)
142
140
  end # def multi_receive_encoded
143
141
 
144
- def rotation_strategy
145
- case @rotation_strategy
146
- when "size"
147
- SizeRotationPolicy.new(@file_size)
148
- when "time"
149
- TimeRotationPolicy.new(@file_time)
150
- when "size_and_time"
151
- SizeAndTimeRotationPolicy.new(@file_size, @file_time)
152
- end
153
- end
154
142
 
155
143
  def rotate_if_needed(prefixs)
156
144
  prefixs.each do |prefix|
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-qingstor'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = 'logstash output plugin for qingstor'
6
- s.description = 'Collect the outcomes of logstash into Qingstor'
6
+ s.description = 'Collect the outputs of logstash and store into Qingstor'
7
7
  s.homepage = 'https://github.com/tacinight/logstash-output-qingstor'
8
8
  s.authors = ['Evan Zhao']
9
9
  s.email = 'tacingiht@gmail.com'
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/qingstor/temporary_file"
4
+ require "logstash/outputs/qingstor/rotation_policy"
5
+
6
+ describe LogStash::Outputs::Qingstor::RotationPolicy do
7
+ let(:size_file) { 1024 * 2 }
8
+ let(:time_file) { 2 }
9
+ let(:name) { "foobar" }
10
+ let(:tmp_file) { Stud::Temporary.file }
11
+ let(:tmp_dir) { tmp_file.path }
12
+ let(:file) { LogStash::Outputs::Qingstor::TemporaryFile.new(name, tmp_file, tmp_dir) }
13
+ let(:content) { "May the code be with you" * 100 }
14
+
15
+
16
+ context "when size_and_time policy" do
17
+ subject { described_class.new("size_and_time", size_file, time_file) }
18
+
19
+ it "raise error if time_file is no grater then 0" do
20
+ expect{ described_class.new("size_and_time", 0, 0) }.to raise_error(LogStash::ConfigurationError)
21
+ expect{ described_class.new("size_and_time", -1, 0) }.to raise_error(LogStash::ConfigurationError)
22
+ expect{ described_class.new("size_and_time", 0, -1) }.to raise_error(LogStash::ConfigurationError)
23
+ expect{ described_class.new("size_and_time", -1, -1) }.to raise_error(LogStash::ConfigurationError)
24
+
25
+ end
26
+
27
+ it "return false if the file is not old enough" do
28
+ expect(subject.rotate?(file)).to be_falsey
29
+ end
30
+
31
+ it "return false if the file is old enough with file size 0" do
32
+ allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
33
+ expect(subject.rotate?(file)).to be_falsey
34
+ end
35
+
36
+ it "return truth if the file is old enough and non-empty" do
37
+ file.write(content)
38
+ file.fsync
39
+ allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
40
+ expect(subject.rotate?(file)).to be_truthy
41
+ end
42
+ end
43
+
44
+ context "when size policy" do
45
+ subject { described_class.new("size", size_file, time_file) }
46
+ it "raise error if size_file is no grater then 0" do
47
+ expect{described_class.new("size", 0, 0)}.to raise_error(LogStash::ConfigurationError)
48
+ expect{described_class.new("size", -1, 0)}.to raise_error(LogStash::ConfigurationError)
49
+ end
50
+
51
+ it "return true if the file has a bigger size value then 'size_file'" do
52
+ file.write(content)
53
+ file.fsync
54
+ expect(subject.rotate?(file)).to be_truthy
55
+ end
56
+ end
57
+
58
+ context "when time policy" do
59
+ subject { described_class.new("time", size_file, time_file) }
60
+ it "raise error if time_file is no grater then 0" do
61
+ expect{described_class.new("time", 0, 0)}.to raise_error(LogStash::ConfigurationError)
62
+ expect{described_class.new("time", 0, -1)}.to raise_error(LogStash::ConfigurationError)
63
+ end
64
+
65
+ it "return false if the file is not old enough" do
66
+ expect(subject.rotate?(file)).to be_falsey
67
+ end
68
+
69
+ it "return false if the file is old enough with file size 0" do
70
+ allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
71
+ expect(subject.rotate?(file)).to be_falsey
72
+ end
73
+
74
+ it "return truth if the file is old enough and non-empty" do
75
+ file.write(content)
76
+ file.fsync
77
+ allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
78
+ expect(subject.rotate?(file)).to be_truthy
79
+ end
80
+ end
81
+ end
@@ -38,7 +38,7 @@ describe LogStash::Outputs::Qingstor::Uploader do
38
38
 
39
39
  it "upload file to the qingstor bucket" do
40
40
  subject.upload(file)
41
- expect(list_remote_file.size).to eq(3)
41
+ expect(list_remote_file.size).to eq(1)
42
42
  end
43
43
 
44
44
  it "execute a callback when the upload is complete" do
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.1.1
4
+ version: 0.1.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: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Collect the outcomes of logstash into Qingstor
97
+ description: Collect the outputs of logstash and store into Qingstor
98
98
  email: tacingiht@gmail.com
99
99
  executables: []
100
100
  extensions: []
@@ -111,7 +111,7 @@ files:
111
111
  - lib/logstash/outputs/qingstor.rb
112
112
  - lib/logstash/outputs/qingstor/file_repository.rb
113
113
  - lib/logstash/outputs/qingstor/qingstor_validator.rb
114
- - lib/logstash/outputs/qingstor/size_and_time_rotation_policy.rb
114
+ - lib/logstash/outputs/qingstor/rotation_policy.rb
115
115
  - lib/logstash/outputs/qingstor/size_rotation_policy.rb
116
116
  - lib/logstash/outputs/qingstor/temporary_file.rb
117
117
  - lib/logstash/outputs/qingstor/temporary_file_factory.rb
@@ -120,11 +120,9 @@ files:
120
120
  - logstash-output-qingstor.gemspec
121
121
  - spec/outputs/qingstor/file_repository_spec.rb
122
122
  - spec/outputs/qingstor/qingstor_validator_spec.rb
123
- - spec/outputs/qingstor/size_and_time_rotation_policy_spec.rb
124
- - spec/outputs/qingstor/size_rotation_policy_spec.rb
123
+ - spec/outputs/qingstor/rotation_policy_spec.rb
125
124
  - spec/outputs/qingstor/temporary_file_factory_spec.rb
126
125
  - spec/outputs/qingstor/temporary_file_spec.rb
127
- - spec/outputs/qingstor/time_rotation_policy_spec.rb
128
126
  - spec/outputs/qingstor/uploader_spec.rb
129
127
  - spec/outputs/qingstor_spec.rb
130
128
  - spec/outputs/qs_access_helper.rb
@@ -158,11 +156,9 @@ summary: logstash output plugin for qingstor
158
156
  test_files:
159
157
  - spec/outputs/qingstor/file_repository_spec.rb
160
158
  - spec/outputs/qingstor/qingstor_validator_spec.rb
161
- - spec/outputs/qingstor/size_and_time_rotation_policy_spec.rb
162
- - spec/outputs/qingstor/size_rotation_policy_spec.rb
159
+ - spec/outputs/qingstor/rotation_policy_spec.rb
163
160
  - spec/outputs/qingstor/temporary_file_factory_spec.rb
164
161
  - spec/outputs/qingstor/temporary_file_spec.rb
165
- - spec/outputs/qingstor/time_rotation_policy_spec.rb
166
162
  - spec/outputs/qingstor/uploader_spec.rb
167
163
  - spec/outputs/qingstor_spec.rb
168
164
  - spec/outputs/qs_access_helper.rb
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/outputs/qingstor/size_rotation_policy"
3
- require "logstash/outputs/qingstor/time_rotation_policy"
4
-
5
- module LogStash
6
- module Outputs
7
- class Qingstor
8
- class SizeAndTimeRotationPolicy
9
- def initialize(size_file, time_file)
10
- @size_strategy = SizeRotationPolicy.new(size_file)
11
- @time_strategy = TimeRotationPolicy.new(time_file)
12
- end
13
-
14
- def rotate?(file)
15
- @size_strategy.rotate?(file) || @time_strategy.rotate?(file)
16
- end
17
-
18
- def needs_periodic?
19
- true
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,39 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
3
- require "logstash/outputs/qingstor/temporary_file"
4
- require "logstash/outputs/qingstor/size_and_time_rotation_policy"
5
-
6
- describe LogStash::Outputs::Qingstor::SizeAndTimeRotationPolicy do
7
- let(:size_file) { 1024 * 2 }
8
- let(:time_file) { 2 }
9
- let(:name) { "foobar" }
10
- let(:tmp_file) { Stud::Temporary.file }
11
- let(:tmp_dir) { tmp_file.path }
12
- let(:file) { LogStash::Outputs::Qingstor::TemporaryFile.new(name, tmp_file, tmp_dir) }
13
- let(:content) { "May the code be with you" * 100 }
14
- subject { described_class.new(size_file, time_file) }
15
-
16
- it "raise error if time_file is no grater then 0" do
17
- expect{ described_class.new(0, 0) }.to raise_error(LogStash::ConfigurationError)
18
- expect{ described_class.new(-1, 0) }.to raise_error(LogStash::ConfigurationError)
19
- expect{ described_class.new(0, -1) }.to raise_error(LogStash::ConfigurationError)
20
- expect{ described_class.new(-1, -1) }.to raise_error(LogStash::ConfigurationError)
21
-
22
- end
23
-
24
- it "return false if the file is not old enough" do
25
- expect(subject.rotate?(file)).to be_falsey
26
- end
27
-
28
- it "return false if the file is old enough with file size 0" do
29
- allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
30
- expect(subject.rotate?(file)).to be_falsey
31
- end
32
-
33
- it "return truth if the file is old enough and non-empty" do
34
- file.write(content)
35
- file.fsync
36
- allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
37
- expect(subject.rotate?(file)).to be_truthy
38
- end
39
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
3
- require "logstash/outputs/qingstor/temporary_file"
4
- require "logstash/outputs/qingstor/size_rotation_policy"
5
-
6
- describe LogStash::Outputs::Qingstor::SizeRotationPolicy do
7
- let(:size_file) { 1024 * 2 }
8
- let(:name) { "foobar" }
9
- let(:tmp_file) { Stud::Temporary.file }
10
- let(:tmp_dir) { tmp_file.path }
11
- let(:file) { LogStash::Outputs::Qingstor::TemporaryFile.new(name, tmp_file, tmp_dir) }
12
- let(:content) { "May the code be with you" * 100 }
13
- subject { described_class.new(size_file) }
14
-
15
- it "raise error if size_file is no grater then 0" do
16
- expect{described_class.new(0)}.to raise_error(LogStash::ConfigurationError)
17
- expect{described_class.new(-1)}.to raise_error(LogStash::ConfigurationError)
18
- end
19
-
20
- it "return true if the file has a bigger size value then 'size_file'" do
21
- file.write(content)
22
- file.fsync
23
- expect(subject.rotate?(file)).to be_truthy
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
3
- require "logstash/outputs/qingstor/temporary_file"
4
- require "logstash/outputs/qingstor/time_rotation_policy"
5
-
6
- describe LogStash::Outputs::Qingstor::TimeRotationPolicy do
7
- let(:time_file) { 2 }
8
- let(:name) { "foobar" }
9
- let(:tmp_file) { Stud::Temporary.file }
10
- let(:tmp_dir) { tmp_file.path }
11
- let(:file) { LogStash::Outputs::Qingstor::TemporaryFile.new(name, tmp_file, tmp_dir) }
12
- let(:content) { "May the code be with you" * 100 }
13
- subject { described_class.new(time_file) }
14
-
15
- it "raise error if time_file is no grater then 0" do
16
- expect{described_class.new(0)}.to raise_error(LogStash::ConfigurationError)
17
- expect{described_class.new(-1)}.to raise_error(LogStash::ConfigurationError)
18
- end
19
-
20
- it "return false if the file is not old enough" do
21
- expect(subject.rotate?(file)).to be_falsey
22
- end
23
-
24
- it "return false if the file is old enough with file size 0" do
25
- allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
26
- expect(subject.rotate?(file)).to be_falsey
27
- end
28
-
29
- it "return truth if the file is old enough and non-empty" do
30
- file.write(content)
31
- file.fsync
32
- allow(file).to receive(:ctime).and_return(Time.now - (time_file * 2 * 60))
33
- expect(subject.rotate?(file)).to be_truthy
34
- end
35
- end