Commit aa1f3827 authored by Markus Koller's avatar Markus Koller

Merge branch 'ali/customize-service-ping-endpoint' into 'master'

Refactor Service Ping URL logic

See merge request gitlab-org/gitlab!68314
parents 51a2683a 7f6c2b7a
......@@ -2,8 +2,9 @@
module ServicePing
class SubmitService
PRODUCTION_URL = 'https://version.gitlab.com/usage_data'
STAGING_URL = 'https://gitlab-services-version-gitlab-com-staging.gs-staging.gitlab.org/usage_data'
PRODUCTION_BASE_URL = 'https://version.gitlab.com'
STAGING_BASE_URL = 'https://gitlab-services-version-gitlab-com-staging.gs-staging.gitlab.org'
USAGE_DATA_PATH = 'usage_data'
METRICS = %w[leader_issues instance_issues percentage_issues leader_notes instance_notes
percentage_notes leader_milestones instance_milestones percentage_milestones
......@@ -41,6 +42,10 @@ module ServicePing
store_metrics(response)
end
def url
URI.join(base_url, USAGE_DATA_PATH)
end
private
def submit_payload(usage_data)
......@@ -81,12 +86,8 @@ module ServicePing
end
# See https://gitlab.com/gitlab-org/gitlab/-/issues/233615 for details
def url
if Rails.env.production?
PRODUCTION_URL
else
STAGING_URL
end
def base_url
Rails.env.production? ? PRODUCTION_BASE_URL : STAGING_BASE_URL
end
end
end
......
......@@ -300,8 +300,32 @@ RSpec.describe ServicePing::SubmitService do
end
end
def stub_response(body:, status: 201)
stub_full_request(subject.send(:url), method: :post)
describe '#url' do
let(:url) { subject.url.to_s }
context 'when Rails.env is production' do
before do
stub_rails_env('production')
end
it 'points to the production Version app' do
expect(url).to eq("#{described_class::PRODUCTION_BASE_URL}/#{described_class::USAGE_DATA_PATH}")
end
end
context 'when Rails.env is not production' do
before do
stub_rails_env('development')
end
it 'points to the staging Version app' do
expect(url).to eq("#{described_class::STAGING_BASE_URL}/#{described_class::USAGE_DATA_PATH}")
end
end
end
def stub_response(url: subject.url, body:, status: 201)
stub_full_request(url, method: :post)
.to_return(
headers: { 'Content-Type' => 'application/json' },
body: body.to_json,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment