Commit 25c6980f authored by Tiger Watson's avatar Tiger Watson

Merge branch 'use-cluster-integrations-by-default' into 'master'

Use cluster integrations by default [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!62725
parents 2cc62492 c67c7053
...@@ -49,7 +49,7 @@ module Projects ...@@ -49,7 +49,7 @@ module Projects
def has_prometheus?(environment_scope) def has_prometheus?(environment_scope)
finders_for_scope(environment_scope).any? do |finder| finders_for_scope(environment_scope).any? do |finder|
finder.cluster.application_prometheus_available? finder.cluster.integration_prometheus_available?
end end
end end
......
...@@ -74,7 +74,6 @@ module EnvironmentsHelper ...@@ -74,7 +74,6 @@ module EnvironmentsHelper
'metrics_dashboard_base_path' => metrics_dashboard_base_path(environment, project), 'metrics_dashboard_base_path' => metrics_dashboard_base_path(environment, project),
'current_environment_name' => environment.name, 'current_environment_name' => environment.name,
'has_metrics' => "#{environment.has_metrics?}", 'has_metrics' => "#{environment.has_metrics?}",
'prometheus_status' => "#{environment.prometheus_status}",
'environment_state' => "#{environment.state}" 'environment_state' => "#{environment.state}"
} }
end end
......
...@@ -141,13 +141,13 @@ module Clusters ...@@ -141,13 +141,13 @@ module Clusters
end end
def install_knative_metrics def install_knative_metrics
return [] unless cluster.application_prometheus_available? return [] unless cluster.application_prometheus&.available?
[Gitlab::Kubernetes::KubectlCmd.apply_file(METRICS_CONFIG)] [Gitlab::Kubernetes::KubectlCmd.apply_file(METRICS_CONFIG)]
end end
def delete_knative_istio_metrics def delete_knative_istio_metrics
return [] unless cluster.application_prometheus_available? return [] unless cluster.application_prometheus&.available?
[Gitlab::Kubernetes::KubectlCmd.delete("--ignore-not-found", "-f", METRICS_CONFIG)] [Gitlab::Kubernetes::KubectlCmd.delete("--ignore-not-found", "-f", METRICS_CONFIG)]
end end
......
...@@ -104,8 +104,8 @@ module Clusters ...@@ -104,8 +104,8 @@ module Clusters
delegate :available?, to: :application_helm, prefix: true, allow_nil: true delegate :available?, to: :application_helm, prefix: true, allow_nil: true
delegate :available?, to: :application_ingress, prefix: true, allow_nil: true delegate :available?, to: :application_ingress, prefix: true, allow_nil: true
delegate :available?, to: :application_knative, prefix: true, allow_nil: true delegate :available?, to: :application_knative, prefix: true, allow_nil: true
delegate :available?, to: :application_elastic_stack, prefix: true, allow_nil: true
delegate :available?, to: :integration_elastic_stack, prefix: true, allow_nil: true delegate :available?, to: :integration_elastic_stack, prefix: true, allow_nil: true
delegate :available?, to: :integration_prometheus, prefix: true, allow_nil: true
delegate :external_ip, to: :application_ingress, prefix: true, allow_nil: true delegate :external_ip, to: :application_ingress, prefix: true, allow_nil: true
delegate :external_hostname, to: :application_ingress, prefix: true, allow_nil: true delegate :external_hostname, to: :application_ingress, prefix: true, allow_nil: true
...@@ -142,7 +142,7 @@ module Clusters ...@@ -142,7 +142,7 @@ module Clusters
scope :with_available_elasticstack, -> { joins(:application_elastic_stack).merge(::Clusters::Applications::ElasticStack.available) } scope :with_available_elasticstack, -> { joins(:application_elastic_stack).merge(::Clusters::Applications::ElasticStack.available) }
scope :with_available_cilium, -> { joins(:application_cilium).merge(::Clusters::Applications::Cilium.available) } scope :with_available_cilium, -> { joins(:application_cilium).merge(::Clusters::Applications::Cilium.available) }
scope :distinct_with_deployed_environments, -> { joins(:environments).merge(::Deployment.success).distinct } scope :distinct_with_deployed_environments, -> { joins(:environments).merge(::Deployment.success).distinct }
scope :preload_elasticstack, -> { preload(:application_elastic_stack) } scope :preload_elasticstack, -> { preload(:integration_elastic_stack) }
scope :preload_environments, -> { preload(:environments) } scope :preload_environments, -> { preload(:environments) }
scope :managed, -> { where(managed: true) } scope :managed, -> { where(managed: true) }
...@@ -325,7 +325,7 @@ module Clusters ...@@ -325,7 +325,7 @@ module Clusters
end end
def elastic_stack_adapter def elastic_stack_adapter
application_elastic_stack || integration_elastic_stack integration_elastic_stack
end end
def elasticsearch_client def elasticsearch_client
...@@ -333,11 +333,7 @@ module Clusters ...@@ -333,11 +333,7 @@ module Clusters
end end
def elastic_stack_available? def elastic_stack_available?
if application_elastic_stack_available? || integration_elastic_stack_available? !!integration_elastic_stack_available?
true
else
false
end
end end
def kubernetes_namespace_for(environment, deployable: environment.last_deployable) def kubernetes_namespace_for(environment, deployable: environment.last_deployable)
...@@ -391,12 +387,8 @@ module Clusters ...@@ -391,12 +387,8 @@ module Clusters
end end
end end
def application_prometheus_available?
integration_prometheus&.available? || application_prometheus&.available?
end
def prometheus_adapter def prometheus_adapter
integration_prometheus || application_prometheus integration_prometheus
end end
private private
......
...@@ -335,10 +335,6 @@ class Environment < ApplicationRecord ...@@ -335,10 +335,6 @@ class Environment < ApplicationRecord
prometheus_adapter.query(:environment, self) if has_metrics_and_can_query? prometheus_adapter.query(:environment, self) if has_metrics_and_can_query?
end end
def prometheus_status
deployment_platform&.cluster&.application_prometheus&.status_name
end
def additional_metrics(*args) def additional_metrics(*args)
return unless has_metrics_and_can_query? return unless has_metrics_and_can_query?
......
...@@ -117,8 +117,8 @@ class PrometheusService < MonitoringService ...@@ -117,8 +117,8 @@ class PrometheusService < MonitoringService
return false if template? return false if template?
return false unless project return false unless project
project.all_clusters.enabled.eager_load(:application_prometheus).any? do |cluster| project.all_clusters.enabled.eager_load(:integration_prometheus).any? do |cluster|
cluster.application_prometheus&.available? cluster.integration_prometheus_available?
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
# DEPRECATED: To be removed as part of https://gitlab.com/groups/gitlab-org/-/epics/5877
module Clusters module Clusters
module Applications module Applications
class ScheduleUpdateService class ScheduleUpdateService
...@@ -7,14 +8,14 @@ module Clusters ...@@ -7,14 +8,14 @@ module Clusters
attr_accessor :application, :project attr_accessor :application, :project
def initialize(application, project) def initialize(cluster_prometheus_adapter, project)
@application = application @application = cluster_prometheus_adapter&.cluster&.application_prometheus
@project = project @project = project
end end
def execute def execute
return unless application return unless application
return unless application.managed_prometheus? return if application.externally_installed?
if recently_scheduled? if recently_scheduled?
worker_class.perform_in(BACKOFF_DELAY, application.name, application.id, project.id, Time.current) worker_class.perform_in(BACKOFF_DELAY, application.name, application.id, project.id, Time.current)
......
...@@ -105,9 +105,9 @@ module Projects ...@@ -105,9 +105,9 @@ module Projects
cluster = alert.environment.deployment_platform&.cluster cluster = alert.environment.deployment_platform&.cluster
return unless cluster&.enabled? return unless cluster&.enabled?
return unless cluster.application_prometheus_available? return unless cluster.integration_prometheus_available?
cluster.application_prometheus || cluster.integration_prometheus cluster.integration_prometheus
end end
def find_alert(project, metric) def find_alert(project, metric)
......
# frozen_string_literal: true # frozen_string_literal: true
# DEPRECATED: To be removed as part of https://gitlab.com/groups/gitlab-org/-/epics/5877
module Prometheus module Prometheus
class CreateDefaultAlertsService < BaseService class CreateDefaultAlertsService < BaseService
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
...@@ -53,12 +54,12 @@ module Prometheus ...@@ -53,12 +54,12 @@ module Prometheus
end end
def schedule_prometheus_update def schedule_prometheus_update
return unless prometheus_application return unless prometheus_adapter
::Clusters::Applications::ScheduleUpdateService.new(prometheus_application, project).execute ::Clusters::Applications::ScheduleUpdateService.new(prometheus_adapter, project).execute
end end
def prometheus_application def prometheus_adapter
environment.cluster_prometheus_adapter environment.cluster_prometheus_adapter
end end
......
%section.settings.no-animate.expanded.cluster-health-graphs.qa-cluster-health-section#cluster-health %section.settings.no-animate.expanded.cluster-health-graphs.qa-cluster-health-section#cluster-health
- if @cluster&.application_prometheus_available? - if @cluster&.integration_prometheus_available?
#prometheus-graphs{ data: @cluster.health_data(clusterable) } #prometheus-graphs{ data: @cluster.health_data(clusterable) }
- else - else
......
...@@ -60,9 +60,9 @@ module EE ...@@ -60,9 +60,9 @@ module EE
end end
def prometheus_adapter def prometheus_adapter
return unless cluster&.application_prometheus_available? return unless cluster&.integration_prometheus_available?
cluster.application_prometheus cluster.integration_prometheus
end end
end end
end end
......
...@@ -78,7 +78,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st ...@@ -78,7 +78,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st
context 'for GitLab embedded cluster health metrics' do context 'for GitLab embedded cluster health metrics' do
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
stub_kubeclient_discover(cluster.platform.api_url) stub_kubeclient_discover(cluster.platform.api_url)
stub_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body) stub_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body)
stub_prometheus_request(/prometheus\/api\/v1/, body: prometheus_values_body) stub_prometheus_request(/prometheus\/api\/v1/, body: prometheus_values_body)
......
...@@ -43,9 +43,9 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do ...@@ -43,9 +43,9 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
end end
before do before do
create(:clusters_applications_prometheus, :installed, create(:clusters_integrations_prometheus,
cluster: prd_cluster, alert_manager_token: token) cluster: prd_cluster, alert_manager_token: token)
create(:clusters_applications_prometheus, :installed, create(:clusters_integrations_prometheus,
cluster: stg_cluster, alert_manager_token: nil) cluster: stg_cluster, alert_manager_token: nil)
end end
......
...@@ -112,7 +112,7 @@ RSpec.describe Security::WafAnomalySummaryService do ...@@ -112,7 +112,7 @@ RSpec.describe Security::WafAnomalySummaryService do
context 'with environment missing external_url' do context 'with environment missing external_url' do
before do before do
allow(environment.deployment_platform.cluster).to receive_message_chain( allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :elasticsearch_client :integration_elastic_stack, :elasticsearch_client
) { es_client } ) { es_client }
allow(environment).to receive(:external_url) { nil } allow(environment).to receive(:external_url) { nil }
...@@ -130,10 +130,10 @@ RSpec.describe Security::WafAnomalySummaryService do ...@@ -130,10 +130,10 @@ RSpec.describe Security::WafAnomalySummaryService do
end end
allow(environment.deployment_platform.cluster).to receive_message_chain( allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :elasticsearch_client :integration_elastic_stack, :elasticsearch_client
) { es_client } ) { es_client }
allow(environment.deployment_platform.cluster).to receive_message_chain( allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :chart_above_v3? :integration_elastic_stack, :chart_above_v3?
) { chart_above_v3 } ) { chart_above_v3 }
end end
......
...@@ -19,9 +19,6 @@ module Gitlab ...@@ -19,9 +19,6 @@ module Gitlab
end end
def cluster_prometheus_adapter def cluster_prometheus_adapter
application = cluster&.application_prometheus
return application if application&.available?
integration = cluster&.integration_prometheus integration = cluster&.integration_prometheus
integration if integration&.available? integration if integration&.available?
end end
......
...@@ -88,6 +88,7 @@ FactoryBot.define do ...@@ -88,6 +88,7 @@ FactoryBot.define do
trait :with_installed_prometheus do trait :with_installed_prometheus do
application_prometheus factory: %i(clusters_applications_prometheus installed) application_prometheus factory: %i(clusters_applications_prometheus installed)
integration_prometheus factory: %i(clusters_integrations_prometheus)
end end
trait :with_all_applications do trait :with_all_applications do
......
...@@ -27,7 +27,7 @@ RSpec.describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory ...@@ -27,7 +27,7 @@ RSpec.describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory
expect(page).to have_css('.cluster-health-graphs') expect(page).to have_css('.cluster-health-graphs')
end end
context 'no prometheus installed' do context 'no prometheus enabled' do
it 'shows install prometheus message' do it 'shows install prometheus message' do
visit cluster_path visit cluster_path
...@@ -37,9 +37,9 @@ RSpec.describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory ...@@ -37,9 +37,9 @@ RSpec.describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory
end end
end end
context 'when there is cluster with installed prometheus' do context 'when there is cluster with enabled prometheus' do
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, enabled: true, cluster: cluster)
stub_kubeclient_discover(cluster.platform.api_url) stub_kubeclient_discover(cluster.platform.api_url)
end end
......
...@@ -173,7 +173,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st ...@@ -173,7 +173,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st
allow(Prometheus::ProxyService).to receive(:new).and_call_original allow(Prometheus::ProxyService).to receive(:new).and_call_original
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
stub_kubeclient_discover(cluster.platform.api_url) stub_kubeclient_discover(cluster.platform.api_url)
stub_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body) stub_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body)
stub_prometheus_request(/prometheus\/api\/v1/, body: prometheus_values_body) stub_prometheus_request(/prometheus\/api\/v1/, body: prometheus_values_body)
......
...@@ -81,7 +81,7 @@ RSpec.describe 'Environments page', :js do ...@@ -81,7 +81,7 @@ RSpec.describe 'Environments page', :js do
context 'when cluster is not reachable' do context 'when cluster is not reachable' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let!(:application_prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } let!(:integration_prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
before do before do
allow_next_instance_of(Kubeclient::Client) do |instance| allow_next_instance_of(Kubeclient::Client) do |instance|
......
...@@ -165,7 +165,7 @@ RSpec.describe Projects::Serverless::FunctionsFinder do ...@@ -165,7 +165,7 @@ RSpec.describe Projects::Serverless::FunctionsFinder do
context 'has prometheus' do context 'has prometheus' do
let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) } let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) }
let!(:knative) { create(:clusters_applications_knative, :installed, cluster: cluster) } let!(:knative) { create(:clusters_applications_knative, :installed, cluster: cluster) }
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
let(:finder) { described_class.new(project) } let(:finder) { described_class.new(project) }
before do before do
......
...@@ -7,7 +7,6 @@ exports[`Dashboard template matches the default snapshot 1`] = ` ...@@ -7,7 +7,6 @@ exports[`Dashboard template matches the default snapshot 1`] = `
environmentstate="available" environmentstate="available"
metricsdashboardbasepath="/monitoring/monitor-project/-/environments/1/metrics" metricsdashboardbasepath="/monitoring/monitor-project/-/environments/1/metrics"
metricsendpoint="/monitoring/monitor-project/-/environments/1/additional_metrics.json" metricsendpoint="/monitoring/monitor-project/-/environments/1/additional_metrics.json"
prometheusstatus=""
> >
<alerts-deprecation-warning-stub /> <alerts-deprecation-warning-stub />
......
...@@ -34,7 +34,6 @@ RSpec.describe EnvironmentsHelper do ...@@ -34,7 +34,6 @@ RSpec.describe EnvironmentsHelper do
'project_path' => project_path(project), 'project_path' => project_path(project),
'tags_path' => project_tags_path(project), 'tags_path' => project_tags_path(project),
'has_metrics' => "#{environment.has_metrics?}", 'has_metrics' => "#{environment.has_metrics?}",
'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), 'custom_metrics_path' => project_prometheus_metrics_path(project),
...@@ -158,7 +157,7 @@ RSpec.describe EnvironmentsHelper do ...@@ -158,7 +157,7 @@ RSpec.describe EnvironmentsHelper do
let(:cluster) { create(:cluster, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
it 'has managed prometheus' do it 'has managed prometheus' do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
expect(metrics_data).to include( expect(metrics_data).to include(
'has_managed_prometheus' => 'true' 'has_managed_prometheus' => 'true'
......
...@@ -61,7 +61,7 @@ RSpec.describe Projects::AlertManagementHelper do ...@@ -61,7 +61,7 @@ RSpec.describe Projects::AlertManagementHelper do
let(:cluster) { create(:cluster, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
it 'has managed prometheus' do it 'has managed prometheus' do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
expect(data).to include( expect(data).to include(
'has-managed-prometheus' => 'true' 'has-managed-prometheus' => 'true'
......
...@@ -21,7 +21,7 @@ RSpec.describe Gitlab::Prometheus::Adapter do ...@@ -21,7 +21,7 @@ RSpec.describe Gitlab::Prometheus::Adapter do
end end
context 'with cluster with prometheus available' do context 'with cluster with prometheus available' do
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
it 'returns prometheus service' do it 'returns prometheus service' do
expect(subject.prometheus_adapter).to eq(prometheus_service) expect(subject.prometheus_adapter).to eq(prometheus_service)
...@@ -32,16 +32,12 @@ RSpec.describe Gitlab::Prometheus::Adapter do ...@@ -32,16 +32,12 @@ RSpec.describe Gitlab::Prometheus::Adapter do
context "prometheus service can't execute queries" do context "prometheus service can't execute queries" do
let(:prometheus_service) { double(:prometheus_service, can_query?: false) } let(:prometheus_service) { double(:prometheus_service, can_query?: false) }
context 'with cluster with prometheus integration' do before do
let!(:prometheus_integration) { create(:clusters_integrations_prometheus, cluster: cluster) } allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
it 'returns the integration' do
expect(subject.prometheus_adapter).to eq(prometheus_integration)
end
end end
context 'with cluster with prometheus not available' do context 'with cluster with prometheus disabled' do
let!(:prometheus) { create(:clusters_applications_prometheus, :installable, cluster: cluster) } let!(:prometheus) { create(:clusters_integrations_prometheus, enabled: false, cluster: cluster) }
it 'returns nil' do it 'returns nil' do
expect(subject.prometheus_adapter).to be_nil expect(subject.prometheus_adapter).to be_nil
...@@ -49,19 +45,11 @@ RSpec.describe Gitlab::Prometheus::Adapter do ...@@ -49,19 +45,11 @@ RSpec.describe Gitlab::Prometheus::Adapter do
end end
context 'with cluster with prometheus available' do context 'with cluster with prometheus available' do
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: cluster) }
it 'returns application handling all environments' do it 'returns application handling all environments' do
expect(subject.prometheus_adapter).to eq(prometheus) expect(subject.prometheus_adapter).to eq(prometheus)
end end
context 'with cluster with prometheus integration' do
let!(:prometheus_integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
it 'returns the application' do
expect(subject.prometheus_adapter).to eq(prometheus)
end
end
end end
context 'with cluster without prometheus installed' do context 'with cluster without prometheus installed' do
......
...@@ -42,7 +42,8 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -42,7 +42,8 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to delegate_method(:available?).to(:application_helm).with_prefix } it { is_expected.to delegate_method(:available?).to(:application_helm).with_prefix }
it { is_expected.to delegate_method(:available?).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_knative).with_prefix } it { is_expected.to delegate_method(:available?).to(:application_knative).with_prefix }
it { is_expected.to delegate_method(:available?).to(:application_elastic_stack).with_prefix } it { is_expected.to delegate_method(:available?).to(:integration_elastic_stack).with_prefix }
it { is_expected.to delegate_method(:available?).to(:integration_prometheus).with_prefix }
it { is_expected.to delegate_method(:external_ip).to(:application_ingress).with_prefix } it { is_expected.to delegate_method(:external_ip).to(:application_ingress).with_prefix }
it { is_expected.to delegate_method(:external_hostname).to(:application_ingress).with_prefix } it { is_expected.to delegate_method(:external_hostname).to(:application_ingress).with_prefix }
...@@ -1349,45 +1350,23 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -1349,45 +1350,23 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
end end
describe '#application_prometheus_available?' do describe '#integration_prometheus_available?' do
let_it_be_with_reload(:cluster) { create(:cluster, :project) } let_it_be_with_reload(:cluster) { create(:cluster, :project) }
subject { cluster.application_prometheus_available? } subject { cluster.integration_prometheus_available? }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
context 'has a integration_prometheus' do context 'when integration is enabled' do
let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) } let!(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
context 'disabled' do
before do
cluster.integration_prometheus.enabled = false
end
it { is_expected.to be_falsey }
end
end end
context 'has a application_prometheus' do context 'when integration is disabled' do
let_it_be(:application) { create(:clusters_applications_prometheus, :installed, :no_helm_installed, cluster: cluster) } let!(:integration) { create(:clusters_integrations_prometheus, enabled: false, cluster: cluster) }
it { is_expected.to be_truthy }
context 'errored' do
before do
cluster.application_prometheus.status = Clusters::Applications::Prometheus.state_machines[:status].states[:errored]
end
it { is_expected.to be_falsey }
end
context 'also has a integration_prometheus' do it { is_expected.to be_falsey }
let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
it { is_expected.to be_truthy }
end
end end
end end
...@@ -1398,7 +1377,7 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -1398,7 +1377,7 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
expect(cluster.prometheus_adapter).to be_nil expect(cluster.prometheus_adapter).to be_nil
end end
context 'has a integration_prometheus' do context 'has integration_prometheus' do
let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) } let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
it 'returns the integration' do it 'returns the integration' do
...@@ -1406,11 +1385,11 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -1406,11 +1385,11 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
end end
context 'has a application_prometheus' do context 'has application_prometheus' do
let_it_be(:application) { create(:clusters_applications_prometheus, :no_helm_installed, cluster: cluster) } let_it_be(:application) { create(:clusters_applications_prometheus, :no_helm_installed, cluster: cluster) }
it 'returns the application' do it 'returns nil' do
expect(cluster.prometheus_adapter).to eq(application) expect(cluster.prometheus_adapter).to be_nil
end end
context 'also has a integration_prometheus' do context 'also has a integration_prometheus' do
......
...@@ -51,10 +51,10 @@ RSpec.describe DeploymentMetrics do ...@@ -51,10 +51,10 @@ RSpec.describe DeploymentMetrics do
context 'with a cluster Prometheus' do context 'with a cluster Prometheus' do
let(:deployment) { create(:deployment, :success, :on_cluster) } let(:deployment) { create(:deployment, :success, :on_cluster) }
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: deployment.cluster) } let!(:prometheus) { create(:clusters_integrations_prometheus, cluster: deployment.cluster) }
before do before do
expect(deployment.cluster.application_prometheus).to receive(:configured?).and_return(true) expect(deployment.cluster.integration_prometheus).to receive(:configured?).and_return(true)
end end
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
...@@ -118,7 +118,7 @@ RSpec.describe DeploymentMetrics do ...@@ -118,7 +118,7 @@ RSpec.describe DeploymentMetrics do
expect(prometheus_adapter).to receive(:query).with(:additional_metrics_deployment, deployment).and_return(simple_metrics) expect(prometheus_adapter).to receive(:query).with(:additional_metrics_deployment, deployment).and_return(simple_metrics)
end end
it { is_expected.to eq(simple_metrics.merge({ deployment_time: deployment.created_at.to_i })) } it { is_expected.to eq(simple_metrics.merge({ deployment_time: deployment.finished_at.to_i })) }
end end
end end
end end
...@@ -1157,51 +1157,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do ...@@ -1157,51 +1157,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
end end
end end
describe '#prometheus_status' do
context 'when a cluster is present' do
context 'when a deployment platform is present' do
let(:cluster) { create(:cluster, :provided_by_user, :project) }
let(:environment) { create(:environment, project: cluster.project) }
subject { environment.prometheus_status }
context 'when the prometheus application status is :updating' do
let!(:prometheus) { create(:clusters_applications_prometheus, :updating, cluster: cluster) }
it { is_expected.to eq(:updating) }
end
context 'when the prometheus application state is :updated' do
let!(:prometheus) { create(:clusters_applications_prometheus, :updated, cluster: cluster) }
it { is_expected.to eq(:updated) }
end
context 'when the prometheus application is not installed' do
it { is_expected.to be_nil }
end
end
context 'when a deployment platform is not present' do
let(:cluster) { create(:cluster, :project) }
let(:environment) { create(:environment, project: cluster.project) }
subject { environment.prometheus_status }
it { is_expected.to be_nil }
end
end
context 'when a cluster is not present' do
let(:project) { create(:project, :stubbed_repository) }
let(:environment) { create(:environment, project: project) }
subject { environment.prometheus_status }
it { is_expected.to be_nil }
end
end
describe '#additional_metrics' do describe '#additional_metrics' do
let(:project) { create(:prometheus_project) } let(:project) { create(:prometheus_project) }
let(:metric_params) { [] } let(:metric_params) { [] }
...@@ -1434,30 +1389,14 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do ...@@ -1434,30 +1389,14 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
let!(:cluster) { create(:cluster, :project, :provided_by_user, projects: [project]) } let!(:cluster) { create(:cluster, :project, :provided_by_user, projects: [project]) }
let!(:deployment) { create(:deployment, :success, environment: environment, project: project, cluster: cluster) } let!(:deployment) { create(:deployment, :success, environment: environment, project: project, cluster: cluster) }
context 'when app does not exist' do context 'when integration does not exist' do
it 'returns false' do it 'returns false' do
expect(environment.elastic_stack_available?).to be(false) expect(environment.elastic_stack_available?).to be(false)
end end
end end
context 'when app exists' do context 'when integration is enabled' do
let!(:application) { create(:clusters_applications_elastic_stack, cluster: cluster) } let!(:integration) { create(:clusters_integrations_elastic_stack, cluster: cluster) }
it 'returns false' do
expect(environment.elastic_stack_available?).to be(false)
end
end
context 'when app is installed' do
let!(:application) { create(:clusters_applications_elastic_stack, :installed, cluster: cluster) }
it 'returns true' do
expect(environment.elastic_stack_available?).to be(true)
end
end
context 'when app is updated' do
let!(:application) { create(:clusters_applications_elastic_stack, :updated, cluster: cluster) }
it 'returns true' do it 'returns true' do
expect(environment.elastic_stack_available?).to be(true) expect(environment.elastic_stack_available?).to be(true)
......
...@@ -323,9 +323,9 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl ...@@ -323,9 +323,9 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
end end
describe '#prometheus_available?' do describe '#prometheus_available?' do
context 'clusters with installed prometheus' do context 'clusters with enabled prometheus' do
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
end end
context 'cluster belongs to project' do context 'cluster belongs to project' do
...@@ -340,7 +340,7 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl ...@@ -340,7 +340,7 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:project) { create(:prometheus_project, group: group) } let(:project) { create(:prometheus_project, group: group) }
let(:cluster) { create(:cluster_for_group, :with_installed_helm, groups: [group]) } let(:cluster) { create(:cluster_for_group, groups: [group]) }
it 'returns true' do it 'returns true' do
expect(service.prometheus_available?).to be(true) expect(service.prometheus_available?).to be(true)
...@@ -349,8 +349,8 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl ...@@ -349,8 +349,8 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
it 'avoids N+1 queries' do it 'avoids N+1 queries' do
service service
5.times do |i| 5.times do |i|
other_cluster = create(:cluster_for_group, :with_installed_helm, groups: [group], environment_scope: i) other_cluster = create(:cluster_for_group, groups: [group], environment_scope: i)
create(:clusters_applications_prometheus, :installing, cluster: other_cluster) create(:clusters_integrations_prometheus, cluster: other_cluster)
end end
expect { service.prometheus_available? }.not_to exceed_query_limit(1) expect { service.prometheus_available? }.not_to exceed_query_limit(1)
end end
...@@ -365,18 +365,9 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl ...@@ -365,18 +365,9 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
end end
end end
context 'clusters with updated prometheus' do context 'clusters with prometheus disabled' 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
context 'clusters without prometheus installed' do
let(:cluster) { create(:cluster, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
let!(:prometheus) { create(:clusters_applications_prometheus, cluster: cluster) } let!(:prometheus) { create(:clusters_integrations_prometheus, :disabled, cluster: cluster) }
it 'returns false' do it 'returns false' do
expect(service.prometheus_available?).to be(false) expect(service.prometheus_available?).to be(false)
...@@ -491,13 +482,13 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl ...@@ -491,13 +482,13 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
expect(service.editable?).to be(true) expect(service.editable?).to be(true)
end end
context 'when cluster exists with prometheus installed' do context 'when cluster exists with prometheus enabled' do
let(:cluster) { create(:cluster, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
before do before do
service.update!(manual_configuration: false) service.update!(manual_configuration: false)
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
end end
it 'remains editable' do it 'remains editable' do
......
...@@ -304,9 +304,9 @@ RSpec.describe Clusters::ClusterPresenter do ...@@ -304,9 +304,9 @@ RSpec.describe Clusters::ClusterPresenter do
expect(presenter.gitlab_managed_apps_logs_path).to eq k8s_project_logs_path(project, cluster_id: cluster.id, format: :json) expect(presenter.gitlab_managed_apps_logs_path).to eq k8s_project_logs_path(project, cluster_id: cluster.id, format: :json)
end end
context 'cluster has elastic stack application installed' do context 'cluster has elastic stack integration enabled' do
before do before do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster) create(:clusters_integrations_elastic_stack, cluster: cluster)
end end
it 'returns path to logs' do it 'returns path to logs' do
......
...@@ -91,9 +91,9 @@ RSpec.describe ClusterEntity do ...@@ -91,9 +91,9 @@ RSpec.describe ClusterEntity do
end end
end end
context 'elastic stack is installed on cluster' do context 'elastic stack is enabled on cluster' do
it 'returns true' do it 'returns true' do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster) create(:clusters_integrations_elastic_stack, cluster: cluster)
expect(subject[:enable_advanced_logs_querying]).to be true expect(subject[:enable_advanced_logs_querying]).to be true
end end
......
...@@ -34,11 +34,11 @@ RSpec.describe ::PodLogs::ElasticsearchService do ...@@ -34,11 +34,11 @@ RSpec.describe ::PodLogs::ElasticsearchService do
describe '#get_raw_pods' do describe '#get_raw_pods' do
before do before do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster) create(:clusters_integrations_elastic_stack, cluster: cluster)
end end
it 'returns success with elasticsearch response' do it 'returns success with elasticsearch response' do
allow_any_instance_of(::Clusters::Applications::ElasticStack) allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client) .to receive(:elasticsearch_client)
.and_return(Elasticsearch::Transport::Client.new) .and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Pods) allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Pods)
...@@ -53,7 +53,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do ...@@ -53,7 +53,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end end
it 'returns an error when ES is unreachable' do it 'returns an error when ES is unreachable' do
allow_any_instance_of(::Clusters::Applications::ElasticStack) allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client) .to receive(:elasticsearch_client)
.and_return(nil) .and_return(nil)
...@@ -64,7 +64,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do ...@@ -64,7 +64,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end end
it 'handles server errors from elasticsearch' do it 'handles server errors from elasticsearch' do
allow_any_instance_of(::Clusters::Applications::ElasticStack) allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client) .to receive(:elasticsearch_client)
.and_return(Elasticsearch::Transport::Client.new) .and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Pods) allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Pods)
...@@ -247,11 +247,11 @@ RSpec.describe ::PodLogs::ElasticsearchService do ...@@ -247,11 +247,11 @@ RSpec.describe ::PodLogs::ElasticsearchService do
let(:expected_cursor) { '9999934,1572449784442' } let(:expected_cursor) { '9999934,1572449784442' }
before do before do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster) create(:clusters_integrations_elastic_stack, cluster: cluster)
end end
it 'returns the logs' do it 'returns the logs' do
allow_any_instance_of(::Clusters::Applications::ElasticStack) allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client) .to receive(:elasticsearch_client)
.and_return(Elasticsearch::Transport::Client.new) .and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines) allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines)
...@@ -267,7 +267,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do ...@@ -267,7 +267,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end end
it 'returns an error when ES is unreachable' do it 'returns an error when ES is unreachable' do
allow_any_instance_of(::Clusters::Applications::ElasticStack) allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client) .to receive(:elasticsearch_client)
.and_return(nil) .and_return(nil)
...@@ -278,7 +278,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do ...@@ -278,7 +278,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end end
it 'handles server errors from elasticsearch' do it 'handles server errors from elasticsearch' do
allow_any_instance_of(::Clusters::Applications::ElasticStack) allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client) .to receive(:elasticsearch_client)
.and_return(Elasticsearch::Transport::Client.new) .and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines) allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines)
...@@ -292,7 +292,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do ...@@ -292,7 +292,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end end
it 'handles cursor errors from elasticsearch' do it 'handles cursor errors from elasticsearch' do
allow_any_instance_of(::Clusters::Applications::ElasticStack) allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client) .to receive(:elasticsearch_client)
.and_return(Elasticsearch::Transport::Client.new) .and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines) allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines)
......
...@@ -663,7 +663,7 @@ RSpec.describe Projects::CreateService, '#execute' do ...@@ -663,7 +663,7 @@ RSpec.describe Projects::CreateService, '#execute' do
stub_feature_flags(projects_post_creation_worker: false) stub_feature_flags(projects_post_creation_worker: false)
end end
context 'Prometheus application is shared via group cluster' do context 'Prometheus integration is shared via group cluster' do
let(:cluster) { create(:cluster, :group, groups: [group]) } let(:cluster) { create(:cluster, :group, groups: [group]) }
let(:group) do let(:group) do
create(:group).tap do |group| create(:group).tap do |group|
...@@ -672,7 +672,7 @@ RSpec.describe Projects::CreateService, '#execute' do ...@@ -672,7 +672,7 @@ RSpec.describe Projects::CreateService, '#execute' do
end end
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
end end
it 'creates PrometheusService record', :aggregate_failures do it 'creates PrometheusService record', :aggregate_failures do
...@@ -685,11 +685,11 @@ RSpec.describe Projects::CreateService, '#execute' do ...@@ -685,11 +685,11 @@ RSpec.describe Projects::CreateService, '#execute' do
end end
end end
context 'Prometheus application is shared via instance cluster' do context 'Prometheus integration is shared via instance cluster' do
let(:cluster) { create(:cluster, :instance) } let(:cluster) { create(:cluster, :instance) }
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
end end
it 'creates PrometheusService record', :aggregate_failures do it 'creates PrometheusService record', :aggregate_failures do
...@@ -712,7 +712,7 @@ RSpec.describe Projects::CreateService, '#execute' do ...@@ -712,7 +712,7 @@ RSpec.describe Projects::CreateService, '#execute' do
end end
end end
context 'shared Prometheus application is not available' do context 'shared Prometheus integration is not available' do
it 'does not persist PrometheusService record', :aggregate_failures do it 'does not persist PrometheusService record', :aggregate_failures do
project = create_project(user, opts) project = create_project(user, opts)
......
...@@ -45,9 +45,9 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do ...@@ -45,9 +45,9 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
end end
before do before do
create(:clusters_applications_prometheus, :installed, create(:clusters_integrations_prometheus,
cluster: prd_cluster, alert_manager_token: token) cluster: prd_cluster, alert_manager_token: token)
create(:clusters_applications_prometheus, :installed, create(:clusters_integrations_prometheus,
cluster: stg_cluster, alert_manager_token: nil) cluster: stg_cluster, alert_manager_token: nil)
end end
...@@ -62,41 +62,6 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do ...@@ -62,41 +62,6 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
end end
end end
context 'with project specific cluster using prometheus application' do
where(:cluster_enabled, :status, :configured_token, :token_input, :result) do
true | :installed | token | token | :success
true | :installed | nil | nil | :success
true | :updated | token | token | :success
true | :updating | token | token | :failure
true | :installed | token | 'x' | :failure
true | :installed | nil | token | :failure
true | :installed | token | nil | :failure
true | nil | token | token | :failure
false | :installed | token | token | :failure
end
with_them do
before do
cluster.update!(enabled: cluster_enabled)
if status
create(:clusters_applications_prometheus, status,
cluster: cluster,
alert_manager_token: configured_token)
end
end
case result = params[:result]
when :success
include_examples 'processes one firing and one resolved prometheus alerts'
when :failure
it_behaves_like 'alerts service responds with an error and takes no actions', :unauthorized
else
raise "invalid result: #{result.inspect}"
end
end
end
context 'with project specific cluster using prometheus integration' do context 'with project specific cluster using prometheus integration' do
where(:cluster_enabled, :integration_enabled, :configured_token, :token_input, :result) do where(:cluster_enabled, :integration_enabled, :configured_token, :token_input, :result) do
true | true | token | token | :success true | true | token | token | :success
......
...@@ -8,13 +8,13 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do ...@@ -8,13 +8,13 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
let(:service_name) { 'prometheus' } let(:service_name) { 'prometheus' }
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
end end
context 'cluster type: group' do context 'cluster type: group' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
let(:cluster) { create(:cluster_for_group, :with_installed_helm, groups: [group]) } let(:cluster) { create(:cluster_for_group, groups: [group]) }
it 'ensures Prometheus service is activated' do it 'ensures Prometheus service is activated' do
expect { described_class.new.perform(cluster.id, service_name) } expect { described_class.new.perform(cluster.id, service_name) }
...@@ -24,7 +24,7 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do ...@@ -24,7 +24,7 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
context 'cluster type: project' do context 'cluster type: project' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
it 'ensures Prometheus service is activated' do it 'ensures Prometheus service is activated' do
expect { described_class.new.perform(cluster.id, service_name) } expect { described_class.new.perform(cluster.id, service_name) }
......
...@@ -6,19 +6,19 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do ...@@ -6,19 +6,19 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'cluster exists' do context 'cluster exists' do
describe 'prometheus service' do describe 'prometheus service' do
let(:service_name) { 'prometheus' } let(:service_name) { 'prometheus' }
let!(:application) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } let!(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
context 'prometheus service exists' do context 'prometheus service exists' do
let!(:prometheus_service) { create(:prometheus_service, project: project, manual_configuration: false, active: true) } let!(:prometheus_service) { create(:prometheus_service, project: project, manual_configuration: false, active: true) }
before do before do
application.delete # prometheus service before save synchronises active stated with application existance. integration.delete # prometheus service before save synchronises active stated with integration existence.
end end
context 'cluster type: group' do context 'cluster type: group' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
let(:cluster) { create(:cluster_for_group, :with_installed_helm, groups: [group]) } let(:cluster) { create(:cluster_for_group, groups: [group]) }
it 'ensures Prometheus service is deactivated' do it 'ensures Prometheus service is deactivated' do
expect { described_class.new.perform(cluster.id, service_name) } expect { described_class.new.perform(cluster.id, service_name) }
...@@ -28,7 +28,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do ...@@ -28,7 +28,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'cluster type: project' do context 'cluster type: project' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
it 'ensures Prometheus service is deactivated' do it 'ensures Prometheus service is deactivated' do
expect { described_class.new.perform(cluster.id, service_name) } expect { described_class.new.perform(cluster.id, service_name) }
...@@ -38,7 +38,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do ...@@ -38,7 +38,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'cluster type: instance' do context 'cluster type: instance' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, :instance) } let(:cluster) { create(:cluster, :instance) }
it 'ensures Prometheus service is deactivated' do it 'ensures Prometheus service is deactivated' do
expect { described_class.new.perform(cluster.id, service_name) } expect { described_class.new.perform(cluster.id, service_name) }
...@@ -50,7 +50,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do ...@@ -50,7 +50,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'prometheus service does not exist' do context 'prometheus service does not exist' do
context 'cluster type: project' do context 'cluster type: project' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) } let(:cluster) { create(:cluster, projects: [project]) }
it 'does not raise errors' do it 'does not raise errors' do
expect { described_class.new.perform(cluster.id, service_name) }.not_to raise_error expect { described_class.new.perform(cluster.id, service_name) }.not_to raise_error
......
...@@ -33,7 +33,7 @@ RSpec.describe Projects::PostCreationWorker do ...@@ -33,7 +33,7 @@ RSpec.describe Projects::PostCreationWorker do
end end
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
end end
it 'creates PrometheusService record', :aggregate_failures do it 'creates PrometheusService record', :aggregate_failures do
...@@ -50,7 +50,7 @@ RSpec.describe Projects::PostCreationWorker do ...@@ -50,7 +50,7 @@ RSpec.describe Projects::PostCreationWorker do
let(:cluster) { create(:cluster, :instance) } let(:cluster) { create(:cluster, :instance) }
before do before do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_integrations_prometheus, cluster: cluster)
end end
it 'creates PrometheusService record', :aggregate_failures do it 'creates PrometheusService record', :aggregate_failures 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