aws-logs 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +6 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +14 -0
- data/aws-logs.gemspec +33 -0
- data/exe/aws-logs +14 -0
- data/lib/aws-logs.rb +1 -0
- data/lib/aws_logs.rb +12 -0
- data/lib/aws_logs/autoloader.rb +22 -0
- data/lib/aws_logs/aws_services.rb +11 -0
- data/lib/aws_logs/cli.rb +33 -0
- data/lib/aws_logs/command.rb +82 -0
- data/lib/aws_logs/completer.rb +159 -0
- data/lib/aws_logs/completer/script.rb +6 -0
- data/lib/aws_logs/completer/script.sh +10 -0
- data/lib/aws_logs/help.rb +9 -0
- data/lib/aws_logs/help/completion.md +20 -0
- data/lib/aws_logs/help/completion_script.md +3 -0
- data/lib/aws_logs/help/tail.md +57 -0
- data/lib/aws_logs/since.rb +82 -0
- data/lib/aws_logs/tail.rb +151 -0
- data/lib/aws_logs/version.rb +3 -0
- data/spec/fixtures/typical/events-1.json +11 -0
- data/spec/fixtures/typical/events-2.json +17 -0
- data/spec/fixtures/typical/events-3.json +23 -0
- data/spec/fixtures/typical/events-4.json +28 -0
- data/spec/lib/cli_spec.rb +8 -0
- data/spec/lib/since_spec.rb +35 -0
- data/spec/lib/tail_spec.rb +88 -0
- data/spec/spec_helper.rb +45 -0
- metadata +240 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
describe AwsLogs::Since do
|
2
|
+
let(:since) { AwsLogs::Since.new(str) }
|
3
|
+
|
4
|
+
context "friendly format" do
|
5
|
+
context "5m" do
|
6
|
+
let(:str) { "5m" }
|
7
|
+
it "5m" do
|
8
|
+
expect(since.to_i).to eq 300
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "1hr" do
|
13
|
+
let(:str) { "1h" }
|
14
|
+
it "1h" do
|
15
|
+
expect(since.to_i).to eq 3600
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "junk" do
|
20
|
+
let(:str) { "junk" }
|
21
|
+
it "junk" do
|
22
|
+
expect(since.to_i).to eq 600 # fallback
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "iso8601 format" do
|
28
|
+
context "2018-08-08 08:08:08" do
|
29
|
+
let(:str) { "2018-08-08 08:08:08" }
|
30
|
+
it "2018-08-08 08:08:08" do
|
31
|
+
expect(since.to_i).to be_a(Integer)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module AwsLogs
|
2
|
+
class Tail
|
3
|
+
# Override to 1 as default. Override on a per spec level if needed.
|
4
|
+
attr_accessor :events
|
5
|
+
def max_loop_count
|
6
|
+
1
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Rainbow.enabled = false
|
12
|
+
|
13
|
+
describe AwsLogs::Tail do
|
14
|
+
# In this spec we override the cloudwatchlogs client. So this tests the logic pretty deeply.
|
15
|
+
context "filter_log_events with 1 cloudwatch api call" do
|
16
|
+
let(:tail) do
|
17
|
+
tail = AwsLogs::Tail.new
|
18
|
+
allow(tail).to receive(:cloudwatchlogs).and_return(cloudwatchlogs)
|
19
|
+
tail
|
20
|
+
end
|
21
|
+
let(:cloudwatchlogs) do
|
22
|
+
logs = double(:logs).as_null_object
|
23
|
+
allow(logs).to receive(:filter_log_events).and_return(*filter_log_events_response)
|
24
|
+
logs
|
25
|
+
end
|
26
|
+
let(:filter_log_events_response) do
|
27
|
+
[
|
28
|
+
mock_response("spec/fixtures/typical/events-2.json"),
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "tail" do
|
33
|
+
it "run" do
|
34
|
+
tail.run
|
35
|
+
expect(tail.output).to eq(<<~EOL)
|
36
|
+
2019-11-27 21:06:50 UTC stream-name message1
|
37
|
+
2019-11-27 21:07:00 UTC stream-name message2
|
38
|
+
EOL
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# In the rest of the specs we only override refresh_events.
|
44
|
+
context "refresh_events" do
|
45
|
+
context "single call" do
|
46
|
+
let(:tail) do
|
47
|
+
tail = AwsLogs::Tail.new
|
48
|
+
allow(tail).to receive(:refresh_events) do
|
49
|
+
tail.events = mock_response("spec/fixtures/typical/events-2.json").events
|
50
|
+
end
|
51
|
+
tail
|
52
|
+
end
|
53
|
+
|
54
|
+
it "run" do
|
55
|
+
tail.run
|
56
|
+
expect(tail.output).to eq(<<~EOL)
|
57
|
+
2019-11-27 21:06:50 UTC stream-name message1
|
58
|
+
2019-11-27 21:07:00 UTC stream-name message2
|
59
|
+
EOL
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "2 calls" do
|
64
|
+
let(:tail) do
|
65
|
+
tail = AwsLogs::Tail.new
|
66
|
+
mock_call_count = 0
|
67
|
+
allow(tail).to receive(:refresh_events) do |start_time,end_time|
|
68
|
+
if mock_call_count == 0
|
69
|
+
tail.events = mock_response("spec/fixtures/typical/events-1.json").events
|
70
|
+
else
|
71
|
+
tail.events = mock_response("spec/fixtures/typical/events-2.json").events
|
72
|
+
end
|
73
|
+
mock_call_count += 1
|
74
|
+
end
|
75
|
+
tail
|
76
|
+
end
|
77
|
+
|
78
|
+
it "even though the mocked events are overrlapping it only prints out the lines once" do
|
79
|
+
allow(tail).to receive(:max_loop_count).and_return(2)
|
80
|
+
tail.run
|
81
|
+
expect(tail.output).to eq(<<~EOL)
|
82
|
+
2019-11-27 21:06:50 UTC stream-name message1
|
83
|
+
2019-11-27 21:07:00 UTC stream-name message2
|
84
|
+
EOL
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
ENV["AWS_LOGS_TEST"] = "1"
|
2
|
+
|
3
|
+
# CodeClimate test coverage: https://docs.codeclimate.com/docs/configuring-test-coverage
|
4
|
+
# require 'simplecov'
|
5
|
+
# SimpleCov.start
|
6
|
+
|
7
|
+
require "pp"
|
8
|
+
require "byebug"
|
9
|
+
root = File.expand_path("../", File.dirname(__FILE__))
|
10
|
+
require "#{root}/lib/aws-logs"
|
11
|
+
|
12
|
+
module Helper
|
13
|
+
def execute(cmd)
|
14
|
+
puts "Running: #{cmd}" if show_command?
|
15
|
+
out = `#{cmd}`
|
16
|
+
puts out if show_command?
|
17
|
+
out
|
18
|
+
end
|
19
|
+
|
20
|
+
# Added SHOW_COMMAND because DEBUG is also used by other libraries like
|
21
|
+
# bundler and it shows its internal debugging logging also.
|
22
|
+
def show_command?
|
23
|
+
ENV['DEBUG'] || ENV['SHOW_COMMAND']
|
24
|
+
end
|
25
|
+
|
26
|
+
def mock_response(file, next_token: nil)
|
27
|
+
data = JSON.load(IO.read(file))
|
28
|
+
events = data["events"].map do |e|
|
29
|
+
Aws::CloudWatchLogs::Types::FilteredLogEvent.new(
|
30
|
+
log_stream_name: e["log_stream_name"],
|
31
|
+
timestamp: e["timestamp"],
|
32
|
+
message: e["message"],
|
33
|
+
event_id: e["event_id"],
|
34
|
+
)
|
35
|
+
end
|
36
|
+
Aws::CloudWatchLogs::Types::FilterLogEventsResponse.new(
|
37
|
+
events: events,
|
38
|
+
next_token: next_token,
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec.configure do |c|
|
44
|
+
c.include Helper
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-logs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tung Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-mfa-secure
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws-sdk-cloudwatchlogs
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rainbow
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: zeitwerk
|
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'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: cli_markdown
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- tongueroo@gmail.com
|
170
|
+
executables:
|
171
|
+
- aws-logs
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".gitignore"
|
176
|
+
- ".rspec"
|
177
|
+
- CHANGELOG.md
|
178
|
+
- Gemfile
|
179
|
+
- Guardfile
|
180
|
+
- LICENSE.txt
|
181
|
+
- README.md
|
182
|
+
- Rakefile
|
183
|
+
- aws-logs.gemspec
|
184
|
+
- exe/aws-logs
|
185
|
+
- lib/aws-logs.rb
|
186
|
+
- lib/aws_logs.rb
|
187
|
+
- lib/aws_logs/autoloader.rb
|
188
|
+
- lib/aws_logs/aws_services.rb
|
189
|
+
- lib/aws_logs/cli.rb
|
190
|
+
- lib/aws_logs/command.rb
|
191
|
+
- lib/aws_logs/completer.rb
|
192
|
+
- lib/aws_logs/completer/script.rb
|
193
|
+
- lib/aws_logs/completer/script.sh
|
194
|
+
- lib/aws_logs/help.rb
|
195
|
+
- lib/aws_logs/help/completion.md
|
196
|
+
- lib/aws_logs/help/completion_script.md
|
197
|
+
- lib/aws_logs/help/tail.md
|
198
|
+
- lib/aws_logs/since.rb
|
199
|
+
- lib/aws_logs/tail.rb
|
200
|
+
- lib/aws_logs/version.rb
|
201
|
+
- spec/fixtures/typical/events-1.json
|
202
|
+
- spec/fixtures/typical/events-2.json
|
203
|
+
- spec/fixtures/typical/events-3.json
|
204
|
+
- spec/fixtures/typical/events-4.json
|
205
|
+
- spec/lib/cli_spec.rb
|
206
|
+
- spec/lib/since_spec.rb
|
207
|
+
- spec/lib/tail_spec.rb
|
208
|
+
- spec/spec_helper.rb
|
209
|
+
homepage: https://github.com/tongueroo/aws-logs
|
210
|
+
licenses:
|
211
|
+
- MIT
|
212
|
+
metadata: {}
|
213
|
+
post_install_message:
|
214
|
+
rdoc_options: []
|
215
|
+
require_paths:
|
216
|
+
- lib
|
217
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
version: '0'
|
227
|
+
requirements: []
|
228
|
+
rubygems_version: 3.0.6
|
229
|
+
signing_key:
|
230
|
+
specification_version: 4
|
231
|
+
summary: Tail AWS CloudWatch Logs
|
232
|
+
test_files:
|
233
|
+
- spec/fixtures/typical/events-1.json
|
234
|
+
- spec/fixtures/typical/events-2.json
|
235
|
+
- spec/fixtures/typical/events-3.json
|
236
|
+
- spec/fixtures/typical/events-4.json
|
237
|
+
- spec/lib/cli_spec.rb
|
238
|
+
- spec/lib/since_spec.rb
|
239
|
+
- spec/lib/tail_spec.rb
|
240
|
+
- spec/spec_helper.rb
|