diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-02 21:07:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-02 21:07:51 +0000 |
commit | d74fcc9b69746c4d9582299c370a95aafe2ac3ac (patch) | |
tree | 8230bdf94ff004521422c9986062278dd3bc5b3f /app/assets/javascripts/monitoring | |
parent | 8a7efa45c38ed3200d173d2c3207a8154e583c16 (diff) | |
download | gitlab-ce-d74fcc9b69746c4d9582299c370a95aafe2ac3ac.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/monitoring')
5 files changed, 43 insertions, 4 deletions
diff --git a/app/assets/javascripts/monitoring/components/panel_type.vue b/app/assets/javascripts/monitoring/components/panel_type.vue index 77ba17b6e68..44e38089da8 100644 --- a/app/assets/javascripts/monitoring/components/panel_type.vue +++ b/app/assets/javascripts/monitoring/components/panel_type.vue @@ -101,7 +101,8 @@ export default { return this.graphData.title || ''; }, alertWidgetAvailable() { - return IS_EE && this.prometheusAlertsAvailable && this.alertsEndpoint && this.graphData; + // This method is extended by ee functionality + return false; }, graphDataHasMetrics() { return ( @@ -209,7 +210,7 @@ export default { > <div class="d-flex align-items-center"> <alert-widget - v-if="alertWidgetAvailable && graphData" + v-if="alertWidgetAvailable" :modal-id="`alert-modal-${index}`" :alerts-endpoint="alertsEndpoint" :relevant-queries="graphData.metrics" diff --git a/app/assets/javascripts/monitoring/constants.js b/app/assets/javascripts/monitoring/constants.js index 3990a8d1f61..6609946e02e 100644 --- a/app/assets/javascripts/monitoring/constants.js +++ b/app/assets/javascripts/monitoring/constants.js @@ -104,3 +104,8 @@ export const endpointKeys = [ * as Vue props. */ export const initialStateKeys = [...endpointKeys, 'currentEnvironmentName']; + +/** + * Constant to indicate if a metric exists in the database + */ +export const NOT_IN_DB_PREFIX = 'NO_DB'; diff --git a/app/assets/javascripts/monitoring/stores/actions.js b/app/assets/javascripts/monitoring/stores/actions.js index 86f416240c8..2e4987b7349 100644 --- a/app/assets/javascripts/monitoring/stores/actions.js +++ b/app/assets/javascripts/monitoring/stores/actions.js @@ -144,7 +144,7 @@ export const fetchPrometheusMetric = ({ commit }, { metric, params }) => { const minStep = 60; const queryDataPoints = 600; - const step = Math.max(minStep, Math.ceil(timeDiff / queryDataPoints)); + const step = metric.step ? metric.step : Math.max(minStep, Math.ceil(timeDiff / queryDataPoints)); const queryParams = { start_time, diff --git a/app/assets/javascripts/monitoring/stores/getters.js b/app/assets/javascripts/monitoring/stores/getters.js index 1affc6f0a76..a6d80c5063e 100644 --- a/app/assets/javascripts/monitoring/stores/getters.js +++ b/app/assets/javascripts/monitoring/stores/getters.js @@ -1,3 +1,5 @@ +import { NOT_IN_DB_PREFIX } from '../constants'; + const metricsIdsInPanel = panel => panel.metrics.filter(metric => metric.metricId && metric.result).map(metric => metric.metricId); @@ -59,6 +61,29 @@ export const metricsWithData = state => groupKey => { }; /** + * Metrics loaded from project-defined dashboards do not have a metric_id. + * This getter checks which metrics are stored in the db (have a metric id) + * This is hopefully a temporary solution until BE processes metrics before passing to FE + * + * Related: + * https://gitlab.com/gitlab-org/gitlab/-/issues/28241 + * https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27447 + */ +export const metricsSavedToDb = state => { + const metricIds = []; + state.dashboard.panelGroups.forEach(({ panels }) => { + panels.forEach(({ metrics }) => { + const metricIdsInDb = metrics + .filter(({ metricId }) => !metricId.startsWith(NOT_IN_DB_PREFIX)) + .map(({ metricId }) => metricId); + + metricIds.push(...metricIdsInDb); + }); + }); + return metricIds; +}; + +/** * Filter environments by names. * * This is used in the environments dropdown with searchable input. diff --git a/app/assets/javascripts/monitoring/stores/utils.js b/app/assets/javascripts/monitoring/stores/utils.js index b5938fb1205..5e620d6c2f5 100644 --- a/app/assets/javascripts/monitoring/stores/utils.js +++ b/app/assets/javascripts/monitoring/stores/utils.js @@ -2,6 +2,7 @@ import { slugify } from '~/lib/utils/text_utility'; import createGqClient, { fetchPolicies } from '~/lib/graphql'; import { SUPPORTED_FORMATS } from '~/lib/utils/unit_format'; import { getIdFromGraphQLId } from '~/graphql_shared/utils'; +import { NOT_IN_DB_PREFIX } from '../constants'; export const gqClient = createGqClient( {}, @@ -14,11 +15,18 @@ export const gqClient = createGqClient( * Metrics loaded from project-defined dashboards do not have a metric_id. * This method creates a unique ID combining metric_id and id, if either is present. * This is hopefully a temporary solution until BE processes metrics before passing to FE + * + * Related: + * https://gitlab.com/gitlab-org/gitlab/-/issues/28241 + * https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27447 + * * @param {Object} metric - metric + * @param {Number} metric.metric_id - Database metric id + * @param {String} metric.id - User-defined identifier * @returns {Object} - normalized metric with a uniqueID */ // eslint-disable-next-line babel/camelcase -export const uniqMetricsId = ({ metric_id, id }) => `${metric_id}_${id}`; +export const uniqMetricsId = ({ metric_id, id }) => `${metric_id || NOT_IN_DB_PREFIX}_${id}`; /** * Project path has a leading slash that doesn't work well |