Skip to content

Commit

Permalink
Merge pull request #2478 from simon3z/events-timeline
Browse files Browse the repository at this point in the history
containers: kubernetes events and timeline
  • Loading branch information
blomquisg committed Jun 4, 2015
2 parents 2989e6d + 323f4d7 commit 25e16af
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 9 deletions.
9 changes: 9 additions & 0 deletions vmdb/app/controllers/mixins/containers_common_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def show_container(record, controller_name, display_name)
drop_breadcrumb(:name => "#{record.name} (Summary)",
:url => "/#{controller_name}/show/#{record.id}")
set_summary_pdf_data if %w(download_pdf summary_only).include?(@display)
elsif @display == "timeline"
@showtype = "timeline"
session[:tl_record_id] = params[:id] if params[:id]
@lastaction = "show_timeline"
@timeline = @timeline_filter = true
tl_build_timeline # Create the timeline report
drop_breadcrumb(:name => "Timelines",
:url => "/#{controller_name}/show/#{record.id}" \
"?refresh=n&display=timeline")
elsif @display == "container_groups" || session[:display] == "container_groups" && params[:display].nil?
title = ui_lookup(:tables => "container_groups")
drop_breadcrumb(:name => record.name + " (All #{title})",
Expand Down
10 changes: 10 additions & 0 deletions vmdb/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,16 @@ def build_toolbar_disable_button(id)
when "host_restart"
return @record.is_available_now_error_message(:reboot) if @record.is_available_now_error_message(:reboot)
end
when "ContainerNodeKubernetes"
case id
when "container_node_timeline"
return "No Timeline data has been collected for this Node" unless @record.has_events? || @record.has_events?(:policy_events)
end
when "ContainerGroupKubernetes"
case id
when "container_group_timeline"
return "No Timeline data has been collected for this ContainerGroup" unless @record.has_events? || @record.has_events?(:policy_events)
end
when "MiqAction"
case id
when "action_edit"
Expand Down
14 changes: 14 additions & 0 deletions vmdb/app/models/container_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ class ContainerGroup < ActiveRecord::Base

# validates :restart_policy, :inclusion => { :in => %w(always onFailure never) }
# validates :dns_policy, :inclusion => { :in => %w(ClusterFirst Default) }

include EventMixin

def event_where_clause(assoc = :ems_events)
case assoc.to_sym
when :ems_events
# TODO: improve relationship using the id
["container_namespace = ? AND container_group_name = ? AND ems_id = ?",
namespace, name, ems_id]
when :policy_events
# TODO: implement policy events and its relationship
["ems_id = ?", ems_id]
end
end
end
13 changes: 13 additions & 0 deletions vmdb/app/models/container_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ def ready_condition
def ready_condition_status
ready_condition.try(:status) || 'None'
end

include EventMixin

def event_where_clause(assoc = :ems_events)
case assoc.to_sym
when :ems_events
# TODO: improve relationship using the id
["container_node_name = ? AND ems_id = ?", name, ems_id]
when :policy_events
# TODO: implement policy events and its relationship
["ems_id = ?", ems_id]
end
end
end
4 changes: 4 additions & 0 deletions vmdb/app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def self.add_amazon(ems_id, event)
self.add(ems_id, EmsEvent::Parsers::Amazon.event_to_hash(event, ems_id))
end

def self.add_kubernetes(ems_id, event)
add(ems_id, EmsEvent::Parsers::Kubernetes.event_to_hash(event, ems_id))
end

def self.add(ems_id, event_hash)
event_type = event_hash[:event_type]
raise MiqException::Error, "event_type must be set in event" if event_type.nil?
Expand Down
21 changes: 21 additions & 0 deletions vmdb/app/models/ems_event/parsers/kubernetes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module EmsEvent::Parsers::Kubernetes
def self.event_to_hash(event, ems_id = nil)
log_header = "MIQ(#{name}.event_to_hash) ems_id: [#{ems_id}]"

$log.debug("#{log_header} event: [#{event.inspect}]")

event_type = "#{event[:kind].upcase}_#{event[:reason].upcase}"

{
:event_type => event_type,
:source => 'KUBERNETES',
:timestamp => event[:timestamp],
:message => event[:message],
:container_node_name => event[:container_node_name],
:container_group_name => event[:container_group_name],
:container_namespace => event[:container_namespace],
:full_data => event,
:ems_id => ems_id
}
end
end
9 changes: 7 additions & 2 deletions vmdb/app/views/container_group/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
- elsif @display == 'container_services' && @showtype != "compare"
= render :partial => "layouts/gtl", :locals => {:action_url => "show/#{@record.id}"}
- else
= render :partial => @showtype

- case @showtype
- when "timeline"
= render(:partial => "layouts/tl_show")
:javascript
var miq_after_onload = "miqAsyncAjax('#{url_for(:action=>@ajax_action, :id=>@record)}');"
- else
= render :partial => @showtype
4 changes: 4 additions & 0 deletions vmdb/app/views/container_node/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
- if 'container_groups'.eql?(@display) && @showtype != "compare"
= render :partial => "layouts/gtl", :locals => {:action_url => "show/#{@record.id}"}
- elsif @showtype == "timeline"
= render(:partial => "layouts/tl_show")
:javascript
var miq_after_onload = "miqAsyncAjax('#{url_for(:action=>@ajax_action, :id=>@record)}');"
- else
= render :partial => @showtype
10 changes: 10 additions & 0 deletions vmdb/app/views/layouts/listnav/_container_group.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
%li
= link_to(_('Summary'), {:action => 'show', :id => @record, :display => 'main'}, :title => _("Show Summary"))

- if @record.has_events? || @record.has_events?(:policy_events)
%li
= link_to('Timelines',
{:action => 'show', :display => 'timeline', :id => @record},
:title => _("Show Timelines"))
- else
%li.disabled
= link_to(_('Timelines'), "#")


= patternfly_accordion_panel(_("Relationships"), false, "container_group_rel") do
%ul.nav.nav-pills.nav-stacked

Expand Down
10 changes: 10 additions & 0 deletions vmdb/app/views/layouts/listnav/_container_node.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
%li
= link_to(_('Summary'), {:action => 'show', :id => @record, :display => 'main'}, :title => _("Show Summary"))

- if @record.has_events? || @record.has_events?(:policy_events)
%li
= link_to('Timelines',
{:action => 'show', :display => 'timeline', :id => @record},
:title => _("Show Timelines"))
- else
%li.disabled
= link_to(_('Timelines'), "#")


= patternfly_accordion_panel(_("Relationships"), false, "container_node_rel") do
%ul.nav.nav-pills.nav-stacked

Expand Down
8 changes: 8 additions & 0 deletions vmdb/app/views/layouts/listnav/_ems_container.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
%ul.nav.nav-pills.nav-stacked
%li
= link_to(_('Summary'), {:action => 'show', :id => @record, :display => 'main'}, :title => _("Show Summary"))
- if @record.has_events? || @record.has_events?(:policy_events)
%li
= link_to(_('Timelines'),
{:action => 'show', :id => @record, :display => 'timeline'},
:title => _("Show Timelines"))
- else
%li.disabled
= link_to(_('Timelines'), "#")

= patternfly_accordion_panel(_("Relationships"), false, "ems_container_rel") do
%ul.nav.nav-pills.nav-stacked
Expand Down
16 changes: 16 additions & 0 deletions vmdb/config/event_handling.tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ event_groups:
- compute.instance.reboot.end
- compute.instance.suspend
- compute.instance.resume
- NODE_REBOOT
- POD_SCHEDULED
:detail:
- PowerOffVM_Task
- PowerOffVM_Task_Complete
Expand Down Expand Up @@ -599,6 +601,8 @@ event_groups:
- VM_FAILURE
- VM_NOT_RESPONDING
- VmConfigMissingEvent
- NODE_NODEREADY
- NODE_NODENOTREADY
:detail:
- DatacenterRenamedEvent
- GeneralUserEvent
Expand Down Expand Up @@ -1396,6 +1400,18 @@ event_handling:
- vm_poweroff
- refresh:
- ems
NODE_REBOOT:
- refresh:
- ems
NODE_NODEREADY:
- refresh:
- ems
NODE_NODENOTREADY:
- refresh:
- ems
POD_SCHEDULED:
- refresh:
- ems

#
# The filtered_events section defines which events should not be added to the
Expand Down
6 changes: 6 additions & 0 deletions vmdb/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@
sections_field_changed
show
show_list
tl_chooser
update
wait_for_task
) +
adv_search_post +
exp_post +
Expand Down Expand Up @@ -376,7 +378,9 @@
sections_field_changed
show
show_list
tl_chooser
update
wait_for_task
) +
adv_search_post +
exp_post +
Expand Down Expand Up @@ -671,7 +675,9 @@
sections_field_changed
show
show_list
tl_chooser
update
wait_for_task
) +
adv_search_post +
compare_post +
Expand Down
7 changes: 7 additions & 0 deletions vmdb/config/vmdb.tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ workers:
:poll: 15.seconds
:event_catcher_kubernetes:
:poll: 1.seconds
:enabled_events:
Node:
- NodeReady
- NodeNotReady
- rebooted
Pod:
- scheduled
:queue_worker_base:
:defaults:
:cpu_usage_threshold: 100.percent
Expand Down
12 changes: 12 additions & 0 deletions vmdb/db/fixtures/miq_product_features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3494,6 +3494,10 @@
:description: Display Individual Containers Providers
:feature_type: view
:identifier: ems_container_show
- :name: Timeline
:description: Display Timelines for Containers Providers
:feature_type: view
:identifier: ems_container_timeline
- :name: Operate
:description: Perform Operations on Containers Providers
:feature_type: control
Expand Down Expand Up @@ -3540,6 +3544,10 @@
:description: Display Individual Container Groups
:feature_type: view
:identifier: container_group_show
- :name: Timeline
:description: Display Timelines for Container Groups
:feature_type: view
:identifier: container_group_timeline
- :name: Modify
:description: Modify Container Groups
:feature_type: admin
Expand Down Expand Up @@ -3577,6 +3585,10 @@
:description: Display Individual Container Nodes
:feature_type: view
:identifier: container_node_show
- :name: Timeline
:description: Display Timelines for Container Nodes
:feature_type: view
:identifier: container_node_timeline
- :name: Modify
:description: Modify Container Nodes
:feature_type: admin
Expand Down
9 changes: 9 additions & 0 deletions vmdb/db/migrate/20150417125852_add_container_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddContainerEvents < ActiveRecord::Migration
def change
add_column :ems_events, :container_node_id, :bigint
add_column :ems_events, :container_node_name, :string
add_column :ems_events, :container_group_id, :bigint
add_column :ems_events, :container_group_name, :string
add_column :ems_events, :container_namespace, :string
end
end
31 changes: 28 additions & 3 deletions vmdb/lib/workers/event_catcher_kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,33 @@ def monitor_events
end

