Commit 4099058e authored by Michael Kozono's avatar Michael Kozono

Merge branch 'rc/update_metrics_dashboard_base_path' into 'master'

Update metrics dashboard base path

See merge request gitlab-org/gitlab!36749
parents 1dbe1911 b2e96637
......@@ -24,7 +24,7 @@ module EnvironmentsHelper
def metrics_data(project, environment)
metrics_data = {}
metrics_data.merge!(project_metrics_data(project)) if project
metrics_data.merge!(environment_metrics_data(environment)) if environment
metrics_data.merge!(environment_metrics_data(environment, project)) if environment
metrics_data.merge!(project_and_environment_metrics_data(project, environment)) if project && environment
metrics_data.merge!(static_metrics_data)
......@@ -66,11 +66,11 @@ module EnvironmentsHelper
}
end
def environment_metrics_data(environment)
def environment_metrics_data(environment, project = nil)
return {} unless environment
{
'metrics-dashboard-base-path' => environment_metrics_path(environment),
'metrics-dashboard-base-path' => metrics_dashboard_base_path(environment, project),
'current-environment-name' => environment.name,
'has-metrics' => "#{environment.has_metrics?}",
'prometheus-status' => "#{environment.prometheus_status}",
......@@ -78,6 +78,17 @@ module EnvironmentsHelper
}
end
def metrics_dashboard_base_path(environment, project)
# This is needed to support our transition from environment scoped metric paths to project scoped.
if project
path = project_metrics_dashboard_path(project)
return path if request.path.include?(path)
end
environment_metrics_path(environment)
end
def project_and_environment_metrics_data(project, environment)
return {} unless project && environment
......
......@@ -95,6 +95,30 @@ RSpec.describe EnvironmentsHelper do
it { is_expected.to include('environment-state' => 'stopped') }
end
context 'when request is from project scoped metrics path' do
let(:request) { double('request', path: path) }
before do
allow(helper).to receive(:request).and_return(request)
end
context '/:namespace/:project/-/metrics' do
let(:path) { project_metrics_dashboard_path(project) }
it 'uses correct path for metrics-dashboard-base-path' do
expect(metrics_data['metrics-dashboard-base-path']).to eq(project_metrics_dashboard_path(project))
end
end
context '/:namespace/:project/-/metrics/some_custom_dashboard.yml' do
let(:path) { "#{project_metrics_dashboard_path(project)}/some_custom_dashboard.yml" }
it 'uses correct path for metrics-dashboard-base-path' do
expect(metrics_data['metrics-dashboard-base-path']).to eq(project_metrics_dashboard_path(project))
end
end
end
end
describe '#custom_metrics_available?' do
......
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