Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-13 15:08:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-13 15:08:49 +0300
commit988424215cf104d9ee24bb1751141424cffb32d1 (patch)
tree9d2525571ecc693902b949ac8441e8c97b299c3c /spec/lib
parent2705a15deaef07b1a38a53b9539d02f8ad499ce3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/application_rate_limiter_spec.rb14
-rw-r--r--spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb2
-rw-r--r--spec/lib/gitlab/instrumentation/rate_limiting_gates_spec.rb39
-rw-r--r--spec/lib/gitlab/instrumentation_helper_spec.rb21
-rw-r--r--spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb3
-rw-r--r--spec/lib/sidebars/projects/menus/monitor_menu_spec.rb8
6 files changed, 85 insertions, 2 deletions
diff --git a/spec/lib/gitlab/application_rate_limiter_spec.rb b/spec/lib/gitlab/application_rate_limiter_spec.rb
index 20c89eab5f5..efe78cd3a35 100644
--- a/spec/lib/gitlab/application_rate_limiter_spec.rb
+++ b/spec/lib/gitlab/application_rate_limiter_spec.rb
@@ -56,6 +56,20 @@ RSpec.describe Gitlab::ApplicationRateLimiter, :clean_gitlab_redis_rate_limiting
end
end
+ context 'when the key is valid' do
+ it 'records the checked key in request storage', :request_store do
+ subject.throttled?(:test_action, scope: [user])
+
+ expect(::Gitlab::Instrumentation::RateLimitingGates.payload)
+ .to eq(::Gitlab::Instrumentation::RateLimitingGates::GATES => [:test_action])
+
+ subject.throttled?(:another_action, scope: [user], peek: true)
+
+ expect(::Gitlab::Instrumentation::RateLimitingGates.payload)
+ .to eq(::Gitlab::Instrumentation::RateLimitingGates::GATES => [:test_action, :another_action])
+ end
+ end
+
shared_examples 'throttles based on key and scope' do
let(:start_time) { Time.current.beginning_of_hour }
diff --git a/spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb b/spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb
index 3f250d13e84..cffcda0a2ca 100644
--- a/spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb
+++ b/spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Gitlab::BackgroundMigration::ExpireOAuthTokens, :migration, schem
sub_batch_size: 2,
pause_ms: 0,
connection: ActiveRecord::Base.connection)
- .perform(1000)
+ .perform
end
before do
diff --git a/spec/lib/gitlab/instrumentation/rate_limiting_gates_spec.rb b/spec/lib/gitlab/instrumentation/rate_limiting_gates_spec.rb
new file mode 100644
index 00000000000..ac308eb7c80
--- /dev/null
+++ b/spec/lib/gitlab/instrumentation/rate_limiting_gates_spec.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Instrumentation::RateLimitingGates, :request_store do
+ describe '.gates' do
+ it 'returns an empty array when no gates are tracked' do
+ expect(described_class.gates).to eq([])
+ end
+
+ it 'returns all gates used in the request' do
+ described_class.track(:foo)
+
+ RequestStore.clear!
+
+ described_class.track(:bar)
+ described_class.track(:baz)
+
+ expect(described_class.gates).to contain_exactly(:bar, :baz)
+ end
+
+ it 'deduplicates its results' do
+ described_class.track(:foo)
+ described_class.track(:bar)
+ described_class.track(:foo)
+
+ expect(described_class.gates).to contain_exactly(:foo, :bar)
+ end
+ end
+
+ describe '.payload' do
+ it 'returns the gates in a hash' do
+ described_class.track(:foo)
+ described_class.track(:bar)
+
+ expect(described_class.payload).to eq(described_class::GATES => [:foo, :bar])
+ end
+ end
+end
diff --git a/spec/lib/gitlab/instrumentation_helper_spec.rb b/spec/lib/gitlab/instrumentation_helper_spec.rb
index a9663012e9a..5fea355ab4f 100644
--- a/spec/lib/gitlab/instrumentation_helper_spec.rb
+++ b/spec/lib/gitlab/instrumentation_helper_spec.rb
@@ -77,6 +77,27 @@ RSpec.describe Gitlab::InstrumentationHelper do
end
end
+ context 'rate-limiting gates' do
+ context 'when the request did not pass through any rate-limiting gates' do
+ it 'logs an empty array of gates' do
+ subject
+
+ expect(payload[:rate_limiting_gates]).to eq([])
+ end
+ end
+
+ context 'when the request passed through rate-limiting gates' do
+ it 'logs an array of gates used' do
+ Gitlab::Instrumentation::RateLimitingGates.track(:foo)
+ Gitlab::Instrumentation::RateLimitingGates.track(:bar)
+
+ subject
+
+ expect(payload[:rate_limiting_gates]).to contain_exactly(:foo, :bar)
+ end
+ end
+ end
+
it 'logs cpu_s duration' do
subject
diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
index 210b9162be0..00ae55237e9 100644
--- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
+++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb
@@ -287,7 +287,8 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do
'job_status' => 'done',
'duration_s' => 0.0,
'completed_at' => timestamp.to_f,
- 'cpu_s' => 1.111112
+ 'cpu_s' => 1.111112,
+ 'rate_limiting_gates' => []
)
end
diff --git a/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb b/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb
index e8c6fb790c3..61b60484692 100644
--- a/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb
+++ b/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb
@@ -72,6 +72,14 @@ RSpec.describe Sidebars::Projects::Menus::MonitorMenu do
let(:item_id) { :logs }
it_behaves_like 'access rights checks'
+
+ context 'when feature disabled' do
+ before do
+ stub_feature_flags(monitor_logging: false)
+ end
+
+ specify { is_expected.to be_nil }
+ end
end
describe 'Tracing' do