2020-01-01 13:55:28 +05:30
|
|
|
import * as getters from '~/monitoring/stores/getters';
|
|
|
|
import mutations from '~/monitoring/stores/mutations';
|
|
|
|
import * as types from '~/monitoring/stores/mutation_types';
|
|
|
|
import { metricStates } from '~/monitoring/constants';
|
|
|
|
import {
|
2020-03-13 15:44:24 +05:30
|
|
|
environmentData,
|
|
|
|
metricsDashboardPayload,
|
2020-01-01 13:55:28 +05:30
|
|
|
mockedEmptyResult,
|
|
|
|
mockedQueryResultPayload,
|
|
|
|
mockedQueryResultPayloadCoresTotal,
|
|
|
|
} from '../mock_data';
|
|
|
|
|
|
|
|
describe('Monitoring store Getters', () => {
|
|
|
|
describe('getMetricStates', () => {
|
|
|
|
let setupState;
|
|
|
|
let state;
|
|
|
|
let getMetricStates;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setupState = (initState = {}) => {
|
|
|
|
state = initState;
|
|
|
|
getMetricStates = getters.getMetricStates(state);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has method-style access', () => {
|
|
|
|
setupState();
|
|
|
|
|
|
|
|
expect(getMetricStates).toEqual(expect.any(Function));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when dashboard has no panel groups, returns empty', () => {
|
|
|
|
setupState({
|
|
|
|
dashboard: {
|
|
|
|
panel_groups: [],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(getMetricStates()).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the dashboard is set', () => {
|
|
|
|
let groups;
|
|
|
|
beforeEach(() => {
|
|
|
|
setupState({
|
|
|
|
dashboard: { panel_groups: [] },
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
groups = state.dashboard.panel_groups;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('no loaded metric returns empty', () => {
|
|
|
|
expect(getMetricStates()).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('on an empty metric with no result, returns NO_DATA', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedEmptyResult);
|
|
|
|
|
|
|
|
expect(getMetricStates()).toEqual([metricStates.NO_DATA]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('on a metric with a result, returns OK', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayload);
|
|
|
|
|
|
|
|
expect(getMetricStates()).toEqual([metricStates.OK]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('on a metric with an error, returns an error', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_FAILURE](state, {
|
|
|
|
metricId: groups[0].panels[0].metrics[0].metricId,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(getMetricStates()).toEqual([metricStates.UNKNOWN_ERROR]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('on multiple metrics with results, returns OK', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayload);
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayloadCoresTotal);
|
|
|
|
|
|
|
|
expect(getMetricStates()).toEqual([metricStates.OK]);
|
|
|
|
|
|
|
|
// Filtered by groups
|
|
|
|
expect(getMetricStates(state.dashboard.panel_groups[0].key)).toEqual([]);
|
|
|
|
expect(getMetricStates(state.dashboard.panel_groups[1].key)).toEqual([metricStates.OK]);
|
|
|
|
});
|
|
|
|
it('on multiple metrics errors', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_FAILURE](state, {
|
|
|
|
metricId: groups[0].panels[0].metrics[0].metricId,
|
|
|
|
});
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_FAILURE](state, {
|
|
|
|
metricId: groups[1].panels[0].metrics[0].metricId,
|
|
|
|
});
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_FAILURE](state, {
|
|
|
|
metricId: groups[1].panels[1].metrics[0].metricId,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Entire dashboard fails
|
|
|
|
expect(getMetricStates()).toEqual([metricStates.UNKNOWN_ERROR]);
|
|
|
|
expect(getMetricStates(groups[0].key)).toEqual([metricStates.UNKNOWN_ERROR]);
|
|
|
|
expect(getMetricStates(groups[1].key)).toEqual([metricStates.UNKNOWN_ERROR]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('on multiple metrics with errors', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
// An success in 1 group
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayload);
|
|
|
|
// An error in 2 groups
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_FAILURE](state, {
|
|
|
|
metricId: groups[0].panels[0].metrics[0].metricId,
|
|
|
|
});
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_FAILURE](state, {
|
|
|
|
metricId: groups[1].panels[1].metrics[0].metricId,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(getMetricStates()).toEqual([metricStates.OK, metricStates.UNKNOWN_ERROR]);
|
|
|
|
expect(getMetricStates(groups[0].key)).toEqual([metricStates.UNKNOWN_ERROR]);
|
|
|
|
expect(getMetricStates(groups[1].key)).toEqual([
|
|
|
|
metricStates.OK,
|
|
|
|
metricStates.UNKNOWN_ERROR,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('metricsWithData', () => {
|
|
|
|
let metricsWithData;
|
|
|
|
let setupState;
|
|
|
|
let state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setupState = (initState = {}) => {
|
|
|
|
state = initState;
|
|
|
|
metricsWithData = getters.metricsWithData(state);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
state = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has method-style access', () => {
|
|
|
|
setupState();
|
|
|
|
|
|
|
|
expect(metricsWithData).toEqual(expect.any(Function));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when dashboard has no panel groups, returns empty', () => {
|
|
|
|
setupState({
|
|
|
|
dashboard: {
|
|
|
|
panel_groups: [],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(metricsWithData()).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the dashboard is set', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setupState({
|
|
|
|
dashboard: { panel_groups: [] },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('no loaded metric returns empty', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
expect(metricsWithData()).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('an empty metric, returns empty', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedEmptyResult);
|
|
|
|
|
|
|
|
expect(metricsWithData()).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('a metric with results, it returns a metric', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayload);
|
|
|
|
|
|
|
|
expect(metricsWithData()).toEqual([mockedQueryResultPayload.metricId]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('multiple metrics with results, it return multiple metrics', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayload);
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayloadCoresTotal);
|
|
|
|
|
|
|
|
expect(metricsWithData()).toEqual([
|
|
|
|
mockedQueryResultPayload.metricId,
|
|
|
|
mockedQueryResultPayloadCoresTotal.metricId,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('multiple metrics with results, it returns metrics filtered by group', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mutations[types.RECEIVE_METRICS_DATA_SUCCESS](state, metricsDashboardPayload);
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayload);
|
|
|
|
mutations[types.RECEIVE_METRIC_RESULT_SUCCESS](state, mockedQueryResultPayloadCoresTotal);
|
|
|
|
|
|
|
|
// First group has no metrics
|
|
|
|
expect(metricsWithData(state.dashboard.panel_groups[0].key)).toEqual([]);
|
|
|
|
|
|
|
|
// Second group has metrics
|
|
|
|
expect(metricsWithData(state.dashboard.panel_groups[1].key)).toEqual([
|
|
|
|
mockedQueryResultPayload.metricId,
|
|
|
|
mockedQueryResultPayloadCoresTotal.metricId,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe('filteredEnvironments', () => {
|
|
|
|
let state;
|
|
|
|
const setupState = (initState = {}) => {
|
|
|
|
state = {
|
|
|
|
...state,
|
|
|
|
...initState,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
setupState({
|
|
|
|
environments: environmentData,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
state = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
input: '',
|
|
|
|
output: 17,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: ' ',
|
|
|
|
output: 17,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: null,
|
|
|
|
output: 17,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'does-not-exist',
|
|
|
|
output: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'noop-branch-',
|
|
|
|
output: 15,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: 'noop-branch-9',
|
|
|
|
output: 1,
|
|
|
|
},
|
|
|
|
].forEach(({ input, output }) => {
|
|
|
|
it(`filteredEnvironments returns ${output} items for ${input}`, () => {
|
|
|
|
setupState({
|
|
|
|
environmentsSearchTerm: input,
|
|
|
|
});
|
|
|
|
expect(getters.filteredEnvironments(state).length).toBe(output);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|