Commit 4f9551b8 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'adriel-use-echarts-metrics-dashboard' into 'master'

Use ECharts for metrics dashboard graphs

See merge request gitlab-org/gitlab-ce!24648
parents 357dba32 33cd912b
...@@ -35,13 +35,7 @@ export default { ...@@ -35,13 +35,7 @@ export default {
computed: { computed: {
chartData() { chartData() {
return this.graphData.queries.reduce((accumulator, query) => { return this.graphData.queries.reduce((accumulator, query) => {
const xLabel = `${query.unit}`; accumulator[query.unit] = query.result.reduce((acc, res) => acc.concat(res.values), []);
accumulator[xLabel] = {};
query.result.forEach(res =>
res.values.forEach(v => {
accumulator[xLabel][v.time.toISOString()] = v.value;
}),
);
return accumulator; return accumulator;
}, {}); }, {});
}, },
...@@ -51,14 +45,17 @@ export default { ...@@ -51,14 +45,17 @@ export default {
name: 'Time', name: 'Time',
type: 'time', type: 'time',
axisLabel: { axisLabel: {
formatter: date => dateFormat(date, 'h:MMtt'), formatter: date => dateFormat(date, 'h:MM TT'),
},
axisPointer: {
snap: true,
}, },
nameTextStyle: { nameTextStyle: {
padding: [18, 0, 0, 0], padding: [18, 0, 0, 0],
}, },
}, },
yAxis: { yAxis: {
name: this.graphData.y_label, name: this.yAxisLabel,
axisLabel: { axisLabel: {
formatter: value => value.toFixed(3), formatter: value => value.toFixed(3),
}, },
...@@ -74,6 +71,10 @@ export default { ...@@ -74,6 +71,10 @@ export default {
xAxisLabel() { xAxisLabel() {
return this.graphData.queries.map(query => query.label).join(', '); return this.graphData.queries.map(query => query.label).join(', ');
}, },
yAxisLabel() {
const [query] = this.graphData.queries;
return `${this.graphData.y_label} (${query.unit})`;
},
}, },
methods: { methods: {
formatTooltipText(params) { formatTooltipText(params) {
...@@ -85,7 +86,7 @@ export default { ...@@ -85,7 +86,7 @@ export default {
</script> </script>
<template> <template>
<div class="prometheus-graph"> <div class="prometheus-graph col-12 col-lg-6">
<div class="prometheus-graph-header"> <div class="prometheus-graph-header">
<h5 class="prometheus-graph-title">{{ graphData.title }}</h5> <h5 class="prometheus-graph-title">{{ graphData.title }}</h5>
<div class="prometheus-graph-widgets"><slot></slot></div> <div class="prometheus-graph-widgets"><slot></slot></div>
......
...@@ -13,7 +13,7 @@ function checkQueryEmptyData(query) { ...@@ -13,7 +13,7 @@ function checkQueryEmptyData(query) {
result: query.result.filter(timeSeries => { result: query.result.filter(timeSeries => {
const newTimeSeries = timeSeries; const newTimeSeries = timeSeries;
const hasValue = series => const hasValue = series =>
!Number.isNaN(series.value) && (series.value !== null || series.value !== undefined); !Number.isNaN(series[1]) && (series[1] !== null || series[1] !== undefined);
const hasNonNullValue = timeSeries.values.find(hasValue); const hasNonNullValue = timeSeries.values.find(hasValue);
newTimeSeries.values = hasNonNullValue ? newTimeSeries.values : []; newTimeSeries.values = hasNonNullValue ? newTimeSeries.values : [];
...@@ -33,10 +33,10 @@ function normalizeMetrics(metrics) { ...@@ -33,10 +33,10 @@ function normalizeMetrics(metrics) {
...query, ...query,
result: query.result.map(result => ({ result: query.result.map(result => ({
...result, ...result,
values: result.values.map(([timestamp, value]) => ({ values: result.values.map(([timestamp, value]) => [
time: new Date(timestamp * 1000), new Date(timestamp * 1000).toISOString(),
value: Number(value), Number(value),
})), ]),
})), })),
})); }));
......
...@@ -240,18 +240,7 @@ ...@@ -240,18 +240,7 @@
} }
.prometheus-graph { .prometheus-graph {
flex: 1 0 auto;
min-width: 450px;
max-width: 100%;
padding: $gl-padding / 2; padding: $gl-padding / 2;
h5 {
font-size: 16px;
}
@include media-breakpoint-down(sm) {
min-width: 100%;
}
} }
.prometheus-graph-header { .prometheus-graph-header {
...@@ -261,6 +250,7 @@ ...@@ -261,6 +250,7 @@
margin-bottom: $gl-padding-8; margin-bottom: $gl-padding-8;
h5 { h5 {
font-size: $gl-font-size-large;
margin: 0; margin: 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment