From ae1f0cc737422bf17b440f5e8a33c03c60ea75f8 Mon Sep 17 00:00:00 2001 From: syasonik Date: Thu, 21 Feb 2019 16:31:48 +0800 Subject: Support multiple queries per chart on metrics dash Adding support for metrics alerts disabled multiple query support. To avoid a data model refactor, this enables the visual of multiple queries per chart on the front end, combining queries based on metric group, title, and y-axis label. This also adds support for adding and editing alerts based on the query selected rather than the single metric associated with the chart. --- .../monitoring/components/charts/area.vue | 14 +++++--- .../monitoring/components/dashboard.vue | 20 ++++++----- .../monitoring/stores/monitoring_store.js | 39 +++++++++++++++++++++- .../unreleased/minimized-multiple-queries-ce.yml | 5 +++ package.json | 2 +- spec/javascripts/monitoring/charts/area_spec.js | 7 ++-- yarn.lock | 8 ++--- 7 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 changelogs/unreleased/minimized-multiple-queries-ce.yml diff --git a/app/assets/javascripts/monitoring/components/charts/area.vue b/app/assets/javascripts/monitoring/components/charts/area.vue index b0bbe272d1f..eb2ab3e135e 100644 --- a/app/assets/javascripts/monitoring/components/charts/area.vue +++ b/app/assets/javascripts/monitoring/components/charts/area.vue @@ -42,10 +42,10 @@ export default { required: false, default: () => [], }, - alertData: { - type: Object, + thresholds: { + type: Array, required: false, - default: () => ({}), + default: () => [], }, }, data() { @@ -64,6 +64,9 @@ export default { }, computed: { chartData() { + // Transforms & supplements query data to render appropriate labels & styles + // Input: [{ queryAttributes1 }, { queryAttributes2 }] + // Output: [{ seriesAttributes1 }, { seriesAttributes2 }] return this.graphData.queries.reduce((acc, query) => { const { appearance } = query; const lineType = @@ -121,6 +124,9 @@ export default { }, earliestDatapoint() { return this.chartData.reduce((acc, series) => { + if (!series.data.length) { + return acc; + } const [[timestamp]] = series.data.sort(([a], [b]) => { if (a < b) { return -1; @@ -235,7 +241,7 @@ export default { :data="chartData" :option="chartOptions" :format-tooltip-text="formatTooltipText" - :thresholds="alertData" + :thresholds="thresholds" :width="width" :height="height" @updated="onChartUpdated" diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue index ba6a17827f7..f5019bc627e 100644 --- a/app/assets/javascripts/monitoring/components/dashboard.vue +++ b/app/assets/javascripts/monitoring/components/dashboard.vue @@ -1,5 +1,6 @@