Commit 86878136 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'sample-metrics-from-ui' into 'master'

Backend for allowing sample metrics to be toggled from ui

See merge request gitlab-org/gitlab!22901
parents eee7f704 5cc30f97
......@@ -222,7 +222,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def metrics_dashboard_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)
end
......
---
title: Backend for allowing sample metrics to be toggled from ui
merge_request: 22901
author:
type: added
......@@ -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],
......
......@@ -9,17 +9,6 @@ describe Projects::Environments::SampleMetricsController do
let_it_be(:environment) { create(:environment, project: project) }
let_it_be(:user) { create(:user) }
before(:context) do
RSpec::Mocks.with_temporary_scope do
stub_env('USE_SAMPLE_METRICS', 'true')
Rails.application.reload_routes!
end
end
after(:context) do
Rails.application.reload_routes!
end
before do
project.add_reporter(user)
sign_in(user)
......
......@@ -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 requested' 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