Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External Logging link for container nodes #13704

Merged
merged 1 commit into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions app/models/container_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class ContainerNode < ApplicationRecord
include MiqPolicyMixin
include NewWithTypeStiMixin
include TenantIdentityMixin
include SupportsFeatureMixin

EXTERNAL_LOGGING_PATH = "/#/discover?_g=()&_a=(columns:!(hostname,level,kubernetes.pod_name,message),filters:!((meta:(disabled:!f,index:'%{index}',key:hostname,negate:!f),%{query})),index:'%{index}',interval:auto,query:(query_string:(analyze_wildcard:!t,query:'*')),sort:!(time,desc))".freeze

# :name, :uid, :creation_timestamp, :resource_version
belongs_to :ext_management_system, :foreign_key => "ems_id"
Expand Down Expand Up @@ -72,17 +75,36 @@ def perf_rollup_parents(interval_name = nil)
[ext_management_system] unless interval_name == 'realtime'
end

def ipaddress
def kubernetes_hostname
labels.find_by(:name => "kubernetes.io/hostname").try(:value)
end

def cockpit_url
URI::HTTP.build(:host => ipaddress, :port => 9090)
URI::HTTP.build(:host => kubernetes_hostname, :port => 9090)
end

def evaluate_alert(_alert_id, _event)
# currently only EmsEvents from hawkular are tested for node alerts,
# and these should automaticaly be translated to alerts.
true
end

supports :external_logging_support do
Copy link
Member

@Fryguy Fryguy Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is funny because it duplicates the word support in certain caller paths. I think you just want supports :external_logging.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, do you want me to change this name in this PR? This will involve changing it in "app/models/mixins/support_feature_mixin.rb" and "app/models/manageiq/providers/container_manager.rb" too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opt for changing it 👍 But in it's own PR - and check if the UI depends on it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't realize it wasn't introduced in this PR. Yeah, then separate PR for sure.

unless ext_management_system.respond_to?(:external_logging_route_name)
unsupported_reason_add(:external_logging_support, _('This provider type does not support External Logging'))
end
end

def external_logging_query
nil # {}.to_query # TODO
end

def external_logging_path
node_hostnames = [kubernetes_hostname || name] # node name cannot be empty, it's an ID
node_hostnames.push(node_hostnames.first.split('.').first).compact!
node_hostnames_query = node_hostnames.uniq.map { |x| "(term:(hostname:'#{x}'))" }.join(",")
query = "bool:(filter:(or:!(#{node_hostnames_query})))"
index = ".operations.*"
EXTERNAL_LOGGING_PATH % {:index => index, :query => query}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@
)
expect(node.container_images.count).to eq(1)
end

describe "#external_logging_path" do
def get_query(path)
index = ".operations.*"
prefix_len = (ContainerNode::EXTERNAL_LOGGING_PATH % {:index => index, :query => 'MARKER'}).index('MARKER')
path[prefix_len..(prefix_len + path[prefix_len..-1].index("index:'.operations.*'") - 4)]
end

it "will query for nothing when no name/fqdn is available" do
node = FactoryGirl.create(:container_node, :name => "")
query = get_query(node.external_logging_path)
expect(query).to eq("bool:(filter:(or:!((term:(hostname:'')))))")
end

it "queries both fqdn and hostname when both are avaialble only from kubernetes lables" do
node = FactoryGirl.create(:container_node, :name => "other_name")
node.labels.create(:name => "kubernetes.io/hostname", :value => "hello.world.com")
query = get_query(node.external_logging_path)
expect(query).to eq("bool:(filter:(or:!((term:(hostname:'hello.world.com')),(term:(hostname:'hello')))))")
end

it "queries both fqdn and hostname when both are avaialble" do
node = FactoryGirl.create(:container_node, :name => "hello.world.com")
query = get_query(node.external_logging_path)
expect(query).to eq("bool:(filter:(or:!((term:(hostname:'hello.world.com')),(term:(hostname:'hello')))))")
end

it "queries only for the name/fqdn when hostname can't be parsed" do
node = FactoryGirl.create(:container_node, :name => "hello")
query = get_query(node.external_logging_path)
expect(query).to eq("bool:(filter:(or:!((term:(hostname:'hello')))))")
end
end
end