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
185ec807
Commit
185ec807
authored
Apr 11, 2019
by
syasonik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save multi-dashboard logic for another MR
parent
a2920682
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
36 deletions
+7
-36
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+1
-1
app/services/metrics_dashboard_service.rb
app/services/metrics_dashboard_service.rb
+6
-35
No files found.
app/controllers/projects/environments_controller.rb
View file @
185ec807
...
...
@@ -163,7 +163,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
respond_to
do
|
format
|
format
.
json
do
dashboard
=
MetricsDashboardService
.
new
(
@project
).
find
(
params
[
:dashboard
])
dashboard
=
MetricsDashboardService
.
new
.
get_dashboard
render
json:
dashboard
,
status: :ok
end
...
...
app/services/metrics_dashboard_service.rb
View file @
185ec807
# 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`
# Fetches the metrics dashboard layout and supplemented the output with DB info.
class
MetricsDashboardService
DASHBOARD_ROOT
=
".gitlab/dashboards"
DASHBOARD_EXTENSION
=
'.yml'
SYSTEM_DASHBOARD_NAME
=
'system_dashboard'
SYSTEM_DASHBOARD_ROOT
=
"config/prometheus"
SYSTEM_DASHBOARD_PATH
=
Rails
.
root
.
join
(
SYSTEM_DASHBOARD_ROOT
,
"
#{
SYSTEM_DASHBOARD_NAME
}#{
DASHBOARD_EXTENSION
}
"
)
def
initialize
(
project
)
@project
=
project
end
SYSTEM_DASHBOARD_PATH
=
Rails
.
root
.
join
(
"config/prometheus"
,
"
#{
SYSTEM_DASHBOARD_NAME
}
.yml"
)
# Returns a DB-supplemented json representation of a dashboard config file.
#
# param: dashboard_name [String] Filename of dashboard w/o an extension.
# If not provided, the system dashboard will be returned.
def
find
(
dashboard_name
=
nil
)
unless
Feature
.
enabled?
(
:environment_metrics_show_multiple_dashboards
,
@project
)
return
process_dashboard
(
system_dashboard
)
end
dashboard
=
Rails
.
cache
.
fetch
(
cache_key
(
dashboard_name
))
do
dashboard_name
?
project_dashboard
(
dashboard
)
:
system_dashboard
end
def
get_dashboard
dashboard
=
Rails
.
cache
.
fetch
(
cache_key
)
{
system_dashboard
}
process_dashboard
(
dashboard
)
end
...
...
@@ -37,19 +19,8 @@ class MetricsDashboardService
YAML
.
load_file
(
SYSTEM_DASHBOARD_PATH
)
end
# Searches the project repo for a custom-defined dashboard.
def
project_dashboard
(
dashboard_name
)
Gitlab
::
Template
::
Finders
::
RepoTemplateFinder
.
new
(
project
,
DASHBOARD_ROOT
,
DASHBOARD_EXTENSION
).
find
(
dashboard_name
).
read
end
def
cache_key
(
dashboard_name
)
return
"metrics_dashboard_
#{
SYSTEM_DASHBOARD_NAME
}
"
unless
dashboard_name
"project_
#{
@project
.
id
}
_metrics_dashboard_
#{
dashboard_name
}
"
def
cache_key
"metrics_dashboard_
#{
SYSTEM_DASHBOARD_NAME
}
"
end
# TODO: "Processing" the dashboard needs to include several steps such as
...
...
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