lstash 0.2.0 → 1.0.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 +4 -4
- data/.devcontainer/Aptfile +6 -0
- data/.devcontainer/Dockerfile +44 -0
- data/.devcontainer/devcontainer.json +36 -0
- data/.github/workflows/test.yml +67 -0
- data/CHANGELOG.md +22 -3
- data/README.md +86 -86
- data/bin/lstash +1 -3
- data/dip.yml +48 -0
- data/docker-compose.yml +28 -0
- data/lib/lstash/cli.rb +42 -29
- data/lib/lstash/client.rb +58 -37
- data/lib/lstash/query.rb +54 -77
- data/lib/lstash/version.rb +1 -1
- data/lib/lstash.rb +4 -4
- data/lstash.gemspec +14 -19
- data/spec/lstash/cli_spec.rb +21 -23
- data/spec/lstash/client_spec.rb +29 -33
- data/spec/lstash/query_spec.rb +62 -60
- data/spec/lstash_spec.rb +3 -3
- data/spec/spec_helper.rb +28 -13
- metadata +17 -58
data/spec/lstash/query_spec.rb
CHANGED
@@ -1,98 +1,96 @@
|
|
1
|
-
require
|
2
|
-
require
|
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)
|
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(
|
14
|
-
after
|
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(
|
22
|
-
its(
|
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) {
|
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) { {
|
40
|
-
its(
|
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) { {
|
45
|
-
its(
|
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) { {
|
50
|
-
its(
|
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) { {
|
55
|
-
its(
|
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) { {
|
60
|
-
its(
|
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) { {
|
65
|
-
its(
|
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
|
-
|
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) {
|
75
|
-
its(
|
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) {
|
80
|
-
its(
|
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) { {
|
85
|
-
its(
|
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) { {
|
90
|
-
its(
|
91
|
-
its(
|
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) { {
|
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
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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)
|
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
|
193
|
+
after { Timecop.return }
|
189
194
|
|
190
195
|
context "from 'firstday' with 'yesterday' anchor" do
|
191
|
-
let(:options) { {
|
196
|
+
let(:options) { {anchor: "yesterday", from: "firstday"} }
|
192
197
|
|
193
|
-
|
194
|
-
|
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) { {
|
203
|
+
let(:options) { {from: "firstday", to: "now"} }
|
199
204
|
|
200
|
-
|
201
|
-
|
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
data/spec/spec_helper.rb
CHANGED
@@ -1,33 +1,48 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(
|
2
|
-
require
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require "lstash"
|
3
3
|
|
4
|
-
require
|
4
|
+
require "rspec/its"
|
5
5
|
|
6
|
-
require
|
6
|
+
require "timecop"
|
7
7
|
|
8
|
-
ENV[
|
9
|
-
ENV[
|
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 =
|
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
|
30
|
+
require "stringio"
|
16
31
|
|
17
|
-
def capture_stdout
|
32
|
+
def capture_stdout
|
18
33
|
old = $stdout
|
19
34
|
$stdout = fake = StringIO.new
|
20
|
-
|
35
|
+
yield
|
21
36
|
fake.string
|
22
37
|
ensure
|
23
38
|
$stdout = old
|
24
39
|
end
|
25
40
|
|
26
|
-
def capture_stderr
|
41
|
+
def capture_stderr
|
27
42
|
old = $stderr
|
28
43
|
$stderr = fake = StringIO.new
|
29
|
-
|
44
|
+
yield
|
30
45
|
fake.string
|
31
46
|
ensure
|
32
47
|
$stderr = old
|
33
|
-
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lstash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Klaas Jan Wierenga
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,48 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.7.1
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: typhoeus
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.4.0
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 1.4.0
|
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:
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !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: 4.1.0
|
89
|
+
version: 7.17.7
|
118
90
|
type: :runtime
|
119
91
|
prerelease: false
|
120
92
|
version_requirements: !ruby/object:Gem::Requirement
|
121
93
|
requirements:
|
122
94
|
- - "~>"
|
123
95
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
96
|
+
version: 7.17.7
|
125
97
|
- !ruby/object:Gem::Dependency
|
126
98
|
name: thor
|
127
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,24 +108,10 @@ dependencies:
|
|
136
108
|
- - "~>"
|
137
109
|
- !ruby/object:Gem::Version
|
138
110
|
version: 0.20.3
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: faraday
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 0.17.4
|
146
|
-
type: :runtime
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 0.17.4
|
153
111
|
description: Count or grep log messages in a specified time range from a Logstash
|
154
112
|
Elasticsearch server.
|
155
113
|
email:
|
156
|
-
- k.j.wierenga@
|
114
|
+
- k.j.wierenga@kerkdienstgemist.nl
|
157
115
|
executables:
|
158
116
|
- lstash
|
159
117
|
extensions: []
|
@@ -163,6 +121,10 @@ extra_rdoc_files:
|
|
163
121
|
- CHANGELOG.md
|
164
122
|
files:
|
165
123
|
- ".autotest"
|
124
|
+
- ".devcontainer/Aptfile"
|
125
|
+
- ".devcontainer/Dockerfile"
|
126
|
+
- ".devcontainer/devcontainer.json"
|
127
|
+
- ".github/workflows/test.yml"
|
166
128
|
- ".gitignore"
|
167
129
|
- ".rspec"
|
168
130
|
- ".ruby-gemset"
|
@@ -174,6 +136,8 @@ files:
|
|
174
136
|
- README.md
|
175
137
|
- Rakefile
|
176
138
|
- bin/lstash
|
139
|
+
- dip.yml
|
140
|
+
- docker-compose.yml
|
177
141
|
- lib/lstash.rb
|
178
142
|
- lib/lstash/cli.rb
|
179
143
|
- lib/lstash/client.rb
|
@@ -185,11 +149,11 @@ files:
|
|
185
149
|
- spec/lstash/query_spec.rb
|
186
150
|
- spec/lstash_spec.rb
|
187
151
|
- spec/spec_helper.rb
|
188
|
-
homepage: https://github.com/
|
152
|
+
homepage: https://github.com/kdgm/lstash
|
189
153
|
licenses:
|
190
154
|
- MIT
|
191
155
|
metadata: {}
|
192
|
-
post_install_message:
|
156
|
+
post_install_message:
|
193
157
|
rdoc_options: []
|
194
158
|
require_paths:
|
195
159
|
- lib
|
@@ -204,14 +168,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
168
|
- !ruby/object:Gem::Version
|
205
169
|
version: '0'
|
206
170
|
requirements: []
|
207
|
-
rubygems_version: 3.0.
|
208
|
-
signing_key:
|
171
|
+
rubygems_version: 3.0.3.1
|
172
|
+
signing_key:
|
209
173
|
specification_version: 4
|
210
174
|
summary: The lstash gem allows you to count or grep log messages in a specific time
|
211
175
|
range from a Logstash Elasticsearch server.
|
212
|
-
test_files:
|
213
|
-
- spec/lstash/cli_spec.rb
|
214
|
-
- spec/lstash/client_spec.rb
|
215
|
-
- spec/lstash/query_spec.rb
|
216
|
-
- spec/lstash_spec.rb
|
217
|
-
- spec/spec_helper.rb
|
176
|
+
test_files: []
|