Commit 6de64f2c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'sy-swap-monitor-monitoring-to-http-integrations' into 'master'

Use HttpIntegrations to monitor demo projects for monitor team

See merge request gitlab-org/gitlab!49263
parents 97b71aa8 46a2adf8
...@@ -149,8 +149,8 @@ module Clusters ...@@ -149,8 +149,8 @@ module Clusters
scope :for_project_namespace, -> (namespace_id) { joins(:projects).where(projects: { namespace_id: namespace_id }) } scope :for_project_namespace, -> (namespace_id) { joins(:projects).where(projects: { namespace_id: namespace_id }) }
scope :with_application_prometheus, -> { includes(:application_prometheus).joins(:application_prometheus) } scope :with_application_prometheus, -> { includes(:application_prometheus).joins(:application_prometheus) }
scope :with_project_alert_service_data, -> (project_ids) do scope :with_project_http_integrations, -> (project_ids) do
conditions = { projects: { alerts_service: [:data] } } conditions = { projects: :alert_management_http_integrations }
includes(conditions).joins(conditions).where(projects: { id: project_ids }) includes(conditions).joins(conditions).where(projects: { id: project_ids })
end end
......
...@@ -63,8 +63,10 @@ module Clusters ...@@ -63,8 +63,10 @@ module Clusters
def send_notification(project) def send_notification(project)
notification_payload = build_notification_payload(project) notification_payload = build_notification_payload(project)
token = project.alerts_service.data.token integration = project.alert_management_http_integrations.active.first
Projects::Alerting::NotifyService.new(project, nil, notification_payload).execute(token)
Projects::Alerting::NotifyService.new(project, nil, notification_payload).execute(integration&.token, integration)
@logger.info(message: 'Successfully notified of Prometheus newly unhealthy', cluster_id: @cluster.id, project_id: project.id) @logger.info(message: 'Successfully notified of Prometheus newly unhealthy', cluster_id: @cluster.id, project_id: project.id)
end end
......
...@@ -20,7 +20,7 @@ module Clusters ...@@ -20,7 +20,7 @@ module Clusters
demo_project_ids = Gitlab::Monitor::DemoProjects.primary_keys demo_project_ids = Gitlab::Monitor::DemoProjects.primary_keys
clusters = Clusters::Cluster.with_application_prometheus clusters = Clusters::Cluster.with_application_prometheus
.with_project_alert_service_data(demo_project_ids) .with_project_http_integrations(demo_project_ids)
# Move to a seperate worker with scoped context if expanded to do work on customer projects # Move to a seperate worker with scoped context if expanded to do work on customer projects
clusters.each { |cluster| Clusters::Applications::PrometheusHealthCheckService.new(cluster).execute } clusters.each { |cluster| Clusters::Applications::PrometheusHealthCheckService.new(cluster).execute }
......
...@@ -262,14 +262,14 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -262,14 +262,14 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
end end
describe '.with_project_alert_service_data' do describe '.with_project_http_integrations' do
subject { described_class.with_project_alert_service_data(project_id) } subject { described_class.with_project_http_integrations(project_id) }
let!(:cluster) { create(:cluster, :project) } let!(:cluster) { create(:cluster, :project) }
let!(:project_id) { cluster.first_project.id } let!(:project_id) { cluster.first_project.id }
context 'project has alert service data' do context 'project has alert service data' do
let!(:alerts_service) { create(:alerts_service, project: cluster.clusterable) } let!(:integration) { create(:alert_management_http_integration, project: cluster.clusterable) }
it { is_expected.to include(cluster) } it { is_expected.to include(cluster) }
end end
......
...@@ -18,7 +18,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute' ...@@ -18,7 +18,7 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
RSpec.shared_examples 'sends alert' do RSpec.shared_examples 'sends alert' do
it 'sends an alert' do it 'sends an alert' do
expect_next_instance_of(Projects::Alerting::NotifyService) do |notify_service| expect_next_instance_of(Projects::Alerting::NotifyService) do |notify_service|
expect(notify_service).to receive(:execute).with(alerts_service.token) expect(notify_service).to receive(:execute).with(integration.token, integration)
end end
subject subject
...@@ -40,8 +40,8 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute' ...@@ -40,8 +40,8 @@ RSpec.describe Clusters::Applications::PrometheusHealthCheckService, '#execute'
end end
context 'when cluster is project_type' do context 'when cluster is project_type' do
let_it_be(:alerts_service) { create(:alerts_service) } let_it_be(:project) { create(:project) }
let_it_be(:project) { create(:project, alerts_service: alerts_service) } let_it_be(:integration) { create(:alert_management_http_integration, project: project) }
let(:applications_prometheus_healthy) { true } let(:applications_prometheus_healthy) { true }
let(:prometheus) { create(:clusters_applications_prometheus, status: prometheus_status_value, healthy: applications_prometheus_healthy) } let(:prometheus) { create(:clusters_applications_prometheus, status: prometheus_status_value, healthy: applications_prometheus_healthy) }
let(:cluster) { create(:cluster, :project, application_prometheus: prometheus, projects: [project]) } let(:cluster) { create(:cluster, :project, application_prometheus: prometheus, projects: [project]) }
......
...@@ -8,7 +8,7 @@ RSpec.describe Clusters::Applications::CheckPrometheusHealthWorker, '#perform' d ...@@ -8,7 +8,7 @@ RSpec.describe Clusters::Applications::CheckPrometheusHealthWorker, '#perform' d
it 'triggers health service' do it 'triggers health service' do
cluster = create(:cluster) cluster = create(:cluster)
allow(Gitlab::Monitor::DemoProjects).to receive(:primary_keys) allow(Gitlab::Monitor::DemoProjects).to receive(:primary_keys)
allow(Clusters::Cluster).to receive_message_chain(:with_application_prometheus, :with_project_alert_service_data).and_return([cluster]) allow(Clusters::Cluster).to receive_message_chain(:with_application_prometheus, :with_project_http_integrations).and_return([cluster])
service_instance = instance_double(Clusters::Applications::PrometheusHealthCheckService) service_instance = instance_double(Clusters::Applications::PrometheusHealthCheckService)
expect(Clusters::Applications::PrometheusHealthCheckService).to receive(:new).with(cluster).and_return(service_instance) expect(Clusters::Applications::PrometheusHealthCheckService).to receive(:new).with(cluster).and_return(service_instance)
......
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