debian-mirror-gitlab/app/models/clusters/integrations/prometheus.rb

69 lines
1.7 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Clusters
module Integrations
class Prometheus < ApplicationRecord
include ::Clusters::Concerns::PrometheusClient
2021-06-08 01:23:25 +05:30
include AfterCommitQueue
2021-04-29 21:17:54 +05:30
self.table_name = 'clusters_integration_prometheus'
self.primary_key = :cluster_id
belongs_to :cluster, class_name: 'Clusters::Cluster', foreign_key: :cluster_id
validates :cluster, presence: true
validates :enabled, inclusion: { in: [true, false] }
2021-12-11 22:18:48 +05:30
# Periodically checked and kept up to date for Monitor demo projects
enum health_status: {
unknown: 0,
healthy: 1,
unhealthy: 2
}
2021-06-08 01:23:25 +05:30
attr_encrypted :alert_manager_token,
mode: :per_attribute_iv,
key: Settings.attr_encrypted_db_key_base_32,
algorithm: 'aes-256-gcm'
default_value_for(:alert_manager_token) { SecureRandom.hex }
2021-11-18 22:05:49 +05:30
scope :enabled, -> { where(enabled: true) }
2021-06-08 01:23:25 +05:30
after_destroy do
run_after_commit do
2021-09-30 23:02:18 +05:30
deactivate_project_integrations
2021-06-08 01:23:25 +05:30
end
end
after_save do
next unless enabled_before_last_save != enabled
run_after_commit do
if enabled
2021-09-30 23:02:18 +05:30
activate_project_integrations
2021-06-08 01:23:25 +05:30
else
2021-09-30 23:02:18 +05:30
deactivate_project_integrations
2021-06-08 01:23:25 +05:30
end
end
end
2021-04-29 21:17:54 +05:30
def available?
enabled?
end
2021-06-08 01:23:25 +05:30
private
2021-09-30 23:02:18 +05:30
def activate_project_integrations
2021-06-08 01:23:25 +05:30
::Clusters::Applications::ActivateServiceWorker
2021-09-30 23:02:18 +05:30
.perform_async(cluster_id, ::Integrations::Prometheus.to_param)
2021-06-08 01:23:25 +05:30
end
2021-09-30 23:02:18 +05:30
def deactivate_project_integrations
2021-06-08 01:23:25 +05:30
::Clusters::Applications::DeactivateServiceWorker
2021-09-30 23:02:18 +05:30
.perform_async(cluster_id, ::Integrations::Prometheus.to_param)
2021-06-08 01:23:25 +05:30
end
2021-04-29 21:17:54 +05:30
end
end
end