diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-23 21:10:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-23 21:10:19 +0300 |
commit | b8d021cb606ac86f41a0ef9dacd133a9677f8414 (patch) | |
tree | aee1c216ff06acc7e3587a9a28af95f0392734f4 /app/assets/javascripts/monitoring | |
parent | 9dbca64417abbec779a219b9e0df9d289d945032 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/monitoring')
3 files changed, 56 insertions, 49 deletions
diff --git a/app/assets/javascripts/monitoring/components/charts/anomaly.vue b/app/assets/javascripts/monitoring/components/charts/anomaly.vue index ac401c6e381..14483fe04de 100644 --- a/app/assets/javascripts/monitoring/components/charts/anomaly.vue +++ b/app/assets/javascripts/monitoring/components/charts/anomaly.vue @@ -1,4 +1,5 @@ <script> +import produce from 'immer'; import { flattenDeep, isNumber } from 'lodash'; import { GlChartSeriesLabel } from '@gitlab/ui/dist/charts'; import { roundOffFloat } from '~/lib/utils/common_utils'; @@ -84,11 +85,13 @@ export default { metricData() { const originalMetricQuery = this.graphData.metrics[0]; - const metricQuery = { ...originalMetricQuery }; - metricQuery.result[0].values = metricQuery.result[0].values.map(([x, y]) => [ - x, - y + this.yOffset, - ]); + const metricQuery = produce(originalMetricQuery, draftQuery => { + // eslint-disable-next-line no-param-reassign + draftQuery.result[0].values = draftQuery.result[0].values.map(([x, y]) => [ + x, + y + this.yOffset, + ]); + }); return { ...this.graphData, type: panelTypes.LINE_CHART, diff --git a/app/assets/javascripts/monitoring/stores/actions.js b/app/assets/javascripts/monitoring/stores/actions.js index e7391a4c9d1..44c200cdb54 100644 --- a/app/assets/javascripts/monitoring/stores/actions.js +++ b/app/assets/javascripts/monitoring/stores/actions.js @@ -114,7 +114,7 @@ export const fetchDashboard = ({ state, commit, dispatch, getters }) => { } return getDashboard(state.dashboardEndpoint, params) - .then(response => { + .then((response) => { dispatch('receiveMetricsDashboardSuccess', { response }); /** * After the dashboard is fetched, there can be non-blocking invalid syntax @@ -125,7 +125,7 @@ export const fetchDashboard = ({ state, commit, dispatch, getters }) => { */ dispatch('fetchDashboardValidationWarnings'); }) - .catch(error => { + .catch((error) => { Sentry.captureException(error); commit(types.SET_ALL_DASHBOARDS, error.response?.data?.all_dashboards ?? []); @@ -185,9 +185,9 @@ export const fetchDashboardData = ({ state, dispatch, getters }) => { dispatch('fetchVariableMetricLabelValues', { defaultQueryParams }); const promises = []; - state.dashboard.panelGroups.forEach(group => { - group.panels.forEach(panel => { - panel.metrics.forEach(metric => { + state.dashboard.panelGroups.forEach((group) => { + group.panels.forEach((panel) => { + panel.metrics.forEach((metric) => { promises.push(dispatch('fetchPrometheusMetric', { metric, defaultQueryParams })); }); }); @@ -231,10 +231,10 @@ export const fetchPrometheusMetric = ( commit(types.REQUEST_METRIC_RESULT, { metricId: metric.metricId }); return getPrometheusQueryData(metric.prometheusEndpointPath, queryParams) - .then(data => { + .then((data) => { commit(types.RECEIVE_METRIC_RESULT_SUCCESS, { metricId: metric.metricId, data }); }) - .catch(error => { + .catch((error) => { Sentry.captureException(error); commit(types.RECEIVE_METRIC_RESULT_FAILURE, { metricId: metric.metricId, error }); @@ -251,15 +251,15 @@ export const fetchDeploymentsData = ({ state, dispatch }) => { } return axios .get(state.deploymentsEndpoint) - .then(resp => resp.data) - .then(response => { + .then((resp) => resp.data) + .then((response) => { if (!response || !response.deployments) { createFlash(s__('Metrics|Unexpected deployment data response from prometheus endpoint')); } dispatch('receiveDeploymentsDataSuccess', response.deployments); }) - .catch(error => { + .catch((error) => { Sentry.captureException(error); dispatch('receiveDeploymentsDataFailure'); createFlash(s__('Metrics|There was an error getting deployment information.')); @@ -285,10 +285,10 @@ export const fetchEnvironmentsData = ({ state, dispatch }) => { states: [ENVIRONMENT_AVAILABLE_STATE], }, }) - .then(resp => + .then((resp) => parseEnvironmentsResponse(resp.data?.project?.data?.environments, state.projectPath), ) - .then(environments => { + .then((environments) => { if (!environments) { createFlash( s__('Metrics|There was an error fetching the environments data, please try again'), @@ -297,7 +297,7 @@ export const fetchEnvironmentsData = ({ state, dispatch }) => { dispatch('receiveEnvironmentsDataSuccess', environments); }) - .catch(err => { + .catch((err) => { Sentry.captureException(err); dispatch('receiveEnvironmentsDataFailure'); createFlash(s__('Metrics|There was an error getting environments information.')); @@ -326,16 +326,18 @@ export const fetchAnnotations = ({ state, dispatch, getters }) => { startingFrom: start, }, }) - .then(resp => resp.data?.project?.environments?.nodes?.[0].metricsDashboard?.annotations.nodes) + .then( + (resp) => resp.data?.project?.environments?.nodes?.[0].metricsDashboard?.annotations.nodes, + ) .then(parseAnnotationsResponse) - .then(annotations => { + .then((annotations) => { if (!annotations) { createFlash(s__('Metrics|There was an error fetching annotations. Please try again.')); } dispatch('receiveAnnotationsSuccess', annotations); }) - .catch(err => { + .catch((err) => { Sentry.captureException(err); dispatch('receiveAnnotationsFailure'); createFlash(s__('Metrics|There was an error getting annotations information.')); @@ -363,7 +365,7 @@ export const fetchDashboardValidationWarnings = ({ state, dispatch, getters }) = dashboardPath, }, }) - .then(resp => resp.data?.project?.environments?.nodes?.[0]?.metricsDashboard) + .then((resp) => resp.data?.project?.environments?.nodes?.[0]?.metricsDashboard) .then(({ schemaValidationWarnings } = {}) => { const hasWarnings = schemaValidationWarnings && schemaValidationWarnings.length !== 0; /** @@ -372,7 +374,7 @@ export const fetchDashboardValidationWarnings = ({ state, dispatch, getters }) = */ dispatch('receiveDashboardValidationWarningsSuccess', hasWarnings || false); }) - .catch(err => { + .catch((err) => { Sentry.captureException(err); dispatch('receiveDashboardValidationWarningsFailure'); createFlash( @@ -437,9 +439,9 @@ export const duplicateSystemDashboard = ({ state }, payload) => { return axios .post(state.dashboardsEndpoint, params) - .then(response => response.data) - .then(data => data.dashboard) - .catch(error => { + .then((response) => response.data) + .then((data) => data.dashboard) + .catch((error) => { Sentry.captureException(error); const { response } = error; @@ -466,7 +468,7 @@ export const fetchVariableMetricLabelValues = ({ state, commit }, { defaultQuery const { start_time, end_time } = defaultQueryParams; const optionsRequests = []; - state.variables.forEach(variable => { + state.variables.forEach((variable) => { if (variable.type === VARIABLE_TYPES.metric_label_values) { const { prometheusEndpointPath, label } = variable.options; @@ -474,7 +476,7 @@ export const fetchVariableMetricLabelValues = ({ state, commit }, { defaultQuery start_time, end_time, }) - .then(data => { + .then((data) => { commit(types.UPDATE_VARIABLE_METRIC_LABEL_VALUES, { variable, label, data }); }) .catch(() => { @@ -512,7 +514,7 @@ export const fetchPanelPreview = ({ state, commit, dispatch }, panelPreviewYml) dispatch('fetchPanelPreviewMetrics'); }) - .catch(error => { + .catch((error) => { commit(types.RECEIVE_PANEL_PREVIEW_FAILURE, extractErrorMessage(error)); }); }; @@ -535,10 +537,10 @@ export const fetchPanelPreviewMetrics = ({ state, commit }) => { return getPrometheusQueryData(metric.prometheusEndpointPath, params, { cancelToken: cancelTokenSource.token, }) - .then(data => { + .then((data) => { commit(types.RECEIVE_PANEL_PREVIEW_METRIC_RESULT_SUCCESS, { index, data }); }) - .catch(error => { + .catch((error) => { Sentry.captureException(error); commit(types.RECEIVE_PANEL_PREVIEW_METRIC_RESULT_FAILURE, { index, error }); diff --git a/app/assets/javascripts/monitoring/stores/getters.js b/app/assets/javascripts/monitoring/stores/getters.js index 8ed83cf02fe..d6a04006264 100644 --- a/app/assets/javascripts/monitoring/stores/getters.js +++ b/app/assets/javascripts/monitoring/stores/getters.js @@ -5,8 +5,10 @@ import { normalizeCustomDashboardPath, } from './utils'; -const metricsIdsInPanel = panel => - panel.metrics.filter(metric => metric.metricId && metric.result).map(metric => metric.metricId); +const metricsIdsInPanel = (panel) => + panel.metrics + .filter((metric) => metric.metricId && metric.result) + .map((metric) => metric.metricId); /** * Returns a reference to the currently selected dashboard @@ -17,8 +19,8 @@ const metricsIdsInPanel = panel => export const selectedDashboard = (state, getters) => { const { allDashboards } = state; return ( - allDashboards.find(d => d.path === getters.fullDashboardPath) || - allDashboards.find(d => d.default) || + allDashboards.find((d) => d.path === getters.fullDashboardPath) || + allDashboards.find((d) => d.default) || null ); }; @@ -32,15 +34,15 @@ export const selectedDashboard = (state, getters) => { * @returns {Function} A function that returns an array of * states in all the metric in the dashboard or group. */ -export const getMetricStates = state => groupKey => { +export const getMetricStates = (state) => (groupKey) => { let groups = state.dashboard.panelGroups; if (groupKey) { - groups = groups.filter(group => group.key === groupKey); + groups = groups.filter((group) => group.key === groupKey); } const metricStates = groups.reduce((acc, group) => { - group.panels.forEach(panel => { - panel.metrics.forEach(metric => { + group.panels.forEach((panel) => { + panel.metrics.forEach((metric) => { if (metric.state) { acc.push(metric.state); } @@ -64,15 +66,15 @@ export const getMetricStates = state => groupKey => { * metrics in the dashboard that contain results, optionally * filtered by group key. */ -export const metricsWithData = state => groupKey => { +export const metricsWithData = (state) => (groupKey) => { let groups = state.dashboard.panelGroups; if (groupKey) { - groups = groups.filter(group => group.key === groupKey); + groups = groups.filter((group) => group.key === groupKey); } const res = []; - groups.forEach(group => { - group.panels.forEach(panel => { + groups.forEach((group) => { + group.panels.forEach((panel) => { res.push(...metricsIdsInPanel(panel)); }); }); @@ -89,7 +91,7 @@ export const metricsWithData = state => groupKey => { * https://gitlab.com/gitlab-org/gitlab/-/issues/28241 * https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27447 */ -export const metricsSavedToDb = state => { +export const metricsSavedToDb = (state) => { const metricIds = []; state.dashboard.panelGroups.forEach(({ panels }) => { panels.forEach(({ metrics }) => { @@ -111,8 +113,8 @@ export const metricsSavedToDb = state => { * @param {Object} state * @returns {Array} List of environments */ -export const filteredEnvironments = state => - state.environments.filter(env => +export const filteredEnvironments = (state) => + state.environments.filter((env) => env.name.toLowerCase().includes((state.environmentsSearchTerm || '').trim().toLowerCase()), ); @@ -125,7 +127,7 @@ export const filteredEnvironments = state => * @param {Object} state * @returns {Array} modified array of links */ -export const linksWithMetadata = state => { +export const linksWithMetadata = (state) => { const metadata = { timeRange: state.timeRange, }; @@ -152,7 +154,7 @@ export const linksWithMetadata = state => { * in the format of {variables[key1]=value1, variables[key2]=value2} */ -export const getCustomVariablesParams = state => +export const getCustomVariablesParams = (state) => state.variables.reduce((acc, variable) => { const { name, value } = variable; if (value !== null) { @@ -168,5 +170,5 @@ export const getCustomVariablesParams = state => * @param {Object} state * @returns {String} full dashboard path */ -export const fullDashboardPath = state => +export const fullDashboardPath = (state) => normalizeCustomDashboardPath(state.currentDashboard, state.customDashboardBasePath); |