def process_event(event)
# TODO: some sane event filtering
$log.info "#{log_prefix} Caught event [#{event}]"
# TODO: add_queue kubernetes event
event_data = {
:timestamp => event.object.lastTimestamp,
:kind => event.object.involvedObject.kind,
:name => event.object.involvedObject.name,
:namespace => event.object.involvedObject['table'][:namespace],
:reason => event.object.reason,
:message => event.object.message
}

@enabled_events ||= worker_settings[:enabled_events]
supported_reasons = @enabled_events[event_data[:kind]] || []

unless supported_reasons.include?(event_data[:reason])
$log.debug "#{log_prefix} Discarding event [#{event_data}]"
return
end

# Handle event data for specific entities
case event_data[:kind]
when 'Node'
event_data[:container_node_name] = event_data[:name]
when 'Pod'
event_data[:container_namespace] = event_data[:namespace]
event_data[:container_group_name] = event_data[:name]
end

$log.info "#{log_prefix} Queuing event [#{event_data}]"
EmsEvent.add_queue('add_kubernetes', @cfg[:ems_id], event_data)
end
end
14 changes: 13 additions & 1 deletion vmdb/product/toolbars/container_group_center_tb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@
:title: 'Remove this #{ui_lookup(:table=>"container_group")} from the VMDB'
:url_parms: '&refresh=y'
:confirm: 'Warning: This #{ui_lookup(:table=>"container_group")} and ALL of its components will be permanently removed from the Virtual Management Database. Are you sure you want to remove this #{ui_lookup(:table=>"container_group")}?'

