Commit d8075a3c authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'rc/add_new_dashboard_route' into 'master'

Add new dashboard route

See merge request gitlab-org/gitlab!33905
parents e2fe6aec cd46f7f9
import monitoringApp from '~/monitoring/monitoring_app';
document.addEventListener('DOMContentLoaded', monitoringApp);
# frozen_string_literal: true
class Projects::EnvironmentsController < Projects::ApplicationController
# Metrics dashboard code is getting decoupled from environments and is being moved
# into app/controllers/projects/metrics_dashboard_controller.rb
# See https://gitlab.com/gitlab-org/gitlab/-/issues/226002 for more details.
include MetricsDashboard
layout 'project'
......
# frozen_string_literal: true
module Projects
class MetricsDashboardController < Projects::ApplicationController
# Metrics dashboard code is in the process of being decoupled from environments
# and is getting moved to this controller. Some code may be duplicated from
# app/controllers/projects/environments_controller.rb
# See https://gitlab.com/gitlab-org/gitlab/-/issues/226002 for more details.
before_action :authorize_metrics_dashboard!
before_action do
push_frontend_feature_flag(:prometheus_computed_alerts)
end
def show
if environment
render 'projects/environments/metrics'
else
render_404
end
end
private
def environment
@environment ||=
if params[:environment]
project.environments.find(params[:environment])
else
project.default_environment
end
end
end
end
---
title: Add new path to access project metrics dashboard
merge_request: 33905
author:
type: added
......@@ -25,6 +25,8 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# Use this scope for all new project routes.
scope '-' do
get 'archive/*id', constraints: { format: Gitlab::PathRegex.archive_formats_regex, id: /.+?/ }, to: 'repositories#archive', as: 'archive'
get 'metrics(/:dashboard_path)', constraints: { dashboard_path: /.+\.yml/ },
to: 'metrics_dashboard#show', as: :metrics_dashboard, format: false
resources :artifacts, only: [:index, :destroy]
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'metrics dashboard page' do
let_it_be(:project) { create(:project) }
let_it_be(:environment) { create(:environment, project: project) }
let_it_be(:environment2) { create(:environment, project: project) }
let_it_be(:user) { project.owner }
before do
project.add_developer(user)
login_as(user)
end
describe 'GET /:namespace/:project/-/metrics' do
it 'returns 200' do
send_request
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns environment' do
send_request
expect(assigns(:environment).id).to eq(environment.id)
end
end
describe 'GET /:namespace/:project/-/metrics?environment=:environment.id' do
it 'returns 200' do
send_request(environment: environment2.id)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns query param environment' do
send_request(environment: environment2.id)
expect(assigns(:environment).id).to eq(environment2.id)
end
context 'when query param environment does not exist' do
it 'responds with 404' do
send_request(environment: 99)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe 'GET /:namespace/:project/-/metrics/:dashboard_path' do
let(:dashboard_path) { '.gitlab/dashboards/dashboard_path.yml' }
it 'returns 200' do
send_request(dashboard_path: dashboard_path)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns environment' do
send_request(dashboard_path: dashboard_path)
expect(assigns(:environment).id).to eq(environment.id)
end
end
describe 'GET :/namespace/:project/-/metrics/:dashboard_path?environment=:environment.id' do
let(:dashboard_path) { '.gitlab/dashboards/dashboard_path.yml' }
it 'returns 200' do
send_request(dahboard_path: dashboard_path, environment: environment.id)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns query param environment' do
send_request(dashboard_path: dashboard_path, environment: environment2.id)
expect(assigns(:environment).id).to eq(environment2.id)
end
context 'when query param environment does not exist' do
it 'responds with 404' do
send_request(dashboard_path: dashboard_path, environment: 99)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
def send_request(params = {})
get namespace_project_metrics_dashboard_path(namespace_id: project.namespace, project_id: project, **params)
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