gitlab-labkit 1.19.0 → 1.20.1
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: 3b916b3579ca06fa9a40b34d2bac1d9ffb5bcb8a51415ad9438956c546400164
|
|
4
|
+
data.tar.gz: a680e485958792ac93e5be3fca0c7598db2c029349d6c7aa3c34a039daf2e350
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53acf37dbe0f4416c5952dfba12e3df3156f233243c69580bb3dfdef6b9727f73d586151a9809225e9a99d537e2499da4f66061c197462debc76d3b3c633160a
|
|
7
|
+
data.tar.gz: bd46d460f292290670b62801a5cb84958b187e086b662d9537df95d0ddc9af6bc1c956050d051a4c14383209b07923fbcfab0992d59c689a5c794811de0a43a2
|
data/lib/labkit/fields.rb
CHANGED
|
@@ -142,7 +142,7 @@ module Labkit
|
|
|
142
142
|
Fields::HTTP_STATUS_CODE => %w[status_code extra.status status_text http_status],
|
|
143
143
|
Fields::HTTP_URL => %w[req_url],
|
|
144
144
|
Fields::DURATION_S => %w[duration duration_ms elapsed_time actual_duration time_ms total_time gitaly.duration],
|
|
145
|
-
Fields::REMOTE_IP => %w[ip source_ip ip_address
|
|
145
|
+
Fields::REMOTE_IP => %w[ip source_ip ip_address],
|
|
146
146
|
Fields::HTTP_HOST => %w[hostname request_host gitlab_host kubernetes.host],
|
|
147
147
|
Fields::GL_PROJECT_ID => %w[extra.project_id meta.project_id meta.search.project_id job_project_id target_project_id],
|
|
148
148
|
Fields::GL_PIPELINE_ID => %w[extra.pipeline_id meta.pipeline_id root_pipeline_id],
|
|
@@ -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
|