diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-29 07:12:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-29 07:12:44 +0000 |
commit | 6a4f265c940d3d0a9aeacf09222920d7d2cc4e45 (patch) | |
tree | 4cf73897e78f8fee50e39edb7d74fa628b6a87da /app | |
parent | cba453953c1598f83b2ed72bc012b65e0df5b767 (diff) | |
download | gitlab-ce-6a4f265c940d3d0a9aeacf09222920d7d2cc4e45.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/monitoring/stores/actions.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/monitoring/stores/getters.js | 22 | ||||
-rw-r--r-- | app/assets/javascripts/monitoring/stores/utils.js | 16 | ||||
-rw-r--r-- | app/controllers/projects/artifacts_controller.rb | 12 | ||||
-rw-r--r-- | app/services/prometheus/proxy_variable_substitution_service.rb | 11 | ||||
-rw-r--r-- | app/workers/irker_worker.rb | 4 |
6 files changed, 54 insertions, 18 deletions
diff --git a/app/assets/javascripts/monitoring/stores/actions.js b/app/assets/javascripts/monitoring/stores/actions.js index b057afa2264..9e3edfb495d 100644 --- a/app/assets/javascripts/monitoring/stores/actions.js +++ b/app/assets/javascripts/monitoring/stores/actions.js @@ -218,13 +218,16 @@ export const fetchPrometheusMetric = ( { commit, state, getters }, { metric, defaultQueryParams }, ) => { - const queryParams = { ...defaultQueryParams }; + let queryParams = { ...defaultQueryParams }; if (metric.step) { queryParams.step = metric.step; } if (Object.keys(state.promVariables).length > 0) { - queryParams.variables = getters.getCustomVariablesArray; + queryParams = { + ...queryParams, + ...getters.getCustomVariablesParams, + }; } commit(types.REQUEST_METRIC_RESULT, { metricId: metric.metricId }); diff --git a/app/assets/javascripts/monitoring/stores/getters.js b/app/assets/javascripts/monitoring/stores/getters.js index ae3ff5596e1..f309addee6b 100644 --- a/app/assets/javascripts/monitoring/stores/getters.js +++ b/app/assets/javascripts/monitoring/stores/getters.js @@ -1,5 +1,5 @@ -import { flatMap } from 'lodash'; import { NOT_IN_DB_PREFIX } from '../constants'; +import { addPrefixToCustomVariableParams } from './utils'; const metricsIdsInPanel = panel => panel.metrics.filter(metric => metric.metricId && metric.result).map(metric => metric.metricId); @@ -116,13 +116,27 @@ export const filteredEnvironments = state => * Maps an variables object to an array along with stripping * the variable prefix. * + * This method outputs an object in the below format + * + * { + * variables[key1]=value1, + * variables[key2]=value2, + * } + * + * This is done so that the backend can identify the custom + * user-defined variables coming through the URL and differentiate + * from other variables used for Prometheus API endpoint. + * * @param {Object} variables - Custom variables provided by the user * @returns {Array} The custom variables array to be send to the API - * in the format of [variable1, variable1_value] + * in the format of {variables[key1]=value1, variables[key2]=value2} */ -export const getCustomVariablesArray = state => - flatMap(state.promVariables, (variable, key) => [key, variable.value]); +export const getCustomVariablesParams = state => + Object.keys(state.promVariables).reduce((acc, variable) => { + acc[addPrefixToCustomVariableParams(variable)] = state.promVariables[variable]?.value; + return acc; + }, {}); // prevent babel-plugin-rewire from generating an invalid default during karma tests export default () => {}; diff --git a/app/assets/javascripts/monitoring/stores/utils.js b/app/assets/javascripts/monitoring/stores/utils.js index a47e5f598f5..b6817e7279a 100644 --- a/app/assets/javascripts/monitoring/stores/utils.js +++ b/app/assets/javascripts/monitoring/stores/utils.js @@ -229,3 +229,19 @@ export const normalizeQueryResult = timeSeries => { return normalizedResult; }; + +/** + * Custom variables defined in the dashboard yml file are + * eventually passed over the wire to the backend Prometheus + * API proxy. + * + * This method adds a prefix to the URL param keys so that + * the backend can differential these variables from the other + * variables. + * + * This is currently only used by getters/getCustomVariablesParams + * + * @param {String} key Variable key that needs to be prefixed + * @returns {String} + */ +export const addPrefixToCustomVariableParams = key => `variables[${key}]`; diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index b8663bc59f2..fef3c6cf424 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -113,7 +113,7 @@ class Projects::ArtifactsController < Projects::ApplicationController def build @build ||= begin - build = build_from_id || build_from_ref + build = build_from_id || build_from_sha || build_from_ref build&.present(current_user: current_user) end end @@ -127,7 +127,8 @@ class Projects::ArtifactsController < Projects::ApplicationController project.builds.find_by_id(params[:job_id]) if params[:job_id] end - def build_from_ref + def build_from_sha + return if params[:job].blank? return unless @ref_name commit = project.commit(@ref_name) @@ -136,6 +137,13 @@ class Projects::ArtifactsController < Projects::ApplicationController project.latest_successful_build_for_sha(params[:job], commit.id) end + def build_from_ref + return if params[:job].blank? + return unless @ref_name + + project.latest_successful_build_for_ref(params[:job], @ref_name) + end + def artifacts_file @artifacts_file ||= build&.artifacts_file_for_type(params[:file_type] || :archive) end diff --git a/app/services/prometheus/proxy_variable_substitution_service.rb b/app/services/prometheus/proxy_variable_substitution_service.rb index aa3a09ba05c..7b98cfc592a 100644 --- a/app/services/prometheus/proxy_variable_substitution_service.rb +++ b/app/services/prometheus/proxy_variable_substitution_service.rb @@ -32,8 +32,8 @@ module Prometheus def validate_variables(_result) return success unless variables - unless variables.is_a?(Array) && variables.size.even? - return error(_('Optional parameter "variables" must be an array of keys and values. Ex: [key1, value1, key2, value2]')) + unless variables.is_a?(ActionController::Parameters) + return error(_('Optional parameter "variables" must be a Hash. Ex: variables[key1]=value1')) end success @@ -88,12 +88,7 @@ module Prometheus end def variables_hash - # .each_slice(2) converts ['key1', 'value1', 'key2', 'value2'] into - # [['key1', 'value1'], ['key2', 'value2']] which is then converted into - # a hash by to_h: {'key1' => 'value1', 'key2' => 'value2'} - # to_h will raise an ArgumentError if the number of elements in the original - # array is not even. - variables&.each_slice(2).to_h + variables.to_h end def query(result) diff --git a/app/workers/irker_worker.rb b/app/workers/irker_worker.rb index 7622f40a949..09f53681e7f 100644 --- a/app/workers/irker_worker.rb +++ b/app/workers/irker_worker.rb @@ -70,7 +70,7 @@ class IrkerWorker # rubocop:disable Scalability/IdempotentWorker def send_new_branch(project, repo_name, committer, branch) repo_path = project.full_path - newbranch = "#{Gitlab.config.gitlab.url}/#{repo_path}/branches" + newbranch = "#{Gitlab.config.gitlab.url}/#{repo_path}/-/branches" newbranch = "\x0302\x1f#{newbranch}\x0f" if @colors privmsg = "[#{repo_name}] #{committer} has created a new branch " \ @@ -124,7 +124,7 @@ class IrkerWorker # rubocop:disable Scalability/IdempotentWorker def compare_url(data, repo_path) sha1 = Commit.truncate_sha(data['before']) sha2 = Commit.truncate_sha(data['after']) - compare_url = "#{Gitlab.config.gitlab.url}/#{repo_path}/compare" \ + compare_url = "#{Gitlab.config.gitlab.url}/#{repo_path}/-/compare" \ "/#{sha1}...#{sha2}" colorize_url compare_url end |