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
d32f5742
Commit
d32f5742
authored
May 22, 2018
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce CE/EE diff in app/controllers/projects/clusters_controller.rb
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
555a220d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
110 deletions
+127
-110
app/controllers/projects/clusters_controller.rb
app/controllers/projects/clusters_controller.rb
+2
-22
ee/app/controllers/ee/projects/clusters_controller.rb
ee/app/controllers/ee/projects/clusters_controller.rb
+31
-0
ee/spec/controllers/projects/clusters_controller_spec.rb
ee/spec/controllers/projects/clusters_controller_spec.rb
+94
-0
spec/controllers/projects/clusters_controller_spec.rb
spec/controllers/projects/clusters_controller_spec.rb
+0
-88
No files found.
app/controllers/projects/clusters_controller.rb
View file @
d32f5742
class
Projects::ClustersController
<
Projects
::
ApplicationController
prepend
EE
::
Projects
::
ClustersController
before_action
:cluster
,
except:
[
:index
,
:new
]
before_action
:authorize_read_cluster!
before_action
:authorize_create_cluster!
,
only:
[
:new
]
...
...
@@ -64,22 +66,6 @@ class Projects::ClustersController < Projects::ApplicationController
end
end
def
metrics
return
render_404
unless
prometheus_adapter
&
.
can_query?
respond_to
do
|
format
|
format
.
json
do
metrics
=
prometheus_adapter
.
query
(
:cluster
)
||
{}
if
metrics
.
any?
render
json:
metrics
else
head
:no_content
end
end
end
end
private
def
cluster
...
...
@@ -87,12 +73,6 @@ class Projects::ClustersController < Projects::ApplicationController
.
present
(
current_user:
current_user
)
end
def
prometheus_adapter
return
unless
cluster
&
.
application_prometheus
&
.
installed?
cluster
.
application_prometheus
end
def
update_params
if
cluster
.
managed?
params
.
require
(
:cluster
).
permit
(
...
...
ee/app/controllers/ee/projects/clusters_controller.rb
0 → 100644
View file @
d32f5742
module
EE
module
Projects
module
ClustersController
extend
ActiveSupport
::
Concern
def
metrics
return
render_404
unless
prometheus_adapter
&
.
can_query?
respond_to
do
|
format
|
format
.
json
do
metrics
=
prometheus_adapter
.
query
(
:cluster
)
||
{}
if
metrics
.
any?
render
json:
metrics
else
head
:no_content
end
end
end
end
private
def
prometheus_adapter
return
unless
cluster
&
.
application_prometheus
&
.
installed?
cluster
.
application_prometheus
end
end
end
end
ee/spec/controllers/projects/clusters_controller_spec.rb
0 → 100644
View file @
d32f5742
require
'spec_helper'
describe
Projects
::
ClustersController
do
include
AccessMatchersForController
set
(
:project
)
{
create
(
:project
)
}
describe
'GET metrics'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_gcp
,
projects:
[
project
])
}
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
"Can't query Prometheus"
do
it
'returns not found'
do
go
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'can query Prometheus'
do
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
,
query:
nil
)
}
before
do
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
end
it
'queries cluster metrics'
do
go
expect
(
prometheus_adapter
).
to
have_received
(
:query
).
with
(
:cluster
)
end
context
'when response has content'
do
let
(
:query_response
)
{
{
response:
nil
}
}
before
do
allow
(
prometheus_adapter
).
to
receive
(
:query
).
and_return
(
query_response
)
end
it
'returns prometheus query response'
do
go
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
.
body
).
to
eq
(
query_response
.
to_json
)
end
end
context
'when response has no content'
do
let
(
:query_response
)
{
{}
}
before
do
allow
(
prometheus_adapter
).
to
receive
(
:query
).
and_return
(
query_response
)
end
it
'returns prometheus query response'
do
go
expect
(
response
).
to
have_gitlab_http_status
(
:no_content
)
end
end
end
end
def
go
get
:metrics
,
format: :json
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
cluster
end
describe
'security'
do
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
,
query:
nil
)
}
before
do
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
end
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
end
end
spec/controllers/projects/clusters_controller_spec.rb
View file @
d32f5742
...
...
@@ -2,7 +2,6 @@ require 'spec_helper'
describe
Projects
::
ClustersController
do
include
AccessMatchersForController
include
GoogleApi
::
CloudPlatformHelpers
set
(
:project
)
{
create
(
:project
)
}
...
...
@@ -155,93 +154,6 @@ describe Projects::ClustersController do
end
end
describe
'GET metrics'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_gcp
,
projects:
[
project
])
}
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
"Can't query Prometheus"
do
it
'returns not found'
do
go
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'can query Prometheus'
do
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
,
query:
nil
)
}
before
do
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
end
it
'queries cluster metrics'
do
go
expect
(
prometheus_adapter
).
to
have_received
(
:query
).
with
(
:cluster
)
end
context
'when response has content'
do
let
(
:query_response
)
{
{
response:
nil
}
}
before
do
allow
(
prometheus_adapter
).
to
receive
(
:query
).
and_return
(
query_response
)
end
it
'returns prometheus query response'
do
go
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
.
body
).
to
eq
(
query_response
.
to_json
)
end
end
context
'when response has no content'
do
let
(
:query_response
)
{
{}
}
before
do
allow
(
prometheus_adapter
).
to
receive
(
:query
).
and_return
(
query_response
)
end
it
'returns prometheus query response'
do
go
expect
(
response
).
to
have_gitlab_http_status
(
:no_content
)
end
end
end
end
def
go
get
:metrics
,
format: :json
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
cluster
end
describe
'security'
do
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
,
query:
nil
)
}
before
do
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
end
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
end
describe
'PUT update'
do
context
'when cluster is provided by GCP'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_gcp
,
projects:
[
project
])
}
...
...
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