diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/config | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/config')
-rw-r--r-- | spec/config/mail_room_spec.rb | 37 | ||||
-rw-r--r-- | spec/config/metrics/aggregates/aggregated_metrics_spec.rb | 95 |
2 files changed, 131 insertions, 1 deletions
diff --git a/spec/config/mail_room_spec.rb b/spec/config/mail_room_spec.rb index 289e18be0d7..6265b54931a 100644 --- a/spec/config/mail_room_spec.rb +++ b/spec/config/mail_room_spec.rb @@ -16,7 +16,9 @@ RSpec.describe 'mail_room.yml' do } cmd = "puts ERB.new(File.read(#{absolute_path(mailroom_config_path).inspect})).result" - output, status = Gitlab::Popen.popen(%W(ruby -rerb -e #{cmd}), absolute_path('config'), vars) + result = Gitlab::Popen.popen_with_detail(%W(ruby -rerb -e #{cmd}), absolute_path('config'), vars) + output = result.stdout + status = result.status raise "Error interpreting #{mailroom_config_path}: #{output}" unless status == 0 YAML.load(output) @@ -68,6 +70,39 @@ RSpec.describe 'mail_room.yml' do end end + context 'when both incoming email and service desk email are enabled for Microsoft Graph' do + let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_enabled_ms_graph.yml' } + let(:queues_config_path) { 'spec/fixtures/config/redis_queues_new_format_host.yml' } + let(:gitlab_redis_queues) { Gitlab::Redis::Queues.new(Rails.env) } + + it 'contains the intended configuration' do + expected_mailbox = { + email: 'gitlab-incoming@gmail.com', + name: 'inbox', + idle_timeout: 60, + expunge_deleted: true + } + expected_options = { + redis_url: gitlab_redis_queues.url, + sentinels: gitlab_redis_queues.sentinels + } + expected_inbox_options = { + tenant_id: '12345', + client_id: 'MY-CLIENT-ID', + client_secret: 'MY-CLIENT-SECRET', + poll_interval: 60 + } + + expect(configuration[:mailboxes].length).to eq(2) + expect(configuration[:mailboxes]).to all(include(expected_mailbox)) + expect(configuration[:mailboxes].map { |m| m[:inbox_method] }).to all(eq('microsoft_graph')) + expect(configuration[:mailboxes].map { |m| m[:inbox_options] }).to all(eq(expected_inbox_options)) + expect(configuration[:mailboxes].map { |m| m[:delivery_options] }).to all(include(expected_options)) + expect(configuration[:mailboxes].map { |m| m[:delivery_options] }).to all(include(expected_options)) + expect(configuration[:mailboxes].map { |m| m[:arbitration_options] }).to all(include(expected_options)) + end + end + def clear_queues_raw_config Gitlab::Redis::Queues.remove_instance_variable(:@_raw_config) rescue NameError diff --git a/spec/config/metrics/aggregates/aggregated_metrics_spec.rb b/spec/config/metrics/aggregates/aggregated_metrics_spec.rb new file mode 100644 index 00000000000..9aba86cdaf2 --- /dev/null +++ b/spec/config/metrics/aggregates/aggregated_metrics_spec.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'aggregated metrics' do + RSpec::Matchers.define :be_known_event do + match do |event| + Gitlab::UsageDataCounters::HLLRedisCounter.known_event?(event) + end + + failure_message do |event| + "Event with name: `#{event}` can not be found within `#{Gitlab::UsageDataCounters::HLLRedisCounter::KNOWN_EVENTS_PATH}`" + end + end + + RSpec::Matchers.define :has_known_source do + match do |aggregate| + Gitlab::Usage::Metrics::Aggregates::SOURCES.include?(aggregate[:source]) + end + + failure_message do |aggregate| + "Aggregate with name: `#{aggregate[:name]}` uses not allowed source `#{aggregate[:source]}`" + end + end + + RSpec::Matchers.define :have_known_time_frame do + allowed_time_frames = [ + Gitlab::Utils::UsageData::ALL_TIME_TIME_FRAME_NAME, + Gitlab::Utils::UsageData::TWENTY_EIGHT_DAYS_TIME_FRAME_NAME, + Gitlab::Utils::UsageData::SEVEN_DAYS_TIME_FRAME_NAME + ] + + match do |aggregate| + (aggregate[:time_frame] - allowed_time_frames).empty? + end + + failure_message do |aggregate| + "Aggregate with name: `#{aggregate[:name]}` uses not allowed time_frame`#{aggregate[:time_frame] - allowed_time_frames}`" + end + end + + let_it_be(:known_events) do + Gitlab::UsageDataCounters::HLLRedisCounter.known_events + end + + Gitlab::Usage::Metrics::Aggregates::Aggregate.new(Time.current).send(:aggregated_metrics).tap do |aggregated_metrics| + it 'all events has unique name' do + event_names = aggregated_metrics&.map { |event| event[:name] } + + expect(event_names).to eq(event_names&.uniq) + end + + it 'all aggregated metrics has known source' do + expect(aggregated_metrics).to all has_known_source + end + + it 'all aggregated metrics has known source' do + expect(aggregated_metrics).to all have_known_time_frame + end + + aggregated_metrics&.select { |agg| agg[:source] == Gitlab::Usage::Metrics::Aggregates::REDIS_SOURCE }&.each do |aggregate| + context "for #{aggregate[:name]} aggregate of #{aggregate[:events].join(' ')}" do + let_it_be(:events_records) { known_events.select { |event| aggregate[:events].include?(event[:name]) } } + + it "does not include 'all' time frame for Redis sourced aggregate" do + expect(aggregate[:time_frame]).not_to include(Gitlab::Utils::UsageData::ALL_TIME_TIME_FRAME_NAME) + end + + it "only refers to known events" do + expect(aggregate[:events]).to all be_known_event + end + + it "has expected structure" do + expect(aggregate.keys).to include(*%w[name operator events]) + end + + it "uses allowed aggregation operators" do + expect(Gitlab::Usage::Metrics::Aggregates::ALLOWED_METRICS_AGGREGATIONS).to include aggregate[:operator] + end + + it "uses events from the same Redis slot" do + event_slots = events_records.map { |event| event[:redis_slot] }.uniq + + expect(event_slots).to contain_exactly(be_present) + end + + it "uses events with the same aggregation period" do + event_slots = events_records.map { |event| event[:aggregation] }.uniq + + expect(event_slots).to contain_exactly(be_present) + end + end + end + end +end |