diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/services/prometheus | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/services/prometheus')
-rw-r--r-- | app/services/prometheus/proxy_service.rb | 10 | ||||
-rw-r--r-- | app/services/prometheus/proxy_variable_substitution_service.rb | 42 |
2 files changed, 49 insertions, 3 deletions
diff --git a/app/services/prometheus/proxy_service.rb b/app/services/prometheus/proxy_service.rb index e0bc5518d30..33635796771 100644 --- a/app/services/prometheus/proxy_service.rb +++ b/app/services/prometheus/proxy_service.rb @@ -22,16 +22,20 @@ module Prometheus attr_accessor :proxyable, :method, :path, :params + PROMETHEUS_QUERY_API = 'query' + PROMETHEUS_QUERY_RANGE_API = 'query_range' + PROMETHEUS_SERIES_API = 'series' + PROXY_SUPPORT = { - 'query' => { + PROMETHEUS_QUERY_API => { method: ['GET'], params: %w(query time timeout) }, - 'query_range' => { + PROMETHEUS_QUERY_RANGE_API => { method: ['GET'], params: %w(query start end step timeout) }, - 'series' => { + PROMETHEUS_SERIES_API => { method: %w(GET), params: %w(match start end) } diff --git a/app/services/prometheus/proxy_variable_substitution_service.rb b/app/services/prometheus/proxy_variable_substitution_service.rb index 10fb3a8c1b5..820b551c30a 100644 --- a/app/services/prometheus/proxy_variable_substitution_service.rb +++ b/app/services/prometheus/proxy_variable_substitution_service.rb @@ -19,10 +19,52 @@ module Prometheus :substitute_params, :substitute_variables + # @param environment [Environment] + # @param params [Hash<Symbol,Any>] + # @param params - query [String] The Prometheus query string. + # @param params - start [String] (optional) A time string in the rfc3339 format. + # @param params - start_time [String] (optional) A time string in the rfc3339 format. + # @param params - end [String] (optional) A time string in the rfc3339 format. + # @param params - end_time [String] (optional) A time string in the rfc3339 format. + # @param params - variables [ActionController::Parameters] (optional) Variables with their values. + # The keys in the Hash should be the name of the variable. The value should be the value of the + # variable. Ex: `ActionController::Parameters.new(variable1: 'value 1', variable2: 'value 2').permit!` + # @return [Prometheus::ProxyVariableSubstitutionService] + # + # Example: + # Prometheus::ProxyVariableSubstitutionService.new(environment, { + # params: { + # start_time: '2020-07-03T06:08:36Z', + # end_time: '2020-07-03T14:08:52Z', + # query: 'up{instance="{{instance}}"}', + # variables: { instance: 'srv1' } + # } + # }) def initialize(environment, params = {}) @environment, @params = environment, params.deep_dup end + # @return - params [Hash<Symbol,Any>] Returns a Hash containing a params key which is + # similar to the `params` that is passed to the initialize method with 2 differences: + # 1. Variables in the query string are substituted with their values. + # If a variable present in the query string has no known value (values + # are obtained from the `variables` Hash in `params` or from + # `Gitlab::Prometheus::QueryVariables.call`), it will not be substituted. + # 2. `start` and `end` keys are added, with their values copied from `start_time` + # and `end_time`. + # + # Example output: + # + # { + # params: { + # start_time: '2020-07-03T06:08:36Z', + # start: '2020-07-03T06:08:36Z', + # end_time: '2020-07-03T14:08:52Z', + # end: '2020-07-03T14:08:52Z', + # query: 'up{instance="srv1"}', + # variables: { instance: 'srv1' } + # } + # } def execute execute_steps end |