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
bf615542
Commit
bf615542
authored
Nov 22, 2021
by
Nikolay Belokolodov
Committed by
Rémy Coutable
Nov 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an option to skip DevOps report generation
parent
c3033257
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
28 deletions
+66
-28
app/services/service_ping/devops_report_service.rb
app/services/service_ping/devops_report_service.rb
+29
-0
app/services/service_ping/submit_service.rb
app/services/service_ping/submit_service.rb
+12
-28
doc/development/service_ping/index.md
doc/development/service_ping/index.md
+6
-0
spec/services/service_ping/submit_service_ping_service_spec.rb
...services/service_ping/submit_service_ping_service_spec.rb
+19
-0
No files found.
app/services/service_ping/devops_report_service.rb
0 → 100644
View file @
bf615542
# frozen_string_literal: true
module
ServicePing
class
DevopsReportService
METRICS
=
%w[leader_issues instance_issues percentage_issues leader_notes instance_notes
percentage_notes leader_milestones instance_milestones percentage_milestones
leader_boards instance_boards percentage_boards leader_merge_requests
instance_merge_requests percentage_merge_requests leader_ci_pipelines
instance_ci_pipelines percentage_ci_pipelines leader_environments instance_environments
percentage_environments leader_deployments instance_deployments percentage_deployments
leader_projects_prometheus_active instance_projects_prometheus_active
percentage_projects_prometheus_active leader_service_desk_issues instance_service_desk_issues
percentage_service_desk_issues]
.
freeze
def
initialize
(
data
)
@data
=
data
end
def
execute
metrics
=
@data
[
'conv_index'
]
||
@data
[
'dev_ops_score'
]
# leaving dev_ops_score here, as the data comes from the gitlab-version-com
return
unless
metrics
.
except
(
'usage_data_id'
).
present?
DevOpsReport
::
Metric
.
create!
(
metrics
.
slice
(
*
METRICS
)
)
end
end
end
app/services/service_ping/submit_service.rb
View file @
bf615542
...
...
@@ -6,29 +6,23 @@ module ServicePing
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
leader_boards instance_boards percentage_boards leader_merge_requests
instance_merge_requests percentage_merge_requests leader_ci_pipelines
instance_ci_pipelines percentage_ci_pipelines leader_environments instance_environments
percentage_environments leader_deployments instance_deployments percentage_deployments
leader_projects_prometheus_active instance_projects_prometheus_active
percentage_projects_prometheus_active leader_service_desk_issues instance_service_desk_issues
percentage_service_desk_issues]
.
freeze
SubmissionError
=
Class
.
new
(
StandardError
)
def
initialize
(
skip_db_write:
false
)
@skip_db_write
=
skip_db_write
end
def
execute
return
unless
ServicePing
::
ServicePingSettings
.
product_intelligence_enabled?
begin
usage_data
=
BuildPayloadService
.
new
.
execute
r
aw_usage_data
,
r
esponse
=
submit_usage_data_payload
(
usage_data
)
response
=
submit_usage_data_payload
(
usage_data
)
rescue
StandardError
return
unless
Gitlab
::
CurrentSettings
.
usage_ping_enabled?
usage_data
=
Gitlab
::
UsageData
.
data
(
force_refresh:
true
)
r
aw_usage_data
,
r
esponse
=
submit_usage_data_payload
(
usage_data
)
response
=
submit_usage_data_payload
(
usage_data
)
end
version_usage_data_id
=
response
.
dig
(
'conv_index'
,
'usage_data_id'
)
||
response
.
dig
(
'dev_ops_score'
,
'usage_data_id'
)
...
...
@@ -37,9 +31,11 @@ module ServicePing
raise
SubmissionError
,
"Invalid usage_data_id in response:
#{
version_usage_data_id
}
"
end
raw_usage_data
.
update_version_metadata!
(
usage_data_id:
version_usage_data_id
)
store_metrics
(
response
)
unless
@skip_db_write
raw_usage_data
=
save_raw_usage_data
(
usage_data
)
raw_usage_data
.
update_version_metadata!
(
usage_data_id:
version_usage_data_id
)
DevopsReportService
.
new
(
response
).
execute
end
end
def
url
...
...
@@ -60,13 +56,11 @@ module ServicePing
def
submit_usage_data_payload
(
usage_data
)
raise
SubmissionError
,
'Usage data is blank'
if
usage_data
.
blank?
raw_usage_data
=
save_raw_usage_data
(
usage_data
)
response
=
submit_payload
(
usage_data
)
raise
SubmissionError
,
"Unsuccessful response code:
#{
response
.
code
}
"
unless
response
.
success?
[
raw_usage_data
,
response
]
response
end
def
save_raw_usage_data
(
usage_data
)
...
...
@@ -75,16 +69,6 @@ module ServicePing
end
end
def
store_metrics
(
response
)
metrics
=
response
[
'conv_index'
]
||
response
[
'dev_ops_score'
]
# leaving dev_ops_score here, as the response data comes from the gitlab-version-com
return
unless
metrics
.
except
(
'usage_data_id'
).
present?
DevOpsReport
::
Metric
.
create!
(
metrics
.
slice
(
*
METRICS
)
)
end
# See https://gitlab.com/gitlab-org/gitlab/-/issues/233615 for details
def
base_url
Rails
.
env
.
production?
?
PRODUCTION_BASE_URL
:
STAGING_BASE_URL
...
...
doc/development/service_ping/index.md
View file @
bf615542
...
...
@@ -521,6 +521,12 @@ To generate Service Ping, use [Teleport](https://goteleport.com/docs/) or a deta
1.
Check the last payload in
`raw_usage_data`
table:
`RawUsageData.last.payload`
1.
Check the when the payload was sent:
`RawUsageData.last.sent_at`
### Skip database write operations
To skip database write operations, DevOps report creation, and storage of usage data payload, you can pass an optional argument
`skip_db_write`
:
`ServicePing::SubmitService.new(skip_db_write: true).execute`
## Troubleshooting
### Cannot disable Service Ping using the configuration file
...
...
spec/services/service_ping/submit_service_ping_service_spec.rb
View file @
bf615542
...
...
@@ -322,6 +322,25 @@ RSpec.describe ServicePing::SubmitService do
expect
{
subject
.
execute
}.
to
raise_error
(
described_class
::
SubmissionError
)
end
end
context
'when skip_db_write passed to service'
do
let
(
:subject
)
{
ServicePing
::
SubmitService
.
new
(
skip_db_write:
true
)
}
before
do
stub_response
(
body:
with_dev_ops_score_params
)
end
it
'does not save RawUsageData'
do
expect
{
subject
.
execute
}
.
not_to
change
{
RawUsageData
.
count
}
end
it
'does not call DevOpsReport service'
do
expect
(
ServicePing
::
DevopsReportService
).
not_to
receive
(
:new
)
subject
.
execute
end
end
end
describe
'#url'
do
...
...
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