logster 2.12.2 → 2.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +5 -0
- data/.streerc +2 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +7 -6
- data/assets/javascript/{chunk.143.f61340b825c6a3bf6dbe.js → chunk.143.5bf090e78cbca9ee78cc.js} +4 -4
- data/assets/javascript/{chunk.178.6d9ae01775c898e7b748.js → chunk.178.135370942038cfbbe65e.js} +3 -3
- data/assets/javascript/client-app.js +103 -35
- data/client-app/app/controllers/show.js +17 -1
- data/client-app/app/templates/show.hbs +2 -0
- data/client-app/package.json +1 -1
- data/client-app/preload-json-manager.rb +10 -17
- data/client-app/yarn.lock +131 -44
- data/lib/examples/sidekiq_logster_reporter.rb +5 -7
- data/lib/logster/base_store.rb +26 -22
- data/lib/logster/cache.rb +2 -1
- data/lib/logster/configuration.rb +3 -3
- data/lib/logster/defer_logger.rb +2 -4
- data/lib/logster/group.rb +17 -20
- data/lib/logster/ignore_pattern.rb +1 -2
- data/lib/logster/logger.rb +18 -16
- data/lib/logster/message.rb +53 -57
- data/lib/logster/middleware/debug_exceptions.rb +12 -10
- data/lib/logster/middleware/reporter.rb +17 -26
- data/lib/logster/middleware/viewer.rb +77 -97
- data/lib/logster/pattern.rb +4 -7
- data/lib/logster/rails/railtie.rb +10 -13
- data/lib/logster/redis_rate_limiter.rb +2 -7
- data/lib/logster/redis_store.rb +79 -99
- data/lib/logster/scheduler.rb +1 -5
- data/lib/logster/suppression_pattern.rb +7 -5
- data/lib/logster/version.rb +1 -1
- data/lib/logster/web.rb +1 -1
- data/lib/logster.rb +15 -17
- data/logster.gemspec +14 -14
- data/test/examples/test_sidekiq_reporter_example.rb +8 -9
- data/test/fake_data/generate.rb +14 -3
- data/test/logster/middleware/test_reporter.rb +9 -7
- data/test/logster/middleware/test_viewer.rb +117 -101
- data/test/logster/test_base_store.rb +79 -58
- data/test/logster/test_cache.rb +5 -11
- data/test/logster/test_defer_logger.rb +3 -3
- data/test/logster/test_group.rb +14 -18
- data/test/logster/test_ignore_pattern.rb +2 -3
- data/test/logster/test_logger.rb +14 -14
- data/test/logster/test_message.rb +29 -31
- data/test/logster/test_pattern.rb +7 -15
- data/test/logster/test_redis_rate_limiter.rb +35 -21
- data/test/logster/test_redis_store.rb +239 -151
- data/test/test_helper.rb +9 -9
- metadata +19 -4
data/test/logster/test_group.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require_relative "../test_helper"
|
4
|
+
require "logster/group"
|
5
|
+
require "logster/message"
|
6
6
|
|
7
7
|
class TestGroup < MiniTest::Test
|
8
8
|
def test_changed_is_true_for_new_instances
|
@@ -11,12 +11,13 @@ class TestGroup < MiniTest::Test
|
|
11
11
|
|
12
12
|
def test_from_json_works_correctly
|
13
13
|
time = (Time.now.to_f * 1000).to_i - 5000
|
14
|
-
json =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
json =
|
15
|
+
JSON.generate(
|
16
|
+
key: "/somekey/",
|
17
|
+
messages_keys: [111, 222, 333].map(&:to_s),
|
18
|
+
timestamp: time,
|
19
|
+
count: 3,
|
20
|
+
)
|
20
21
|
group = Logster::Group.from_json(json)
|
21
22
|
refute group.changed?
|
22
23
|
assert_equal 3, group.count
|
@@ -34,7 +35,7 @@ class TestGroup < MiniTest::Test
|
|
34
35
|
assert_equal 1, group.count
|
35
36
|
|
36
37
|
msg2 = get_message
|
37
|
-
msg2.timestamp -=
|
38
|
+
msg2.timestamp -= 10_000
|
38
39
|
group.add_message(msg2)
|
39
40
|
assert_equal 2, group.count
|
40
41
|
assert_equal msg1.timestamp, group.timestamp
|
@@ -42,12 +43,7 @@ class TestGroup < MiniTest::Test
|
|
42
43
|
|
43
44
|
def test_adding_multiple_messages_works_correctly
|
44
45
|
group = get_group
|
45
|
-
messages = [
|
46
|
-
get_message(10),
|
47
|
-
get_message(5),
|
48
|
-
get_message(74),
|
49
|
-
get_message(26)
|
50
|
-
]
|
46
|
+
messages = [get_message(10), get_message(5), get_message(74), get_message(26)]
|
51
47
|
messages << messages[0]
|
52
48
|
group.messages = messages
|
53
49
|
group.count = 4
|
@@ -66,7 +62,7 @@ class TestGroup < MiniTest::Test
|
|
66
62
|
get_message(74),
|
67
63
|
get_message(26),
|
68
64
|
get_message(44),
|
69
|
-
get_message(390)
|
65
|
+
get_message(390),
|
70
66
|
]
|
71
67
|
messages.each { |m| group.add_message(m) }
|
72
68
|
# the count attr keeps track of the number of messages
|
@@ -91,6 +87,6 @@ class TestGroup < MiniTest::Test
|
|
91
87
|
end
|
92
88
|
|
93
89
|
def get_message(timestamp = nil)
|
94
|
-
Logster::Message.new(0,
|
90
|
+
Logster::Message.new(0, "", "testmessage", timestamp)
|
95
91
|
end
|
96
92
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
3
|
+
require_relative "../test_helper"
|
4
|
+
require "logster/ignore_pattern"
|
5
5
|
|
6
6
|
class TestIgnorePattern < Minitest::Test
|
7
|
-
|
8
7
|
def test_string_message_pattern
|
9
8
|
msg = Logster::Message.new(Logger::WARN, "test", "my error (oh no!)")
|
10
9
|
msg_frog = Logster::Message.new(Logger::WARN, "test", "a frog")
|
data/test/logster/test_logger.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require_relative "../test_helper"
|
4
|
+
require "logster/logger"
|
5
|
+
require "logger"
|
6
6
|
|
7
7
|
class TestStore < Logster::BaseStore
|
8
8
|
attr_accessor :calls
|
@@ -13,7 +13,6 @@ class TestStore < Logster::BaseStore
|
|
13
13
|
end
|
14
14
|
|
15
15
|
class TestLogger < Minitest::Test
|
16
|
-
|
17
16
|
def setup
|
18
17
|
@store = TestStore.new
|
19
18
|
@logger = Logster::Logger.new(@store)
|
@@ -35,9 +34,7 @@ class TestLogger < Minitest::Test
|
|
35
34
|
@logger.override_level = 2
|
36
35
|
|
37
36
|
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
38
|
-
Thread.new
|
39
|
-
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
40
|
-
end.join
|
37
|
+
Thread.new { @logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" }) }.join
|
41
38
|
|
42
39
|
@logger.override_level = nil
|
43
40
|
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
@@ -64,9 +61,7 @@ class TestLogger < Minitest::Test
|
|
64
61
|
|
65
62
|
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
66
63
|
|
67
|
-
[@store, @other_store].each
|
68
|
-
assert_equal "backtrace", store.calls[0][3][:backtrace]
|
69
|
-
end
|
64
|
+
[@store, @other_store].each { |store| assert_equal "backtrace", store.calls[0][3][:backtrace] }
|
70
65
|
end
|
71
66
|
|
72
67
|
def test_add_with_one_argument
|
@@ -76,7 +71,8 @@ class TestLogger < Minitest::Test
|
|
76
71
|
assert_equal "test", @store.calls.first[2]
|
77
72
|
end
|
78
73
|
|
79
|
-
class NewLogger < Logster::Logger
|
74
|
+
class NewLogger < Logster::Logger
|
75
|
+
end
|
80
76
|
|
81
77
|
def test_inherited_logger_backtrace_with_chain
|
82
78
|
@other_store = TestStore.new
|
@@ -85,9 +81,7 @@ class TestLogger < Minitest::Test
|
|
85
81
|
|
86
82
|
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
87
83
|
|
88
|
-
[@store, @other_store].each
|
89
|
-
assert_equal "backtrace", store.calls[0][3][:backtrace]
|
90
|
-
end
|
84
|
+
[@store, @other_store].each { |store| assert_equal "backtrace", store.calls[0][3][:backtrace] }
|
91
85
|
end
|
92
86
|
|
93
87
|
def test_progname_parameter
|
@@ -127,6 +121,12 @@ class TestLogger < Minitest::Test
|
|
127
121
|
assert_equal custom_err.backtrace.join("\n"), @store.calls[2][3][:backtrace]
|
128
122
|
end
|
129
123
|
|
124
|
+
def test_formatter
|
125
|
+
@logger.formatter = ->(severity, datetime, progname, msg) { "[test] #{msg}" }
|
126
|
+
@logger.add(0, "hello")
|
127
|
+
assert_equal "[test] hello", @store.calls[0][2]
|
128
|
+
end
|
129
|
+
|
130
130
|
private
|
131
131
|
|
132
132
|
def error_instance(error_class)
|
@@ -1,15 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
3
|
+
require_relative "../test_helper"
|
4
|
+
require "logster/message"
|
5
5
|
|
6
6
|
class TestMessage < MiniTest::Test
|
7
|
-
|
8
7
|
def test_merge_similar
|
9
|
-
msg1 = Logster::Message.new(0,
|
8
|
+
msg1 = Logster::Message.new(0, "", "test", 10)
|
10
9
|
msg1.populate_from_env(a: "1", b: "2")
|
11
10
|
|
12
|
-
msg2 = Logster::Message.new(0,
|
11
|
+
msg2 = Logster::Message.new(0, "", "test", 20)
|
13
12
|
msg2.populate_from_env(a: "2", c: "3")
|
14
13
|
assert_equal(msg2.grouping_key, msg1.grouping_key)
|
15
14
|
msg1.merge_similar_message(msg2)
|
@@ -21,35 +20,35 @@ class TestMessage < MiniTest::Test
|
|
21
20
|
|
22
21
|
def test_populate_from_env_will_add_time_to_env_unless_it_already_exists
|
23
22
|
t = (Time.now.to_f * 1000).to_i
|
24
|
-
msg = Logster::Message.new(0,
|
23
|
+
msg = Logster::Message.new(0, "", "test", t)
|
25
24
|
msg.populate_from_env({})
|
26
25
|
assert_equal(t, msg.env["time"])
|
27
26
|
|
28
|
-
msg = Logster::Message.new(0,
|
27
|
+
msg = Logster::Message.new(0, "", "test", t)
|
29
28
|
msg.populate_from_env(time: 5)
|
30
29
|
assert_nil(msg.env["time"])
|
31
30
|
assert_equal(5, msg.env[:time])
|
32
31
|
|
33
|
-
msg = Logster::Message.new(0,
|
32
|
+
msg = Logster::Message.new(0, "", "test", t)
|
34
33
|
msg.populate_from_env("time" => 6)
|
35
34
|
assert_equal(6, msg.env["time"])
|
36
35
|
assert_nil(msg.env[:time])
|
37
36
|
|
38
|
-
msg = Logster::Message.new(0,
|
37
|
+
msg = Logster::Message.new(0, "", "test", t)
|
39
38
|
msg.populate_from_env([{ "time" => 6 }, { "time" => 8 }])
|
40
39
|
assert_equal([6, 8], msg.env.map { |e| e["time"] })
|
41
40
|
assert_equal([nil, nil], msg.env.map { |e| e[:time] })
|
42
41
|
|
43
|
-
msg = Logster::Message.new(0,
|
42
|
+
msg = Logster::Message.new(0, "", "test", t)
|
44
43
|
msg.populate_from_env([{ dsd: 6 }, { dsd: 8 }])
|
45
44
|
assert_equal([t, t], msg.env.map { |e| e["time"] })
|
46
45
|
end
|
47
46
|
|
48
47
|
def test_merge_messages_both_with_array_envs
|
49
|
-
msg1 = Logster::Message.new(0,
|
48
|
+
msg1 = Logster::Message.new(0, "", "test", 10)
|
50
49
|
msg1.env = [{ a: "aa", b: "bb" }, { c: "cc", d: "dd" }]
|
51
50
|
|
52
|
-
msg2 = Logster::Message.new(0,
|
51
|
+
msg2 = Logster::Message.new(0, "", "test", 20)
|
53
52
|
msg2.env = [{ e: "ee", f: "ff" }, { g: "gg", h: "hh" }]
|
54
53
|
|
55
54
|
msg1.merge_similar_message(msg2)
|
@@ -57,10 +56,10 @@ class TestMessage < MiniTest::Test
|
|
57
56
|
end
|
58
57
|
|
59
58
|
def test_merge_messages_one_with_array_envs
|
60
|
-
msg1 = Logster::Message.new(0,
|
59
|
+
msg1 = Logster::Message.new(0, "", "test", 10)
|
61
60
|
msg1.env = { e: "ee", f: "ff" }
|
62
61
|
|
63
|
-
msg2 = Logster::Message.new(0,
|
62
|
+
msg2 = Logster::Message.new(0, "", "test", 20)
|
64
63
|
msg2.env = [{ a: "aa", b: "bb" }, { c: "cc", d: "dd" }]
|
65
64
|
|
66
65
|
msg1.merge_similar_message(msg2)
|
@@ -69,11 +68,10 @@ class TestMessage < MiniTest::Test
|
|
69
68
|
|
70
69
|
def test_adds_application_version
|
71
70
|
Logster.config.application_version = "abc"
|
72
|
-
msg = Logster::Message.new(0,
|
71
|
+
msg = Logster::Message.new(0, "", "test", 10)
|
73
72
|
msg.populate_from_env({})
|
74
73
|
|
75
74
|
assert_equal("abc", msg.env["application_version"])
|
76
|
-
|
77
75
|
ensure
|
78
76
|
Logster.config.application_version = nil
|
79
77
|
end
|
@@ -81,7 +79,7 @@ class TestMessage < MiniTest::Test
|
|
81
79
|
def test_use_full_hostname
|
82
80
|
Logster::Message.instance_variable_set(:@hostname, nil)
|
83
81
|
Logster.config.use_full_hostname = true
|
84
|
-
msg = Logster::Message.new(0,
|
82
|
+
msg = Logster::Message.new(0, "", "test", 10)
|
85
83
|
msg.populate_from_env({})
|
86
84
|
|
87
85
|
assert_equal(`hostname -f`.strip!, msg.env["hostname"])
|
@@ -91,8 +89,8 @@ class TestMessage < MiniTest::Test
|
|
91
89
|
end
|
92
90
|
|
93
91
|
def test_merging_sums_count_for_both_messages
|
94
|
-
msg1 = Logster::Message.new(0,
|
95
|
-
msg2 = Logster::Message.new(0,
|
92
|
+
msg1 = Logster::Message.new(0, "", "test", 10, count: 15)
|
93
|
+
msg2 = Logster::Message.new(0, "", "test", 20, count: 13)
|
96
94
|
msg2.env = {}
|
97
95
|
|
98
96
|
assert_equal(msg1.grouping_key, msg2.grouping_key)
|
@@ -108,8 +106,8 @@ class TestMessage < MiniTest::Test
|
|
108
106
|
message: "invalid encoding",
|
109
107
|
env: {
|
110
108
|
a: "bad_value",
|
111
|
-
b: ["bad_value"]
|
112
|
-
}
|
109
|
+
b: ["bad_value"],
|
110
|
+
},
|
113
111
|
}
|
114
112
|
json = hash.to_json.gsub("bad_value", "45\xC0\xBE")
|
115
113
|
message = Logster::Message.from_json(json)
|
@@ -120,7 +118,7 @@ class TestMessage < MiniTest::Test
|
|
120
118
|
end
|
121
119
|
|
122
120
|
def test_populate_from_env_works_on_array
|
123
|
-
msg = Logster::Message.new(0,
|
121
|
+
msg = Logster::Message.new(0, "", "test", 10)
|
124
122
|
hash = { "custom_key" => "key" }
|
125
123
|
msg.populate_from_env([hash])
|
126
124
|
|
@@ -130,9 +128,9 @@ class TestMessage < MiniTest::Test
|
|
130
128
|
end
|
131
129
|
|
132
130
|
def test_merging_envs_add_new_envs_to_buffer
|
133
|
-
msg1 = Logster::Message.new(0,
|
131
|
+
msg1 = Logster::Message.new(0, "", "test", 10, count: 50)
|
134
132
|
msg1.env = 50.times.map { |n| { a: n } }
|
135
|
-
msg2 = Logster::Message.new(0,
|
133
|
+
msg2 = Logster::Message.new(0, "", "test", 20, count: 13)
|
136
134
|
msg2.env = 13.times.map { |n| { b: n } }
|
137
135
|
|
138
136
|
assert_equal(msg1.grouping_key, msg2.grouping_key)
|
@@ -159,7 +157,7 @@ class TestMessage < MiniTest::Test
|
|
159
157
|
end
|
160
158
|
|
161
159
|
def test_drop_redundant_envs
|
162
|
-
message = Logster::Message.new(Logger::WARN,
|
160
|
+
message = Logster::Message.new(Logger::WARN, "", "message")
|
163
161
|
message.env = [{ a: 4 }] * 10
|
164
162
|
assert_equal(10, message.env.size)
|
165
163
|
message.drop_redundant_envs(5)
|
@@ -172,7 +170,7 @@ class TestMessage < MiniTest::Test
|
|
172
170
|
end
|
173
171
|
|
174
172
|
def test_apply_env_size_limit_keeps_as_many_keys_as_possible
|
175
|
-
message = Logster::Message.new(Logger::WARN,
|
173
|
+
message = Logster::Message.new(Logger::WARN, "", "message", 1)
|
176
174
|
env = { a: 1, bb: 22, ccc: 333 }
|
177
175
|
message.env = env.dup
|
178
176
|
message.apply_env_size_limit(24)
|
@@ -207,7 +205,7 @@ class TestMessage < MiniTest::Test
|
|
207
205
|
/var/www/discourse/lib/scheduler/defer.rb:79:in `block (2 levels) in start_thread'
|
208
206
|
TEXT
|
209
207
|
gems_dir = "/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/"
|
210
|
-
message = Logster::Message.new(Logger::WARN,
|
208
|
+
message = Logster::Message.new(Logger::WARN, "", "message", 1)
|
211
209
|
|
212
210
|
message.backtrace = backtrace.dup
|
213
211
|
assert_operator(message.to_json(exclude_env: true).bytesize, :>=, 500)
|
@@ -229,7 +227,7 @@ class TestMessage < MiniTest::Test
|
|
229
227
|
rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:60:in `with_connection'
|
230
228
|
/var/www/discourse
|
231
229
|
TEXT
|
232
|
-
message = Logster::Message.new(Logger::WARN,
|
230
|
+
message = Logster::Message.new(Logger::WARN, "", "message", 1)
|
233
231
|
message.backtrace = backtrace.dup
|
234
232
|
assert_operator(message.to_json(exclude_env: true).bytesize, :>=, 350)
|
235
233
|
message.apply_message_size_limit(350)
|
@@ -239,7 +237,7 @@ class TestMessage < MiniTest::Test
|
|
239
237
|
|
240
238
|
def test_truncate_backtrace_shouldnt_corrupt_backtrace_when_it_contains_multibytes_characters
|
241
239
|
backtrace = "aहa"
|
242
|
-
message = Logster::Message.new(Logger::WARN,
|
240
|
+
message = Logster::Message.new(Logger::WARN, "", "message", 1)
|
243
241
|
message.backtrace = backtrace.dup
|
244
242
|
message.truncate_backtrace(3)
|
245
243
|
assert_equal("a", message.backtrace)
|
@@ -254,7 +252,7 @@ class TestMessage < MiniTest::Test
|
|
254
252
|
end
|
255
253
|
|
256
254
|
def test_apply_message_size_limit_doesnt_remove_backtrace_entirely
|
257
|
-
message = Logster::Message.new(Logger::WARN,
|
255
|
+
message = Logster::Message.new(Logger::WARN, "", "message", 1)
|
258
256
|
message.backtrace = "a" * 1000
|
259
257
|
assert_operator(message.to_json(exclude_env: true).bytesize, :>=, 500)
|
260
258
|
message.apply_message_size_limit(500)
|
@@ -263,7 +261,7 @@ class TestMessage < MiniTest::Test
|
|
263
261
|
end
|
264
262
|
|
265
263
|
def test_apply_message_size_limit_doesnt_hang_forever_and_doesnt_remove_backtrace_entirely
|
266
|
-
message = Logster::Message.new(Logger::WARN,
|
264
|
+
message = Logster::Message.new(Logger::WARN, "", "message", 1)
|
267
265
|
message.backtrace = "aa" * 100
|
268
266
|
message.apply_message_size_limit(10)
|
269
267
|
assert_equal(("aa" * 100).size, message.backtrace.size)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require_relative "../test_helper"
|
4
|
+
require "logster/redis_store"
|
5
|
+
require "logster/pattern"
|
6
6
|
|
7
7
|
class TestPattern < Minitest::Test
|
8
8
|
class FakePattern < Logster::Pattern
|
@@ -90,22 +90,16 @@ class TestPattern < Minitest::Test
|
|
90
90
|
def test_save_works_correctly
|
91
91
|
bad_patterns = ["/bruken", nil, "[a-z", "/(osa|sss{1/"]
|
92
92
|
bad_patterns.each do |p|
|
93
|
-
assert_raises(Logster::Pattern::PatternError)
|
94
|
-
FakePattern.new(p).save
|
95
|
-
end
|
93
|
+
assert_raises(Logster::Pattern::PatternError) { FakePattern.new(p).save }
|
96
94
|
end
|
97
95
|
assert_equal(0, FakePattern.find_all.size)
|
98
96
|
|
99
97
|
good_patterns = ["/logster/i", /logster/, "sssd", "(ccx|tqe){1,5}", "logster"]
|
100
|
-
good_patterns.each
|
101
|
-
FakePattern.new(p).save
|
102
|
-
end
|
98
|
+
good_patterns.each { |p| FakePattern.new(p).save }
|
103
99
|
results = FakePattern.find_all
|
104
100
|
assert_equal(4, results.size) # 4 because /logster/ and logster are the same
|
105
101
|
good_patterns_regex = [/logster/i, /logster/, /sssd/, /(ccx|tqe){1,5}/]
|
106
|
-
results.each
|
107
|
-
assert_includes(good_patterns_regex, p)
|
108
|
-
end
|
102
|
+
results.each { |p| assert_includes(good_patterns_regex, p) }
|
109
103
|
end
|
110
104
|
|
111
105
|
def test_modify_works_correctly
|
@@ -123,9 +117,7 @@ class TestPattern < Minitest::Test
|
|
123
117
|
record = FakePattern.new(/LoGsTEr/)
|
124
118
|
record.save
|
125
119
|
|
126
|
-
assert_raises(Logster::Pattern::PatternError)
|
127
|
-
record.modify("/badReg")
|
128
|
-
end
|
120
|
+
assert_raises(Logster::Pattern::PatternError) { record.modify("/badReg") }
|
129
121
|
all_patterns = FakePattern.find_all
|
130
122
|
assert_equal(1, all_patterns.size)
|
131
123
|
assert_equal(/LoGsTEr/, all_patterns.first)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require_relative "../test_helper"
|
4
|
+
require "logster/redis_store"
|
5
|
+
require "rack"
|
6
6
|
|
7
7
|
class TestRedisRateLimiter < Minitest::Test
|
8
8
|
def setup
|
@@ -19,13 +19,17 @@ class TestRedisRateLimiter < Minitest::Test
|
|
19
19
|
|
20
20
|
@redis.set("dont_nuke", "1")
|
21
21
|
|
22
|
-
@rate_limiter =
|
23
|
-
|
24
|
-
|
22
|
+
@rate_limiter =
|
23
|
+
Logster::RedisRateLimiter.new(
|
24
|
+
@redis,
|
25
|
+
[Logger::WARN],
|
26
|
+
8,
|
27
|
+
60,
|
28
|
+
Proc.new { "prefix" },
|
29
|
+
Proc.new { called += 1 },
|
30
|
+
)
|
25
31
|
|
26
|
-
9.times
|
27
|
-
@rate_limiter.check(Logger::WARN)
|
28
|
-
end
|
32
|
+
9.times { @rate_limiter.check(Logger::WARN) }
|
29
33
|
|
30
34
|
assert_equal 10, @rate_limiter.check(Logger::WARN)
|
31
35
|
|
@@ -40,7 +44,6 @@ class TestRedisRateLimiter < Minitest::Test
|
|
40
44
|
|
41
45
|
assert_equal "1", @redis.get("dont_nuke")
|
42
46
|
@redis.del("dont_nuke")
|
43
|
-
|
44
47
|
end
|
45
48
|
|
46
49
|
def test_check
|
@@ -48,9 +51,8 @@ class TestRedisRateLimiter < Minitest::Test
|
|
48
51
|
Timecop.freeze(time)
|
49
52
|
called = 0
|
50
53
|
|
51
|
-
@rate_limiter =
|
52
|
-
@redis, [Logger::WARN], 8, 60, nil, Proc.new { called += 1 }
|
53
|
-
)
|
54
|
+
@rate_limiter =
|
55
|
+
Logster::RedisRateLimiter.new(@redis, [Logger::WARN], 8, 60, nil, Proc.new { called += 1 })
|
54
56
|
|
55
57
|
assert_equal(1, @rate_limiter.check(Logger::WARN))
|
56
58
|
assert_redis_key(60, 0)
|
@@ -113,9 +115,15 @@ class TestRedisRateLimiter < Minitest::Test
|
|
113
115
|
Timecop.freeze(time)
|
114
116
|
called = 0
|
115
117
|
|
116
|
-
@rate_limiter =
|
117
|
-
|
118
|
-
|
118
|
+
@rate_limiter =
|
119
|
+
Logster::RedisRateLimiter.new(
|
120
|
+
@redis,
|
121
|
+
[Logger::WARN, Logger::ERROR],
|
122
|
+
4,
|
123
|
+
60,
|
124
|
+
nil,
|
125
|
+
Proc.new { called += 1 },
|
126
|
+
)
|
119
127
|
|
120
128
|
assert_equal(1, @rate_limiter.check(Logger::WARN))
|
121
129
|
assert_equal(2, @rate_limiter.check(Logger::ERROR))
|
@@ -170,16 +178,22 @@ class TestRedisRateLimiter < Minitest::Test
|
|
170
178
|
def test_raw_connection
|
171
179
|
time = Time.new(2015, 1, 1, 1, 1)
|
172
180
|
Timecop.freeze(time)
|
173
|
-
@rate_limiter =
|
181
|
+
@rate_limiter =
|
182
|
+
Logster::RedisRateLimiter.new(@redis, [Logger::WARN], 1, 60, Proc.new { "lobster" })
|
174
183
|
|
175
184
|
assert_equal(1, @rate_limiter.check(Logger::WARN))
|
176
185
|
assert_redis_key(60, 0)
|
177
186
|
|
178
187
|
toggle = true
|
179
188
|
|
180
|
-
@rate_limiter =
|
181
|
-
|
182
|
-
|
189
|
+
@rate_limiter =
|
190
|
+
Logster::RedisRateLimiter.new(
|
191
|
+
@redis,
|
192
|
+
[Logger::WARN],
|
193
|
+
1,
|
194
|
+
60,
|
195
|
+
Proc.new { toggle ? "lobster1" : "lobster2" },
|
196
|
+
)
|
183
197
|
|
184
198
|
assert_includes(key, "lobster1")
|
185
199
|
|
@@ -188,7 +202,7 @@ class TestRedisRateLimiter < Minitest::Test
|
|
188
202
|
end
|
189
203
|
|
190
204
|
def test_retrieve_rate
|
191
|
-
time = Time.new(2015, 1, 1, 1
|
205
|
+
time = Time.new(2015, 1, 1, 1, 1)
|
192
206
|
Timecop.freeze(time)
|
193
207
|
|
194
208
|
@rate_limiter = Logster::RedisRateLimiter.new(@redis, [Logger::WARN], 1, 60)
|