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 ...@@ -222,8 +222,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def metrics_dashboard_params def metrics_dashboard_params
params params
.permit(:embedded, :group, :title, :y_label, :dashboard_path, :environment) .permit(:embedded, :group, :title, :y_label, :dashboard_path, :environment, :sample_metrics)
.merge(dashboard_path: params[:dashboard], environment: environment) .merge(dashboard_path: params[:dashboard], environment: environment, sample_metrics: params[:sample_metrics])
end end
def include_all_dashboards? def include_all_dashboards?
......
...@@ -242,7 +242,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -242,7 +242,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get '/prometheus/api/v1/*proxy_path', to: 'environments/prometheus_api#proxy', as: :prometheus_api 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 end
collection do collection do
......
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
private private
def endpoint_for_metric(metric) def endpoint_for_metric(metric)
if ENV['USE_SAMPLE_METRICS'] if params[:sample_metrics]
Gitlab::Routing.url_helpers.sample_metrics_project_environment_path( Gitlab::Routing.url_helpers.sample_metrics_project_environment_path(
project, project,
params[:environment], params[:environment],
......
...@@ -86,6 +86,16 @@ describe Gitlab::Metrics::Dashboard::Processor do ...@@ -86,6 +86,16 @@ describe Gitlab::Metrics::Dashboard::Processor do
expect(metrics).to eq %w(metric_b metric_a2 metric_a1) expect(metrics).to eq %w(metric_b metric_a2 metric_a1)
end end
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 end
shared_examples_for 'errors with message' do |expected_message| shared_examples_for 'errors with message' do |expected_message|
...@@ -147,4 +157,12 @@ describe Gitlab::Metrics::Dashboard::Processor do ...@@ -147,4 +157,12 @@ describe Gitlab::Metrics::Dashboard::Processor do
query: query query: query
) )
end end
def sample_metrics_path(metric)
Gitlab::Routing.url_helpers.sample_metrics_project_environment_path(
project,
environment,
identifier: metric
)
end
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