summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorrpereira2 <rpereira@gitlab.com>2019-04-03 14:50:48 +0530
committerPeter Leitzen <pleitzen@gitlab.com>2019-04-04 22:22:46 +0200
commitb3aba1203d7f6a0c96c836593f19165bbf066cd0 (patch)
treeaa7c72a6afd5f2dfb6d1b35507fae6d2b0386b44 /app
parentaa27c9491f58ec30e5e3afd035e1337694102a80 (diff)
downloadgitlab-ce-b3aba1203d7f6a0c96c836593f19165bbf066cd0.tar.gz
Filter params based on the proxy_path
- Permit params in ProxyService class to avoid having to make changes to both ProxyService and to PrometheusApiController when adding support for more prometheus apis. - Also refactor the cache specs.
Diffstat (limited to 'app')
-rw-r--r--app/services/prometheus/proxy_service.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/app/services/prometheus/proxy_service.rb b/app/services/prometheus/proxy_service.rb
index 4a0d1dcd83f..c08adfda851 100644
--- a/app/services/prometheus/proxy_service.rb
+++ b/app/services/prometheus/proxy_service.rb
@@ -13,8 +13,14 @@ module Prometheus
attr_accessor :proxyable, :method, :path, :params
PROXY_SUPPORT = {
- 'query' => 'GET',
- 'query_range' => 'GET'
+ 'query' => {
+ method: ['GET'],
+ params: [:query, :time, :timeout]
+ },
+ 'query_range' => {
+ method: ['GET'],
+ params: [:query, :start, :end, :step, :timeout]
+ }
}.freeze
def self.from_cache(proxyable_class_name, proxyable_id, method, path, params)
@@ -35,9 +41,11 @@ module Prometheus
def initialize(proxyable, method, path, params)
@proxyable = proxyable
@path = path
+
# Convert ActionController::Parameters to hash because reactive_cache_worker
# does not play nice with ActionController::Parameters.
- @params = params.to_hash
+ @params = permit_params(params, path).to_hash
+
@method = method
end
@@ -94,8 +102,16 @@ module Prometheus
prometheus_adapter&.can_query?
end
+ def permit_params(params, path)
+ if params.is_a?(ActionController::Parameters)
+ params.permit(PROXY_SUPPORT.dig(path, :params))
+ else
+ params
+ end
+ end
+
def can_proxy?
- PROXY_SUPPORT[@path] == @method
+ PROXY_SUPPORT.dig(@path, :method)&.include?(@method)
end
end
end