summaryrefslogtreecommitdiff
path: root/spec/frontend/monitoring/fixture_data.js
blob: 97edf7bda743d044db30298c5185ce9549033333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { stateAndPropsFromDataset } from '~/monitoring/utils';
import { mapToDashboardViewModel } from '~/monitoring/stores/utils';
import { metricStates } from '~/monitoring/constants';
import { convertObjectProps } from '~/lib/utils/common_utils';
import { convertToCamelCase } from '~/lib/utils/text_utility';

import { metricsResult } from './mock_data';

// Use globally available `getJSONFixture` so this file can be imported by both karma and jest specs
export const metricsDashboardResponse = getJSONFixture(
  'metrics_dashboard/environment_metrics_dashboard.json',
);

export const metricsDashboardPayload = metricsDashboardResponse.dashboard;

const datasetState = stateAndPropsFromDataset(
  // It's preferable to have props in snake_case, this will be addressed at:
  // https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33574
  convertObjectProps(
    // Some props use kebab-case, convert to snake_case first
    key => convertToCamelCase(key.replace(/-/g, '_')),
    metricsDashboardResponse.metrics_data,
  ),
);

// new properties like addDashboardDocumentationPath prop and alertsEndpoint
// was recently added to dashboard.vue component this needs to be
// added to fixtures data
// https://gitlab.com/gitlab-org/gitlab/-/issues/229256
export const dashboardProps = {
  ...datasetState.dataProps,
  addDashboardDocumentationPath: 'https://path/to/docs',
  alertsEndpoint: null,
};

export const metricsDashboardViewModel = mapToDashboardViewModel(metricsDashboardPayload);

export const metricsDashboardPanelCount = 22;
export const metricResultStatus = {
  // First metric in fixture `metrics_dashboard/environment_metrics_dashboard.json`
  metricId: 'NO_DB_response_metrics_nginx_ingress_throughput_status_code',
  data: {
    resultType: 'matrix',
    result: metricsResult,
  },
};
export const metricResultPods = {
  // Second metric in fixture `metrics_dashboard/environment_metrics_dashboard.json`
  metricId: 'NO_DB_response_metrics_nginx_ingress_latency_pod_average',
  data: {
    resultType: 'matrix',
    result: metricsResult,
  },
};
export const metricResultEmpty = {
  metricId: 'NO_DB_response_metrics_nginx_ingress_16_throughput_status_code',
  data: {
    resultType: 'matrix',
    result: [],
  },
};

// Graph data

const firstPanel = metricsDashboardViewModel.panelGroups[0].panels[0];

export const graphData = {
  ...firstPanel,
  metrics: firstPanel.metrics.map(metric => ({
    ...metric,
    result: metricsResult,
    state: metricStates.OK,
  })),
};

export const graphDataEmpty = {
  ...firstPanel,
  metrics: firstPanel.metrics.map(metric => ({
    ...metric,
    result: [],
    state: metricStates.NO_DATA,
  })),
};