Commit 273c1336 authored by Thong Kuah's avatar Thong Kuah

Fix cluster metrics override for EE

parent dd8a715b
# frozen_string_literal: true
class Projects::ClustersController < Clusters::ClustersController
prepend EE::Projects::ClustersController
include ProjectUnauthorized
prepend_before_action :project
......
......@@ -100,7 +100,7 @@ Rails.application.routes.draw do
member do
# EE specific
get :metrics, to: 'clusters/cluster_metrics#show', as: :metrics
get :metrics, format: :json
scope :applications do
post '/:application', to: 'clusters/applications#create', as: :install_applications
......
import '~/pages/clusters/show';
import '~/pages/projects/clusters/show';
import initClusterHealth from './cluster_health';
document.addEventListener('DOMContentLoaded', initClusterHealth);
# frozen_string_literal: true
class Clusters::ClusterMetricsController < Clusters::BaseController
before_action :cluster, only: :metrics
before_action :authorize_read_cluster!
def show
return render_404 unless prometheus_adapter&.can_query?
respond_to do |format|
format.json do
metrics = prometheus_adapter.query(:cluster) || {}
if metrics.any?
render json: metrics
else
head :no_content
end
end
end
end
private
def cluster
@cluster ||= clusterable.clusters.find(params[:id])
.present(current_user: current_user)
end
def prometheus_adapter
return unless cluster&.application_prometheus_available?
cluster.application_prometheus
end
end
module EE
module Projects
module ClustersController
extend ActiveSupport::Concern
def metrics
return render_404 unless prometheus_adapter&.can_query?
respond_to do |format|
format.json do
metrics = prometheus_adapter.query(:cluster) || {}
if metrics.any?
render json: metrics
else
head :no_content
end
end
end
end
private
def prometheus_adapter
return unless cluster&.application_prometheus_available?
cluster.application_prometheus
end
end
end
end
......@@ -10,7 +10,7 @@
"empty-loading-svg-path": image_path('illustrations/monitoring/loading.svg'),
"empty-no-data-svg-path": image_path('illustrations/monitoring/no_data.svg'),
"empty-unable-to-connect-svg-path": image_path('illustrations/monitoring/unable_to_connect.svg'),
"metrics-endpoint": metrics_cluster_path(clusterable_params.merge(format: :json)),
"metrics-endpoint": metrics_namespace_project_cluster_path( format: :json ),
"project-path": project_path(@project),
"tags-path": project_tags_path(@project) } }
......
require 'spec_helper'
describe Clusters::ClusterMetricsController do
describe Projects::ClustersController do
include AccessMatchersForController
set(:project) { create(:project) }
describe 'GET show' do
describe 'GET metrics' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
describe 'functionality' do
......@@ -69,11 +69,10 @@ describe Clusters::ClusterMetricsController do
end
def go
get :show,
format: :json,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: cluster
get :metrics, format: :json,
namespace_id: project.namespace,
project_id: project,
id: cluster
end
describe 'security' do
......
......@@ -9,7 +9,7 @@ describe 'Gcp Cluster', :js do
before do
project.add_maintainer(user)
gitlab_sign_in(user)
allow(ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
allow(Projects::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
end
context 'when a user has a licence to use multiple clusers' do
......
......@@ -75,11 +75,14 @@ describe 'EE Clusters', :js do
context 'when user adds an Google Kubernetes Engine cluster' do
before do
allow_any_instance_of(ClustersController)
allow_any_instance_of(Projects::ClustersController)
.to receive(:token_in_session).and_return('token')
allow_any_instance_of(ClustersController)
allow_any_instance_of(Projects::ClustersController)
.to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
allow_any_instance_of(Projects::ClustersController).to receive(:authorize_google_project_billing)
allow_any_instance_of(Projects::ClustersController).to receive(:google_project_billing_status).and_return(true)
allow_any_instance_of(GoogleApi::CloudPlatform::Client)
.to receive(:projects_zones_clusters_create) do
OpenStruct.new(
......
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