Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
1f5ae8cd
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,发现更多精彩内容 >>
提交
1f5ae8cd
编写于
9月 13, 2017
作者:
P
Phil Hughes
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'refactor-monitoring-service' into 'master'
Refactor MonitoringService class See merge request !14003
上级
7771afd5
70e9e884
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
54 deletion
+61
-54
app/assets/javascripts/monitoring/components/dashboard.vue
app/assets/javascripts/monitoring/components/dashboard.vue
+14
-47
app/assets/javascripts/monitoring/services/monitoring_service.js
...ets/javascripts/monitoring/services/monitoring_service.js
+42
-7
changelogs/unreleased/refactor-monitoring-service.yml
changelogs/unreleased/refactor-monitoring-service.yml
+5
-0
未找到文件。
app/assets/javascripts/monitoring/components/dashboard.vue
浏览文件 @
1f5ae8cd
<
script
>
/* global Flash */
import
_
from
'
underscore
'
;
import
statusCodes
from
'
../../lib/utils/http_status
'
;
import
MonitoringService
from
'
../services/monitoring_service
'
;
import
GraphGroup
from
'
./graph_group.vue
'
;
import
Graph
from
'
./graph.vue
'
;
...
...
@@ -21,10 +20,9 @@
hasMetrics
:
gl
.
utils
.
convertPermissionToBoolean
(
metricsData
.
hasMetrics
),
documentationPath
:
metricsData
.
documentationPath
,
settingsPath
:
metricsData
.
settingsPath
,
e
ndpoint
:
metricsData
.
additionalMetrics
,
metricsE
ndpoint
:
metricsData
.
additionalMetrics
,
deploymentEndpoint
:
metricsData
.
deploymentEndpoint
,
showEmptyState
:
true
,
backOffRequestCounter
:
0
,
updateAspectRatio
:
false
,
updatedAspectRatios
:
0
,
resizeThrottled
:
{},
...
...
@@ -39,50 +37,16 @@
methods
:
{
getGraphsData
()
{
const
maxNumberOfRequests
=
3
;
this
.
state
=
'
loading
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
{
this
.
service
.
get
().
then
((
resp
)
=>
{
if
(
resp
.
status
===
statusCodes
.
NO_CONTENT
)
{
this
.
backOffRequestCounter
=
this
.
backOffRequestCounter
+=
1
;
if
(
this
.
backOffRequestCounter
<
maxNumberOfRequests
)
{
next
();
}
else
{
stop
(
new
Error
(
'
Failed to connect to the prometheus server
'
));
}
}
else
{
stop
(
resp
);
}
}).
catch
(
stop
);
})
.
then
((
resp
)
=>
{
if
(
resp
.
status
===
statusCodes
.
NO_CONTENT
)
{
this
.
state
=
'
unableToConnect
'
;
return
false
;
}
return
resp
.
json
();
})
.
then
((
metricGroupsData
)
=>
{
if
(
!
metricGroupsData
)
return
false
;
this
.
store
.
storeMetrics
(
metricGroupsData
.
data
);
return
this
.
getDeploymentData
();
})
.
then
((
deploymentData
)
=>
{
if
(
deploymentData
!==
false
)
{
this
.
store
.
storeDeploymentData
(
deploymentData
.
deployments
);
this
.
showEmptyState
=
false
;
}
return
{};
})
.
catch
(()
=>
{
this
.
state
=
'
unableToConnect
'
;
});
},
getDeploymentData
()
{
return
this
.
service
.
getDeploymentData
(
this
.
deploymentEndpoint
)
.
then
(
resp
=>
resp
.
json
())
.
catch
(()
=>
new
Flash
(
'
Error getting deployment information.
'
));
Promise
.
all
([
this
.
service
.
getGraphsData
()
.
then
(
data
=>
this
.
store
.
storeMetrics
(
data
)),
this
.
service
.
getDeploymentData
()
.
then
(
data
=>
this
.
store
.
storeDeploymentData
(
data
))
.
catch
(()
=>
new
Flash
(
'
Error getting deployment information.
'
)),
])
.
then
(()
=>
{
this
.
showEmptyState
=
false
;
})
.
catch
(()
=>
{
this
.
state
=
'
unableToConnect
'
;
});
},
resize
()
{
...
...
@@ -99,7 +63,10 @@
},
created
()
{
this
.
service
=
new
MonitoringService
(
this
.
endpoint
);
this
.
service
=
new
MonitoringService
({
metricsEndpoint
:
this
.
metricsEndpoint
,
deploymentEndpoint
:
this
.
deploymentEndpoint
,
});
eventHub
.
$on
(
'
toggleAspectRatio
'
,
this
.
toggleAspectRatio
);
},
...
...
app/assets/javascripts/monitoring/services/monitoring_service.js
浏览文件 @
1f5ae8cd
import
Vue
from
'
vue
'
;
import
VueResource
from
'
vue-resource
'
;
import
statusCodes
from
'
../../lib/utils/http_status
'
;
Vue
.
use
(
VueResource
);
const
MAX_REQUESTS
=
3
;
function
backOffRequest
(
makeRequestCallback
)
{
let
requestCounter
=
0
;
return
gl
.
utils
.
backOff
((
next
,
stop
)
=>
{
makeRequestCallback
().
then
((
resp
)
=>
{
if
(
resp
.
status
===
statusCodes
.
NO_CONTENT
)
{
requestCounter
+=
1
;
if
(
requestCounter
<
MAX_REQUESTS
)
{
next
();
}
else
{
stop
(
new
Error
(
'
Failed to connect to the prometheus server
'
));
}
}
else
{
stop
(
resp
);
}
}).
catch
(
stop
);
});
}
export
default
class
MonitoringService
{
constructor
(
endpoint
)
{
this
.
graphs
=
Vue
.
resource
(
endpoint
);
constructor
({
metricsEndpoint
,
deploymentEndpoint
})
{
this
.
metricsEndpoint
=
metricsEndpoint
;
this
.
deploymentEndpoint
=
deploymentEndpoint
;
}
get
()
{
return
this
.
graphs
.
get
();
getGraphsData
()
{
return
backOffRequest
(()
=>
Vue
.
http
.
get
(
this
.
metricsEndpoint
))
.
then
(
resp
=>
resp
.
json
())
.
then
((
response
)
=>
{
if
(
!
response
||
!
response
.
data
)
{
throw
new
Error
(
'
Unexpected metrics data response from prometheus endpoint
'
);
}
return
response
.
data
;
});
}
// eslint-disable-next-line class-methods-use-this
getDeploymentData
(
endpoint
)
{
return
Vue
.
http
.
get
(
endpoint
);
getDeploymentData
()
{
return
backOffRequest
(()
=>
Vue
.
http
.
get
(
this
.
deploymentEndpoint
))
.
then
(
resp
=>
resp
.
json
())
.
then
((
response
)
=>
{
if
(
!
response
||
!
response
.
deployments
)
{
throw
new
Error
(
'
Unexpected deployment data response from prometheus endpoint
'
);
}
return
response
.
deployments
;
});
}
}
changelogs/unreleased/refactor-monitoring-service.yml
0 → 100644
浏览文件 @
1f5ae8cd
---
title
:
Perform prometheus data endpoint requests in parallel
merge_request
:
14003
author
:
type
:
fixed
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录