Commit e347170c authored by Sean McGivern's avatar Sean McGivern

Merge branch '51972-prometheus-not-showing-as-installed-even-though-it-is' into 'master'

Resolve "Prometheus not showing as installed, even though it is"

Closes #51972

See merge request gitlab-org/gitlab-ce!22356
parents 68d4dc88 3a3ec6f0
...@@ -19,7 +19,7 @@ module Clusters ...@@ -19,7 +19,7 @@ module Clusters
def set_initial_status def set_initial_status
return unless not_installable? return unless not_installable?
if cluster&.application_ingress_installed? && cluster.application_ingress.external_ip if cluster&.application_ingress_available? && cluster.application_ingress.external_ip
self.status = 'installable' self.status = 'installable'
end end
end end
......
...@@ -43,8 +43,9 @@ module Clusters ...@@ -43,8 +43,9 @@ module Clusters
delegate :active?, to: :platform_kubernetes, prefix: true, allow_nil: true delegate :active?, to: :platform_kubernetes, prefix: true, allow_nil: true
delegate :rbac?, to: :platform_kubernetes, prefix: true, allow_nil: true delegate :rbac?, to: :platform_kubernetes, prefix: true, allow_nil: true
delegate :installed?, to: :application_helm, prefix: true, allow_nil: true delegate :available?, to: :application_helm, prefix: true, allow_nil: true
delegate :installed?, to: :application_ingress, prefix: true, allow_nil: true delegate :available?, to: :application_ingress, prefix: true, allow_nil: true
delegate :available?, to: :application_prometheus, prefix: true, allow_nil: true
enum platform_type: { enum platform_type: {
kubernetes: 1 kubernetes: 1
......
...@@ -15,7 +15,7 @@ module Clusters ...@@ -15,7 +15,7 @@ module Clusters
def set_initial_status def set_initial_status
return unless not_installable? return unless not_installable?
self.status = 'installable' if cluster&.application_helm_installed? self.status = 'installable' if cluster&.application_helm_available?
end end
def self.application_name def self.application_name
......
...@@ -66,6 +66,10 @@ module Clusters ...@@ -66,6 +66,10 @@ module Clusters
end end
end end
end end
def available?
installed? || updated?
end
end end
end end
end end
...@@ -26,7 +26,7 @@ class PrometheusService < MonitoringService ...@@ -26,7 +26,7 @@ class PrometheusService < MonitoringService
end end
def editable? def editable?
manual_configuration? || !prometheus_installed? manual_configuration? || !prometheus_available?
end end
def title def title
...@@ -75,17 +75,17 @@ class PrometheusService < MonitoringService ...@@ -75,17 +75,17 @@ class PrometheusService < MonitoringService
RestClient::Resource.new(api_url) if api_url && manual_configuration? && active? RestClient::Resource.new(api_url) if api_url && manual_configuration? && active?
end end
def prometheus_installed? def prometheus_available?
return false if template? return false if template?
return false unless project return false unless project
project.clusters.enabled.any? { |cluster| cluster.application_prometheus&.installed? } project.clusters.enabled.any? { |cluster| cluster.application_prometheus_available? }
end end
private private
def synchronize_service_state def synchronize_service_state
self.active = prometheus_installed? || manual_configuration? self.active = prometheus_available? || manual_configuration?
true true
end end
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
- else - else
.container-fluid .container-fluid
.row .row
- if service.prometheus_installed? - if service.prometheus_available?
.col-sm-2 .col-sm-2
.svg-container .svg-container
= image_tag 'illustrations/monitoring/getting_started.svg' = image_tag 'illustrations/monitoring/getting_started.svg'
......
---
title: Show available clusters when installed or updated
merge_request: 22356
author:
type: fixed
...@@ -4,7 +4,7 @@ describe Clusters::Applications::Ingress do ...@@ -4,7 +4,7 @@ describe Clusters::Applications::Ingress do
let(:ingress) { create(:clusters_applications_ingress) } let(:ingress) { create(:clusters_applications_ingress) }
include_examples 'cluster application core specs', :clusters_applications_ingress include_examples 'cluster application core specs', :clusters_applications_ingress
include_examples 'cluster application status specs', :cluster_application_ingress include_examples 'cluster application status specs', :clusters_applications_ingress
before do before do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in) allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
......
...@@ -4,7 +4,7 @@ describe Clusters::Applications::Prometheus do ...@@ -4,7 +4,7 @@ describe Clusters::Applications::Prometheus do
include KubernetesHelpers include KubernetesHelpers
include_examples 'cluster application core specs', :clusters_applications_prometheus include_examples 'cluster application core specs', :clusters_applications_prometheus
include_examples 'cluster application status specs', :cluster_application_prometheus include_examples 'cluster application status specs', :clusters_applications_prometheus
describe '.installed' do describe '.installed' do
subject { described_class.installed } subject { described_class.installed }
......
...@@ -4,7 +4,7 @@ describe Clusters::Applications::Runner do ...@@ -4,7 +4,7 @@ describe Clusters::Applications::Runner do
let(:ci_runner) { create(:ci_runner) } let(:ci_runner) { create(:ci_runner) }
include_examples 'cluster application core specs', :clusters_applications_runner include_examples 'cluster application core specs', :clusters_applications_runner
include_examples 'cluster application status specs', :cluster_application_runner include_examples 'cluster application status specs', :clusters_applications_runner
it { is_expected.to belong_to(:runner) } it { is_expected.to belong_to(:runner) }
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Clusters::Cluster do describe Clusters::Cluster do
...@@ -15,8 +17,9 @@ describe Clusters::Cluster do ...@@ -15,8 +17,9 @@ describe Clusters::Cluster do
it { is_expected.to delegate_method(:on_creation?).to(:provider) } it { is_expected.to delegate_method(:on_creation?).to(:provider) }
it { is_expected.to delegate_method(:active?).to(:platform_kubernetes).with_prefix } it { is_expected.to delegate_method(:active?).to(:platform_kubernetes).with_prefix }
it { is_expected.to delegate_method(:rbac?).to(:platform_kubernetes).with_prefix } it { is_expected.to delegate_method(:rbac?).to(:platform_kubernetes).with_prefix }
it { is_expected.to delegate_method(:installed?).to(:application_helm).with_prefix } it { is_expected.to delegate_method(:available?).to(:application_helm).with_prefix }
it { is_expected.to delegate_method(:installed?).to(:application_ingress).with_prefix } it { is_expected.to delegate_method(:available?).to(:application_ingress).with_prefix }
it { is_expected.to delegate_method(:available?).to(:application_prometheus).with_prefix }
it { is_expected.to respond_to :project } it { is_expected.to respond_to :project }
describe '.enabled' do describe '.enabled' do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe PrometheusService, :use_clean_rails_memory_store_caching do describe PrometheusService, :use_clean_rails_memory_store_caching do
...@@ -83,13 +85,22 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do ...@@ -83,13 +85,22 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
end end
end end
describe '#prometheus_installed?' do describe '#prometheus_available?' do
context 'clusters with installed prometheus' do context 'clusters with installed prometheus' do
let!(:cluster) { create(:cluster, projects: [project]) } let!(:cluster) { create(:cluster, projects: [project]) }
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
it 'returns true' do it 'returns true' do
expect(service.prometheus_installed?).to be(true) expect(service.prometheus_available?).to be(true)
end
end
context 'clusters with updated prometheus' do
let!(:cluster) { create(:cluster, projects: [project]) }
let!(:prometheus) { create(:clusters_applications_prometheus, :updated, cluster: cluster) }
it 'returns true' do
expect(service.prometheus_available?).to be(true)
end end
end end
...@@ -98,7 +109,7 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do ...@@ -98,7 +109,7 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
let!(:prometheus) { create(:clusters_applications_prometheus, cluster: cluster) } let!(:prometheus) { create(:clusters_applications_prometheus, cluster: cluster) }
it 'returns false' do it 'returns false' do
expect(service.prometheus_installed?).to be(false) expect(service.prometheus_available?).to be(false)
end end
end end
...@@ -106,13 +117,13 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do ...@@ -106,13 +117,13 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
let(:cluster) { create(:cluster, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
it 'returns false' do it 'returns false' do
expect(service.prometheus_installed?).to be(false) expect(service.prometheus_available?).to be(false)
end end
end end
context 'no clusters' do context 'no clusters' do
it 'returns false' do it 'returns false' do
expect(service.prometheus_installed?).to be(false) expect(service.prometheus_available?).to be(false)
end end
end end
end end
...@@ -150,7 +161,7 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do ...@@ -150,7 +161,7 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
context 'with prometheus installed in the cluster' do context 'with prometheus installed in the cluster' do
before do before do
allow(service).to receive(:prometheus_installed?).and_return(true) allow(service).to receive(:prometheus_available?).and_return(true)
end end
context 'when service is inactive' do context 'when service is inactive' do
......
...@@ -11,60 +11,4 @@ shared_examples 'cluster application core specs' do |application_name| ...@@ -11,60 +11,4 @@ shared_examples 'cluster application core specs' do |application_name|
expect(Clusters::Cluster::APPLICATIONS[subject.name]).to eq(described_class) expect(Clusters::Cluster::APPLICATIONS[subject.name]).to eq(described_class)
end end
end end
describe 'status state machine' do
describe '#make_installing' do
subject { create(application_name, :scheduled) }
it 'is installing' do
subject.make_installing!
expect(subject).to be_installing
end
end
describe '#make_installed' do
subject { create(application_name, :installing) }
it 'is installed' do
subject.make_installed
expect(subject).to be_installed
end
end
describe '#make_errored' do
subject { create(application_name, :installing) }
let(:reason) { 'some errors' }
it 'is errored' do
subject.make_errored(reason)
expect(subject).to be_errored
expect(subject.status_reason).to eq(reason)
end
end
describe '#make_scheduled' do
subject { create(application_name, :installable) }
it 'is scheduled' do
subject.make_scheduled
expect(subject).to be_scheduled
end
describe 'when was errored' do
subject { create(application_name, :errored) }
it 'clears #status_reason' do
expect(subject.status_reason).not_to be_nil
subject.make_scheduled!
expect(subject.status_reason).to be_nil
end
end
end
end
end end
...@@ -28,4 +28,87 @@ shared_examples 'cluster application status specs' do |application_name| ...@@ -28,4 +28,87 @@ shared_examples 'cluster application status specs' do |application_name|
end end
end end
end end
describe 'status state machine' do
describe '#make_installing' do
subject { create(application_name, :scheduled) }
it 'is installing' do
subject.make_installing!
expect(subject).to be_installing
end
end
describe '#make_installed' do
subject { create(application_name, :installing) }
it 'is installed' do
subject.make_installed
expect(subject).to be_installed
end
end
describe '#make_errored' do
subject { create(application_name, :installing) }
let(:reason) { 'some errors' }
it 'is errored' do
subject.make_errored(reason)
expect(subject).to be_errored
expect(subject.status_reason).to eq(reason)
end
end
describe '#make_scheduled' do
subject { create(application_name, :installable) }
it 'is scheduled' do
subject.make_scheduled
expect(subject).to be_scheduled
end
describe 'when was errored' do
subject { create(application_name, :errored) }
it 'clears #status_reason' do
expect(subject.status_reason).not_to be_nil
subject.make_scheduled!
expect(subject.status_reason).to be_nil
end
end
end
end
describe '#available?' do
using RSpec::Parameterized::TableSyntax
where(:trait, :available) do
:not_installable | false
:installable | false
:scheduled | false
:installing | false
:installed | true
:updating | false
:updated | true
:errored | false
:update_errored | false
:timeouted | false
end
with_them do
subject { build(application_name, trait) }
if params[:available]
it { is_expected.to be_available }
else
it { is_expected.not_to be_available }
end
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