logster 2.12.1 → 2.13.0
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 +10 -1
- data/Gemfile +1 -1
- data/assets/javascript/{chunk.143.2faa04830259ce9aa59a.js → chunk.143.91d07e8cdd5c4b9e4731.js} +4 -4
- data/assets/javascript/{chunk.178.ca5ade1d8cbdbfbe6d72.js → chunk.178.16d0c9057345120bdba1.js} +3 -3
- data/assets/javascript/client-app.js +4 -2
- data/client-app/app/components/back-trace.js +4 -0
- data/client-app/package.json +1 -1
- data/client-app/preload-json-manager.rb +10 -17
- data/client-app/tests/integration/components/back-trace-test.js +17 -0
- data/client-app/yarn.lock +22 -22
- 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
@@ -1,11 +1,10 @@
|
|
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 TestRedisStore < Minitest::Test
|
8
|
-
|
9
8
|
def setup
|
10
9
|
@store = Logster::RedisStore.new(Redis.new)
|
11
10
|
@store.clear_all
|
@@ -28,8 +27,8 @@ class TestRedisStore < Minitest::Test
|
|
28
27
|
def test_delete_with_custom_grouping_patterns
|
29
28
|
Logster.config.enable_custom_patterns_via_ui = true
|
30
29
|
Logster::GroupingPattern.new(/delete/, store: @store).save
|
31
|
-
msg1 = @store.report(Logger::WARN,
|
32
|
-
msg2 = @store.report(Logger::WARN,
|
30
|
+
msg1 = @store.report(Logger::WARN, "", "this will be deleted")
|
31
|
+
msg2 = @store.report(Logger::WARN, "", "delete this plz")
|
33
32
|
|
34
33
|
groups = @store.find_pattern_groups
|
35
34
|
assert_equal 1, groups.size
|
@@ -53,7 +52,7 @@ class TestRedisStore < Minitest::Test
|
|
53
52
|
keys = []
|
54
53
|
gkeys = []
|
55
54
|
6.times do |n|
|
56
|
-
m = @store.report(Logger::WARN,
|
55
|
+
m = @store.report(Logger::WARN, "", "#{n} delete")
|
57
56
|
keys << m.key
|
58
57
|
gkeys << m.grouping_key
|
59
58
|
end
|
@@ -90,15 +89,11 @@ class TestRedisStore < Minitest::Test
|
|
90
89
|
end
|
91
90
|
|
92
91
|
def test_latest_after
|
93
|
-
10.times
|
94
|
-
@store.report(Logger::WARN, "test", "A#{i}")
|
95
|
-
end
|
92
|
+
10.times { |i| @store.report(Logger::WARN, "test", "A#{i}") }
|
96
93
|
|
97
94
|
message = @store.latest[-1]
|
98
95
|
|
99
|
-
3.times
|
100
|
-
@store.report(Logger::WARN, "test", i.to_s)
|
101
|
-
end
|
96
|
+
3.times { |i| @store.report(Logger::WARN, "test", i.to_s) }
|
102
97
|
|
103
98
|
message = @store.latest(after: message.key, limit: 3)[0]
|
104
99
|
|
@@ -106,15 +101,9 @@ class TestRedisStore < Minitest::Test
|
|
106
101
|
end
|
107
102
|
|
108
103
|
def test_latest_before
|
109
|
-
10.times
|
110
|
-
|
111
|
-
|
112
|
-
10.times do
|
113
|
-
@store.report(Logger::WARN, "test", "B")
|
114
|
-
end
|
115
|
-
10.times do
|
116
|
-
@store.report(Logger::WARN, "test", "C")
|
117
|
-
end
|
104
|
+
10.times { @store.report(Logger::WARN, "test", "A") }
|
105
|
+
10.times { @store.report(Logger::WARN, "test", "B") }
|
106
|
+
10.times { @store.report(Logger::WARN, "test", "C") }
|
118
107
|
|
119
108
|
messages = @store.latest(limit: 10)
|
120
109
|
assert_equal("C", messages[0].message)
|
@@ -133,23 +122,21 @@ class TestRedisStore < Minitest::Test
|
|
133
122
|
Logster.config.enable_custom_patterns_via_ui = true
|
134
123
|
Logster::GroupingPattern.new(/group 1/, store: @store).save
|
135
124
|
Logster::GroupingPattern.new(/group 2/, store: @store).save
|
136
|
-
msg1 = @store.report(Logger::WARN,
|
125
|
+
msg1 = @store.report(Logger::WARN, "", "first message")
|
137
126
|
group_1_keys = []
|
138
|
-
3.times { |n| group_1_keys << @store.report(Logger::WARN,
|
139
|
-
msg2 = @store.report(Logger::WARN,
|
140
|
-
group_1_keys << @store.report(Logger::WARN,
|
141
|
-
msg3 = @store.report(Logger::WARN,
|
127
|
+
3.times { |n| group_1_keys << @store.report(Logger::WARN, "", "group 1 #{n}").key }
|
128
|
+
msg2 = @store.report(Logger::WARN, "", "second message")
|
129
|
+
group_1_keys << @store.report(Logger::WARN, "", "group 1 3").key
|
130
|
+
msg3 = @store.report(Logger::WARN, "", "third message")
|
142
131
|
group_2_keys = []
|
143
|
-
3.times { |n| group_2_keys << @store.report(Logger::WARN,
|
144
|
-
msg4 = @store.report(Logger::WARN,
|
132
|
+
3.times { |n| group_2_keys << @store.report(Logger::WARN, "", "group 2 #{n}").key }
|
133
|
+
msg4 = @store.report(Logger::WARN, "", "fourth message")
|
145
134
|
|
146
135
|
results = @store.latest
|
147
|
-
assert_equal [msg1.key, msg2.key, "/group 1/", msg3.key, "/group 2/", msg4.key],
|
136
|
+
assert_equal [msg1.key, msg2.key, "/group 1/", msg3.key, "/group 2/", msg4.key],
|
137
|
+
results.map(&:key)
|
148
138
|
groups = results.select { |r| r.class == Logster::Group::GroupWeb }
|
149
|
-
assert_equal(
|
150
|
-
[group_1_keys.last, group_2_keys.last],
|
151
|
-
groups.map(&:row_id)
|
152
|
-
)
|
139
|
+
assert_equal([group_1_keys.last, group_2_keys.last], groups.map(&:row_id))
|
153
140
|
assert_equal 4, groups[0].messages.size
|
154
141
|
assert_equal 3, groups[1].messages.size
|
155
142
|
|
@@ -172,7 +159,7 @@ class TestRedisStore < Minitest::Test
|
|
172
159
|
results = @store.latest(after: msg4.key)
|
173
160
|
assert_equal 0, results.size
|
174
161
|
|
175
|
-
group_2_keys << @store.report(Logger::WARN,
|
162
|
+
group_2_keys << @store.report(Logger::WARN, "", "group 2 3").key
|
176
163
|
results = @store.latest(after: msg4.key)
|
177
164
|
assert_equal ["/group 2/"], results.map(&:key)
|
178
165
|
assert_equal group_2_keys.last, results[0].row_id
|
@@ -243,7 +230,7 @@ class TestRedisStore < Minitest::Test
|
|
243
230
|
message = @store.report(Logger::WARN, "test", "A", env: old_env)
|
244
231
|
|
245
232
|
extra_env = { "saved_env" => "saved value!" }
|
246
|
-
similar = @store.report(Logger::WARN,
|
233
|
+
similar = @store.report(Logger::WARN, "test", "A", env: extra_env)
|
247
234
|
message.merge_similar_message(similar)
|
248
235
|
|
249
236
|
@store.replace_and_bump(message)
|
@@ -256,9 +243,7 @@ class TestRedisStore < Minitest::Test
|
|
256
243
|
def test_ensure_env_doesnt_exceed_50_item
|
257
244
|
Logster.config.allow_grouping = true
|
258
245
|
message = nil
|
259
|
-
52.times
|
260
|
-
message = @store.report(Logger::WARN, "", "mssage", env: { a: n })
|
261
|
-
end
|
246
|
+
52.times { |n| message = @store.report(Logger::WARN, "", "mssage", env: { a: n }) }
|
262
247
|
message = @store.get(message.key)
|
263
248
|
assert_equal(52, message.count)
|
264
249
|
assert_equal(50, message.env.size)
|
@@ -337,17 +322,15 @@ class TestRedisStore < Minitest::Test
|
|
337
322
|
def test_clear
|
338
323
|
env = { "clear_env" => "cllleear" }
|
339
324
|
@store.max_backlog = 25
|
340
|
-
a_message =
|
325
|
+
a_message =
|
326
|
+
@store.report(Logger::WARN, "test", "A", timestamp: Time.now - (24 * 60 * 60), env: env)
|
341
327
|
@store.protect a_message.key
|
342
|
-
20.times
|
343
|
-
|
344
|
-
|
345
|
-
c_message = @store.report(Logger::WARN, "test", "C", timestamp: Time.now + (24 * 60 * 60), env: env)
|
328
|
+
20.times { @store.report(Logger::WARN, "test", "B", env: env) }
|
329
|
+
c_message =
|
330
|
+
@store.report(Logger::WARN, "test", "C", timestamp: Time.now + (24 * 60 * 60), env: env)
|
346
331
|
@store.protect c_message.key
|
347
332
|
d_message = @store.report(Logger::WARN, "test", "D", env: env)
|
348
|
-
10.times
|
349
|
-
@store.report(Logger::WARN, "test", "E", env: env)
|
350
|
-
end
|
333
|
+
10.times { @store.report(Logger::WARN, "test", "E", env: env) }
|
351
334
|
|
352
335
|
latest = @store.latest
|
353
336
|
assert_equal(25, latest.length)
|
@@ -376,9 +359,9 @@ class TestRedisStore < Minitest::Test
|
|
376
359
|
Logster.config.allow_grouping = true
|
377
360
|
Logster::GroupingPattern.new(/discourse/, store: @store).save
|
378
361
|
Logster::GroupingPattern.new(/logster/, store: @store).save
|
379
|
-
msg = @store.report(Logger::WARN,
|
362
|
+
msg = @store.report(Logger::WARN, "", "discourse")
|
380
363
|
@store.protect(msg.key)
|
381
|
-
@store.report(Logger::WARN,
|
364
|
+
@store.report(Logger::WARN, "", "logster")
|
382
365
|
groups = @store.find_pattern_groups
|
383
366
|
assert_equal 2, groups.size
|
384
367
|
|
@@ -386,7 +369,7 @@ class TestRedisStore < Minitest::Test
|
|
386
369
|
groups = @store.find_pattern_groups
|
387
370
|
assert_equal 1, groups.size
|
388
371
|
assert_equal msg.key, groups[0].messages_keys[0]
|
389
|
-
assert_equal
|
372
|
+
assert_equal "/discourse/", groups[0].key
|
390
373
|
|
391
374
|
@store.unprotect(msg.key)
|
392
375
|
@store.clear
|
@@ -416,13 +399,9 @@ class TestRedisStore < Minitest::Test
|
|
416
399
|
messages = @store.latest(after: messages.last.key)
|
417
400
|
assert_equal(0, messages.length)
|
418
401
|
|
419
|
-
10.times
|
420
|
-
@store.report(Logger::INFO, "test", "A")
|
421
|
-
end
|
402
|
+
10.times { @store.report(Logger::INFO, "test", "A") }
|
422
403
|
@store.report(Logger::ERROR, "test", "C")
|
423
|
-
10.times
|
424
|
-
@store.report(Logger::INFO, "test", "A")
|
425
|
-
end
|
404
|
+
10.times { @store.report(Logger::INFO, "test", "A") }
|
426
405
|
|
427
406
|
latest = @store.latest(severity: [Logger::ERROR, Logger::WARN], limit: 2)
|
428
407
|
|
@@ -524,8 +503,8 @@ class TestRedisStore < Minitest::Test
|
|
524
503
|
m1 = @store.get(m1_key)
|
525
504
|
m2 = @store.get(m2_key)
|
526
505
|
# original env should preserved in redis memory
|
527
|
-
assert_equal([
|
528
|
-
assert_equal([
|
506
|
+
assert_equal(%w[business5 standard3], m1.env.map { |env| env["cluster"] })
|
507
|
+
assert_equal(%w[business2 standard7], m2.env.map { |env| env["cluster"] })
|
529
508
|
end
|
530
509
|
|
531
510
|
def test_both_env_and_title_match_search
|
@@ -543,12 +522,27 @@ class TestRedisStore < Minitest::Test
|
|
543
522
|
begin
|
544
523
|
Logster.config.allow_grouping = true
|
545
524
|
backtrace = caller
|
546
|
-
message =
|
525
|
+
message =
|
526
|
+
@store.report(
|
527
|
+
Logger::WARN,
|
528
|
+
"",
|
529
|
+
"my error",
|
530
|
+
env: {
|
531
|
+
whatever: "something",
|
532
|
+
backtrace: backtrace,
|
533
|
+
},
|
534
|
+
)
|
547
535
|
|
548
|
-
@store.ignore = [
|
549
|
-
|
550
|
-
|
551
|
-
|
536
|
+
@store.ignore = [Logster::IgnorePattern.new("business")]
|
537
|
+
@store.report(
|
538
|
+
Logger::WARN,
|
539
|
+
"",
|
540
|
+
"my error",
|
541
|
+
env: {
|
542
|
+
cluster: "business17",
|
543
|
+
backtrace: backtrace,
|
544
|
+
},
|
545
|
+
)
|
552
546
|
|
553
547
|
message = @store.get(message.key)
|
554
548
|
assert(Array === message.env)
|
@@ -565,8 +559,20 @@ class TestRedisStore < Minitest::Test
|
|
565
559
|
end
|
566
560
|
|
567
561
|
def test_array_env_negative_search
|
568
|
-
@store.report(
|
569
|
-
|
562
|
+
@store.report(
|
563
|
+
Logger::INFO,
|
564
|
+
"test",
|
565
|
+
"message ABCD",
|
566
|
+
env: [{ cluster: "business5" }, { cluster: "standard3" }],
|
567
|
+
count: 2,
|
568
|
+
)
|
569
|
+
@store.report(
|
570
|
+
Logger::INFO,
|
571
|
+
"test",
|
572
|
+
"message WXYZ",
|
573
|
+
env: [{ cluster: "business2" }, { cluster: "standard7" }],
|
574
|
+
count: 2,
|
575
|
+
)
|
570
576
|
|
571
577
|
messages = @store.latest
|
572
578
|
assert_equal(2, messages.length)
|
@@ -581,14 +587,26 @@ class TestRedisStore < Minitest::Test
|
|
581
587
|
end
|
582
588
|
|
583
589
|
def test_negative_search_MUST_not_match_title_in_order_to_include_message
|
584
|
-
@store.report(
|
590
|
+
@store.report(
|
591
|
+
Logger::INFO,
|
592
|
+
"test",
|
593
|
+
"message ABCD",
|
594
|
+
env: [{ cluster: "business5" }, { cluster: "standard3" }],
|
595
|
+
count: 2,
|
596
|
+
)
|
585
597
|
|
586
598
|
messages = @store.latest(search: "-ABCD")
|
587
599
|
assert_equal(0, messages.size) # cause title has ABCD
|
588
600
|
end
|
589
601
|
|
590
602
|
def test_positive_search_looks_at_title_OR_env
|
591
|
-
@store.report(
|
603
|
+
@store.report(
|
604
|
+
Logger::INFO,
|
605
|
+
"test",
|
606
|
+
"message",
|
607
|
+
env: [{ cluster: "business5 ABCDEFG" }, { cluster: "standard3" }],
|
608
|
+
count: 2,
|
609
|
+
)
|
592
610
|
|
593
611
|
messages = @store.latest(search: "ABCDEFG")
|
594
612
|
assert_equal(1, messages.size)
|
@@ -624,34 +642,82 @@ class TestRedisStore < Minitest::Test
|
|
624
642
|
assert_equal(1, @store.latest.count)
|
625
643
|
|
626
644
|
@store.report(Logger::WARN, "application", "test error1", backtrace: "backtrace1")
|
627
|
-
@store.report(
|
645
|
+
@store.report(
|
646
|
+
Logger::WARN,
|
647
|
+
"application",
|
648
|
+
"test error1",
|
649
|
+
backtrace: "backtrace1",
|
650
|
+
env: {
|
651
|
+
"application_version" => "xyz",
|
652
|
+
},
|
653
|
+
)
|
628
654
|
|
629
655
|
assert_equal(2, @store.latest.count)
|
630
|
-
|
631
656
|
ensure
|
632
657
|
Logster.config.application_version = nil
|
633
658
|
end
|
634
659
|
|
635
660
|
def test_solve_grouped
|
636
661
|
Logster.config.allow_grouping = true
|
637
|
-
@store.report(
|
638
|
-
|
662
|
+
@store.report(
|
663
|
+
Logger::WARN,
|
664
|
+
"application",
|
665
|
+
"test error1",
|
666
|
+
backtrace: "backtrace1",
|
667
|
+
env: {
|
668
|
+
"application_version" => "xyz",
|
669
|
+
},
|
670
|
+
)
|
671
|
+
m =
|
672
|
+
@store.report(
|
673
|
+
Logger::WARN,
|
674
|
+
"application",
|
675
|
+
"test error1",
|
676
|
+
backtrace: "backtrace1",
|
677
|
+
env: {
|
678
|
+
"application_version" => "efg",
|
679
|
+
},
|
680
|
+
)
|
639
681
|
|
640
682
|
assert_equal(1, @store.latest.count)
|
641
683
|
|
642
684
|
@store.solve(m.key)
|
643
685
|
|
644
|
-
@store.report(
|
645
|
-
|
686
|
+
@store.report(
|
687
|
+
Logger::WARN,
|
688
|
+
"application",
|
689
|
+
"test error1",
|
690
|
+
backtrace: "backtrace1",
|
691
|
+
env: {
|
692
|
+
"application_version" => "xyz",
|
693
|
+
},
|
694
|
+
)
|
695
|
+
@store.report(
|
696
|
+
Logger::WARN,
|
697
|
+
"application",
|
698
|
+
"test error1",
|
699
|
+
backtrace: "backtrace1",
|
700
|
+
env: {
|
701
|
+
"application_version" => "efg",
|
702
|
+
},
|
703
|
+
)
|
646
704
|
|
647
705
|
assert_equal(0, @store.latest.count)
|
648
|
-
|
649
706
|
ensure
|
650
707
|
Logster.config.allow_grouping = false
|
651
708
|
end
|
652
709
|
|
653
710
|
def test_clears_solved
|
654
|
-
m =
|
711
|
+
m =
|
712
|
+
@store.report(
|
713
|
+
Logger::WARN,
|
714
|
+
"application",
|
715
|
+
"test error2",
|
716
|
+
backtrace: "backtrace1",
|
717
|
+
env: {
|
718
|
+
"application_version" => "abc",
|
719
|
+
},
|
720
|
+
)
|
655
721
|
@store.solve(m.key)
|
656
722
|
|
657
723
|
assert_equal(1, @store.solved.length)
|
@@ -661,8 +727,16 @@ class TestRedisStore < Minitest::Test
|
|
661
727
|
end
|
662
728
|
|
663
729
|
def test_solving_with_some_missing_version
|
664
|
-
|
665
|
-
|
730
|
+
m =
|
731
|
+
@store.report(
|
732
|
+
Logger::WARN,
|
733
|
+
"application",
|
734
|
+
"test error1",
|
735
|
+
backtrace: "backtrace1",
|
736
|
+
env: {
|
737
|
+
"application_version" => "xyz",
|
738
|
+
},
|
739
|
+
)
|
666
740
|
@store.report(Logger::WARN, "application", "test error1", backtrace: "backtrace1")
|
667
741
|
|
668
742
|
@store.solve(m.key)
|
@@ -671,27 +745,20 @@ class TestRedisStore < Minitest::Test
|
|
671
745
|
end
|
672
746
|
|
673
747
|
def test_env
|
674
|
-
env =
|
675
|
-
"
|
676
|
-
|
677
|
-
|
748
|
+
env =
|
749
|
+
Rack::MockRequest.env_for("/test").merge(
|
750
|
+
"HTTP_HOST" => "www.site.com",
|
751
|
+
"HTTP_USER_AGENT" => "SOME WHERE",
|
752
|
+
)
|
678
753
|
orig = env.dup
|
679
754
|
orig["test"] = "tests"
|
680
755
|
orig["test1"] = "tests1"
|
681
756
|
Logster.add_to_env(env, "test", "tests")
|
682
757
|
Logster.add_to_env(env, "test1", "tests1")
|
683
758
|
|
684
|
-
orig.delete_if
|
685
|
-
!%w{
|
686
|
-
HTTP_HOST
|
687
|
-
REQUEST_METHOD
|
688
|
-
HTTP_USER_AGENT
|
689
|
-
test
|
690
|
-
test1
|
691
|
-
}.include? k
|
692
|
-
end
|
759
|
+
orig.delete_if { |k, v| !%w[HTTP_HOST REQUEST_METHOD HTTP_USER_AGENT test test1].include? k }
|
693
760
|
|
694
|
-
@store.report(Logger::INFO, "test", "test",
|
761
|
+
@store.report(Logger::INFO, "test", "test", env: env)
|
695
762
|
|
696
763
|
env = @store.latest.last.env
|
697
764
|
|
@@ -717,7 +784,11 @@ class TestRedisStore < Minitest::Test
|
|
717
784
|
end
|
718
785
|
|
719
786
|
def test_suppressed_logs_are_counted
|
720
|
-
@store.ignore = [
|
787
|
+
@store.ignore = [
|
788
|
+
/store ignore/,
|
789
|
+
Logster::IgnorePattern.new(/ignore pattern/),
|
790
|
+
"an ignore string",
|
791
|
+
]
|
721
792
|
@store.allow_custom_patterns = true
|
722
793
|
Logster::SuppressionPattern.new(/sup pattern/, store: @store).save
|
723
794
|
|
@@ -741,7 +812,7 @@ class TestRedisStore < Minitest::Test
|
|
741
812
|
end
|
742
813
|
|
743
814
|
def test_rate_limits
|
744
|
-
%w
|
815
|
+
%w[minute hour].each do |duration|
|
745
816
|
begin
|
746
817
|
called = false
|
747
818
|
|
@@ -749,7 +820,7 @@ class TestRedisStore < Minitest::Test
|
|
749
820
|
Logster::RedisRateLimiter,
|
750
821
|
@store.public_send("register_rate_limit_per_#{duration}", Logger::WARN, 0) do
|
751
822
|
called = true
|
752
|
-
end
|
823
|
+
end,
|
753
824
|
)
|
754
825
|
|
755
826
|
@store.report(Logger::WARN, "test", "test")
|
@@ -762,25 +833,25 @@ class TestRedisStore < Minitest::Test
|
|
762
833
|
|
763
834
|
def test_rate_limits_only_checks_when_message_is_bumped_or_saved
|
764
835
|
Logster.config.allow_grouping = true
|
765
|
-
Logster.config.application_version =
|
836
|
+
Logster.config.application_version = "abc"
|
766
837
|
|
767
838
|
@store.ignore = [/^ActiveRecord::RecordNotFound/]
|
768
839
|
rate_limit = @store.register_rate_limit_per_minute(Logger::WARN, 0)
|
769
840
|
|
770
|
-
message = @store.report(Logger::WARN,
|
841
|
+
message = @store.report(Logger::WARN, "message 1", "Error!", backtrace: "here")
|
771
842
|
assert_equal(1, rate_limit.retrieve_rate)
|
772
843
|
|
773
|
-
@store.report(Logger::WARN,
|
844
|
+
@store.report(Logger::WARN, "message 1", "Error!", backtrace: "here")
|
774
845
|
assert_equal(2, rate_limit.retrieve_rate)
|
775
846
|
|
776
847
|
@store.solve(message.key)
|
777
|
-
@store.report(Logger::WARN,
|
848
|
+
@store.report(Logger::WARN, "message 1", "Error!", backtrace: "here")
|
778
849
|
assert_equal(2, rate_limit.retrieve_rate)
|
779
850
|
|
780
|
-
@store.report(Logger::WARN,
|
851
|
+
@store.report(Logger::WARN, "message 2", "Error!")
|
781
852
|
assert_equal(3, rate_limit.retrieve_rate)
|
782
853
|
|
783
|
-
@store.report(Logger::WARN,
|
854
|
+
@store.report(Logger::WARN, "message 3", "ActiveRecord::RecordNotFound")
|
784
855
|
assert_equal(3, rate_limit.retrieve_rate)
|
785
856
|
ensure
|
786
857
|
Logster.config.allow_grouping = false
|
@@ -792,7 +863,7 @@ class TestRedisStore < Minitest::Test
|
|
792
863
|
begin
|
793
864
|
time = Time.now
|
794
865
|
Timecop.freeze(time)
|
795
|
-
current_namespace =
|
866
|
+
current_namespace = "first"
|
796
867
|
@store.redis_prefix = Proc.new { current_namespace }
|
797
868
|
|
798
869
|
called_first = 0
|
@@ -802,14 +873,14 @@ class TestRedisStore < Minitest::Test
|
|
802
873
|
@store.report(Logger::WARN, "test", "test")
|
803
874
|
assert_equal(1, called_first)
|
804
875
|
|
805
|
-
current_namespace =
|
876
|
+
current_namespace = "second"
|
806
877
|
@store.register_rate_limit_per_minute(Logger::WARN, 0) { called_second += 1 }
|
807
878
|
@store.report(Logger::WARN, "test", "test")
|
808
879
|
assert_equal(1, called_first)
|
809
880
|
assert_equal(1, called_second)
|
810
881
|
|
811
882
|
Timecop.freeze(time + 10) do
|
812
|
-
current_namespace =
|
883
|
+
current_namespace = "first"
|
813
884
|
@store.report(Logger::WARN, "test", "test")
|
814
885
|
|
815
886
|
assert_equal(2, called_first)
|
@@ -845,10 +916,18 @@ class TestRedisStore < Minitest::Test
|
|
845
916
|
config_reset(
|
846
917
|
maximum_message_size_bytes: 300,
|
847
918
|
max_env_bytes: 30,
|
848
|
-
max_env_count_per_message: 5
|
919
|
+
max_env_count_per_message: 5,
|
849
920
|
) do
|
850
921
|
env = [{ aaa: 111, bbb: 222, ccc: 333, ddd: 444 }] * 7
|
851
|
-
message =
|
922
|
+
message =
|
923
|
+
@store.report(
|
924
|
+
Logger::WARN,
|
925
|
+
"",
|
926
|
+
"test",
|
927
|
+
backtrace: "aa\n" * 100,
|
928
|
+
env: env.dup,
|
929
|
+
timestamp: 777,
|
930
|
+
)
|
852
931
|
message = @store.get(message.key)
|
853
932
|
assert_operator(message.to_json(exclude_env: true).bytesize, :<, 300)
|
854
933
|
assert_equal(5, message.env.size)
|
@@ -860,34 +939,43 @@ class TestRedisStore < Minitest::Test
|
|
860
939
|
end
|
861
940
|
|
862
941
|
def test_ensure_messages_meet_config_size_limits_when_merged_together
|
863
|
-
|
864
|
-
config_reset(
|
865
|
-
max_env_bytes: 30,
|
866
|
-
max_env_count_per_message: 5,
|
867
|
-
allow_grouping: true
|
868
|
-
) do
|
942
|
+
config_reset(max_env_bytes: 30, max_env_count_per_message: 5, allow_grouping: true) do
|
869
943
|
env = [{ a: 1, aa: 22, aaa: 333, aaaa: 4444 }] * 3
|
870
944
|
env_2 = [{ b: 1, bb: 22, bbb: 333, bbbb: 4444 }] * 3
|
871
|
-
@store.report(Logger::WARN,
|
872
|
-
message =
|
945
|
+
@store.report(Logger::WARN, "", "test", backtrace: "aa\n" * 100, env: env.dup, timestamp: 777)
|
946
|
+
message =
|
947
|
+
@store.report(
|
948
|
+
Logger::WARN,
|
949
|
+
"",
|
950
|
+
"test",
|
951
|
+
backtrace: "aa\n" * 100,
|
952
|
+
env: env_2.dup,
|
953
|
+
timestamp: 777,
|
954
|
+
)
|
873
955
|
message = @store.get(message.key)
|
874
956
|
assert_equal(5, message.env.size)
|
875
|
-
message
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
957
|
+
message
|
958
|
+
.env
|
959
|
+
.first(3)
|
960
|
+
.each do |e|
|
961
|
+
assert_operator(e.to_json.bytesize, :<=, 30)
|
962
|
+
assert_equal({ "b" => 1, "bb" => 22, "time" => 777 }, e)
|
963
|
+
end
|
964
|
+
message
|
965
|
+
.env
|
966
|
+
.last(2)
|
967
|
+
.each do |e|
|
968
|
+
assert_operator(e.to_json.bytesize, :<=, 30)
|
969
|
+
assert_equal({ "a" => 1, "aa" => 22, "time" => 777 }, e)
|
970
|
+
end
|
883
971
|
end
|
884
972
|
end
|
885
973
|
|
886
974
|
def test_custom_grouping_patterns
|
887
975
|
Logster.config.enable_custom_patterns_via_ui = true
|
888
976
|
Logster::GroupingPattern.new(/delete/, store: @store).save
|
889
|
-
msg1 = @store.report(Logger::WARN,
|
890
|
-
msg2 = @store.report(Logger::WARN,
|
977
|
+
msg1 = @store.report(Logger::WARN, "", "delete this plz", timestamp: 1)
|
978
|
+
msg2 = @store.report(Logger::WARN, "", "delete that plz", timestamp: 2)
|
891
979
|
group = @store.find_pattern_groups(load_messages: true)[0]
|
892
980
|
assert_equal 2, group.count
|
893
981
|
assert_equal "/delete/", group.key
|
@@ -902,9 +990,9 @@ class TestRedisStore < Minitest::Test
|
|
902
990
|
Logster.config.allow_grouping = true
|
903
991
|
Logster::GroupingPattern.new(/delete/, store: @store).save
|
904
992
|
backtrace = caller
|
905
|
-
@store.report(Logger::WARN,
|
906
|
-
msg2 = @store.report(Logger::WARN,
|
907
|
-
msg3 = @store.report(Logger::WARN,
|
993
|
+
@store.report(Logger::WARN, "", "delete this plz", backtrace: backtrace, timestamp: 1)
|
994
|
+
msg2 = @store.report(Logger::WARN, "", "delete that plz", backtrace: backtrace, timestamp: 2)
|
995
|
+
msg3 = @store.report(Logger::WARN, "", "delete this plz", backtrace: backtrace, timestamp: 3)
|
908
996
|
group = @store.find_pattern_groups(load_messages: false)[0]
|
909
997
|
assert_equal 2, group.count
|
910
998
|
assert_equal [msg3.key, msg2.key], group.messages_keys
|
@@ -918,10 +1006,10 @@ class TestRedisStore < Minitest::Test
|
|
918
1006
|
Logster.config.enable_custom_patterns_via_ui = true
|
919
1007
|
Logster::GroupingPattern.new(/delete/, store: @store).save
|
920
1008
|
Logster::GroupingPattern.new(/env/, store: @store).save
|
921
|
-
@store.report(Logger::WARN,
|
1009
|
+
@store.report(Logger::WARN, "", "delete and env")
|
922
1010
|
groups = @store.find_pattern_groups
|
923
1011
|
assert_equal 1, groups.size
|
924
|
-
assert_includes [
|
1012
|
+
assert_includes %w[/delete/ /env/], groups[0].key
|
925
1013
|
ensure
|
926
1014
|
Logster.config.enable_custom_patterns_via_ui = false
|
927
1015
|
end
|
@@ -936,8 +1024,8 @@ class TestRedisStore < Minitest::Test
|
|
936
1024
|
assert_equal 0, groups.size # because there are no messages yet
|
937
1025
|
|
938
1026
|
2.times do |n|
|
939
|
-
@store.report(Logger::WARN,
|
940
|
-
@store.report(Logger::WARN,
|
1027
|
+
@store.report(Logger::WARN, "", "with search #{n}")
|
1028
|
+
@store.report(Logger::WARN, "", "pattern group #{n}")
|
941
1029
|
end
|
942
1030
|
groups = @store.find_pattern_groups
|
943
1031
|
assert_equal 2, groups.size
|
@@ -968,9 +1056,7 @@ class TestRedisStore < Minitest::Test
|
|
968
1056
|
Logster.config.enable_custom_patterns_via_ui = true
|
969
1057
|
Logster::GroupingPattern.new(/trim/, store: @store).save
|
970
1058
|
keys = []
|
971
|
-
5.times
|
972
|
-
keys << @store.report(Logger::WARN, '', "trim backlog #{n}").key
|
973
|
-
end
|
1059
|
+
5.times { |n| keys << @store.report(Logger::WARN, "", "trim backlog #{n}").key }
|
974
1060
|
groups = @store.find_pattern_groups
|
975
1061
|
assert_equal 1, groups.size
|
976
1062
|
assert_equal 4, groups[0].messages_keys.size
|
@@ -983,14 +1069,14 @@ class TestRedisStore < Minitest::Test
|
|
983
1069
|
|
984
1070
|
def test_adding_grouping_pattern_works_retroactively
|
985
1071
|
Logster.config.enable_custom_patterns_via_ui = true
|
986
|
-
@store.report(Logger::WARN,
|
987
|
-
@store.report(Logger::WARN,
|
1072
|
+
@store.report(Logger::WARN, "", "trim this plz")
|
1073
|
+
@store.report(Logger::WARN, "", "trim that plz")
|
988
1074
|
Logster::GroupingPattern.new(/trim/, store: @store).save
|
989
1075
|
results = @store.latest
|
990
1076
|
assert_equal 1, results.size
|
991
1077
|
assert_equal 2, results[0].messages.size
|
992
1078
|
|
993
|
-
@store.report(Logger::WARN,
|
1079
|
+
@store.report(Logger::WARN, "", "trim this more plz")
|
994
1080
|
results = @store.latest
|
995
1081
|
assert_equal 1, results.size
|
996
1082
|
assert_equal 3, results[0].messages.size
|
@@ -1000,8 +1086,8 @@ class TestRedisStore < Minitest::Test
|
|
1000
1086
|
|
1001
1087
|
def test_adding_grouping_pattern_doesnt_add_a_message_to_more_than_one_group
|
1002
1088
|
Logster.config.enable_custom_patterns_via_ui = true
|
1003
|
-
@store.report(Logger::WARN,
|
1004
|
-
@store.report(Logger::WARN,
|
1089
|
+
@store.report(Logger::WARN, "", "trim this plz")
|
1090
|
+
@store.report(Logger::WARN, "", "trim this plz 2")
|
1005
1091
|
Logster::GroupingPattern.new(/trim/, store: @store).save
|
1006
1092
|
Logster::GroupingPattern.new(/this/, store: @store).save
|
1007
1093
|
groups = @store.find_pattern_groups
|
@@ -1014,18 +1100,18 @@ class TestRedisStore < Minitest::Test
|
|
1014
1100
|
def test_latest_doesnt_include_rows_that_are_removed_from_grouping_patterns_due_to_max_size
|
1015
1101
|
Logster.config.enable_custom_patterns_via_ui = true
|
1016
1102
|
Logster::Group.instance_variable_set(:@max_size, 5)
|
1017
|
-
msg1 = @store.report(Logger::WARN,
|
1018
|
-
msg2 = @store.report(Logger::WARN,
|
1103
|
+
msg1 = @store.report(Logger::WARN, "", "first message")
|
1104
|
+
msg2 = @store.report(Logger::WARN, "", "second message")
|
1019
1105
|
Logster::GroupingPattern.new(/noisy/, store: @store).save
|
1020
1106
|
|
1021
1107
|
grouped = []
|
1022
1108
|
7.times do |n|
|
1023
|
-
grouped << @store.report(Logger::WARN,
|
1109
|
+
grouped << @store.report(Logger::WARN, "", "noisy message #{n}", timestamp: n).key
|
1024
1110
|
end
|
1025
|
-
msg3 = @store.report(Logger::WARN,
|
1111
|
+
msg3 = @store.report(Logger::WARN, "", "third message")
|
1026
1112
|
results = @store.latest
|
1027
1113
|
|
1028
|
-
assert_equal [msg1.key, msg2.key,
|
1114
|
+
assert_equal [msg1.key, msg2.key, "/noisy/", msg3.key], results.map(&:key)
|
1029
1115
|
assert_equal grouped.reverse.first(5), results[2].messages.map(&:key)
|
1030
1116
|
ensure
|
1031
1117
|
Logster.config.enable_custom_patterns_via_ui = false
|
@@ -1036,10 +1122,14 @@ class TestRedisStore < Minitest::Test
|
|
1036
1122
|
config_reset(allow_grouping: true) do
|
1037
1123
|
backtrace = "a" * Logster.config.maximum_message_size_bytes
|
1038
1124
|
title = "sasasas"
|
1039
|
-
msg = @store.report(Logger::WARN,
|
1040
|
-
msg2 = @store.report(Logger::WARN,
|
1125
|
+
msg = @store.report(Logger::WARN, "", title, backtrace: backtrace.dup)
|
1126
|
+
msg2 = @store.report(Logger::WARN, "", title, backtrace: backtrace.dup)
|
1041
1127
|
assert_equal(msg.key, msg2.key)
|
1042
|
-
assert_operator(
|
1128
|
+
assert_operator(
|
1129
|
+
msg.to_json(exclude_env: true).bytesize,
|
1130
|
+
:<=,
|
1131
|
+
Logster.config.maximum_message_size_bytes,
|
1132
|
+
)
|
1043
1133
|
assert_operator(msg.backtrace.size, :<, backtrace.size)
|
1044
1134
|
end
|
1045
1135
|
end
|
@@ -1050,13 +1140,13 @@ class TestRedisStore < Minitest::Test
|
|
1050
1140
|
DistributedMutex("download_20450e291e8f1e5ba03ca7f20fb7d9da570c94a6"):
|
1051
1141
|
held for too long, expected max: 60 secs, took an extra 73 secs
|
1052
1142
|
TEXT
|
1053
|
-
msg = @store.report(Logger::WARN,
|
1143
|
+
msg = @store.report(Logger::WARN, "", first_message, backtrace: caller)
|
1054
1144
|
|
1055
1145
|
second_message = <<~TEXT
|
1056
1146
|
DistributedMutex("download_e09ae082c60a351dedec67ed869652862b232a0b"):
|
1057
1147
|
held for too long, expected max: 60 secs, took an extra 287 secs
|
1058
1148
|
TEXT
|
1059
|
-
msg2 = @store.report(Logger::WARN,
|
1149
|
+
msg2 = @store.report(Logger::WARN, "", second_message, backtrace: caller)
|
1060
1150
|
|
1061
1151
|
assert_equal(msg.key, msg2.key)
|
1062
1152
|
end
|
@@ -1072,9 +1162,7 @@ class TestRedisStore < Minitest::Test
|
|
1072
1162
|
end
|
1073
1163
|
yield
|
1074
1164
|
ensure
|
1075
|
-
defaults.each
|
1076
|
-
Logster.config.public_send("#{k}=", v)
|
1077
|
-
end
|
1165
|
+
defaults.each { |k, v| Logster.config.public_send("#{k}=", v) }
|
1078
1166
|
end
|
1079
1167
|
|
1080
1168
|
def reset_redis
|