- :name: container_group_monitoring
:items:
- :buttonSelect: container_group_monitoring_choice
:image: monitoring
:title: Monitoring
:text: Monitoring
:items:
- :button: container_group_timeline
:image: timeline
:text: "Timelines"
:title: "Show Timelines for this Group"
:url: '/show'
:url_parms: '?display=timeline'
13 changes: 13 additions & 0 deletions vmdb/product/toolbars/container_node_center_tb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@
:title: 'Remove this #{ui_lookup(:table=>"container_node")} from the VMDB'
:url_parms: '&refresh=y'
:confirm: 'Warning: This #{ui_lookup(:table=>"container_node")} and ALL of its components will be permanently removed from the Virtual Management Database. Are you sure you want to remove this #{ui_lookup(:table=>"container_node")}?'
- :name: container_node_monitoring
:items:
- :buttonSelect: container_node_monitoring_choice
:image: monitoring
:title: Monitoring
:text: Monitoring
:items:
- :button: container_node_timeline
:image: timeline
:text: "Timelines"
:title: "Show Timelines for this Node"
:url: '/show'
:url_parms: '?display=timeline'
13 changes: 13 additions & 0 deletions vmdb/product/toolbars/ems_container_center_tb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@
:title: 'Remove this #{ui_lookup(:table=>"ems_container")} from the VMDB'
:url_parms: '&refresh=y'
:confirm: 'Warning: This #{ui_lookup(:table=>"ems_container")} and ALL of its components will be permanently removed from the Virtual Management Database. Are you sure you want to remove this #{ui_lookup(:table=>"ems_container")}?'
- :name: ems_container_monitoring
:items:
- :buttonSelect: ems_container_monitoring_choice
:image: monitoring
:title: Monitoring
:text: Monitoring
:items:
- :button: ems_container_timeline
:image: timeline
:text: 'Timelines'
:title: 'Show Timelines for this #{ui_lookup(:table=>"ems_container")}'
:url: '/show'
:url_parms: '?display=timeline'

0 comments on commit 25e16af

Please sign in to comment.