Commit 61dd3ada authored by Miguel Rincon's avatar Miguel Rincon Committed by Jose Vargas

Generate heatmap mock data

This change allows the test suite to generate heatmap mock data.
parent 2ec919be
......@@ -36,7 +36,7 @@ export default {
);
},
xAxisName() {
return this.graphData.x_label || '';
return this.graphData.xLabel || '';
},
yAxisName() {
return this.graphData.y_label || '';
......
......@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils';
import { GlHeatmap } from '@gitlab/ui/dist/charts';
import timezoneMock from 'timezone-mock';
import Heatmap from '~/monitoring/components/charts/heatmap.vue';
import { graphDataPrometheusQueryRangeMultiTrack } from '../../mock_data';
import { heatmapGraphData } from '../../graph_data';
describe('Heatmap component', () => {
let wrapper;
......@@ -10,10 +10,12 @@ describe('Heatmap component', () => {
const findChart = () => wrapper.find(GlHeatmap);
const graphData = heatmapGraphData();
const createWrapper = (props = {}) => {
wrapper = shallowMount(Heatmap, {
propsData: {
graphData: graphDataPrometheusQueryRangeMultiTrack,
graphData: heatmapGraphData(),
containerWidth: 100,
...props,
},
......@@ -38,11 +40,11 @@ describe('Heatmap component', () => {
});
it('should display a label on the x axis', () => {
expect(wrapper.vm.xAxisName).toBe(graphDataPrometheusQueryRangeMultiTrack.x_label);
expect(wrapper.vm.xAxisName).toBe(graphData.xLabel);
});
it('should display a label on the y axis', () => {
expect(wrapper.vm.yAxisName).toBe(graphDataPrometheusQueryRangeMultiTrack.y_label);
expect(wrapper.vm.yAxisName).toBe(graphData.y_label);
});
// According to the echarts docs https://echarts.apache.org/en/option.html#series-heatmap.data
......@@ -54,24 +56,24 @@ describe('Heatmap component', () => {
const row = wrapper.vm.chartData[0];
expect(row.length).toBe(3);
expect(wrapper.vm.chartData.length).toBe(30);
expect(wrapper.vm.chartData.length).toBe(6);
});
it('returns a series of labels for the x axis', () => {
const { xAxisLabels } = wrapper.vm;
expect(xAxisLabels.length).toBe(5);
expect(xAxisLabels.length).toBe(2);
});
describe('y axis labels', () => {
const gmtLabels = ['3:00 PM', '4:00 PM', '5:00 PM', '6:00 PM', '7:00 PM', '8:00 PM'];
const gmtLabels = ['8:10 PM', '8:12 PM', '8:14 PM'];
it('y-axis labels are formatted in AM/PM format', () => {
expect(findChart().props('yAxisLabels')).toEqual(gmtLabels);
});
describe('when in PT timezone', () => {
const ptLabels = ['8:00 AM', '9:00 AM', '10:00 AM', '11:00 AM', '12:00 PM', '1:00 PM'];
const ptLabels = ['1:10 PM', '1:12 PM', '1:14 PM'];
const utcLabels = gmtLabels; // Identical in this case
beforeAll(() => {
......
......@@ -14,11 +14,10 @@ import {
mockNamespace,
mockNamespacedData,
mockTimeRange,
graphDataPrometheusQueryRangeMultiTrack,
barMockData,
} from '../mock_data';
import { dashboardProps, graphData, graphDataEmpty } from '../fixture_data';
import { anomalyGraphData, singleStatGraphData } from '../graph_data';
import { anomalyGraphData, singleStatGraphData, heatmapGraphData } from '../graph_data';
import { panelTypes } from '~/monitoring/constants';
......@@ -235,7 +234,7 @@ describe('Dashboard Panel', () => {
${anomalyGraphData()} | ${MonitorAnomalyChart} | ${false}
${dataWithType(panelTypes.COLUMN)} | ${MonitorColumnChart} | ${false}
${dataWithType(panelTypes.STACKED_COLUMN)} | ${MonitorStackedColumnChart} | ${false}
${graphDataPrometheusQueryRangeMultiTrack} | ${MonitorHeatmapChart} | ${false}
${heatmapGraphData()} | ${MonitorHeatmapChart} | ${false}
${barMockData} | ${MonitorBarChart} | ${false}
`('when $data.type data is provided', ({ data, component, hasCtxMenu }) => {
const attrs = { attr1: 'attr1Value', attr2: 'attr2Value' };
......@@ -523,7 +522,7 @@ describe('Dashboard Panel', () => {
});
it('displays a heatmap in local timezone', () => {
createWrapper({ graphData: graphDataPrometheusQueryRangeMultiTrack });
createWrapper({ graphData: heatmapGraphData() });
expect(wrapper.find(MonitorHeatmapChart).props('timezone')).toBe('LOCAL');
});
......@@ -538,7 +537,7 @@ describe('Dashboard Panel', () => {
});
it('displays a heatmap with UTC', () => {
createWrapper({ graphData: graphDataPrometheusQueryRangeMultiTrack });
createWrapper({ graphData: heatmapGraphData() });
expect(wrapper.find(MonitorHeatmapChart).props('timezone')).toBe('UTC');
});
});
......
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]);
// Normalized Prometheus Responses
......@@ -162,3 +163,23 @@ 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,
});
};
......@@ -244,83 +244,6 @@ export const metricsResult = [
},
];
export const graphDataPrometheusQueryRangeMultiTrack = {
title: 'Super Chart A3',
type: 'heatmap',
weight: 3,
x_label: 'Status Code',
y_label: 'Time',
metrics: [
{
metricId: '1_metric_b',
id: 'response_metrics_nginx_ingress_throughput_status_code',
query_range:
'sum(rate(nginx_upstream_responses_total{upstream=~"%{kube_namespace}-%{ci_environment_slug}-.*"}[60m])) by (status_code)',
unit: 'req / sec',
label: 'Status Code',
prometheus_endpoint_path:
'/root/rails_nodb/environments/3/prometheus/api/v1/query_range?query=sum%28rate%28nginx_upstream_responses_total%7Bupstream%3D~%22%25%7Bkube_namespace%7D-%25%7Bci_environment_slug%7D-.%2A%22%7D%5B2m%5D%29%29+by+%28status_code%29',
result: [
{
metric: { status_code: '1xx' },
values: [
['2019-08-30T15:00:00.000Z', 0],
['2019-08-30T16:00:00.000Z', 2],
['2019-08-30T17:00:00.000Z', 0],
['2019-08-30T18:00:00.000Z', 0],
['2019-08-30T19:00:00.000Z', 0],
['2019-08-30T20:00:00.000Z', 3],
],
},
{
metric: { status_code: '2xx' },
values: [
['2019-08-30T15:00:00.000Z', 1],
['2019-08-30T16:00:00.000Z', 3],
['2019-08-30T17:00:00.000Z', 6],
['2019-08-30T18:00:00.000Z', 10],
['2019-08-30T19:00:00.000Z', 8],
['2019-08-30T20:00:00.000Z', 6],
],
},
{
metric: { status_code: '3xx' },
values: [
['2019-08-30T15:00:00.000Z', 1],
['2019-08-30T16:00:00.000Z', 2],
['2019-08-30T17:00:00.000Z', 3],
['2019-08-30T18:00:00.000Z', 3],
['2019-08-30T19:00:00.000Z', 2],
['2019-08-30T20:00:00.000Z', 1],
],
},
{
metric: { status_code: '4xx' },
values: [
['2019-08-30T15:00:00.000Z', 2],
['2019-08-30T16:00:00.000Z', 0],
['2019-08-30T17:00:00.000Z', 0],
['2019-08-30T18:00:00.000Z', 2],
['2019-08-30T19:00:00.000Z', 0],
['2019-08-30T20:00:00.000Z', 2],
],
},
{
metric: { status_code: '5xx' },
values: [
['2019-08-30T15:00:00.000Z', 0],
['2019-08-30T16:00:00.000Z', 1],
['2019-08-30T17:00:00.000Z', 0],
['2019-08-30T18:00:00.000Z', 0],
['2019-08-30T19:00:00.000Z', 0],
['2019-08-30T20:00:00.000Z', 2],
],
},
],
},
],
};
export const stackedColumnMockedData = {
title: 'memories',
type: 'stacked-column',
......
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