Skip to content

Commit

Permalink
monitoring manager building to endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Zellner committed Dec 24, 2017
1 parent 474010f commit bb88857
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
13 changes: 13 additions & 0 deletions app/models/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ class Endpoint < ApplicationRecord
validates :url, :uniqueness => true, :if => :url
validate :validate_certificate_authority

after_create :endpoint_created
after_destroy :endpoint_destroyed

def endpoint_created
# Make sure monitoring manager is created for the prometheus endpoint
resource.endpoint_created(role) if resource.respond_to?(:endpoint_created)
end

def endpoint_destroyed
# Make sure monitoring manager is delete for the prometheus endpoint
resource.endpoint_destroyed(role) if resource.respond_to?(:endpoint_destroyed)
end

def verify_ssl=(val)
val = resolve_verify_ssl_value(val)
super
Expand Down
27 changes: 17 additions & 10 deletions app/models/mixins/has_monitoring_manager_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
module HasMonitoringManagerMixin
extend ActiveSupport::Concern

private
def build_monitoring_manager_with_params
monitoring_manager = build_monitoring_manager(:parent_manager => self,
:name => "#{name} Monitoring Manager",
:zone_id => zone_id,
:provider_region => provider_region)
monitoring_manager
end

def endpoint_created(role)
if role == "prometheus_alerts" && monitoring_manager.nil?
monitoring_manager = build_monitoring_manager_with_params
monitoring_manager.save
end
end

def ensure_monitoring_manager
# monitoring_manager should be defined by child classes.
if monitoring_manager_needed? && monitoring_manager.nil?
build_monitoring_manager(:parent_manager => self)
monitoring_manager.name = "#{name} Monitoring Manager"
monitoring_manager.zone_id = zone_id
monitoring_manager.provider_region = provider_region
elsif !monitoring_manager_needed? && monitoring_manager.present?
def endpoint_destroyed(role)
if role == "prometheus_alerts" && monitoring_manager.present?
# TODO: if someone deletes the alerts endpoint and then quickly readds it they can end up without a manager.
monitoring_manager.delete_queue
monitoring_manager.destroy_queue
end
end
end

0 comments on commit bb88857

Please sign in to comment.