Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gpt
large_projects
gitlabhq1
Commits
da13d415
Commit
da13d415
authored
6 years ago
by
Tiago Botelho
Browse files
Options
Download
Email Patches
Plain Diff
Backports CE relevant changes from EE
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/5163
parent
851a1992
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
122 additions
and
51 deletions
+122
-51
app/helpers/environments_helper.rb
app/helpers/environments_helper.rb
+17
-0
app/models/clusters/applications/prometheus.rb
app/models/clusters/applications/prometheus.rb
+4
-0
app/models/concerns/prometheus_adapter.rb
app/models/concerns/prometheus_adapter.rb
+11
-4
app/models/internal_id.rb
app/models/internal_id.rb
+1
-1
app/services/clusters/applications/check_installation_progress_service.rb
...sters/applications/check_installation_progress_service.rb
+3
-3
app/services/prometheus/adapter_service.rb
app/services/prometheus/adapter_service.rb
+1
-1
app/views/projects/environments/metrics.html.haml
app/views/projects/environments/metrics.html.haml
+1
-12
lib/gitlab/kubernetes/config_map.rb
lib/gitlab/kubernetes/config_map.rb
+5
-5
lib/gitlab/kubernetes/helm/api.rb
lib/gitlab/kubernetes/helm/api.rb
+11
-9
lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
...prometheus/queries/additional_metrics_deployment_query.rb
+1
-0
lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
...rometheus/queries/additional_metrics_environment_query.rb
+1
-0
lib/gitlab/prometheus/queries/query_additional_metrics.rb
lib/gitlab/prometheus/queries/query_additional_metrics.rb
+1
-1
spec/lib/gitlab/kubernetes/config_map_spec.rb
spec/lib/gitlab/kubernetes/config_map_spec.rb
+6
-0
spec/lib/gitlab/kubernetes/helm/api_spec.rb
spec/lib/gitlab/kubernetes/helm/api_spec.rb
+6
-6
spec/models/clusters/applications/prometheus_spec.rb
spec/models/clusters/applications/prometheus_spec.rb
+49
-6
spec/support/prometheus/additional_metrics_shared_examples.rb
.../support/prometheus/additional_metrics_shared_examples.rb
+4
-3
No files found.
app/helpers/environments_helper.rb
View file @
da13d415
...
...
@@ -4,4 +4,21 @@ module EnvironmentsHelper
endpoint:
project_environments_path
(
@project
,
format: :json
)
}
end
def
metrics_data
{
"settings-path"
=>
edit_project_service_path
(
@project
,
'prometheus'
),
"clusters-path"
=>
project_clusters_path
(
@project
),
"documentation-path"
=>
help_page_path
(
'administration/monitoring/prometheus/index.md'
),
"empty-getting-started-svg-path"
=>
image_path
(
'illustrations/monitoring/getting_started.svg'
),
"empty-loading-svg-path"
=>
image_path
(
'illustrations/monitoring/loading.svg'
),
"empty-no-data-svg-path"
=>
image_path
(
'illustrations/monitoring/no_data.svg'
),
"empty-unable-to-connect-svg-path"
=>
image_path
(
'illustrations/monitoring/unable_to_connect.svg'
),
"metrics-endpoint"
=>
additional_metrics_project_environment_path
(
@project
,
@environment
,
format: :json
),
"deployment-endpoint"
=>
project_environment_deployments_path
(
@project
,
@environment
,
format: :json
),
"project-path"
=>
project_path
(
@project
),
"tags-path"
=>
project_tags_path
(
@project
),
"has-metrics"
=>
"
#{
@environment
.
has_metrics?
}
"
,
}
end
end
This diff is collapsed.
Click to expand it.
app/models/clusters/applications/prometheus.rb
View file @
da13d415
...
...
@@ -21,6 +21,10 @@ module Clusters
end
end
def
ready?
status_name
==
:installed
end
def
chart
'stable/prometheus'
end
...
...
This diff is collapsed.
Click to expand it.
app/models/concerns/prometheus_adapter.rb
View file @
da13d415
...
...
@@ -24,11 +24,10 @@ module PrometheusAdapter
def
query
(
query_name
,
*
args
)
return
unless
can_query?
query_class
=
Gitlab
::
Prometheus
::
Queries
.
const_get
(
"
#{
query_name
.
to_s
.
classify
}
Query"
)
query_class
=
query_klass_for
(
query_name
)
query_args
=
build_query_args
(
*
args
)
args
.
map!
(
&
:id
)
with_reactive_cache
(
query_class
.
name
,
*
args
,
&
query_class
.
method
(
:transform_reactive_result
))
with_reactive_cache
(
query_class
.
name
,
*
query_args
,
&
query_class
.
method
(
:transform_reactive_result
))
end
# Cache metrics for specific environment
...
...
@@ -44,5 +43,13 @@ module PrometheusAdapter
rescue
Gitlab
::
PrometheusClient
::
Error
=>
err
{
success:
false
,
result:
err
.
message
}
end
def
query_klass_for
(
query_name
)
Gitlab
::
Prometheus
::
Queries
.
const_get
(
"
#{
query_name
.
to_s
.
classify
}
Query"
)
end
def
build_query_args
(
*
args
)
args
.
map
(
&
:id
)
end
end
end
This diff is collapsed.
Click to expand it.
app/models/internal_id.rb
View file @
da13d415
...
...
@@ -14,7 +14,7 @@ class InternalId < ActiveRecord::Base
belongs_to
:project
belongs_to
:namespace
enum
usage:
{
issues:
0
,
merge_requests:
1
,
deployments:
2
,
milestones:
3
,
epics:
4
,
ci_pipelines:
5
}
enum
usage:
{
issues:
0
,
merge_requests:
1
,
deployments:
2
,
milestones:
3
,
epics:
4
,
ci_pipelines:
5
,
prometheus_alerts:
6
}
validates
:usage
,
presence:
true
...
...
This diff is collapsed.
Click to expand it.
app/services/clusters/applications/check_installation_progress_service.rb
View file @
da13d415
...
...
@@ -48,17 +48,17 @@ module Clusters
end
def
remove_installation_pod
helm_api
.
delete_
installation_
pod!
(
install_command
.
pod_name
)
helm_api
.
delete_pod!
(
install_command
.
pod_name
)
rescue
# no-op
end
def
installation_phase
helm_api
.
installation_
status
(
install_command
.
pod_name
)
helm_api
.
status
(
install_command
.
pod_name
)
end
def
installation_errors
helm_api
.
installation_
log
(
install_command
.
pod_name
)
helm_api
.
log
(
install_command
.
pod_name
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
app/services/prometheus/adapter_service.rb
View file @
da13d415
...
...
@@ -28,7 +28,7 @@ module Prometheus
return
unless
deployment_platform
.
respond_to?
(
:cluster
)
cluster
=
deployment_platform
.
cluster
return
unless
cluster
.
application_prometheus
&
.
installed
?
return
unless
cluster
.
application_prometheus
&
.
ready
?
cluster
.
application_prometheus
end
...
...
This diff is collapsed.
Click to expand it.
app/views/projects/environments/metrics.html.haml
View file @
da13d415
...
...
@@ -9,15 +9,4 @@
Environment:
=
link_to
@environment
.
name
,
environment_path
(
@environment
)
#prometheus-graphs
{
data:
{
"settings-path"
:
edit_project_service_path
(
@project
,
'prometheus'
),
"clusters-path"
:
project_clusters_path
(
@project
),
"documentation-path"
:
help_page_path
(
'administration/monitoring/prometheus/index.md'
),
"empty-getting-started-svg-path"
:
image_path
(
'illustrations/monitoring/getting_started.svg'
),
"empty-loading-svg-path"
:
image_path
(
'illustrations/monitoring/loading.svg'
),
"empty-no-data-svg-path"
:
image_path
(
'illustrations/monitoring/no_data.svg'
),
"empty-unable-to-connect-svg-path"
:
image_path
(
'illustrations/monitoring/unable_to_connect.svg'
),
"metrics-endpoint"
:
additional_metrics_project_environment_path
(
@project
,
@environment
,
format: :json
),
"deployment-endpoint"
:
project_environment_deployments_path
(
@project
,
@environment
,
format: :json
),
"project-path"
:
project_path
(
@project
),
"tags-path"
:
project_tags_path
(
@project
),
"has-metrics"
:
"#{@environment.has_metrics?}"
}
}
#prometheus-graphs
{
data:
metrics_data
}
This diff is collapsed.
Click to expand it.
lib/gitlab/kubernetes/config_map.rb
View file @
da13d415
module
Gitlab
module
Kubernetes
class
ConfigMap
def
initialize
(
name
,
values
)
def
initialize
(
name
,
values
=
""
)
@name
=
name
@values
=
values
end
...
...
@@ -13,6 +13,10 @@ module Gitlab
resource
end
def
config_map_name
"values-content-configuration-
#{
name
}
"
end
private
attr_reader
:name
,
:values
...
...
@@ -25,10 +29,6 @@ module Gitlab
}
end
def
config_map_name
"values-content-configuration-
#{
name
}
"
end
def
namespace
Gitlab
::
Kubernetes
::
Helm
::
NAMESPACE
end
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/kubernetes/helm/api.rb
View file @
da13d415
...
...
@@ -2,15 +2,17 @@ module Gitlab
module
Kubernetes
module
Helm
class
Api
attr_reader
:kubeclient
,
:namespace
def
initialize
(
kubeclient
)
@kubeclient
=
kubeclient
@namespace
=
Gitlab
::
Kubernetes
::
Namespace
.
new
(
Gitlab
::
Kubernetes
::
Helm
::
NAMESPACE
,
kubeclient
)
end
def
install
(
command
)
@
namespace
.
ensure_exists!
namespace
.
ensure_exists!
create_config_map
(
command
)
if
command
.
config_map?
@
kubeclient
.
create_pod
(
command
.
pod_resource
)
kubeclient
.
create_pod
(
command
.
pod_resource
)
end
##
...
...
@@ -20,23 +22,23 @@ module Gitlab
#
# values: "Pending", "Running", "Succeeded", "Failed", "Unknown"
#
def
installation_
status
(
pod_name
)
@
kubeclient
.
get_pod
(
pod_name
,
@
namespace
.
name
).
status
.
phase
def
status
(
pod_name
)
kubeclient
.
get_pod
(
pod_name
,
namespace
.
name
).
status
.
phase
end
def
installation_
log
(
pod_name
)
@
kubeclient
.
get_pod_log
(
pod_name
,
@
namespace
.
name
).
body
def
log
(
pod_name
)
kubeclient
.
get_pod_log
(
pod_name
,
namespace
.
name
).
body
end
def
delete_
installation_
pod!
(
pod_name
)
@
kubeclient
.
delete_pod
(
pod_name
,
@
namespace
.
name
)
def
delete_pod!
(
pod_name
)
kubeclient
.
delete_pod
(
pod_name
,
namespace
.
name
)
end
private
def
create_config_map
(
command
)
command
.
config_map_resource
.
tap
do
|
config_map_resource
|
@
kubeclient
.
create_config_map
(
config_map_resource
)
kubeclient
.
create_config_map
(
config_map_resource
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
View file @
da13d415
...
...
@@ -8,6 +8,7 @@ module Gitlab
Deployment
.
find_by
(
id:
deployment_id
).
try
do
|
deployment
|
query_metrics
(
deployment
.
project
,
deployment
.
environment
,
common_query_context
(
deployment
.
environment
,
timeframe_start:
(
deployment
.
created_at
-
30
.
minutes
).
to_f
,
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
View file @
da13d415
...
...
@@ -8,6 +8,7 @@ module Gitlab
::
Environment
.
find_by
(
id:
environment_id
).
try
do
|
environment
|
query_metrics
(
environment
.
project
,
environment
,
common_query_context
(
environment
,
timeframe_start:
8
.
hours
.
ago
.
to_f
,
timeframe_end:
Time
.
now
.
to_f
)
)
end
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/prometheus/queries/query_additional_metrics.rb
View file @
da13d415
...
...
@@ -2,7 +2,7 @@ module Gitlab
module
Prometheus
module
Queries
module
QueryAdditionalMetrics
def
query_metrics
(
project
,
query_context
)
def
query_metrics
(
project
,
environment
,
query_context
)
matched_metrics
(
project
).
map
(
&
query_group
(
query_context
))
.
select
(
&
method
(
:group_with_any_metrics
))
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/kubernetes/config_map_spec.rb
View file @
da13d415
...
...
@@ -22,4 +22,10 @@ describe Gitlab::Kubernetes::ConfigMap do
is_expected
.
to
eq
(
resource
)
end
end
describe
'#config_map_name'
do
it
'returns the config_map name'
do
expect
(
config_map
.
config_map_name
).
to
eq
(
"values-content-configuration-
#{
application
.
name
}
"
)
end
end
end
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/kubernetes/helm/api_spec.rb
View file @
da13d415
...
...
@@ -55,33 +55,33 @@ describe Gitlab::Kubernetes::Helm::Api do
end
end
describe
'#
installation_
status'
do
describe
'#status'
do
let
(
:phase
)
{
Gitlab
::
Kubernetes
::
Pod
::
RUNNING
}
let
(
:pod
)
{
Kubeclient
::
Resource
.
new
(
status:
{
phase:
phase
})
}
# partial representation
it
'fetches POD phase from kubernetes cluster'
do
expect
(
client
).
to
receive
(
:get_pod
).
with
(
command
.
pod_name
,
gitlab_namespace
).
once
.
and_return
(
pod
)
expect
(
subject
.
installation_
status
(
command
.
pod_name
)).
to
eq
(
phase
)
expect
(
subject
.
status
(
command
.
pod_name
)).
to
eq
(
phase
)
end
end
describe
'#
installation_
log'
do
describe
'#log'
do
let
(
:log
)
{
'some output'
}
let
(
:response
)
{
RestClient
::
Response
.
new
(
log
)
}
it
'fetches POD phase from kubernetes cluster'
do
expect
(
client
).
to
receive
(
:get_pod_log
).
with
(
command
.
pod_name
,
gitlab_namespace
).
once
.
and_return
(
response
)
expect
(
subject
.
installation_
log
(
command
.
pod_name
)).
to
eq
(
log
)
expect
(
subject
.
log
(
command
.
pod_name
)).
to
eq
(
log
)
end
end
describe
'#delete_
installation_
pod!'
do
describe
'#delete_pod!'
do
it
'deletes the POD from kubernetes cluster'
do
expect
(
client
).
to
receive
(
:delete_pod
).
with
(
command
.
pod_name
,
gitlab_namespace
).
once
subject
.
delete_
installation_
pod!
(
command
.
pod_name
)
subject
.
delete_pod!
(
command
.
pod_name
)
end
end
end
This diff is collapsed.
Click to expand it.
spec/models/clusters/applications/prometheus_spec.rb
View file @
da13d415
...
...
@@ -34,6 +34,47 @@ describe Clusters::Applications::Prometheus do
end
end
describe
'#ready'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:cluster
)
{
create
(
:cluster
,
projects:
[
project
])
}
it
'returns true when installed'
do
application
=
create
(
:clusters_applications_prometheus
,
:installed
,
cluster:
cluster
)
expect
(
application
.
ready?
).
to
be
true
end
it
'returns false when not_installable'
do
application
=
create
(
:clusters_applications_prometheus
,
:not_installable
,
cluster:
cluster
)
expect
(
application
.
ready?
).
to
be
false
end
it
'returns false when installable'
do
application
=
create
(
:clusters_applications_prometheus
,
:installable
,
cluster:
cluster
)
expect
(
application
.
ready?
).
to
be
false
end
it
'returns false when scheduled'
do
application
=
create
(
:clusters_applications_prometheus
,
:scheduled
,
cluster:
cluster
)
expect
(
application
.
ready?
).
to
be
false
end
it
'returns false when installing'
do
application
=
create
(
:clusters_applications_prometheus
,
:installing
,
cluster:
cluster
)
expect
(
application
.
ready?
).
to
be
false
end
it
'returns false when errored'
do
application
=
create
(
:clusters_applications_prometheus
,
:errored
,
cluster:
cluster
)
expect
(
application
.
ready?
).
to
be
false
end
end
describe
'#prometheus_client'
do
context
'cluster is nil'
do
it
'returns nil'
do
...
...
@@ -102,14 +143,16 @@ describe Clusters::Applications::Prometheus do
let
(
:kubeclient
)
{
double
(
'kubernetes client'
)
}
let
(
:prometheus
)
{
create
(
:clusters_applications_prometheus
)
}
subject
{
prometheus
.
i
nstall
_c
ommand
}
it
{
is_expected
.
to
be_an_instance_of
(
Gitlab
::
Kubernetes
::
Helm
::
InstallCommand
)
}
it
'returns an instance of Gitlab::Kubernetes::Helm::I
nstall
C
ommand
'
do
expect
(
prometheus
.
install_command
).
to
be_an_instance_of
(
Gitlab
::
Kubernetes
::
Helm
::
InstallCommand
)
end
it
'should be initialized with 3 arguments'
do
expect
(
subject
.
name
).
to
eq
(
'prometheus'
)
expect
(
subject
.
chart
).
to
eq
(
'stable/prometheus'
)
expect
(
subject
.
values
).
to
eq
(
prometheus
.
values
)
command
=
prometheus
.
install_command
expect
(
command
.
name
).
to
eq
(
'prometheus'
)
expect
(
command
.
chart
).
to
eq
(
'stable/prometheus'
)
expect
(
command
.
values
).
to
eq
(
prometheus
.
values
)
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/support/prometheus/additional_metrics_shared_examples.rb
View file @
da13d415
...
...
@@ -25,7 +25,7 @@ RSpec.shared_examples 'additional metrics query' do
shared_examples
'query context containing environment slug and filter'
do
it
'contains ci_environment_slug'
do
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
project
,
hash_including
(
ci_environment_slug:
environment
.
slug
))
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
project
,
environment
,
hash_including
(
ci_environment_slug:
environment
.
slug
))
subject
.
query
(
*
query_params
)
end
...
...
@@ -33,6 +33,7 @@ RSpec.shared_examples 'additional metrics query' do
it
'contains environment filter'
do
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
project
,
environment
,
hash_including
(
environment_filter:
"container_name!=
\"
POD
\"
,environment=
\"
#{
environment
.
slug
}
\"
"
)
...
...
@@ -50,7 +51,7 @@ RSpec.shared_examples 'additional metrics query' do
it_behaves_like
'query context containing environment slug and filter'
it
'query context contains kube_namespace'
do
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
project
,
hash_including
(
kube_namespace:
kube_namespace
))
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
project
,
environment
,
hash_including
(
kube_namespace:
kube_namespace
))
subject
.
query
(
*
query_params
)
end
...
...
@@ -74,7 +75,7 @@ RSpec.shared_examples 'additional metrics query' do
it_behaves_like
'query context containing environment slug and filter'
it
'query context contains empty kube_namespace'
do
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
project
,
hash_including
(
kube_namespace:
''
))
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
project
,
environment
,
hash_including
(
kube_namespace:
''
))
subject
.
query
(
*
query_params
)
end
...
...
This diff is collapsed.
Click to expand it.
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