Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
069783b5
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,体验更适合开发者的 AI 搜索 >>
提交
069783b5
编写于
5月 29, 2017
作者:
K
Kushal Pandya
提交者:
Filipa Lacerda
5月 29, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add performance deltas between app deployments on Merge Request widget
上级
437bb928
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
104 addition
and
14 deletion
+104
-14
app/assets/javascripts/lib/utils/number_utils.js
app/assets/javascripts/lib/utils/number_utils.js
+10
-0
app/assets/javascripts/vue_merge_request_widget/components/mr_widget_memory_usage.js
...merge_request_widget/components/mr_widget_memory_usage.js
+33
-11
changelogs/unreleased/27439-memory-usage-info.yml
changelogs/unreleased/27439-memory-usage-info.yml
+4
-0
spec/javascripts/lib/utils/number_utility_spec.js
spec/javascripts/lib/utils/number_utility_spec.js
+8
-1
spec/javascripts/vue_mr_widget/components/mr_widget_memory_usage_spec.js
...s/vue_mr_widget/components/mr_widget_memory_usage_spec.js
+49
-2
未找到文件。
app/assets/javascripts/lib/utils/number_utils.js
浏览文件 @
069783b5
...
...
@@ -42,3 +42,13 @@ export function formatRelevantDigits(number) {
export
function
bytesToKiB
(
number
)
{
return
number
/
BYTES_IN_KIB
;
}
/**
* Utility function that calculates MiB of the given bytes.
*
* @param {Number} number bytes
* @return {Number} MiB
*/
export
function
bytesToMiB
(
number
)
{
return
number
/
(
BYTES_IN_KIB
*
BYTES_IN_KIB
);
}
app/assets/javascripts/vue_merge_request_widget/components/mr_widget_memory_usage.js
浏览文件 @
069783b5
import
statusCodes
from
'
~/lib/utils/http_status
'
;
import
{
bytesToMiB
}
from
'
~/lib/utils/number_utils
'
;
import
MemoryGraph
from
'
../../vue_shared/components/memory_graph
'
;
import
MRWidgetService
from
'
../services/mr_widget_service
'
;
...
...
@@ -9,8 +11,8 @@ export default {
},
data
()
{
return
{
//
memoryFrom: 0,
//
memoryTo: 0,
memoryFrom
:
0
,
memoryTo
:
0
,
memoryMetrics
:
[],
deploymentTime
:
0
,
hasMetrics
:
false
,
...
...
@@ -35,18 +37,38 @@ export default {
shouldShowMetricsUnavailable
()
{
return
!
this
.
loadingMetrics
&&
!
this
.
hasMetrics
&&
!
this
.
loadFailed
;
},
memoryChangeType
()
{
const
memoryTo
=
Number
(
this
.
memoryTo
);
const
memoryFrom
=
Number
(
this
.
memoryFrom
);
if
(
memoryTo
>
memoryFrom
)
{
return
'
increased
'
;
}
else
if
(
memoryTo
<
memoryFrom
)
{
return
'
decreased
'
;
}
return
'
unchanged
'
;
},
},
methods
:
{
getMegabytes
(
bytesString
)
{
const
valueInBytes
=
Number
(
bytesString
).
toFixed
(
2
);
return
(
bytesToMiB
(
valueInBytes
)).
toFixed
(
2
);
},
computeGraphData
(
metrics
,
deploymentTime
)
{
this
.
loadingMetrics
=
false
;
const
{
memory_values
}
=
metrics
;
// if (memory_previous.length > 0) {
// this.memoryFrom = Number(memory_previous[0].value[1]).toFixed(2);
// }
//
// if (memory_current.length > 0) {
// this.memoryTo = Number(memory_current[0].value[1]).toFixed(2);
// }
const
{
memory_before
,
memory_after
,
memory_values
}
=
metrics
;
// Both `memory_before` and `memory_after` objects
// have peculiar structure where accessing only a specific
// index yeilds correct value that we can use to show memory delta.
if
(
memory_before
.
length
>
0
)
{
this
.
memoryFrom
=
this
.
getMegabytes
(
memory_before
[
0
].
value
[
1
]);
}
if
(
memory_after
.
length
>
0
)
{
this
.
memoryTo
=
this
.
getMegabytes
(
memory_after
[
0
].
value
[
1
]);
}
if
(
memory_values
.
length
>
0
)
{
this
.
hasMetrics
=
true
;
...
...
@@ -102,7 +124,7 @@ export default {
<p
v-if="shouldShowMemoryGraph"
class="usage-info js-usage-info">
Deployment memory usage:
Memory usage <b>{{memoryChangeType}}</b> from {{memoryFrom}}MB to {{memoryTo}}MB
</p>
<p
v-if="shouldShowLoadFailure"
...
...
changelogs/unreleased/27439-memory-usage-info.yml
0 → 100644
浏览文件 @
069783b5
---
title
:
Add performance deltas between app deployments on Merge Request widget
merge_request
:
11730
author
:
spec/javascripts/lib/utils/number_utility_spec.js
浏览文件 @
069783b5
import
{
formatRelevantDigits
,
bytesToKiB
}
from
'
~/lib/utils/number_utils
'
;
import
{
formatRelevantDigits
,
bytesToKiB
,
bytesToMiB
}
from
'
~/lib/utils/number_utils
'
;
describe
(
'
Number Utils
'
,
()
=>
{
describe
(
'
formatRelevantDigits
'
,
()
=>
{
...
...
@@ -45,4 +45,11 @@ describe('Number Utils', () => {
expect
(
bytesToKiB
(
1000
)).
toEqual
(
0.9765625
);
});
});
describe
(
'
bytesToMiB
'
,
()
=>
{
it
(
'
calculates MiB for the given bytes
'
,
()
=>
{
expect
(
bytesToMiB
(
1048576
)).
toEqual
(
1
);
expect
(
bytesToMiB
(
1000000
)).
toEqual
(
0.95367431640625
);
});
});
});
spec/javascripts/vue_mr_widget/components/mr_widget_memory_usage_spec.js
浏览文件 @
069783b5
...
...
@@ -7,6 +7,18 @@ const url = '/root/acets-review-apps/environments/15/deployments/1/metrics';
const
metricsMockData
=
{
success
:
true
,
metrics
:
{
memory_before
:
[
{
metric
:
{},
value
:
[
1495785220.607
,
'
9572875.906976745
'
],
},
],
memory_after
:
[
{
metric
:
{},
value
:
[
1495787020.607
,
'
4485853.130206379
'
],
},
],
memory_values
:
[
{
metric
:
{},
...
...
@@ -39,7 +51,7 @@ const createComponent = () => {
const
messages
=
{
loadingMetrics
:
'
Loading deployment statistics.
'
,
hasMetrics
:
'
Deployment memory usage:
'
,
hasMetrics
:
'
Memory usage unchanged from 0MB to 0MB
'
,
loadFailed
:
'
Failed to load deployment statistics.
'
,
metricsUnavailable
:
'
Deployment statistics are not available currently.
'
,
};
...
...
@@ -89,17 +101,52 @@ describe('MemoryUsage', () => {
});
});
describe
(
'
computed
'
,
()
=>
{
describe
(
'
memoryChangeType
'
,
()
=>
{
it
(
'
should return "increased" if memoryFrom value is less than memoryTo value
'
,
()
=>
{
vm
.
memoryFrom
=
4.28
;
vm
.
memoryTo
=
9.13
;
expect
(
vm
.
memoryChangeType
).
toEqual
(
'
increased
'
);
});
it
(
'
should return "decreased" if memoryFrom value is less than memoryTo value
'
,
()
=>
{
vm
.
memoryFrom
=
9.13
;
vm
.
memoryTo
=
4.28
;
expect
(
vm
.
memoryChangeType
).
toEqual
(
'
decreased
'
);
});
it
(
'
should return "unchanged" if memoryFrom value equal to memoryTo value
'
,
()
=>
{
vm
.
memoryFrom
=
1
;
vm
.
memoryTo
=
1
;
expect
(
vm
.
memoryChangeType
).
toEqual
(
'
unchanged
'
);
});
});
});
describe
(
'
methods
'
,
()
=>
{
const
{
metrics
,
deployment_time
}
=
metricsMockData
;
describe
(
'
getMegabytes
'
,
()
=>
{
it
(
'
should return Megabytes from provided Bytes value
'
,
()
=>
{
const
memoryInBytes
=
'
9572875.906976745
'
;
expect
(
vm
.
getMegabytes
(
memoryInBytes
)).
toEqual
(
'
9.13
'
);
});
});
describe
(
'
computeGraphData
'
,
()
=>
{
it
(
'
should populate sparkline graph
'
,
()
=>
{
vm
.
computeGraphData
(
metrics
,
deployment_time
);
const
{
hasMetrics
,
memoryMetrics
,
deploymentTime
}
=
vm
;
const
{
hasMetrics
,
memoryMetrics
,
deploymentTime
,
memoryFrom
,
memoryTo
}
=
vm
;
expect
(
hasMetrics
).
toBeTruthy
();
expect
(
memoryMetrics
.
length
>
0
).
toBeTruthy
();
expect
(
deploymentTime
).
toEqual
(
deployment_time
);
expect
(
memoryFrom
).
toEqual
(
'
9.13
'
);
expect
(
memoryTo
).
toEqual
(
'
4.28
'
);
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录