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
def has_prometheus?(environment_scope)
finders_for_scope(environment_scope).any? do |finder|
finder.cluster.application_prometheus_available?
finder.cluster.integration_prometheus_available?
end
end
......
......@@ -74,7 +74,6 @@ module EnvironmentsHelper
'metrics_dashboard_base_path' => metrics_dashboard_base_path(environment, project),
'current_environment_name' => environment.name,
'has_metrics' => "#{environment.has_metrics?}",
'prometheus_status' => "#{environment.prometheus_status}",
'environment_state' => "#{environment.state}"
}
end
......
......@@ -141,13 +141,13 @@ module Clusters
end
def install_knative_metrics
return [] unless cluster.application_prometheus_available?
return [] unless cluster.application_prometheus&.available?
[Gitlab::Kubernetes::KubectlCmd.apply_file(METRICS_CONFIG)]
end
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)]
end
......
......@@ -104,8 +104,8 @@ module Clusters
delegate :available?, to: :application_helm, 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_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_hostname, to: :application_ingress, prefix: true, allow_nil: true
......@@ -142,7 +142,7 @@ module Clusters
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 :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 :managed, -> { where(managed: true) }
......@@ -325,7 +325,7 @@ module Clusters
end
def elastic_stack_adapter
application_elastic_stack || integration_elastic_stack
integration_elastic_stack
end
def elasticsearch_client
......@@ -333,11 +333,7 @@ module Clusters
end
def elastic_stack_available?
if application_elastic_stack_available? || integration_elastic_stack_available?
true
else
false
end
!!integration_elastic_stack_available?
end
def kubernetes_namespace_for(environment, deployable: environment.last_deployable)
......@@ -391,12 +387,8 @@ module Clusters
end
end
def application_prometheus_available?
integration_prometheus&.available? || application_prometheus&.available?
end
def prometheus_adapter
integration_prometheus || application_prometheus
integration_prometheus
end
private
......
......@@ -335,10 +335,6 @@ class Environment < ApplicationRecord
prometheus_adapter.query(:environment, self) if has_metrics_and_can_query?
end
def prometheus_status
deployment_platform&.cluster&.application_prometheus&.status_name
end
def additional_metrics(*args)
return unless has_metrics_and_can_query?
......
......@@ -117,8 +117,8 @@ class PrometheusService < MonitoringService
return false if template?
return false unless project
project.all_clusters.enabled.eager_load(:application_prometheus).any? do |cluster|
cluster.application_prometheus&.available?
project.all_clusters.enabled.eager_load(:integration_prometheus).any? do |cluster|
cluster.integration_prometheus_available?
end
end
......
# frozen_string_literal: true
# DEPRECATED: To be removed as part of https://gitlab.com/groups/gitlab-org/-/epics/5877
module Clusters
module Applications
class ScheduleUpdateService
......@@ -7,14 +8,14 @@ module Clusters
attr_accessor :application, :project
def initialize(application, project)
@application = application
def initialize(cluster_prometheus_adapter, project)
@application = cluster_prometheus_adapter&.cluster&.application_prometheus
@project = project
end
def execute
return unless application
return unless application.managed_prometheus?
return if application.externally_installed?
if recently_scheduled?
worker_class.perform_in(BACKOFF_DELAY, application.name, application.id, project.id, Time.current)
......
......@@ -105,9 +105,9 @@ module Projects
cluster = alert.environment.deployment_platform&.cluster
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
def find_alert(project, metric)
......
# frozen_string_literal: true
# DEPRECATED: To be removed as part of https://gitlab.com/groups/gitlab-org/-/epics/5877
module Prometheus
class CreateDefaultAlertsService < BaseService
include Gitlab::Utils::StrongMemoize
......@@ -53,12 +54,12 @@ module Prometheus
end
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
def prometheus_application
def prometheus_adapter
environment.cluster_prometheus_adapter
end
......
%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) }
- else
......
......@@ -60,9 +60,9 @@ module EE
end
def prometheus_adapter
return unless cluster&.application_prometheus_available?
return unless cluster&.integration_prometheus_available?
cluster.application_prometheus
cluster.integration_prometheus
end
end
end
......
......@@ -78,7 +78,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st
context 'for GitLab embedded cluster health metrics' do
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
stub_kubeclient_discover(cluster.platform.api_url)
stub_prometheus_request(/prometheus-prometheus-server/, 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
end
before do
create(:clusters_applications_prometheus, :installed,
create(:clusters_integrations_prometheus,
cluster: prd_cluster, alert_manager_token: token)
create(:clusters_applications_prometheus, :installed,
create(:clusters_integrations_prometheus,
cluster: stg_cluster, alert_manager_token: nil)
end
......
......@@ -112,7 +112,7 @@ RSpec.describe Security::WafAnomalySummaryService do
context 'with environment missing external_url' do
before do
allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :elasticsearch_client
:integration_elastic_stack, :elasticsearch_client
) { es_client }
allow(environment).to receive(:external_url) { nil }
......@@ -130,10 +130,10 @@ RSpec.describe Security::WafAnomalySummaryService do
end
allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :elasticsearch_client
:integration_elastic_stack, :elasticsearch_client
) { es_client }
allow(environment.deployment_platform.cluster).to receive_message_chain(
:application_elastic_stack, :chart_above_v3?
:integration_elastic_stack, :chart_above_v3?
) { chart_above_v3 }
end
......
......@@ -19,9 +19,6 @@ module Gitlab
end
def cluster_prometheus_adapter
application = cluster&.application_prometheus
return application if application&.available?
integration = cluster&.integration_prometheus
integration if integration&.available?
end
......
......@@ -88,6 +88,7 @@ FactoryBot.define do
trait :with_installed_prometheus do
application_prometheus factory: %i(clusters_applications_prometheus installed)
integration_prometheus factory: %i(clusters_integrations_prometheus)
end
trait :with_all_applications do
......
......@@ -27,7 +27,7 @@ RSpec.describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory
expect(page).to have_css('.cluster-health-graphs')
end
context 'no prometheus installed' do
context 'no prometheus enabled' do
it 'shows install prometheus message' do
visit cluster_path
......@@ -37,9 +37,9 @@ RSpec.describe 'Cluster Health board', :js, :kubeclient, :use_clean_rails_memory
end
end
context 'when there is cluster with installed prometheus' do
context 'when there is cluster with enabled prometheus' 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)
end
......
......@@ -173,7 +173,7 @@ RSpec.describe 'Metrics rendering', :js, :kubeclient, :use_clean_rails_memory_st
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_prometheus_request(/prometheus-prometheus-server/, body: prometheus_values_body)
stub_prometheus_request(/prometheus\/api\/v1/, body: prometheus_values_body)
......
......@@ -81,7 +81,7 @@ RSpec.describe 'Environments page', :js do
context 'when cluster is not reachable' do
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
allow_next_instance_of(Kubeclient::Client) do |instance|
......
......@@ -165,7 +165,7 @@ RSpec.describe Projects::Serverless::FunctionsFinder do
context 'has prometheus' do
let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true) }
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) }
before do
......
......@@ -7,7 +7,6 @@ exports[`Dashboard template matches the default snapshot 1`] = `
environmentstate="available"
metricsdashboardbasepath="/monitoring/monitor-project/-/environments/1/metrics"
metricsendpoint="/monitoring/monitor-project/-/environments/1/additional_metrics.json"
prometheusstatus=""
>
<alerts-deprecation-warning-stub />
......
......@@ -34,7 +34,6 @@ RSpec.describe EnvironmentsHelper do
'project_path' => project_path(project),
'tags_path' => project_tags_path(project),
'has_metrics' => "#{environment.has_metrics?}",
'prometheus_status' => "#{environment.prometheus_status}",
'external_dashboard_url' => nil,
'environment_state' => environment.state,
'custom_metrics_path' => project_prometheus_metrics_path(project),
......@@ -158,7 +157,7 @@ RSpec.describe EnvironmentsHelper do
let(:cluster) { create(:cluster, projects: [project]) }
it 'has managed prometheus' do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
expect(metrics_data).to include(
'has_managed_prometheus' => 'true'
......
......@@ -61,7 +61,7 @@ RSpec.describe Projects::AlertManagementHelper do
let(:cluster) { create(:cluster, projects: [project]) }
it 'has managed prometheus' do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
expect(data).to include(
'has-managed-prometheus' => 'true'
......
......@@ -21,7 +21,7 @@ RSpec.describe Gitlab::Prometheus::Adapter do
end
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
expect(subject.prometheus_adapter).to eq(prometheus_service)
......@@ -32,16 +32,12 @@ RSpec.describe Gitlab::Prometheus::Adapter do
context "prometheus service can't execute queries" do
let(:prometheus_service) { double(:prometheus_service, can_query?: false) }
context 'with cluster with prometheus integration' do
let!(:prometheus_integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
it 'returns the integration' do
expect(subject.prometheus_adapter).to eq(prometheus_integration)
end
before do
allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
end
context 'with cluster with prometheus not available' do
let!(:prometheus) { create(:clusters_applications_prometheus, :installable, cluster: cluster) }
context 'with cluster with prometheus disabled' do
let!(:prometheus) { create(:clusters_integrations_prometheus, enabled: false, cluster: cluster) }
it 'returns nil' do
expect(subject.prometheus_adapter).to be_nil
......@@ -49,19 +45,11 @@ RSpec.describe Gitlab::Prometheus::Adapter do
end
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
expect(subject.prometheus_adapter).to eq(prometheus)
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
context 'with cluster without prometheus installed' 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_ingress).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_hostname).to(:application_ingress).with_prefix }
......@@ -1349,45 +1350,23 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end
end
describe '#application_prometheus_available?' do
describe '#integration_prometheus_available?' do
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 }
context 'has a integration_prometheus' do
let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
context 'when integration is enabled' do
let!(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
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
context 'has a application_prometheus' do
let_it_be(:application) { create(:clusters_applications_prometheus, :installed, :no_helm_installed, 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 'when integration is disabled' do
let!(:integration) { create(:clusters_integrations_prometheus, enabled: false, cluster: cluster) }
context 'also has a integration_prometheus' do
let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
it { is_expected.to be_truthy }
end
it { is_expected.to be_falsey }
end
end
......@@ -1398,7 +1377,7 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
expect(cluster.prometheus_adapter).to be_nil
end
context 'has a integration_prometheus' do
context 'has integration_prometheus' do
let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
it 'returns the integration' do
......@@ -1406,11 +1385,11 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
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) }
it 'returns the application' do
expect(cluster.prometheus_adapter).to eq(application)
it 'returns nil' do
expect(cluster.prometheus_adapter).to be_nil
end
context 'also has a integration_prometheus' do
......
......@@ -51,10 +51,10 @@ RSpec.describe DeploymentMetrics do
context 'with a cluster Prometheus' do
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
expect(deployment.cluster.application_prometheus).to receive(:configured?).and_return(true)
expect(deployment.cluster.integration_prometheus).to receive(:configured?).and_return(true)
end
it { is_expected.to be_truthy }
......@@ -118,7 +118,7 @@ RSpec.describe DeploymentMetrics do
expect(prometheus_adapter).to receive(:query).with(:additional_metrics_deployment, deployment).and_return(simple_metrics)
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
......@@ -1157,51 +1157,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
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
let(:project) { create(:prometheus_project) }
let(:metric_params) { [] }
......@@ -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!(: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
expect(environment.elastic_stack_available?).to be(false)
end
end
context 'when app exists' do
let!(:application) { create(:clusters_applications_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) }
context 'when integration is enabled' do
let!(:integration) { create(:clusters_integrations_elastic_stack, cluster: cluster) }
it 'returns true' do
expect(environment.elastic_stack_available?).to be(true)
......
......@@ -323,9 +323,9 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
end
describe '#prometheus_available?' do
context 'clusters with installed prometheus' do
context 'clusters with enabled prometheus' do
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
end
context 'cluster belongs to project' do
......@@ -340,7 +340,7 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
let_it_be(:group) { create(: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
expect(service.prometheus_available?).to be(true)
......@@ -349,8 +349,8 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
it 'avoids N+1 queries' do
service
5.times do |i|
other_cluster = create(:cluster_for_group, :with_installed_helm, groups: [group], environment_scope: i)
create(:clusters_applications_prometheus, :installing, cluster: other_cluster)
other_cluster = create(:cluster_for_group, groups: [group], environment_scope: i)
create(:clusters_integrations_prometheus, cluster: other_cluster)
end
expect { service.prometheus_available? }.not_to exceed_query_limit(1)
end
......@@ -365,18 +365,9 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
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
context 'clusters without prometheus installed' do
context 'clusters with prometheus disabled' do
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
expect(service.prometheus_available?).to be(false)
......@@ -491,13 +482,13 @@ RSpec.describe PrometheusService, :use_clean_rails_memory_store_caching, :snowpl
expect(service.editable?).to be(true)
end
context 'when cluster exists with prometheus installed' do
context 'when cluster exists with prometheus enabled' do
let(:cluster) { create(:cluster, projects: [project]) }
before do
service.update!(manual_configuration: false)
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
end
it 'remains editable' 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)
end
context 'cluster has elastic stack application installed' do
context 'cluster has elastic stack integration enabled' do
before do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster)
create(:clusters_integrations_elastic_stack, cluster: cluster)
end
it 'returns path to logs' do
......
......@@ -91,9 +91,9 @@ RSpec.describe ClusterEntity do
end
end
context 'elastic stack is installed on cluster' do
context 'elastic stack is enabled on cluster' 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
end
......
......@@ -34,11 +34,11 @@ RSpec.describe ::PodLogs::ElasticsearchService do
describe '#get_raw_pods' do
before do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster)
create(:clusters_integrations_elastic_stack, cluster: cluster)
end
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)
.and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Pods)
......@@ -53,7 +53,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end
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)
.and_return(nil)
......@@ -64,7 +64,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end
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)
.and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Pods)
......@@ -247,11 +247,11 @@ RSpec.describe ::PodLogs::ElasticsearchService do
let(:expected_cursor) { '9999934,1572449784442' }
before do
create(:clusters_applications_elastic_stack, :installed, cluster: cluster)
create(:clusters_integrations_elastic_stack, cluster: cluster)
end
it 'returns the logs' do
allow_any_instance_of(::Clusters::Applications::ElasticStack)
allow_any_instance_of(::Clusters::Integrations::ElasticStack)
.to receive(:elasticsearch_client)
.and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines)
......@@ -267,7 +267,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end
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)
.and_return(nil)
......@@ -278,7 +278,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end
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)
.and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines)
......@@ -292,7 +292,7 @@ RSpec.describe ::PodLogs::ElasticsearchService do
end
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)
.and_return(Elasticsearch::Transport::Client.new)
allow_any_instance_of(::Gitlab::Elasticsearch::Logs::Lines)
......
......@@ -663,7 +663,7 @@ RSpec.describe Projects::CreateService, '#execute' do
stub_feature_flags(projects_post_creation_worker: false)
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(:group) do
create(:group).tap do |group|
......@@ -672,7 +672,7 @@ RSpec.describe Projects::CreateService, '#execute' do
end
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
end
it 'creates PrometheusService record', :aggregate_failures do
......@@ -685,11 +685,11 @@ RSpec.describe Projects::CreateService, '#execute' do
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) }
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
end
it 'creates PrometheusService record', :aggregate_failures do
......@@ -712,7 +712,7 @@ RSpec.describe Projects::CreateService, '#execute' do
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
project = create_project(user, opts)
......
......@@ -45,9 +45,9 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
end
before do
create(:clusters_applications_prometheus, :installed,
create(:clusters_integrations_prometheus,
cluster: prd_cluster, alert_manager_token: token)
create(:clusters_applications_prometheus, :installed,
create(:clusters_integrations_prometheus,
cluster: stg_cluster, alert_manager_token: nil)
end
......@@ -62,41 +62,6 @@ RSpec.describe Projects::Prometheus::Alerts::NotifyService do
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
where(:cluster_enabled, :integration_enabled, :configured_token, :token_input, :result) do
true | true | token | token | :success
......
......@@ -8,13 +8,13 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
let(:service_name) { 'prometheus' }
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
end
context 'cluster type: group' do
let(:group) { create(: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
expect { described_class.new.perform(cluster.id, service_name) }
......@@ -24,7 +24,7 @@ RSpec.describe Clusters::Applications::ActivateServiceWorker, '#perform' do
context 'cluster type: project' do
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
expect { described_class.new.perform(cluster.id, service_name) }
......
......@@ -6,19 +6,19 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'cluster exists' do
describe 'prometheus service' do
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
let!(:prometheus_service) { create(:prometheus_service, project: project, manual_configuration: false, active: true) }
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
context 'cluster type: group' do
let(:group) { create(: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
expect { described_class.new.perform(cluster.id, service_name) }
......@@ -28,7 +28,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'cluster type: project' do
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
expect { described_class.new.perform(cluster.id, service_name) }
......@@ -38,7 +38,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'cluster type: instance' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, :with_installed_helm, :instance) }
let(:cluster) { create(:cluster, :instance) }
it 'ensures Prometheus service is deactivated' do
expect { described_class.new.perform(cluster.id, service_name) }
......@@ -50,7 +50,7 @@ RSpec.describe Clusters::Applications::DeactivateServiceWorker, '#perform' do
context 'prometheus service does not exist' do
context 'cluster type: project' do
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
expect { described_class.new.perform(cluster.id, service_name) }.not_to raise_error
......
......@@ -33,7 +33,7 @@ RSpec.describe Projects::PostCreationWorker do
end
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
end
it 'creates PrometheusService record', :aggregate_failures do
......@@ -50,7 +50,7 @@ RSpec.describe Projects::PostCreationWorker do
let(:cluster) { create(:cluster, :instance) }
before do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:clusters_integrations_prometheus, cluster: cluster)
end
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