diff options
author | Reuben Pereira <rpereira@gitlab.com> | 2019-04-15 15:31:59 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-04-15 15:31:59 +0000 |
commit | 434359446a5436d6c11b66c7107ecaea133cd6e1 (patch) | |
tree | 126ef533dcd8488d14c408e46e67596c29573b43 /app/controllers/projects/environments | |
parent | e7c9bcec5c44e3afd7e89dc5380d9d7aa5235150 (diff) | |
download | gitlab-ce-434359446a5436d6c11b66c7107ecaea133cd6e1.tar.gz |
Add ability to do variable substitution
- In prometheus proxy api, allow variables to be replaced. For example,
if 'up{env="%{ci_environment_slug}"}' is passed to the endpoint, it
becomes 'up{env="production"}' before being sent to prometheus.
Diffstat (limited to 'app/controllers/projects/environments')
-rw-r--r-- | app/controllers/projects/environments/prometheus_api_controller.rb | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/app/controllers/projects/environments/prometheus_api_controller.rb b/app/controllers/projects/environments/prometheus_api_controller.rb index fd3320637b0..f8ef23cd83e 100644 --- a/app/controllers/projects/environments/prometheus_api_controller.rb +++ b/app/controllers/projects/environments/prometheus_api_controller.rb @@ -7,9 +7,9 @@ class Projects::Environments::PrometheusApiController < Projects::ApplicationCon def proxy result = Prometheus::ProxyService.new( environment, - request.method, - params[:proxy_path], - params.permit! + proxy_method, + proxy_path, + proxy_params ).execute if result.nil? @@ -31,7 +31,30 @@ class Projects::Environments::PrometheusApiController < Projects::ApplicationCon private + def query_context + Gitlab::Prometheus::QueryVariables.call(environment) + end + def environment @environment ||= project.environments.find(params[:id]) end + + def proxy_method + request.method + end + + def proxy_path + params[:proxy_path] + end + + def proxy_params + substitute_query_variables(params).permit! + end + + def substitute_query_variables(params) + query = params[:query] + return params unless query + + params.merge(query: query % query_context) + end end |