lstash 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,98 +1,96 @@
1
- require 'spec_helper'
2
- require 'lstash/query'
1
+ require "spec_helper"
2
+ require "lstash/query"
3
3
 
4
4
  describe Lstash::Query do
5
-
6
5
  context "running on 2014-08-03" do
7
- let(:time) { '2014-08-03 15:54:33' }
6
+ let(:time) { "2014-08-03 15:54:33" }
8
7
  let(:query_string) { nil }
9
8
  let(:options) { {} }
10
9
 
11
10
  subject { Lstash::Query.new(query_string, options) }
12
11
 
13
- before { Timecop.freeze(Time.parse(time)) }
14
- after { Timecop.return }
12
+ before { Timecop.freeze(time) }
13
+ after { Timecop.return }
15
14
 
16
15
  it { should_not be nil }
17
16
  # it "should initialize properly" do
18
17
  # expect(subject).not_to be nil
19
18
  # end
20
19
 
21
- its('from') { should eq Time.parse('2014-08-03 00:00:00.000000000 +0200') }
22
- its('to') { should eq Time.parse('2014-08-03 15:54:33.000000000 +0200') }
20
+ its("from") { should eq Time.parse("2014-08-02 00:00:00 +0200") }
21
+ its("to") { should eq Time.parse("2014-08-03 00:00:00 +0200") }
23
22
 
24
23
  # its(:date_range) { should eq (Date.parse('2014-08-02')..Date.parse('2014-08-03')) }
25
24
 
26
25
  # its(:indices) { should eq [ "logstash-2014.08.02", "logstash-2014.08.03" ] }
27
26
 
28
27
  context "with specific query" do
29
- let(:query_string) { 'program:haproxy' }
28
+ let(:query_string) { "program:haproxy" }
30
29
  its(:query_string) { should eq query_string }
31
30
  end
32
31
 
33
32
  context "without query" do
34
33
  let(:query_string) { nil }
35
- its(:query_string) { should eql '*' }
34
+ its(:query_string) { should eql "*" }
36
35
  end
37
36
 
38
37
  context "from 'yesterday'" do
39
- let(:options) { { from: 'yesterday' }}
40
- its('from') { should eq Time.parse('2014-08-02 00:00:00.000000000 +0200') }
38
+ let(:options) { {from: "yesterday"} }
39
+ its("from") { should eq Time.parse("2014-08-02 00:00:00 +0200") }
41
40
  end
42
41
 
43
42
  context "from 'today'" do
44
- let(:options) { { from: 'today' }}
45
- its('from') { should eq Time.parse('2014-08-03 00:00:00.000000000 +0200') }
43
+ let(:options) { {from: "today"} }
44
+ its("from") { should eq Time.parse("2014-08-03 00:00:00 +0200") }
46
45
  end
47
46
 
48
47
  context "from 'now'" do
49
- let(:options) { { from: 'now' }}
50
- its('from') { should eq Time.parse('2014-08-03 15:54:33.000000000 +0200') }
48
+ let(:options) { {from: "now"} }
49
+ its("from") { should eq Time.parse("2014-08-03 15:54:33 +0200") }
51
50
  end
52
51
 
53
52
  context "to 'yesterday'" do
54
- let(:options) { { to: 'yesterday' }}
55
- its('to') { should eq Time.parse('2014-08-02 00:00:00.000000000 +0200') }
53
+ let(:options) { {to: "yesterday"} }
54
+ its("to") { should eq Time.parse("2014-08-02 00:00:00 +0200") }
56
55
  end
57
56
 
58
57
  context "to 'today'" do
59
- let(:options) { { to: 'today' }}
60
- its('to') { should eq Time.parse('2014-08-03 00:00:00.000000000 +0200') }
58
+ let(:options) { {to: "today"} }
59
+ its("to") { should eq Time.parse("2014-08-03 00:00:00 +0200") }
61
60
  end
62
61
 
63
62
  context "to 'now'" do
64
- let(:options) { { to: 'now' }}
65
- its('to') { should eq Time.parse('2014-08-03 15:54:33.000000000 +0200') }
63
+ let(:options) { {to: "now"} }
64
+ its("to") { should eq Time.parse("2014-08-03 15:54:33 +0200") }
66
65
  end
67
66
 
68
67
  context "from 'firstday'" do
