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
5ca140df
Commit
5ca140df
authored
Feb 13, 2020
by
Kirstie Cook
Committed by
Imre Farkas
Feb 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create SelfMonitoringDashboardService and add specs
Set the default dashboard for self monitoring project
parent
5b5b4d87
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
191 additions
and
1 deletion
+191
-1
app/models/project.rb
app/models/project.rb
+4
-0
app/services/metrics/dashboard/self_monitoring_dashboard_service.rb
...es/metrics/dashboard/self_monitoring_dashboard_service.rb
+37
-0
changelogs/unreleased/121719-self-monitoring-default.yml
changelogs/unreleased/121719-self-monitoring-default.yml
+5
-0
lib/gitlab/metrics/dashboard/finder.rb
lib/gitlab/metrics/dashboard/finder.rb
+13
-1
lib/gitlab/metrics/dashboard/service_selector.rb
lib/gitlab/metrics/dashboard/service_selector.rb
+1
-0
spec/lib/gitlab/metrics/dashboard/finder_spec.rb
spec/lib/gitlab/metrics/dashboard/finder_spec.rb
+34
-0
spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb
spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb
+6
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+18
-0
spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb
...trics/dashboard/self_monitoring_dashboard_service_spec.rb
+69
-0
spec/support/helpers/metrics_dashboard_helpers.rb
spec/support/helpers/metrics_dashboard_helpers.rb
+4
-0
No files found.
app/models/project.rb
View file @
5ca140df
...
...
@@ -2335,6 +2335,10 @@ class Project < ApplicationRecord
false
end
def
self_monitoring?
Gitlab
::
CurrentSettings
.
self_monitoring_project_id
==
id
end
private
def
closest_namespace_setting
(
name
)
...
...
app/services/metrics/dashboard/self_monitoring_dashboard_service.rb
0 → 100644
View file @
5ca140df
# frozen_string_literal: true
# Fetches the self monitoring metrics dashboard and formats the output.
# Use Gitlab::Metrics::Dashboard::Finder to retrieve dashboards.
module
Metrics
module
Dashboard
class
SelfMonitoringDashboardService
<
::
Metrics
::
Dashboard
::
PredefinedDashboardService
DASHBOARD_PATH
=
'config/prometheus/self_monitoring_default.yml'
DASHBOARD_NAME
=
'Default'
SEQUENCE
=
[
STAGES
::
ProjectMetricsInserter
,
STAGES
::
EndpointInserter
,
STAGES
::
Sorter
].
freeze
class
<<
self
def
valid_params?
(
params
)
matching_dashboard?
(
params
[
:dashboard_path
])
||
self_monitoring_project?
(
params
)
end
def
all_dashboard_paths
(
_project
)
[{
path:
DASHBOARD_PATH
,
display_name:
DASHBOARD_NAME
,
default:
true
,
system_dashboard:
false
}]
end
def
self_monitoring_project?
(
params
)
params
[
:dashboard_path
].
nil?
&&
params
[
:environment
]
&
.
project
&
.
self_monitoring?
end
end
end
end
end
changelogs/unreleased/121719-self-monitoring-default.yml
0 → 100644
View file @
5ca140df
---
title
:
Set default dashboard for self monitoring project
merge_request
:
24814
author
:
type
:
added
lib/gitlab/metrics/dashboard/finder.rb
View file @
5ca140df
...
...
@@ -65,7 +65,7 @@ module Gitlab
def
find_all_paths_from_source
(
project
)
Gitlab
::
Metrics
::
Dashboard
::
Cache
.
delete_all!
system_service
.
all_dashboard_paths
(
project
)
default_dashboard_path
(
project
)
.
+
project_service
.
all_dashboard_paths
(
project
)
end
...
...
@@ -79,6 +79,18 @@ module Gitlab
::
Metrics
::
Dashboard
::
ProjectDashboardService
end
def
self_monitoring_service
::
Metrics
::
Dashboard
::
SelfMonitoringDashboardService
end
def
default_dashboard_path
(
project
)
if
project
.
self_monitoring?
self_monitoring_service
.
all_dashboard_paths
(
project
)
else
system_service
.
all_dashboard_paths
(
project
)
end
end
def
service_for
(
options
)
Gitlab
::
Metrics
::
Dashboard
::
ServiceSelector
.
call
(
options
)
end
...
...
lib/gitlab/metrics/dashboard/service_selector.rb
View file @
5ca140df
...
...
@@ -18,6 +18,7 @@ module Gitlab
::
Metrics
::
Dashboard
::
DefaultEmbedService
,
::
Metrics
::
Dashboard
::
SystemDashboardService
,
::
Metrics
::
Dashboard
::
PodDashboardService
,
::
Metrics
::
Dashboard
::
SelfMonitoringDashboardService
,
::
Metrics
::
Dashboard
::
ProjectDashboardService
].
freeze
...
...
spec/lib/gitlab/metrics/dashboard/finder_spec.rb
View file @
5ca140df
...
...
@@ -44,6 +44,12 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi
it_behaves_like
'valid dashboard service response'
end
context
'when the self monitoring dashboard is specified'
do
let
(
:dashboard_path
)
{
self_monitoring_dashboard_path
}
it_behaves_like
'valid dashboard service response'
end
context
'when no dashboard is specified'
do
let
(
:service_call
)
{
described_class
.
find
(
project
,
user
,
environment:
environment
)
}
...
...
@@ -152,5 +158,33 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi
expect
(
all_dashboard_paths
).
to
contain_exactly
(
system_dashboard
,
project_dashboard
)
end
end
context
'when the project is self monitoring'
do
let
(
:self_monitoring_dashboard
)
do
{
path:
self_monitoring_dashboard_path
,
display_name:
'Default'
,
default:
true
,
system_dashboard:
false
}
end
let
(
:dashboard_path
)
{
'.gitlab/dashboards/test.yml'
}
let
(
:project
)
{
project_with_dashboard
(
dashboard_path
)
}
before
do
stub_application_setting
(
self_monitoring_project_id:
project
.
id
)
end
it
'includes self monitoring and project dashboards'
do
project_dashboard
=
{
path:
dashboard_path
,
display_name:
'test.yml'
,
default:
false
,
system_dashboard:
false
}
expect
(
all_dashboard_paths
).
to
contain_exactly
(
self_monitoring_dashboard
,
project_dashboard
)
end
end
end
end
spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb
View file @
5ca140df
...
...
@@ -30,6 +30,12 @@ describe Gitlab::Metrics::Dashboard::ServiceSelector do
end
end
context
'when the path is for the self monitoring dashboard'
do
let
(
:arguments
)
{
{
dashboard_path:
self_monitoring_dashboard_path
}
}
it
{
is_expected
.
to
be
Metrics
::
Dashboard
::
SelfMonitoringDashboardService
}
end
context
'when the embedded flag is provided'
do
let
(
:arguments
)
{
{
embedded:
true
}
}
...
...
spec/models/project_spec.rb
View file @
5ca140df
...
...
@@ -5592,6 +5592,24 @@ describe Project do
it
{
is_expected
.
to
be_falsey
}
end
describe
'#self_monitoring?'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
subject
{
project
.
self_monitoring?
}
context
'when the project is instance self monitoring'
do
before
do
stub_application_setting
(
self_monitoring_project_id:
project
.
id
)
end
it
{
is_expected
.
to
be
true
}
end
context
'when the project is not self monitoring'
do
it
{
is_expected
.
to
be
false
}
end
end
def
rugged_config
rugged_repo
(
project
.
repository
).
config
end
...
...
spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb
0 → 100644
View file @
5ca140df
# frozen_string_literal: true
require
'spec_helper'
describe
Metrics
::
Dashboard
::
SelfMonitoringDashboardService
,
:use_clean_rails_memory_store_caching
do
include
MetricsDashboardHelpers
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
before
do
project
.
add_maintainer
(
user
)
stub_application_setting
(
self_monitoring_project_id:
project
.
id
)
end
describe
'#get_dashboard'
do
let
(
:service_params
)
{
[
project
,
user
,
{
environment:
environment
}]
}
let
(
:service_call
)
{
described_class
.
new
(
*
service_params
).
get_dashboard
}
it_behaves_like
'valid dashboard service response'
it_behaves_like
'raises error for users with insufficient permissions'
it_behaves_like
'caches the unprocessed dashboard for subsequent calls'
end
describe
'.all_dashboard_paths'
do
it
'returns the dashboard attributes'
do
all_dashboards
=
described_class
.
all_dashboard_paths
(
project
)
expect
(
all_dashboards
).
to
eq
(
[{
path:
described_class
::
DASHBOARD_PATH
,
display_name:
described_class
::
DASHBOARD_NAME
,
default:
true
,
system_dashboard:
false
}]
)
end
end
describe
'.valid_params?'
do
subject
{
described_class
.
valid_params?
(
params
)
}
context
'with environment'
do
let
(
:params
)
{
{
environment:
environment
}
}
it
{
is_expected
.
to
be_truthy
}
end
context
'with dashboard_path'
do
let
(
:params
)
{
{
dashboard_path:
self_monitoring_dashboard_path
}
}
it
{
is_expected
.
to
be_truthy
}
end
context
'with a different dashboard selected'
do
let
(
:dashboard_path
)
{
'.gitlab/dashboards/test.yml'
}
let
(
:params
)
{
{
dashboard_path:
dashboard_path
,
environment:
environment
}
}
it
{
is_expected
.
to
be_falsey
}
end
context
'missing environment and dashboard_path'
do
let
(
:params
)
{
{}
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
spec/support/helpers/metrics_dashboard_helpers.rb
View file @
5ca140df
...
...
@@ -29,4 +29,8 @@ module MetricsDashboardHelpers
def
business_metric_title
PrometheusMetricEnums
.
group_details
[
:business
][
:group_title
]
end
def
self_monitoring_dashboard_path
Metrics
::
Dashboard
::
SelfMonitoringDashboardService
::
DASHBOARD_PATH
end
end
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