debian-mirror-gitlab/app/assets/javascripts/monitoring/stores/mutations.js

107 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import Vue from 'vue';
2019-12-26 22:10:19 +05:30
import { slugify } from '~/lib/utils/text_utility';
2019-09-04 21:01:54 +05:30
import * as types from './mutation_types';
2019-12-26 22:10:19 +05:30
import { normalizeMetrics, normalizeMetric, normalizeQueryResult } from './utils';
2019-12-21 20:55:43 +05:30
const normalizePanel = panel => panel.metrics.map(normalizeMetric);
2019-09-04 21:01:54 +05:30
export default {
[types.REQUEST_METRICS_DATA](state) {
state.emptyState = 'loading';
state.showEmptyState = true;
},
[types.RECEIVE_METRICS_DATA_SUCCESS](state, groupData) {
2019-12-26 22:10:19 +05:30
state.dashboard.panel_groups = groupData.map((group, i) => {
const key = `${slugify(group.group || 'default')}-${i}`;
2019-12-21 20:55:43 +05:30
let { metrics = [], panels = [] } = group;
// each panel has metric information that needs to be normalized
2019-12-26 22:10:19 +05:30
2019-12-21 20:55:43 +05:30
panels = panels.map(panel => ({
...panel,
metrics: normalizePanel(panel),
}));
2019-09-04 21:01:54 +05:30
// for backwards compatibility, and to limit Vue template changes:
// for each group alias panels to metrics
// for each panel alias metrics to queries
2019-12-26 22:10:19 +05:30
metrics = panels.map(panel => ({
...panel,
queries: panel.metrics,
}));
2019-09-04 21:01:54 +05:30
return {
...group,
2019-12-21 20:55:43 +05:30
panels,
2019-12-26 22:10:19 +05:30
key,
metrics: normalizeMetrics(metrics),
2019-09-04 21:01:54 +05:30
};
});
2019-12-26 22:10:19 +05:30
if (!state.dashboard.panel_groups.length) {
2019-09-04 21:01:54 +05:30
state.emptyState = 'noData';
}
},
[types.RECEIVE_METRICS_DATA_FAILURE](state, error) {
state.emptyState = error ? 'unableToConnect' : 'noData';
state.showEmptyState = true;
},
[types.RECEIVE_DEPLOYMENTS_DATA_SUCCESS](state, deployments) {
state.deploymentData = deployments;
},
[types.RECEIVE_DEPLOYMENTS_DATA_FAILURE](state) {
state.deploymentData = [];
},
[types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS](state, environments) {
state.environments = environments;
},
[types.RECEIVE_ENVIRONMENTS_DATA_FAILURE](state) {
state.environments = [];
},
[types.SET_QUERY_RESULT](state, { metricId, result }) {
if (!metricId || !result || result.length === 0) {
return;
}
state.showEmptyState = false;
2019-12-26 22:10:19 +05:30
state.dashboard.panel_groups.forEach(group => {
2019-09-04 21:01:54 +05:30
group.metrics.forEach(metric => {
metric.queries.forEach(query => {
if (query.metric_id === metricId) {
state.metricsWithData.push(metricId);
// ensure dates/numbers are correctly formatted for charts
const normalizedResults = result.map(normalizeQueryResult);
Vue.set(query, 'result', Object.freeze(normalizedResults));
}
});
});
});
},
[types.SET_ENDPOINTS](state, endpoints) {
state.metricsEndpoint = endpoints.metricsEndpoint;
state.environmentsEndpoint = endpoints.environmentsEndpoint;
state.deploymentsEndpoint = endpoints.deploymentsEndpoint;
state.dashboardEndpoint = endpoints.dashboardEndpoint;
2019-09-30 21:07:59 +05:30
state.currentDashboard = endpoints.currentDashboard;
state.projectPath = endpoints.projectPath;
2019-09-04 21:01:54 +05:30
},
[types.SET_GETTING_STARTED_EMPTY_STATE](state) {
state.emptyState = 'gettingStarted';
},
[types.SET_NO_DATA_EMPTY_STATE](state) {
state.showEmptyState = true;
state.emptyState = 'noData';
},
2019-09-30 21:07:59 +05:30
[types.SET_ALL_DASHBOARDS](state, dashboards) {
2019-12-26 22:10:19 +05:30
state.allDashboards = dashboards || [];
2019-09-30 21:07:59 +05:30
},
2019-10-12 21:52:04 +05:30
[types.SET_SHOW_ERROR_BANNER](state, enabled) {
state.showErrorBanner = enabled;
},
2019-12-26 22:10:19 +05:30
[types.SET_PANEL_GROUP_METRICS](state, payload) {
const panelGroup = state.dashboard.panel_groups.find(pg => payload.key === pg.key);
panelGroup.metrics = payload.metrics;
},
2019-09-04 21:01:54 +05:30
};