Commit c8ee259d authored by rpereira2's avatar rpereira2

Move metrics helper out of EE

Since custom metrics is moving into Core, move the custom metrics
helper function out of EE.
parent 92d4d9bf
...@@ -18,6 +18,10 @@ module EnvironmentsHelper ...@@ -18,6 +18,10 @@ module EnvironmentsHelper
} }
end end
def custom_metrics_available?(project)
can?(current_user, :admin_project, project)
end
def metrics_data(project, environment) def metrics_data(project, environment)
{ {
"settings-path" => edit_project_service_path(project, 'prometheus'), "settings-path" => edit_project_service_path(project, 'prometheus'),
...@@ -39,7 +43,10 @@ module EnvironmentsHelper ...@@ -39,7 +43,10 @@ module EnvironmentsHelper
"has-metrics" => "#{environment.has_metrics?}", "has-metrics" => "#{environment.has_metrics?}",
"prometheus-status" => "#{environment.prometheus_status}", "prometheus-status" => "#{environment.prometheus_status}",
"external-dashboard-url" => project.metrics_setting_external_dashboard_url, "external-dashboard-url" => project.metrics_setting_external_dashboard_url,
"environment-state" => "#{environment.state}" "environment-state" => "#{environment.state}",
"custom-metrics-path" => project_prometheus_metrics_path(project),
"validate-query-path" => validate_query_project_prometheus_metrics_path(project),
"custom-metrics-available" => "#{custom_metrics_available?(project)}"
} }
end end
......
...@@ -26,15 +26,8 @@ module EE ...@@ -26,15 +26,8 @@ module EE
super.merge(ee_environments_folder_list_view_data) super.merge(ee_environments_folder_list_view_data)
end end
def custom_metrics_available?(project)
can?(current_user, :admin_project, project)
end
def metrics_data(project, environment) def metrics_data(project, environment)
ee_metrics_data = { ee_metrics_data = {
"custom-metrics-path" => project_prometheus_metrics_path(project),
"validate-query-path" => validate_query_project_prometheus_metrics_path(project),
"custom-metrics-available" => "#{custom_metrics_available?(project)}",
"alerts-endpoint" => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json), "alerts-endpoint" => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
"prometheus-alerts-available" => "#{can?(current_user, :read_prometheus_alerts, project)}" "prometheus-alerts-available" => "#{can?(current_user, :read_prometheus_alerts, project)}"
} }
......
...@@ -26,9 +26,6 @@ describe EnvironmentsHelper do ...@@ -26,9 +26,6 @@ describe EnvironmentsHelper do
it 'returns additional configuration' do it 'returns additional configuration' do
expect(subject).to include( expect(subject).to include(
'custom-metrics-path' => project_prometheus_metrics_path(project),
'validate-query-path' => validate_query_project_prometheus_metrics_path(project),
'custom-metrics-available' => 'true',
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json), 'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
'prometheus-alerts-available' => 'true', 'prometheus-alerts-available' => 'true',
'logs_path' => project_logs_path(project, environment_name: environment.name) 'logs_path' => project_logs_path(project, environment_name: environment.name)
...@@ -72,22 +69,4 @@ describe EnvironmentsHelper do ...@@ -72,22 +69,4 @@ describe EnvironmentsHelper do
) )
end end
end end
describe '#custom_metrics_available?' do
subject { helper.custom_metrics_available?(project) }
before do
project.add_maintainer(user)
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?)
.with(user, :admin_project, project)
.and_return(true)
end
it 'returns true' do
expect(subject).to eq(true)
end
end
end end
...@@ -34,7 +34,10 @@ describe EnvironmentsHelper do ...@@ -34,7 +34,10 @@ describe EnvironmentsHelper do
'has-metrics' => "#{environment.has_metrics?}", 'has-metrics' => "#{environment.has_metrics?}",
'prometheus-status' => "#{environment.prometheus_status}", 'prometheus-status' => "#{environment.prometheus_status}",
'external-dashboard-url' => nil, 'external-dashboard-url' => nil,
'environment-state' => environment.state 'environment-state' => environment.state,
'custom-metrics-path' => project_prometheus_metrics_path(project),
'validate-query-path' => validate_query_project_prometheus_metrics_path(project),
'custom-metrics-available' => 'true'
) )
end end
...@@ -58,4 +61,22 @@ describe EnvironmentsHelper do ...@@ -58,4 +61,22 @@ describe EnvironmentsHelper do
it { is_expected.to include('environment-state' => 'stopped') } it { is_expected.to include('environment-state' => 'stopped') }
end end
end end
describe '#custom_metrics_available?' do
subject { helper.custom_metrics_available?(project) }
before do
project.add_maintainer(user)
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?)
.with(user, :admin_project, project)
.and_return(true)
end
it 'returns true' do
expect(subject).to eq(true)
end
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