Commit 7f6c2b7a authored by Alishan Ladhani's avatar Alishan Ladhani

Refactor Service Ping URL logic

parent ca17296d
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
module ServicePing module ServicePing
class SubmitService class SubmitService
PRODUCTION_URL = 'https://version.gitlab.com/usage_data' PRODUCTION_BASE_URL = 'https://version.gitlab.com'
STAGING_URL = 'https://gitlab-services-version-gitlab-com-staging.gs-staging.gitlab.org/usage_data' 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 METRICS = %w[leader_issues instance_issues percentage_issues leader_notes instance_notes
percentage_notes leader_milestones instance_milestones percentage_milestones percentage_notes leader_milestones instance_milestones percentage_milestones
...@@ -41,6 +42,10 @@ module ServicePing ...@@ -41,6 +42,10 @@ module ServicePing
store_metrics(response) store_metrics(response)
end end
def url
URI.join(base_url, USAGE_DATA_PATH)
end
private private
def submit_payload(usage_data) def submit_payload(usage_data)
...@@ -81,12 +86,8 @@ module ServicePing ...@@ -81,12 +86,8 @@ module ServicePing
end end
# See https://gitlab.com/gitlab-org/gitlab/-/issues/233615 for details # See https://gitlab.com/gitlab-org/gitlab/-/issues/233615 for details
def url def base_url
if Rails.env.production? Rails.env.production? ? PRODUCTION_BASE_URL : STAGING_BASE_URL
PRODUCTION_URL
else
STAGING_URL
end
end end
end end
end end
......
...@@ -300,8 +300,32 @@ RSpec.describe ServicePing::SubmitService do ...@@ -300,8 +300,32 @@ RSpec.describe ServicePing::SubmitService do
end end
end end
def stub_response(body:, status: 201) describe '#url' do
stub_full_request(subject.send(:url), method: :post) 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( .to_return(
headers: { 'Content-Type' => 'application/json' }, headers: { 'Content-Type' => 'application/json' },
body: body.to_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