Skip to content
代码片段 群组 项目
未验证 提交 2b540efd 编辑于 作者: Sylvester Chin's avatar Sylvester Chin 提交者: GitLab
浏览文件

Introduce histogram for ApplicationRateLimiter

This MR removes the emit_application_rate_limiter_histogram feature flag
and starts tracking application rate limit throttles using a histogram.

Changelog: other
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/169655
上级 965b3a0c
No related branches found
No related tags found
无相关合并请求
---
name: emit_application_rate_limiter_histogram
feature_issue_url: https://gitlab.com/gitlab-com/gl-infra/production-engineering/-/work_items/25767
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/169655
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/499992
milestone: '17.6'
group: group::scalability
type: gitlab_com_derisk
default_enabled: false
...@@ -197,7 +197,7 @@ The following metrics are available: ...@@ -197,7 +197,7 @@ The following metrics are available:
| `gitlab_rack_attack_events_total` | Counter | 17.6 | Counts the total number of events handled by Rack Attack. | `event_type`, `event_name` | | `gitlab_rack_attack_events_total` | Counter | 17.6 | Counts the total number of events handled by Rack Attack. | `event_type`, `event_name` |
| `gitlab_rack_attack_throttle_limit` | Gauge | 17.6 | Reports the maximum number of requests that a client can make before Rack Attack throttles them. | `event_name` | | `gitlab_rack_attack_throttle_limit` | Gauge | 17.6 | Reports the maximum number of requests that a client can make before Rack Attack throttles them. | `event_name` |
| `gitlab_rack_attack_throttle_period_seconds` | Gauge | 17.6 | Reports the duration over which requests for a client are counted before Rack Attack throttles them. | `event_name` | | `gitlab_rack_attack_throttle_period_seconds` | Gauge | 17.6 | Reports the duration over which requests for a client are counted before Rack Attack throttles them. | `event_name` |
| `gitlab_application_rate_limiter_throttles_total` | Histogram | 17.6 | Utilization ratio of a throttle in GitLab Application Rate Limiter. | `throttle_key`, `peek`, `feature_category` | | `gitlab_application_rate_limiter_throttle_utilization_ratio` | Histogram | 17.6 | Utilization ratio of a throttle in GitLab Application Rate Limiter. | `throttle_key`, `peek`, `feature_category` |
## Metrics controlled by a feature flag ## Metrics controlled by a feature flag
......
...@@ -199,7 +199,6 @@ def peek(key, scope:, threshold: nil, interval: nil, users_allowlist: nil) ...@@ -199,7 +199,6 @@ def peek(key, scope:, threshold: nil, interval: nil, users_allowlist: nil)
end end
def report_metrics(key, value, threshold, peek) def report_metrics(key, value, threshold, peek)
return if Feature.disabled?(:emit_application_rate_limiter_histogram, Feature.current_request)
return if threshold == 0 # guard against div-by-zero return if threshold == 0 # guard against div-by-zero
label = { label = {
......
...@@ -77,6 +77,12 @@ ...@@ -77,6 +77,12 @@
let(:project1) { instance_double(Project, id: '1') } let(:project1) { instance_double(Project, id: '1') }
let(:project2) { instance_double(Project, id: '2') } let(:project2) { instance_double(Project, id: '2') }
before do
if described_class.instance_variable_defined?(:@application_rate_limiter_histogram)
described_class.remove_instance_variable(:@application_rate_limiter_histogram)
end
end
it 'returns true when unique actioned resources count exceeds threshold' do it 'returns true when unique actioned resources count exceeds threshold' do
travel_to(start_time) do travel_to(start_time) do
expect(subject.throttled?(:test_action, scope: scope, resource: project1)).to eq(false) expect(subject.throttled?(:test_action, scope: scope, resource: project1)).to eq(false)
...@@ -108,15 +114,21 @@ ...@@ -108,15 +114,21 @@
end end
end end
context 'when the emit_application_rate_limiter_histogram feature flag is enabled' do describe 'emitting metrics for throttling utilization' do
before do let(:histogram_double) { instance_double(Prometheus::Client::Histogram) }
around do |example|
# check if defined
if described_class.instance_variable_defined?(:@application_rate_limiter_histogram) if described_class.instance_variable_defined?(:@application_rate_limiter_histogram)
described_class.remove_instance_variable(:@application_rate_limiter_histogram) described_class.remove_instance_variable(:@application_rate_limiter_histogram)
end end
example.run
described_class.remove_instance_variable(:@application_rate_limiter_histogram)
end end
it 'observe histogram metrics using a memoized histogram instance' do it 'observe histogram metrics using a memoized histogram instance' do
histogram_double = instance_double(Prometheus::Client::Histogram)
expect(Gitlab::Metrics).to receive(:histogram) expect(Gitlab::Metrics).to receive(:histogram)
.once .once
.with( .with(
...@@ -128,24 +140,8 @@ ...@@ -128,24 +140,8 @@
.and_return(histogram_double) .and_return(histogram_double)
expect(histogram_double).to receive(:observe).twice expect(histogram_double).to receive(:observe).twice
subject.throttled?(:test_action, scope: []) subject.throttled?(:test_action, scope: [], threshold: 1)
subject.throttled?(:test_action, scope: []) subject.throttled?(:test_action, scope: [], threshold: 1)
end
end
context 'when the emit_application_rate_limiter_histogram feature flag is disabled' do
before do
if described_class.instance_variable_defined?(:@application_rate_limiter_histogram)
described_class.remove_instance_variable(:@application_rate_limiter_histogram)
end
stub_feature_flags(emit_application_rate_limiter_histogram: false)
end
it 'does not emit metrics' do
expect(Gitlab::Metrics).not_to receive(:histogram)
subject.throttled?(:test_action, scope: [])
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册