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: cb897d7171414d685d81aa2d55930e9633a46ac6aee0bdca4f36ed34b38e307e
4
- data.tar.gz: bd171795616da76cf4262da0f70d6a4e3746bea4e5eab74b3fe554d3597a0c87
3
+ metadata.gz: f5f66c856712fe4736592757a1dab3a95aa920359ed0bbca72a638d0983df164
4
+ data.tar.gz: 89f0452f48f07968f29b3890fb7f71b1aac42b5f4b6e7cdcad556a0c3f548d6f
5
5
  SHA512:
6
- metadata.gz: 4d4174c89606b5949876451b31bdb40a76db573284ed5976afe9806eb33ac592e90d425cb8c3c48412756be9a7db777cfdb00f14649601ff8d0bcc05807bc8c9
7
- data.tar.gz: b46236e5b3f59f97cd371f250c397553c32656a51994b556ae43fa4751b2eeb95c5b5bdbc3276d5ad156c861df7f7ff4f39ec93bd3826c854dbfff975fc77602
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, or
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 = [:block, :log].freeze
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) or :log (count and log, but do not block)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate