debian-mirror-gitlab/spec/tasks/gitlab/usage_data_rake_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
3.2 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'rake_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe 'gitlab:usage data take tasks', :silence_stdout, feature_category: :service_ping do
2022-10-11 01:57:18 +05:30
include StubRequests
2021-04-29 21:17:54 +05:30
include UsageDataHelpers
2022-10-11 01:57:18 +05:30
let(:metrics_file) { Rails.root.join('tmp', 'test', 'sql_metrics_queries.json') }
2020-11-24 15:15:51 +05:30
before do
Rake.application.rake_require 'tasks/gitlab/usage_data'
2022-10-11 01:57:18 +05:30
2020-11-24 15:15:51 +05:30
# stub prometheus external http calls https://gitlab.com/gitlab-org/gitlab/-/issues/245277
2021-04-29 21:17:54 +05:30
stub_prometheus_queries
2022-03-02 08:16:31 +05:30
stub_database_flavor_check
2020-11-24 15:15:51 +05:30
end
2022-10-11 01:57:18 +05:30
after do
FileUtils.rm_rf(metrics_file)
end
2020-11-24 15:15:51 +05:30
describe 'dump_sql_in_yaml' do
it 'dumps SQL queries in yaml format' do
expect { run_rake_task('gitlab:usage_data:dump_sql_in_yaml') }.to output(/.*recorded_at:.*/).to_stdout
end
end
describe 'dump_sql_in_json' do
it 'dumps SQL queries in json format' do
expect { run_rake_task('gitlab:usage_data:dump_sql_in_json') }.to output(/.*"recorded_at":.*/).to_stdout
end
end
2022-10-11 01:57:18 +05:30
describe 'dump_non_sql_in_json' do
it 'dumps non SQL data in json format' do
expect { run_rake_task('gitlab:usage_data:dump_non_sql_in_json') }.to output(/.*"recorded_at":.*/).to_stdout
end
end
describe 'generate_sql_metrics_fixture' do
it 'generates fixture file correctly' do
run_rake_task('gitlab:usage_data:generate_sql_metrics_queries')
expect(Pathname.new(metrics_file)).to exist
end
end
describe 'generate_and_send' do
let(:service_ping_payload_url) do
File.join(ServicePing::SubmitService::STAGING_BASE_URL, ServicePing::SubmitService::USAGE_DATA_PATH)
end
let(:service_ping_metadata_url) do
File.join(ServicePing::SubmitService::STAGING_BASE_URL, ServicePing::SubmitService::METADATA_PATH)
end
let(:payload) { { recorded_at: Time.current } }
before do
allow_next_instance_of(ServicePing::BuildPayload) do |service|
allow(service).to receive(:execute).and_return(payload)
end
stub_response(body: payload.merge(conv_index: { usage_data_id: 123 }))
stub_response(body: nil, url: service_ping_metadata_url, status: 201)
end
it 'generates and sends Service Ping payload' do
expect { run_rake_task('gitlab:usage_data:generate_and_send') }.to output(/.*201.*/).to_stdout
end
2022-11-25 23:54:43 +05:30
describe 'generate_ci_template_events' do
2023-03-04 22:38:38 +05:30
around do |example|
2022-11-25 23:54:43 +05:30
FileUtils.rm_rf(Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH)
2023-03-04 22:38:38 +05:30
example.run
`git checkout -- #{Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH}`
end
2023-04-23 21:23:45 +05:30
it "generates #{Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH}",
quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/386191' do
2022-11-25 23:54:43 +05:30
run_rake_task('gitlab:usage_data:generate_ci_template_events')
expect(File.exist?(Gitlab::UsageDataCounters::CiTemplateUniqueCounter::KNOWN_EVENTS_FILE_PATH)).to be true
end
end
2022-10-11 01:57:18 +05:30
private
2023-03-04 22:38:38 +05:30
def stub_response(body:, url: service_ping_payload_url, status: 201)
2022-10-11 01:57:18 +05:30
stub_full_request(url, method: :post)
.to_return(
headers: { 'Content-Type' => 'application/json' },
body: body.to_json,
status: status
)
end
end
2020-11-24 15:15:51 +05:30
end