Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
19812e3e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
19812e3e
编写于
6月 20, 2017
作者:
P
Pawel Chojnacki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make queries not die when underlying data cannot be found
上级
15b7b9ec
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
50 addition
and
46 deletion
+50
-46
lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
...prometheus/queries/additional_metrics_deployment_query.rb
+9
-8
lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
...rometheus/queries/additional_metrics_environment_query.rb
+9
-8
lib/gitlab/prometheus/queries/deployment_query.rb
lib/gitlab/prometheus/queries/deployment_query.rb
+17
-16
lib/gitlab/prometheus/queries/environment_query.rb
lib/gitlab/prometheus/queries/environment_query.rb
+13
-12
spec/controllers/projects/deployments_controller_spec.rb
spec/controllers/projects/deployments_controller_spec.rb
+2
-2
未找到文件。
lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
浏览文件 @
19812e3e
...
...
@@ -5,15 +5,16 @@ module Gitlab
include
QueryAdditionalMetrics
def
query
(
deployment_id
)
deployment
=
Deployment
.
find_by
(
id:
deployment_id
)
query_context
=
{
environment_slug:
deployment
.
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{deployment.environment.slug}"}
,
timeframe_start:
(
deployment
.
created_at
-
30
.
minutes
).
to_f
,
timeframe_end:
(
deployment
.
created_at
+
30
.
minutes
).
to_f
}
Deployment
.
find_by
(
id:
deployment_id
).
try
do
|
deployment
|
query_context
=
{
environment_slug:
deployment
.
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{deployment.environment.slug}"}
,
timeframe_start:
(
deployment
.
created_at
-
30
.
minutes
).
to_f
,
timeframe_end:
(
deployment
.
created_at
+
30
.
minutes
).
to_f
}
query_metrics
(
query_context
)
query_metrics
(
query_context
)
end
end
end
end
...
...
lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
浏览文件 @
19812e3e
...
...
@@ -5,15 +5,16 @@ module Gitlab
include
QueryAdditionalMetrics
def
query
(
environment_id
)
environment
=
Environment
.
find_by
(
id:
environment_id
)
query_context
=
{
environment_slug:
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{environment.slug}"}
,
timeframe_start:
8
.
hours
.
ago
.
to_f
,
timeframe_end:
Time
.
now
.
to_f
}
Environment
.
find_by
(
id:
environment_id
).
try
do
|
environment
|
query_context
=
{
environment_slug:
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{environment.slug}"}
,
timeframe_start:
8
.
hours
.
ago
.
to_f
,
timeframe_end:
Time
.
now
.
to_f
}
query_metrics
(
query_context
)
query_metrics
(
query_context
)
end
end
end
end
...
...
lib/gitlab/prometheus/queries/deployment_query.rb
浏览文件 @
19812e3e
...
...
@@ -3,26 +3,27 @@ module Gitlab
module
Queries
class
DeploymentQuery
<
BaseQuery
def
query
(
deployment_id
)
deployment
=
Deployment
.
find_by
(
id:
deployment_id
)
environment_slug
=
deployment
.
environment
.
slug
Deployment
.
find_by
(
id:
deployment_id
).
try
do
|
deployment
|
environment_slug
=
deployment
.
environment
.
slug
memory_query
=
raw_memory_usage_query
(
environment_slug
)
memory_avg_query
=
%{avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="#{environment_slug}"}[30m]))}
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
cpu_avg_query
=
%{avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="#{environment_slug}"}[30m])) * 100}
memory_query
=
raw_memory_usage_query
(
environment_slug
)
memory_avg_query
=
%{avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="#{environment_slug}"}[30m]))}
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
cpu_avg_query
=
%{avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="#{environment_slug}"}[30m])) * 100}
timeframe_start
=
(
deployment
.
created_at
-
30
.
minutes
).
to_f
timeframe_end
=
(
deployment
.
created_at
+
30
.
minutes
).
to_f
timeframe_start
=
(
deployment
.
created_at
-
30
.
minutes
).
to_f
timeframe_end
=
(
deployment
.
created_at
+
30
.
minutes
).
to_f
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_before:
client_query
(
memory_avg_query
,
time:
deployment
.
created_at
.
to_f
),
memory_after:
client_query
(
memory_avg_query
,
time:
timeframe_end
),
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_before:
client_query
(
memory_avg_query
,
time:
deployment
.
created_at
.
to_f
),
memory_after:
client_query
(
memory_avg_query
,
time:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_before:
client_query
(
cpu_avg_query
,
time:
deployment
.
created_at
.
to_f
),
cpu_after:
client_query
(
cpu_avg_query
,
time:
timeframe_end
)
}
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_before:
client_query
(
cpu_avg_query
,
time:
deployment
.
created_at
.
to_f
),
cpu_after:
client_query
(
cpu_avg_query
,
time:
timeframe_end
)
}
end
end
end
end
...
...
lib/gitlab/prometheus/queries/environment_query.rb
浏览文件 @
19812e3e
...
...
@@ -3,20 +3,21 @@ module Gitlab
module
Queries
class
EnvironmentQuery
<
BaseQuery
def
query
(
environment_id
)
environment
=
Environment
.
find_by
(
id:
environment_id
)
environment_slug
=
environment
.
slug
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_end
=
Time
.
now
.
to_f
Environment
.
find_by
(
id:
environment_id
).
try
do
|
environment
|
environment_slug
=
environment
.
slug
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_end
=
Time
.
now
.
to_f
memory_query
=
raw_memory_usage_query
(
environment_slug
)
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
memory_query
=
raw_memory_usage_query
(
environment_slug
)
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_current:
client_query
(
memory_query
,
time:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_current:
client_query
(
cpu_query
,
time:
timeframe_end
)
}
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_current:
client_query
(
memory_query
,
time:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_current:
client_query
(
cpu_query
,
time:
timeframe_end
)
}
end
end
end
end
...
...
spec/controllers/projects/deployments_controller_spec.rb
浏览文件 @
19812e3e
...
...
@@ -141,7 +141,7 @@ describe Projects::DeploymentsController do
end
it
'returns a empty response 204 response'
do
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
)
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
,
format: :json
)
expect
(
response
).
to
have_http_status
(
204
)
expect
(
response
.
body
).
to
eq
(
''
)
end
...
...
@@ -161,7 +161,7 @@ describe Projects::DeploymentsController do
end
it
'returns a metrics JSON document'
do
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
)
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
,
format: :json
)
expect
(
response
).
to
be_ok
expect
(
json_response
[
'success'
]).
to
be
(
true
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录