69
-
70
- let(:options) { { from: 'firstday' } }
71
- its('from') { should eq Time.parse('2014-08-01 00:00:00.000000000 +0200') }
68
+ let(:options) { {from: "firstday"} }
69
+ its("from") { should eq Time.parse("2014-08-01 00:00:00 +0200") }
72
70
 
73
71
  context "anchor 'yesterday'" do
74
- let(:anchor) { 'yesterday' }
75
- its('from') { should eq Time.parse('2014-08-01 00:00:00.000000000 +0200') }
72
+ let(:anchor) { "yesterday" }
73
+ its("from") { should eq Time.parse("2014-08-01 00:00:00 +0200") }
76
74
  end
77
75
 
78
76
  context "anchor 'today'" do
79
- let(:anchor) { 'today' }
80
- its('from') { should eq Time.parse('2014-08-01 00:00:00.000000000 +0200') }
77
+ let(:anchor) { "today" }
78
+ its("from") { should eq Time.parse("2014-08-01 00:00:00 +0200") }
81
79
  end
82
80
 
83
81
  context "anchor '2014-07-17'" do
84
- let(:options) { { from: 'firstday', anchor: '2014-07-17' } }
85
- its('from') { should eq Time.parse('2014-07-01 00:00:00.000000000 +0200') }
82
+ let(:options) { {from: "firstday", anchor: "2014-07-17"} }
83
+ its("from") { should eq Time.parse("2014-07-01 00:00:00 +0200") }
86
84
  end
87
85
 
88
86
  context "date range" do
89
- let(:options) { { from: 'firstday', anchor: 'yesterday' } }
90
- its('from') { should eq Time.parse('2014-08-01 00:00:00.000000000 +0200') }
91
- its('to') { should eq Time.parse('2014-08-03 15:54:33.000000000 +0200') }
87
+ let(:options) { {from: "firstday", anchor: "yesterday"} }
88
+ its("from") { should eq Time.parse("2014-08-01 00:00:00 +0200") }
89
+ its("to") { should eq Time.parse("2014-08-03 00:00:00 +0200") }
92
90
  end
93
91
 
94
92
  context "each_period" do
95
- let(:options) { { from: 'firstday', anchor: 'yesterday', to: 'today' } }
93
+ let(:options) { {from: "firstday", anchor: "yesterday", to: "today"} }
96
94
  it "should iterate over range by hour" do
97
95
  indices = []
98
96
  queries = []
@@ -100,13 +98,13 @@ describe Lstash::Query do
100
98
  indices << index
101
99
  queries << query
102
100
  end
