diff options
Diffstat (limited to 'spec/frontend/monitoring/graph_data.js')
-rw-r--r-- | spec/frontend/monitoring/graph_data.js | 92 |
1 files changed, 88 insertions, 4 deletions
diff --git a/spec/frontend/monitoring/graph_data.js b/spec/frontend/monitoring/graph_data.js index e1b95723f3d..f85351e55d7 100644 --- a/spec/frontend/monitoring/graph_data.js +++ b/spec/frontend/monitoring/graph_data.js @@ -1,10 +1,38 @@ import { mapPanelToViewModel, normalizeQueryResponseData } from '~/monitoring/stores/utils'; import { panelTypes, metricStates } from '~/monitoring/constants'; -const initTime = 1435781451.781; +const initTime = 1435781450; // "Wed, 01 Jul 2015 20:10:50 GMT" +const intervalSeconds = 120; const makeValue = val => [initTime, val]; -const makeValues = vals => vals.map((val, i) => [initTime + 15 * i, val]); +const makeValues = vals => vals.map((val, i) => [initTime + intervalSeconds * i, val]); + +// Raw Promethues Responses + +export const prometheusMatrixMultiResult = ({ + values1 = ['1', '2', '3'], + values2 = ['4', '5', '6'], +} = {}) => ({ + resultType: 'matrix', + result: [ + { + metric: { + __name__: 'up', + job: 'prometheus', + instance: 'localhost:9090', + }, + values: makeValues(values1), + }, + { + metric: { + __name__: 'up', + job: 'node', + instance: 'localhost:9091', + }, + values: makeValues(values2), + }, + ], +}); // Normalized Prometheus Responses @@ -82,7 +110,7 @@ const matrixMultiResult = ({ values1 = ['1', '2', '3'], values2 = ['4', '5', '6' * @param {Object} dataOptions.isMultiSeries */ export const timeSeriesGraphData = (panelOptions = {}, dataOptions = {}) => { - const { metricCount = 1, isMultiSeries = false } = dataOptions; + const { metricCount = 1, isMultiSeries = false, withLabels = true } = dataOptions; return mapPanelToViewModel({ title: 'Time Series Panel', @@ -90,7 +118,7 @@ export const timeSeriesGraphData = (panelOptions = {}, dataOptions = {}) => { x_label: 'X Axis', y_label: 'Y Axis', metrics: Array.from(Array(metricCount), (_, i) => ({ - label: `Metric ${i + 1}`, + label: withLabels ? `Metric ${i + 1}` : undefined, state: metricStates.OK, result: isMultiSeries ? matrixMultiResult() : matrixSingleResult(), })), @@ -162,3 +190,59 @@ export const anomalyGraphData = (panelOptions = {}, dataOptions = {}) => { ...panelOptions, }); }; + +/** + * Generate mock graph data for heatmaps according to options + */ +export const heatmapGraphData = (panelOptions = {}, dataOptions = {}) => { + const { metricCount = 1 } = dataOptions; + + return mapPanelToViewModel({ + title: 'Heatmap Panel', + type: panelTypes.HEATMAP, + x_label: 'X Axis', + y_label: 'Y Axis', + metrics: Array.from(Array(metricCount), (_, i) => ({ + label: `Metric ${i + 1}`, + state: metricStates.OK, + result: matrixMultiResult(), + })), + ...panelOptions, + }); +}; + +/** + * Generate gauge chart mock graph data according to options + * + * @param {Object} panelOptions - Panel options as in YML. + * + */ +export const gaugeChartGraphData = (panelOptions = {}) => { + const { + minValue = 100, + maxValue = 1000, + split = 20, + thresholds = { + mode: 'absolute', + values: [500, 800], + }, + format = 'kilobytes', + } = panelOptions; + + return mapPanelToViewModel({ + title: 'Gauge Chart Panel', + type: panelTypes.GAUGE_CHART, + min_value: minValue, + max_value: maxValue, + split, + thresholds, + format, + metrics: [ + { + label: `Metric`, + state: metricStates.OK, + result: matrixSingleResult(), + }, + ], + }); +}; |