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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
a2920682
Commit
a2920682
authored
Apr 11, 2019
by
syasonik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add inital dashboard endpoint support
parent
6735f4c7
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
349 additions
and
0 deletions
+349
-0
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+14
-0
app/services/metrics_dashboard_service.rb
app/services/metrics_dashboard_service.rb
+60
-0
config/prometheus/system_dashboard.yml
config/prometheus/system_dashboard.yml
+274
-0
config/routes/project.rb
config/routes/project.rb
+1
-0
No files found.
app/controllers/projects/environments_controller.rb
View file @
a2920682
...
@@ -12,6 +12,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
...
@@ -12,6 +12,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action
:expire_etag_cache
,
only:
[
:index
]
before_action
:expire_etag_cache
,
only:
[
:index
]
before_action
only:
[
:metrics
,
:additional_metrics
]
do
before_action
only:
[
:metrics
,
:additional_metrics
]
do
push_frontend_feature_flag
(
:metrics_time_window
)
push_frontend_feature_flag
(
:metrics_time_window
)
push_frontend_feature_flag
(
:environment_metrics_use_prometheus_endpoint
)
push_frontend_feature_flag
(
:environment_metrics_show_multiple_dashboards
)
end
end
def
index
def
index
...
@@ -156,6 +158,18 @@ class Projects::EnvironmentsController < Projects::ApplicationController
...
@@ -156,6 +158,18 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
end
end
end
def
metrics_dashboard
access_denied!
unless
Feature
.
enabled?
(
:environment_metrics_use_prometheus_endpoint
,
project
)
respond_to
do
|
format
|
format
.
json
do
dashboard
=
MetricsDashboardService
.
new
(
@project
).
find
(
params
[
:dashboard
])
render
json:
dashboard
,
status: :ok
end
end
end
def
search
def
search
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
json
do
format
.
json
do
...
...
app/services/metrics_dashboard_service.rb
0 → 100644
View file @
a2920682
# 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`
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
# 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
process_dashboard
(
dashboard
)
end
private
# Returns the base metrics shipped with every GitLab service.
def
system_dashboard
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
}
"
end
# TODO: "Processing" the dashboard needs to include several steps such as
# inserting metric ids and alert information.
def
process_dashboard
(
dashboard
)
dashboard
.
to_json
end
end
config/prometheus/system_dashboard.yml
0 → 100644
View file @
a2920682
This diff is collapsed.
Click to expand it.
config/routes/project.rb
View file @
a2920682
...
@@ -218,6 +218,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
...
@@ -218,6 +218,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get
:terminal
get
:terminal
get
:metrics
get
:metrics
get
:additional_metrics
get
:additional_metrics
get
:metrics_dashboard
get
'/terminal.ws/authorize'
,
to:
'environments#terminal_websocket_authorize'
,
constraints:
{
format:
nil
}
get
'/terminal.ws/authorize'
,
to:
'environments#terminal_websocket_authorize'
,
constraints:
{
format:
nil
}
get
'/prometheus/api/v1/*proxy_path'
,
to:
'environments/prometheus_api#proxy'
get
'/prometheus/api/v1/*proxy_path'
,
to:
'environments/prometheus_api#proxy'
...
...
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