103
- expect(indices.count).to eq ((subject.to - subject.from)/3600).round
104
- expect(indices.uniq).to eq %w(
101
+ expect(indices.count).to eq ((subject.to - subject.from) / 3600).round
102
+ expect(indices.uniq).to eq %w[
105
103
  logstash-2014.07.31
106
104
  logstash-2014.08.01
107
105
  logstash-2014.08.02
108
- )
109
- expect(queries.map(&:from).map(&:to_s)).to eq ([
106
+ ]
107
+ expect(queries.map(&:from).map(&:to_s)).to eq([
110
108
  "2014-07-31 22:00:00 UTC",
111
109
  "2014-07-31 23:00:00 UTC",
112
110
  "2014-08-01 00:00:00 UTC",
@@ -158,50 +156,54 @@ describe Lstash::Query do
158
156
  ])
159
157
  end
160
158
  end
161
-
162
159
  end
163
160
 
164
161
  context "search" do
165
162
  it "should produce the correct elasticsearch search request attributes" do
166
- expect(subject.search(0, 10)).to eq ({
167
- :sort => [{"@timestamp"=>{:order=>"asc"}}],
168
- :fields => %w(message),
169
- :query => {:filtered=>{
170
- :query => { :bool => { :should => [ { :query_string => { :query=>"*" }}]}},
171
- :filter=> { :bool => { :must => [ { :range => { "@timestamp" => { :gte => 1407016800000, :lt => 1407074073000}}}]}}}},
172
- :from => 0,
173
- :size => 10
163
+ expect(subject.search(0, 10)).to eq({
164
+ sort: [{"@timestamp" => {order: "asc"}}],
165
+ _source: %w[message],
166
+ query: {
167
+ bool: {
168
+ must: [
169
+ {
170
+ query_string: {query: "*"}
171
+ }
172
+ ],
173
+ filter: {
174
+ range: {"@timestamp" => {gte: 1406930400000, lt: 1407016800000}}
175
+ }
176
+ }
177
+ },
178
+ from: 0,
179
+ size: 10
174
180
  })
175
181
  end
176
182
  end
177
-
178
183
  end
179
184
 
180
185
  context "running on 2014-08-01" do
181
- let(:time) { '2014-08-01 12:53:03' }
186
+ let(:time) { "2014-08-01 12:53:03" }
182
187
  let(:query_string) { nil }
183
188
  let(:options) { {} }
184
189
 
185
190
  subject { Lstash::Query.new(query_string, options) }
186
191
 
187
192
  before { Timecop.freeze(Time.parse(time)) }
188
- after { Timecop.return }
193
+ after { Timecop.return }
189
194
 
190
195
  context "from 'firstday' with 'yesterday' anchor" do
191
- let(:options) { { anchor: 'yesterday', from: 'firstday' } }
196
+ let(:options) { {anchor: "yesterday", from: "firstday"} }
192
197
 
193
- its('from') { should eq Time.parse('2014-07-01 00:00:00.000000000 +0200') }
194
- its('to') { should eq Time.parse('2014-08-01 12:53:03.000000000 +0200') }
198
+ its("from") { should eq Time.parse("2014-07-01 00:00:00 +0200") }
199
+ its("to") { should eq Time.parse("2014-08-01 00:00:00 +0200") }
195
200
  end
196
201
 
197
202
  context "from 'firstday' with default 'today' anchor" do
198
- let(:options) { { from: 'firstday', to: 'now' } }
203
+ let(:options) { {from: "firstday", to: "now"} }
199
204
 
200
- its('from') { should eq Time.parse('2014-08-01 00:00:00.000000000 +0200') }
201
- its('to') { should eq Time.parse('2014-08-01 12:53:03.000000000 +0200') }
205
+ its("from") { should eq Time.parse("2014-08-01 00:00:00 +0200") }
206
+ its("to") { should eq Time.parse("2014-08-01 12:53:03 +0200") }
202
207
  end
203
-
204
208
  end
205
-
206
209
  end
207
-
data/spec/lstash_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
- require 'spec_helper'
2
- require 'lstash/cli'
1
+ require "spec_helper"
2
+ require "lstash/cli"
3
3
 
4
4
  describe Lstash do
5
- it 'should have a version number' do
5
+ it "should have a version number" do
6
6
  expect(Lstash::VERSION).not_to be nil
7
7
  end
8
8
  end
data/spec/spec_helper.rb CHANGED
@@ -1,33 +1,48 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'lstash'
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "lstash"
3
3
 
4
- require 'rspec/its'
4
+ require "rspec/its"
5
5
 
6
- require 'timecop'
6
+ require "timecop"
7
7
 
8
- ENV['ES_URL'] = nil
9
- ENV['TZ'] = 'Europe/Amsterdam' # Test in a specific timezone.
8
+ ENV["ES_URL"] = nil
9
+ ENV["TZ"] = "Europe/Amsterdam" # Test in a specific timezone.
10
10
 
11
11
  RSpec.configure do |config|
12
- config.order = 'random'
12
+ config.order = "random"
13
+
14
+ # Suggestions taken from http://railscasts.com/episodes/413-fast-tests
15
+ #
16
+ # Focus on specific specs by tagging with `:focus`
17
+ # or use `fit` instead of `it`.
18
+ # ```ruby
19
+ # it "focus test", :focus do
20
+ # end
21
+ #
22
+ # fit "focus test" do
23
+ # end
24
+ # ```
25
+ config.alias_example_to :fit, focus: true
26
+ config.filter_run focus: true
27
+ config.run_all_when_everything_filtered = true
13
28
  end
14
29
 
15
- require 'stringio'
30
+ require "stringio"
16
31
 
17
- def capture_stdout(&blk)
32
+ def capture_stdout
18
33
  old = $stdout
19
34
  $stdout = fake = StringIO.new
20
- blk.call
35
+ yield
21
36
  fake.string
22
37
  ensure
23
38
  $stdout = old
24
39
  end
25
40
 
26
- def capture_stderr(&blk)
41
+ def capture_stderr
27
42
  old = $stderr
28
43
  $stderr = fake = StringIO.new
29
- blk.call
44
+ yield
30
45
  fake.string
31
46
  ensure
32
47
  $stderr = old
33
- end
48
+ end
metadata CHANGED
@@ -1,145 +1,117 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lstash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaas Jan Wierenga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 10.3.2
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 10.3.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 3.0.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 3.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-its
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.0.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.0.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: timecop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.7.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: typhoeus
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ! '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: 0.7.1
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: elasticsearch
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ~>
87
+ - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: '0.4'
89
+ version: 7.17.7
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ~>
94
+ - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: '0.4'
111
- - !ruby/object:Gem::Dependency
112
- name: hashie
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ! '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
96
+ version: 7.17.7
125
97
  - !ruby/object:Gem::Dependency
126
98
  name: thor
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
- - - ! '>='
101
+ - - "~>"
130
102
  - !ruby/object:Gem::Version
131
- version: '0'
103
+ version: 0.20.3
132
104
  type: :runtime
133
105
  prerelease: false
134
106
  version_requirements: !ruby/object:Gem::Requirement
135
107
  requirements:
136
- - - ! '>='
108
+ - - "~>"
137
109
  - !ruby/object:Gem::Version
138
- version: '0'
110
+ version: 0.20.3
139
111
  description: Count or grep log messages in a specified time range from a Logstash
140
112
  Elasticsearch server.
141
113
  email:
142
- - k.j.wierenga@gmail.com
114
+ - k.j.wierenga@kerkdienstgemist.nl
143
115
  executables:
144
116
  - lstash
145
117
  extensions: []
@@ -148,18 +120,24 @@ extra_rdoc_files:
148
120
  - README.md
149
121
  - CHANGELOG.md
150
122
  files:
151
- - .autotest
152
- - .gitignore
153
- - .rspec
154
- - .ruby-gemset
155
- - .ruby-version
156
- - .travis.yml
123
+ - ".autotest"
124
+ - ".devcontainer/Aptfile"
125
+ - ".devcontainer/Dockerfile"
126
+ - ".devcontainer/devcontainer.json"
127
+ - ".github/workflows/test.yml"
128
+ - ".gitignore"
129
+ - ".rspec"
130
+ - ".ruby-gemset"
131
+ - ".ruby-version"
132
+ - ".travis.yml"
157
133
  - CHANGELOG.md
158
134
  - Gemfile
159
135
  - LICENSE.txt
160
136
  - README.md
161
137
  - Rakefile
162
138
  - bin/lstash
139
+ - dip.yml
140
+ - docker-compose.yml
163
141
  - lib/lstash.rb
164
142
  - lib/lstash/cli.rb
165
143
  - lib/lstash/client.rb
@@ -171,7 +149,7 @@ files:
171
149
  - spec/lstash/query_spec.rb
172
150
  - spec/lstash_spec.rb
173
151
  - spec/spec_helper.rb
174
- homepage: https://github.com/kjwierenga/lstash
152
+ homepage: https://github.com/kdgm/lstash
175
153
  licenses:
176
154
  - MIT
177
155
  metadata: {}
@@ -181,24 +159,18 @@ require_paths:
181
159
  - lib
182
160
  required_ruby_version: !ruby/object:Gem::Requirement
183
161
  requirements:
184
- - - ! '>='
162
+ - - ">="
185
163
  - !ruby/object:Gem::Version
186
164
  version: '0'
187
165
  required_rubygems_version: !ruby/object:Gem::Requirement
188
166
  requirements:
189
- - - ! '>='
167
+ - - ">="
190
168
  - !ruby/object:Gem::Version
191
169
  version: '0'
192
170
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.4.5
171
+ rubygems_version: 3.0.3.1
195
172
  signing_key:
196
173
  specification_version: 4
197
174
  summary: The lstash gem allows you to count or grep log messages in a specific time
198
175
  range from a Logstash Elasticsearch server.
199
- test_files:
200
- - spec/lstash/cli_spec.rb
201
- - spec/lstash/client_spec.rb
202
- - spec/lstash/query_spec.rb
203
- - spec/lstash_spec.rb
204
- - spec/spec_helper.rb
176
+ test_files: []