gitlab-labkit 1.19.0 → 1.20.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f5f66c856712fe4736592757a1dab3a95aa920359ed0bbca72a638d0983df164
|
|
4
|
+
data.tar.gz: 89f0452f48f07968f29b3890fb7f71b1aac42b5f4b6e7cdcad556a0c3f548d6f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1a9bf8af827028ae5e68857650cdf2af5e6c49c16360e123a1f653c0e38530ba89a4f1a5179ee50d540dc4f71a1fd766f93517d622d1a25d72d39be5e545b0b1
|
|
7
|
+
data.tar.gz: 58da58ed8eae9c02437fd0a3f41a529e36feeade438d9dcee63d4448165a95b4d1b3d100c1e27384aa5763a002fbcf9eccc33cb283258e8baafbfbc9366bc56b
|
|
@@ -42,21 +42,26 @@ module Labkit
|
|
|
42
42
|
|
|
43
43
|
private
|
|
44
44
|
|
|
45
|
+
# :log rules are non-terminating: they emit metrics and continue,
|
|
46
|
+
# so a shadow :log rule cannot disable a following :block rule.
|
|
45
47
|
def check_rules(identifier)
|
|
46
48
|
@rules.each do |rule|
|
|
47
49
|
next unless rule_matches?(rule, identifier)
|
|
48
50
|
|
|
49
51
|
result = evaluate_rule(rule, identifier)
|
|
50
52
|
report_matched_metrics(result)
|
|
51
|
-
return result
|
|
53
|
+
return result unless rule.action == :log
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
report_unmatched_metrics
|
|
55
57
|
Result.new(matched: false, action: :allow)
|
|
56
58
|
end
|
|
57
59
|
|
|
60
|
+
# Mirror of check_rules without metrics: peek skips :log rules (their state
|
|
61
|
+
# is unobservable through peek).
|
|
58
62
|
def peek_rules(identifier)
|
|
59
63
|
@rules.each do |rule|
|
|
64
|
+
next if rule.action == :log
|
|
60
65
|
next unless rule_matches?(rule, identifier)
|
|
61
66
|
|
|
62
67
|
return peek_rule(rule, identifier)
|
|
@@ -5,6 +5,9 @@ module Labkit
|
|
|
5
5
|
module Metrics
|
|
6
6
|
module_function
|
|
7
7
|
|
|
8
|
+
# :log rules are non-terminating: a check that matched only :log rules
|
|
9
|
+
# increments calls_total once per matched :log rule AND once with
|
|
10
|
+
# rule="unmatched", action="allow", since no terminating decision was made.
|
|
8
11
|
def calls_total
|
|
9
12
|
Labkit::Metrics::Client.counter(
|
|
10
13
|
:gitlab_labkit_rate_limiter_calls_total,
|
|
@@ -8,9 +8,9 @@ module Labkit
|
|
|
8
8
|
# action - the outcome: what the caller should do
|
|
9
9
|
# :block = rule matched, exceeded, rule configured to block
|
|
10
10
|
# :log = rule matched, exceeded, rule configured to log only
|
|
11
|
-
# :allow = rule matched but count within limit,
|
|
11
|
+
# :allow = rule matched but count within limit, rule configured to allow,
|
|
12
12
|
# no rule matched, or error (fail-open)
|
|
13
|
-
# The rule's configured action is available via rule.action
|
|
13
|
+
# The rule's configured action is available via rule.action.
|
|
14
14
|
# rule - the matched Rule object (nil when matched? is false)
|
|
15
15
|
# error? - true if Redis was unavailable; result fails open (exceeded? is false)
|
|
16
16
|
# info - Result::Info with per-window counters; nil when matched? is false or error?
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Labkit
|
|
4
4
|
module RateLimit
|
|
5
|
-
KNOWN_ACTIONS = [
|
|
5
|
+
KNOWN_ACTIONS = %i[block log allow].freeze
|
|
6
6
|
RULE_NAME_PATTERN = /\A[a-z0-9_]+\z/
|
|
7
7
|
RULE_NAME_MAX_LENGTH = 64
|
|
8
8
|
|
|
@@ -12,7 +12,9 @@ module Labkit
|
|
|
12
12
|
# the rule to apply; empty hash matches any identifier
|
|
13
13
|
# limit - request threshold; may be a callable (resolved per check)
|
|
14
14
|
# period - window in seconds; may be a callable (resolved per check)
|
|
15
|
-
# action - :block (enforce)
|
|
15
|
+
# action - :block (enforce), :log (count and log only, do not block,
|
|
16
|
+
# evaluation continues to subsequent rules), or :allow
|
|
17
|
+
# (bypass: short-circuit evaluation with no Redis writes)
|
|
16
18
|
# characteristics - identifier keys used to build the compound Redis counter key
|
|
17
19
|
#
|
|
18
20
|
# +name+ must be a lowercase alphanumeric-and-underscore string of at most 64
|