Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7f6c2b7a
Commit
7f6c2b7a
authored
Aug 16, 2021
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Service Ping URL logic
parent
ca17296d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
10 deletions
+35
-10
app/services/service_ping/submit_service.rb
app/services/service_ping/submit_service.rb
+9
-8
spec/services/service_ping/submit_service_ping_service_spec.rb
...services/service_ping/submit_service_ping_service_spec.rb
+26
-2
No files found.
app/services/service_ping/submit_service.rb
View file @
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
...
...
spec/services/service_ping/submit_service_ping_service_spec.rb
View file @
7f6c2b7a
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment