Commit a81bba38 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'dbodicherla-update-variables-name-conventions' into 'master'

Update metric dashboard promVariables to variables

See merge request gitlab-org/gitlab!32721
parents 30254ffa 4f0a592b
...@@ -226,7 +226,7 @@ export default { ...@@ -226,7 +226,7 @@ export default {
'allDashboards', 'allDashboards',
'environmentsLoading', 'environmentsLoading',
'expandedPanel', 'expandedPanel',
'promVariables', 'variables',
'isUpdatingStarredValue', 'isUpdatingStarredValue',
]), ]),
...mapGetters('monitoringDashboard', [ ...mapGetters('monitoringDashboard', [
...@@ -251,7 +251,7 @@ export default { ...@@ -251,7 +251,7 @@ export default {
return !this.environmentsLoading && this.filteredEnvironments.length === 0; return !this.environmentsLoading && this.filteredEnvironments.length === 0;
}, },
shouldShowVariablesSection() { shouldShowVariablesSection() {
return Object.keys(this.promVariables).length > 0; return Object.keys(this.variables).length > 0;
}, },
}, },
watch: { watch: {
...@@ -273,7 +273,7 @@ export default { ...@@ -273,7 +273,7 @@ export default {
handler({ group, panel }) { handler({ group, panel }) {
const dashboardPath = this.currentDashboard || this.selectedDashboard?.path; const dashboardPath = this.currentDashboard || this.selectedDashboard?.path;
updateHistory({ updateHistory({
url: panelToUrl(dashboardPath, convertVariablesForURL(this.promVariables), group, panel), url: panelToUrl(dashboardPath, convertVariablesForURL(this.variables), group, panel),
title: document.title, title: document.title,
}); });
}, },
...@@ -344,7 +344,7 @@ export default { ...@@ -344,7 +344,7 @@ export default {
}, },
generatePanelUrl(groupKey, panel) { generatePanelUrl(groupKey, panel) {
const dashboardPath = this.currentDashboard || this.selectedDashboard?.path; const dashboardPath = this.currentDashboard || this.selectedDashboard?.path;
return panelToUrl(dashboardPath, convertVariablesForURL(this.promVariables), groupKey, panel); return panelToUrl(dashboardPath, convertVariablesForURL(this.variables), groupKey, panel);
}, },
hideAddMetricModal() { hideAddMetricModal() {
this.$refs.addMetricModal.hide(); this.$refs.addMetricModal.hide();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import CustomVariable from './variables/custom_variable.vue'; import CustomVariable from './variables/custom_variable.vue';
import TextVariable from './variables/text_variable.vue'; import TextVariable from './variables/text_variable.vue';
import { setPromCustomVariablesFromUrl } from '../utils'; import { setCustomVariablesFromUrl } from '../utils';
export default { export default {
components: { components: {
...@@ -10,12 +10,12 @@ export default { ...@@ -10,12 +10,12 @@ export default {
TextVariable, TextVariable,
}, },
computed: { computed: {
...mapState('monitoringDashboard', ['promVariables']), ...mapState('monitoringDashboard', ['variables']),
}, },
methods: { methods: {
...mapActions('monitoringDashboard', ['fetchDashboardData', 'updateVariableValues']), ...mapActions('monitoringDashboard', ['fetchDashboardData', 'updateVariableValues']),
refreshDashboard(variable, value) { refreshDashboard(variable, value) {
if (this.promVariables[variable].value !== value) { if (this.variables[variable].value !== value) {
const changedVariable = { key: variable, value }; const changedVariable = { key: variable, value };
// update the Vuex store // update the Vuex store
this.updateVariableValues(changedVariable); this.updateVariableValues(changedVariable);
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
// mutation respond directly. // mutation respond directly.
// This can be further investigate in // This can be further investigate in
// https://gitlab.com/gitlab-org/gitlab/-/issues/217713 // https://gitlab.com/gitlab-org/gitlab/-/issues/217713
setPromCustomVariablesFromUrl(this.promVariables); setCustomVariablesFromUrl(this.variables);
// fetch data // fetch data
this.fetchDashboardData(); this.fetchDashboardData();
} }
...@@ -41,7 +41,7 @@ export default { ...@@ -41,7 +41,7 @@ export default {
</script> </script>
<template> <template>
<div ref="variablesSection" class="d-sm-flex flex-sm-wrap pt-2 pr-1 pb-0 pl-2 variables-section"> <div ref="variablesSection" class="d-sm-flex flex-sm-wrap pt-2 pr-1 pb-0 pl-2 variables-section">
<div v-for="(variable, key) in promVariables" :key="key" class="mb-1 pr-2 d-flex d-sm-block"> <div v-for="(variable, key) in variables" :key="key" class="mb-1 pr-2 d-flex d-sm-block">
<component <component
:is="variableComponent(variable.type)" :is="variableComponent(variable.type)"
class="mb-0 flex-grow-1" class="mb-0 flex-grow-1"
......
...@@ -223,7 +223,7 @@ export const fetchPrometheusMetric = ( ...@@ -223,7 +223,7 @@ export const fetchPrometheusMetric = (
queryParams.step = metric.step; queryParams.step = metric.step;
} }
if (Object.keys(state.promVariables).length > 0) { if (Object.keys(state.variables).length > 0) {
queryParams.variables = getters.getCustomVariablesArray; queryParams.variables = getters.getCustomVariablesArray;
} }
......
...@@ -122,7 +122,7 @@ export const filteredEnvironments = state => ...@@ -122,7 +122,7 @@ export const filteredEnvironments = state =>
*/ */
export const getCustomVariablesArray = state => export const getCustomVariablesArray = state =>
flatMap(state.promVariables, (variable, key) => [key, variable.value]); flatMap(state.variables, (variable, key) => [key, variable.value]);
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
...@@ -189,11 +189,11 @@ export default { ...@@ -189,11 +189,11 @@ export default {
state.expandedPanel.panel = panel; state.expandedPanel.panel = panel;
}, },
[types.SET_VARIABLES](state, variables) { [types.SET_VARIABLES](state, variables) {
state.promVariables = variables; state.variables = variables;
}, },
[types.UPDATE_VARIABLE_VALUES](state, updatedVariable) { [types.UPDATE_VARIABLE_VALUES](state, updatedVariable) {
Object.assign(state.promVariables[updatedVariable.key], { Object.assign(state.variables[updatedVariable.key], {
...state.promVariables[updatedVariable.key], ...state.variables[updatedVariable.key],
value: updatedVariable.value, value: updatedVariable.value,
}); });
}, },
......
...@@ -34,7 +34,11 @@ export default () => ({ ...@@ -34,7 +34,11 @@ export default () => ({
panel: null, panel: null,
}, },
allDashboards: [], allDashboards: [],
promVariables: {}, /**
* User-defined custom variables are passed
* via the dashboard.yml file.
*/
variables: {},
// Other project data // Other project data
annotations: [], annotations: [],
......
...@@ -151,7 +151,7 @@ export const removePrefixFromLabel = label => ...@@ -151,7 +151,7 @@ export const removePrefixFromLabel = label =>
/** /**
* Convert parsed template variables to an object * Convert parsed template variables to an object
* with just keys and values. Prepare the promVariables * with just keys and values. Prepare the variables
* to be added to the URL. Keys of the object will * to be added to the URL. Keys of the object will
* have a prefix so that these params can be * have a prefix so that these params can be
* differentiated from other URL params. * differentiated from other URL params.
...@@ -183,15 +183,15 @@ export const getPromCustomVariablesFromUrl = (search = window.location.search) = ...@@ -183,15 +183,15 @@ export const getPromCustomVariablesFromUrl = (search = window.location.search) =
}; };
/** /**
* Update the URL with promVariables. This usually get triggered when * Update the URL with variables. This usually get triggered when
* the user interacts with the dynamic input elements in the monitoring * the user interacts with the dynamic input elements in the monitoring
* dashboard header. * dashboard header.
* *
* @param {Object} promVariables user defined variables * @param {Object} variables user defined variables
*/ */
export const setPromCustomVariablesFromUrl = promVariables => { export const setCustomVariablesFromUrl = variables => {
// prep the variables to append to URL // prep the variables to append to URL
const parsedVariables = convertVariablesForURL(promVariables); const parsedVariables = convertVariablesForURL(variables);
// update the URL // update the URL
updateHistory({ updateHistory({
url: mergeUrlParams(parsedVariables, window.location.href), url: mergeUrlParams(parsedVariables, window.location.href),
...@@ -262,7 +262,7 @@ export const expandedPanelPayloadFromUrl = (dashboard, search = window.location. ...@@ -262,7 +262,7 @@ export const expandedPanelPayloadFromUrl = (dashboard, search = window.location.
* If no group/panel is set, the dashboard URL is returned. * If no group/panel is set, the dashboard URL is returned.
* *
* @param {?String} dashboard - Dashboard path, used as identifier for a dashboard * @param {?String} dashboard - Dashboard path, used as identifier for a dashboard
* @param {?Object} promVariables - Custom variables that came from the URL * @param {?Object} variables - Custom variables that came from the URL
* @param {?String} group - Group Identifier * @param {?String} group - Group Identifier
* @param {?Object} panel - Panel object from the dashboard * @param {?Object} panel - Panel object from the dashboard
* @param {?String} url - Base URL including current search params * @param {?String} url - Base URL including current search params
...@@ -270,14 +270,14 @@ export const expandedPanelPayloadFromUrl = (dashboard, search = window.location. ...@@ -270,14 +270,14 @@ export const expandedPanelPayloadFromUrl = (dashboard, search = window.location.
*/ */
export const panelToUrl = ( export const panelToUrl = (
dashboard = null, dashboard = null,
promVariables, variables,
group, group,
panel, panel,
url = window.location.href, url = window.location.href,
) => { ) => {
const params = { const params = {
dashboard, dashboard,
...promVariables, ...variables,
}; };
if (group && panel) { if (group && panel) {
......
...@@ -67,7 +67,7 @@ describe('Metrics dashboard/variables section component', () => { ...@@ -67,7 +67,7 @@ describe('Metrics dashboard/variables section component', () => {
namespaced: true, namespaced: true,
state: { state: {
showEmptyState: false, showEmptyState: false,
promVariables: sampleVariables, variables: sampleVariables,
}, },
actions: { actions: {
fetchDashboardData, fetchDashboardData,
......
...@@ -334,11 +334,11 @@ describe('Monitoring store Getters', () => { ...@@ -334,11 +334,11 @@ describe('Monitoring store Getters', () => {
beforeEach(() => { beforeEach(() => {
state = { state = {
promVariables: {}, variables: {},
}; };
}); });
it('transforms the promVariables object to an array in the [variable, variable_value] format for all variable types', () => { it('transforms the variables object to an array in the [variable, variable_value] format for all variable types', () => {
mutations[types.SET_VARIABLES](state, mockTemplatingDataResponses.allVariableTypes); mutations[types.SET_VARIABLES](state, mockTemplatingDataResponses.allVariableTypes);
const variablesArray = getters.getCustomVariablesArray(state); const variablesArray = getters.getCustomVariablesArray(state);
...@@ -354,7 +354,7 @@ describe('Monitoring store Getters', () => { ...@@ -354,7 +354,7 @@ describe('Monitoring store Getters', () => {
]); ]);
}); });
it('transforms the promVariables object to an empty array when no keys are present', () => { it('transforms the variables object to an empty array when no keys are present', () => {
mutations[types.SET_VARIABLES](state, {}); mutations[types.SET_VARIABLES](state, {});
const variablesArray = getters.getCustomVariablesArray(state); const variablesArray = getters.getCustomVariablesArray(state);
......
...@@ -412,13 +412,13 @@ describe('Monitoring mutations', () => { ...@@ -412,13 +412,13 @@ describe('Monitoring mutations', () => {
it('stores an empty variables array when no custom variables are given', () => { it('stores an empty variables array when no custom variables are given', () => {
mutations[types.SET_VARIABLES](stateCopy, {}); mutations[types.SET_VARIABLES](stateCopy, {});
expect(stateCopy.promVariables).toEqual({}); expect(stateCopy.variables).toEqual({});
}); });
it('stores variables in the key key_value format in the array', () => { it('stores variables in the key key_value format in the array', () => {
mutations[types.SET_VARIABLES](stateCopy, { pod: 'POD', stage: 'main ops' }); mutations[types.SET_VARIABLES](stateCopy, { pod: 'POD', stage: 'main ops' });
expect(stateCopy.promVariables).toEqual({ pod: 'POD', stage: 'main ops' }); expect(stateCopy.variables).toEqual({ pod: 'POD', stage: 'main ops' });
}); });
}); });
...@@ -427,11 +427,11 @@ describe('Monitoring mutations', () => { ...@@ -427,11 +427,11 @@ describe('Monitoring mutations', () => {
mutations[types.SET_VARIABLES](stateCopy, {}); mutations[types.SET_VARIABLES](stateCopy, {});
}); });
it('updates only the value of the variable in promVariables', () => { it('updates only the value of the variable in variables', () => {
mutations[types.SET_VARIABLES](stateCopy, { environment: { value: 'prod', type: 'text' } }); mutations[types.SET_VARIABLES](stateCopy, { environment: { value: 'prod', type: 'text' } });
mutations[types.UPDATE_VARIABLE_VALUES](stateCopy, { key: 'environment', value: 'new prod' }); mutations[types.UPDATE_VARIABLE_VALUES](stateCopy, { key: 'environment', value: 'new prod' });
expect(stateCopy.promVariables).toEqual({ environment: { value: 'new prod', type: 'text' } }); expect(stateCopy.variables).toEqual({ environment: { value: 'new prod', type: 'text' } });
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment