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
04870b96
Commit
04870b96
authored
Jul 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
4ec30fdd
bdecc719
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
238 additions
and
246 deletions
+238
-246
app/services/metrics/dashboard/base_service.rb
app/services/metrics/dashboard/base_service.rb
+70
-0
app/services/metrics/dashboard/default_embed_service.rb
app/services/metrics/dashboard/default_embed_service.rb
+63
-0
app/services/metrics/dashboard/project_dashboard_service.rb
app/services/metrics/dashboard/project_dashboard_service.rb
+48
-0
app/services/metrics/dashboard/system_dashboard_service.rb
app/services/metrics/dashboard/system_dashboard_service.rb
+47
-0
lib/gitlab/metrics/dashboard/base_service.rb
lib/gitlab/metrics/dashboard/base_service.rb
+0
-72
lib/gitlab/metrics/dashboard/dynamic_dashboard_service.rb
lib/gitlab/metrics/dashboard/dynamic_dashboard_service.rb
+0
-65
lib/gitlab/metrics/dashboard/finder.rb
lib/gitlab/metrics/dashboard/finder.rb
+5
-5
lib/gitlab/metrics/dashboard/project_dashboard_service.rb
lib/gitlab/metrics/dashboard/project_dashboard_service.rb
+0
-50
lib/gitlab/metrics/dashboard/system_dashboard_service.rb
lib/gitlab/metrics/dashboard/system_dashboard_service.rb
+0
-49
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+1
-1
spec/lib/gitlab/metrics/dashboard/finder_spec.rb
spec/lib/gitlab/metrics/dashboard/finder_spec.rb
+1
-1
spec/services/metrics/dashboard/default_embed_service_spec.rb
.../services/metrics/dashboard/default_embed_service_spec.rb
+1
-1
spec/services/metrics/dashboard/project_dashboard_service_spec.rb
...vices/metrics/dashboard/project_dashboard_service_spec.rb
+1
-1
spec/services/metrics/dashboard/system_dashboard_service_spec.rb
...rvices/metrics/dashboard/system_dashboard_service_spec.rb
+1
-1
No files found.
app/services/metrics/dashboard/base_service.rb
0 → 100644
View file @
04870b96
# frozen_string_literal: true
# Searches a projects repository for a metrics dashboard and formats the output.
# Expects any custom dashboards will be located in `.gitlab/dashboards`
module
Metrics
module
Dashboard
class
BaseService
<
::
BaseService
PROCESSING_ERROR
=
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
BaseStage
::
DashboardProcessingError
NOT_FOUND_ERROR
=
Gitlab
::
Template
::
Finders
::
RepoTemplateFinder
::
FileNotFoundError
def
get_dashboard
return
error
(
'Insufficient permissions.'
,
:unauthorized
)
unless
allowed?
success
(
dashboard:
process_dashboard
)
rescue
NOT_FOUND_ERROR
error
(
"
#{
dashboard_path
}
could not be found."
,
:not_found
)
rescue
PROCESSING_ERROR
=>
e
error
(
e
.
message
,
:unprocessable_entity
)
end
# Summary of all known dashboards for the service.
# @return [Array<Hash>] ex) [{ path: String, default: Boolean }]
def
self
.
all_dashboard_paths
(
_project
)
raise
NotImplementedError
end
# Returns an un-processed dashboard from the cache.
def
raw_dashboard
Gitlab
::
Metrics
::
Dashboard
::
Cache
.
fetch
(
cache_key
)
{
get_raw_dashboard
}
end
private
# Determines whether users should be able to view
# dashboards at all.
def
allowed?
Ability
.
allowed?
(
current_user
,
:read_environment
,
project
)
end
# Returns a new dashboard Hash, supplemented with DB info
def
process_dashboard
Gitlab
::
Metrics
::
Dashboard
::
Processor
.
new
(
project
,
params
[
:environment
],
raw_dashboard
)
.
process
(
insert_project_metrics:
insert_project_metrics?
)
end
# @return [String] Relative filepath of the dashboard yml
def
dashboard_path
params
[
:dashboard_path
]
end
# @return [Hash] an unmodified dashboard
def
get_raw_dashboard
raise
NotImplementedError
end
# @return [String]
def
cache_key
raise
NotImplementedError
end
# Determines whether custom metrics should be included
# in the processed output.
# @return [Boolean]
def
insert_project_metrics?
false
end
end
end
end
app/services/metrics/dashboard/default_embed_service.rb
0 → 100644
View file @
04870b96
# frozen_string_literal: true
# Responsible for returning a filtered system dashboard
# containing only the default embedded metrics. In future,
# this class may be updated to support filtering to
# alternate metrics/panels.
#
# Why isn't this filtering in a processing stage? By filtering
# here, we ensure the dynamically-determined dashboard is cached.
#
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module
Metrics
module
Dashboard
class
DefaultEmbedService
<
::
Metrics
::
Dashboard
::
BaseService
# For the default filtering for embedded metrics,
# uses the 'id' key in dashboard-yml definition for
# identification.
DEFAULT_EMBEDDED_METRICS_IDENTIFIERS
=
%w(
system_metrics_kubernetes_container_memory_total
system_metrics_kubernetes_container_cores_total
)
.
freeze
# Returns a new dashboard with only the matching
# metrics from the system dashboard, stripped of groups.
# @return [Hash]
def
raw_dashboard
panels
=
panel_groups
.
each_with_object
([])
do
|
group
,
panels
|
matched_panels
=
group
[
'panels'
].
select
{
|
panel
|
matching_panel?
(
panel
)
}
panels
.
concat
(
matched_panels
)
end
{
'panel_groups'
=>
[{
'panels'
=>
panels
}]
}
end
def
cache_key
"dynamic_metrics_dashboard_
#{
metric_identifiers
.
join
(
'_'
)
}
"
end
private
# Returns an array of the panels groups on the
# system dashboard
def
panel_groups
::
Metrics
::
Dashboard
::
SystemDashboardService
.
new
(
project
,
nil
)
.
raw_dashboard
[
'panel_groups'
]
end
# Identifies a panel as "matching" if any metric ids in
# the panel is in the list of identifiers to collect.
def
matching_panel?
(
panel
)
panel
[
'metrics'
].
any?
do
|
metric
|
metric_identifiers
.
include?
(
metric
[
'id'
])
end
end
def
metric_identifiers
DEFAULT_EMBEDDED_METRICS_IDENTIFIERS
end
end
end
end
app/services/metrics/dashboard/project_dashboard_service.rb
0 → 100644
View file @
04870b96
# frozen_string_literal: true
# Searches a projects repository for a metrics dashboard and formats the output.
# Expects any custom dashboards will be located in `.gitlab/dashboards`
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module
Metrics
module
Dashboard
class
ProjectDashboardService
<
::
Metrics
::
Dashboard
::
BaseService
DASHBOARD_ROOT
=
".gitlab/dashboards"
class
<<
self
def
all_dashboard_paths
(
project
)
file_finder
(
project
)
.
list_files_for
(
DASHBOARD_ROOT
)
.
map
do
|
filepath
|
{
path:
filepath
,
display_name:
name_for_path
(
filepath
),
default:
false
}
end
end
def
file_finder
(
project
)
Gitlab
::
Template
::
Finders
::
RepoTemplateFinder
.
new
(
project
,
DASHBOARD_ROOT
,
'.yml'
)
end
# Grabs the filepath after the base directory.
def
name_for_path
(
filepath
)
filepath
.
delete_prefix
(
"
#{
DASHBOARD_ROOT
}
/"
)
end
end
private
# Searches the project repo for a custom-defined dashboard.
def
get_raw_dashboard
yml
=
self
.
class
.
file_finder
(
project
).
read
(
dashboard_path
)
YAML
.
safe_load
(
yml
)
end
def
cache_key
"project_
#{
project
.
id
}
_metrics_dashboard_
#{
dashboard_path
}
"
end
end
end
end
app/services/metrics/dashboard/system_dashboard_service.rb
0 → 100644
View file @
04870b96
# frozen_string_literal: true
# Fetches the system metrics dashboard and formats the output.
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module
Metrics
module
Dashboard
class
SystemDashboardService
<
::
Metrics
::
Dashboard
::
BaseService
SYSTEM_DASHBOARD_PATH
=
'config/prometheus/common_metrics.yml'
SYSTEM_DASHBOARD_NAME
=
'Default'
class
<<
self
def
all_dashboard_paths
(
_project
)
[{
path:
SYSTEM_DASHBOARD_PATH
,
display_name:
SYSTEM_DASHBOARD_NAME
,
default:
true
}]
end
def
system_dashboard?
(
filepath
)
filepath
==
SYSTEM_DASHBOARD_PATH
end
end
private
def
dashboard_path
SYSTEM_DASHBOARD_PATH
end
# Returns the base metrics shipped with every GitLab service.
def
get_raw_dashboard
yml
=
File
.
read
(
Rails
.
root
.
join
(
dashboard_path
))
YAML
.
safe_load
(
yml
)
end
def
cache_key
"metrics_dashboard_
#{
dashboard_path
}
"
end
def
insert_project_metrics?
true
end
end
end
end
lib/gitlab/metrics/dashboard/base_service.rb
deleted
100644 → 0
View file @
4ec30fdd
# frozen_string_literal: true
# Searches a projects repository for a metrics dashboard and formats the output.
# Expects any custom dashboards will be located in `.gitlab/dashboards`
module
Gitlab
module
Metrics
module
Dashboard
class
BaseService
<
::
BaseService
PROCESSING_ERROR
=
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
BaseStage
::
DashboardProcessingError
NOT_FOUND_ERROR
=
Gitlab
::
Template
::
Finders
::
RepoTemplateFinder
::
FileNotFoundError
def
get_dashboard
return
error
(
'Insufficient permissions.'
,
:unauthorized
)
unless
allowed?
success
(
dashboard:
process_dashboard
)
rescue
NOT_FOUND_ERROR
error
(
"
#{
dashboard_path
}
could not be found."
,
:not_found
)
rescue
PROCESSING_ERROR
=>
e
error
(
e
.
message
,
:unprocessable_entity
)
end
# Summary of all known dashboards for the service.
# @return [Array<Hash>] ex) [{ path: String, default: Boolean }]
def
self
.
all_dashboard_paths
(
_project
)
raise
NotImplementedError
end
# Returns an un-processed dashboard from the cache.
def
raw_dashboard
Gitlab
::
Metrics
::
Dashboard
::
Cache
.
fetch
(
cache_key
)
{
get_raw_dashboard
}
end
private
# Determines whether users should be able to view
# dashboards at all.
def
allowed?
Ability
.
allowed?
(
current_user
,
:read_environment
,
project
)
end
# Returns a new dashboard Hash, supplemented with DB info
def
process_dashboard
Gitlab
::
Metrics
::
Dashboard
::
Processor
.
new
(
project
,
params
[
:environment
],
raw_dashboard
)
.
process
(
insert_project_metrics:
insert_project_metrics?
)
end
# @return [String] Relative filepath of the dashboard yml
def
dashboard_path
params
[
:dashboard_path
]
end
# @return [Hash] an unmodified dashboard
def
get_raw_dashboard
raise
NotImplementedError
end
# @return [String]
def
cache_key
raise
NotImplementedError
end
# Determines whether custom metrics should be included
# in the processed output.
# @return [Boolean]
def
insert_project_metrics?
false
end
end
end
end
end
lib/gitlab/metrics/dashboard/dynamic_dashboard_service.rb
deleted
100644 → 0
View file @
4ec30fdd
# frozen_string_literal: true
# Responsible for returning a filtered system dashboard
# containing only the default embedded metrics. In future,
# this class may be updated to support filtering to
# alternate metrics/panels.
#
# Why isn't this filtering in a processing stage? By filtering
# here, we ensure the dynamically-determined dashboard is cached.
#
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module
Gitlab
module
Metrics
module
Dashboard
class
DynamicDashboardService
<
Gitlab
::
Metrics
::
Dashboard
::
BaseService
# For the default filtering for embedded metrics,
# uses the 'id' key in dashboard-yml definition for
# identification.
DEFAULT_EMBEDDED_METRICS_IDENTIFIERS
=
%w(
system_metrics_kubernetes_container_memory_total
system_metrics_kubernetes_container_cores_total
)
.
freeze
# Returns a new dashboard with only the matching
# metrics from the system dashboard, stripped of groups.
# @return [Hash]
def
raw_dashboard
panels
=
panel_groups
.
each_with_object
([])
do
|
group
,
panels
|
matched_panels
=
group
[
'panels'
].
select
{
|
panel
|
matching_panel?
(
panel
)
}
panels
.
concat
(
matched_panels
)
end
{
'panel_groups'
=>
[{
'panels'
=>
panels
}]
}
end
def
cache_key
"dynamic_metrics_dashboard_
#{
metric_identifiers
.
join
(
'_'
)
}
"
end
private
# Returns an array of the panels groups on the
# system dashboard
def
panel_groups
Gitlab
::
Metrics
::
Dashboard
::
SystemDashboardService
.
new
(
project
,
nil
)
.
raw_dashboard
[
'panel_groups'
]
end
# Identifies a panel as "matching" if any metric ids in
# the panel is in the list of identifiers to collect.
def
matching_panel?
(
panel
)
panel
[
'metrics'
].
any?
do
|
metric
|
metric_identifiers
.
include?
(
metric
[
'id'
])
end
end
def
metric_identifiers
DEFAULT_EMBEDDED_METRICS_IDENTIFIERS
end
end
end
end
end
lib/gitlab/metrics/dashboard/finder.rb
View file @
04870b96
...
...
@@ -47,22 +47,22 @@ module Gitlab
private
def
service_for_path
(
dashboard_path
,
embedded
:)
return
dynamic
_service
if
embedded
return
embed
_service
if
embedded
return
system_service
if
system_dashboard?
(
dashboard_path
)
project_service
end
def
system_service
Gitlab
::
Metrics
::
Dashboard
::
SystemDashboardService
::
Metrics
::
Dashboard
::
SystemDashboardService
end
def
project_service
Gitlab
::
Metrics
::
Dashboard
::
ProjectDashboardService
::
Metrics
::
Dashboard
::
ProjectDashboardService
end
def
dynamic
_service
Gitlab
::
Metrics
::
Dashboard
::
DynamicDashboar
dService
def
embed
_service
::
Metrics
::
Dashboard
::
DefaultEmbe
dService
end
def
system_dashboard?
(
filepath
)
...
...
lib/gitlab/metrics/dashboard/project_dashboard_service.rb
deleted
100644 → 0
View file @
4ec30fdd
# frozen_string_literal: true
# Searches a projects repository for a metrics dashboard and formats the output.
# Expects any custom dashboards will be located in `.gitlab/dashboards`
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module
Gitlab
module
Metrics
module
Dashboard
class
ProjectDashboardService
<
Gitlab
::
Metrics
::
Dashboard
::
BaseService
DASHBOARD_ROOT
=
".gitlab/dashboards"
class
<<
self
def
all_dashboard_paths
(
project
)
file_finder
(
project
)
.
list_files_for
(
DASHBOARD_ROOT
)
.
map
do
|
filepath
|
{
path:
filepath
,
display_name:
name_for_path
(
filepath
),
default:
false
}
end
end
def
file_finder
(
project
)
Gitlab
::
Template
::
Finders
::
RepoTemplateFinder
.
new
(
project
,
DASHBOARD_ROOT
,
'.yml'
)
end
# Grabs the filepath after the base directory.
def
name_for_path
(
filepath
)
filepath
.
delete_prefix
(
"
#{
DASHBOARD_ROOT
}
/"
)
end
end
private
# Searches the project repo for a custom-defined dashboard.
def
get_raw_dashboard
yml
=
self
.
class
.
file_finder
(
project
).
read
(
dashboard_path
)
YAML
.
safe_load
(
yml
)
end
def
cache_key
"project_
#{
project
.
id
}
_metrics_dashboard_
#{
dashboard_path
}
"
end
end
end
end
end
lib/gitlab/metrics/dashboard/system_dashboard_service.rb
deleted
100644 → 0
View file @
4ec30fdd
# frozen_string_literal: true
# Fetches the system metrics dashboard and formats the output.
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module
Gitlab
module
Metrics
module
Dashboard
class
SystemDashboardService
<
Gitlab
::
Metrics
::
Dashboard
::
BaseService
SYSTEM_DASHBOARD_PATH
=
'config/prometheus/common_metrics.yml'
SYSTEM_DASHBOARD_NAME
=
'Default'
class
<<
self
def
all_dashboard_paths
(
_project
)
[{
path:
SYSTEM_DASHBOARD_PATH
,
display_name:
SYSTEM_DASHBOARD_NAME
,
default:
true
}]
end
def
system_dashboard?
(
filepath
)
filepath
==
SYSTEM_DASHBOARD_PATH
end
end
private
def
dashboard_path
SYSTEM_DASHBOARD_PATH
end
# Returns the base metrics shipped with every GitLab service.
def
get_raw_dashboard
yml
=
File
.
read
(
Rails
.
root
.
join
(
dashboard_path
))
YAML
.
safe_load
(
yml
)
end
def
cache_key
"metrics_dashboard_
#{
dashboard_path
}
"
end
def
insert_project_metrics?
true
end
end
end
end
end
spec/controllers/projects/environments_controller_spec.rb
View file @
04870b96
...
...
@@ -551,7 +551,7 @@ describe Projects::EnvironmentsController do
end
context
'when the specified dashboard is the default dashboard'
do
let
(
:dashboard_path
)
{
Gitlab
::
Metrics
::
Dashboard
::
SystemDashboardService
::
SYSTEM_DASHBOARD_PATH
}
let
(
:dashboard_path
)
{
::
Metrics
::
Dashboard
::
SystemDashboardService
::
SYSTEM_DASHBOARD_PATH
}
it_behaves_like
'the default dashboard'
end
...
...
spec/lib/gitlab/metrics/dashboard/finder_spec.rb
View file @
04870b96
...
...
@@ -8,7 +8,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi
set
(
:project
)
{
build
(
:project
)
}
set
(
:user
)
{
create
(
:user
)
}
set
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:system_dashboard_path
)
{
Gitlab
::
Metrics
::
Dashboard
::
SystemDashboardService
::
SYSTEM_DASHBOARD_PATH
}
let
(
:system_dashboard_path
)
{
::
Metrics
::
Dashboard
::
SystemDashboardService
::
SYSTEM_DASHBOARD_PATH
}
before
do
project
.
add_maintainer
(
user
)
...
...
spec/
lib/gitlab/metrics/dashboard/dynamic_dashboar
d_service_spec.rb
→
spec/
services/metrics/dashboard/default_embe
d_service_spec.rb
View file @
04870b96
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Dashboard
::
DynamicDashboar
dService
,
:use_clean_rails_memory_store_caching
do
describe
Metrics
::
Dashboard
::
DefaultEmbe
dService
,
:use_clean_rails_memory_store_caching
do
include
MetricsDashboardHelpers
set
(
:project
)
{
build
(
:project
)
}
...
...
spec/
lib/gitlab
/metrics/dashboard/project_dashboard_service_spec.rb
→
spec/
services
/metrics/dashboard/project_dashboard_service_spec.rb
View file @
04870b96
...
...
@@ -2,7 +2,7 @@
require
'rails_helper'
describe
Gitlab
::
Metrics
::
Dashboard
::
ProjectDashboardService
,
:use_clean_rails_memory_store_caching
do
describe
Metrics
::
Dashboard
::
ProjectDashboardService
,
:use_clean_rails_memory_store_caching
do
include
MetricsDashboardHelpers
set
(
:user
)
{
create
(
:user
)
}
...
...
spec/
lib/gitlab
/metrics/dashboard/system_dashboard_service_spec.rb
→
spec/
services
/metrics/dashboard/system_dashboard_service_spec.rb
View file @
04870b96
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Dashboard
::
SystemDashboardService
,
:use_clean_rails_memory_store_caching
do
describe
Metrics
::
Dashboard
::
SystemDashboardService
,
:use_clean_rails_memory_store_caching
do
include
MetricsDashboardHelpers
set
(
:user
)
{
create
(
:user
)
}
...
...
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