Commit 66ff5cb0 authored by Kirstie Cook's avatar Kirstie Cook

Backend for allowing sample metrics to be toggled from ui

parent c618698c
......@@ -222,8 +222,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def metrics_dashboard_params
params
.permit(:embedded, :group, :title, :y_label, :dashboard_path, :environment)
.merge(dashboard_path: params[:dashboard], environment: environment)
.permit(:embedded, :group, :title, :y_label, :dashboard_path, :environment, :sample_metrics)
.merge(dashboard_path: params[:dashboard], environment: environment, sample_metrics: params[:sample_metrics])
end
def include_all_dashboards?
......
......@@ -242,7 +242,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get '/prometheus/api/v1/*proxy_path', to: 'environments/prometheus_api#proxy', as: :prometheus_api
get '/sample_metrics', to: 'environments/sample_metrics#query' if ENV['USE_SAMPLE_METRICS']
get '/sample_metrics', to: 'environments/sample_metrics#query'
end
collection do
......
......@@ -16,7 +16,7 @@ module Gitlab
private
def endpoint_for_metric(metric)
if ENV['USE_SAMPLE_METRICS']
if params[:sample_metrics]
Gitlab::Routing.url_helpers.sample_metrics_project_environment_path(
project,
params[:environment],
......
......@@ -86,6 +86,16 @@ describe Gitlab::Metrics::Dashboard::Processor do
expect(metrics).to eq %w(metric_b metric_a2 metric_a1)
end
end
context 'when sample metrics are present' do
let(:process_params) { [project, dashboard_yml, sequence, { environment: environment, sample_metrics: true }] }
it 'includes a sample metrics path for the prometheus endpoint with each metric' do
expect(all_metrics).to satisfy_all do |metric|
metric[:prometheus_endpoint_path] == sample_metrics_path(metric[:id])
end
end
end
end
shared_examples_for 'errors with message' do |expected_message|
......@@ -147,4 +157,12 @@ describe Gitlab::Metrics::Dashboard::Processor do
query: query
)
end
def sample_metrics_path(metric)
Gitlab::Routing.url_helpers.sample_metrics_project_environment_path(
project,
environment,
identifier: metric
)
end
end
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