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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.8 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'
2023-01-13 00:05:48 +05:30
after_initialize :set_alert_manager_token, if: :new_record?
2021-06-08 01:23:25 +05:30
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
2023-01-13 00:05:48 +05:30
def set_alert_manager_token
self.alert_manager_token = SecureRandom.hex
end
2021-09-30 23:02:18 +05:30
def activate_project_integrations
2022-08-13 15:12:31 +05:30
::Clusters::Applications::ActivateIntegrationWorker
.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
2022-08-13 15:12:31 +05:30
::Clusters::Applications::DeactivateIntegrationWorker
.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