From f32b10aa65bc5553e241665dd84a67b342bf2bc6 Mon Sep 17 00:00:00 2001 From: Dilip Raghunathan Date: Fri, 15 Feb 2019 18:24:14 -0800 Subject: [PATCH 1/2] Zero Fill for Pod Counts by Phase --- source/code/plugin/filter_inventory2mdm.rb | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/source/code/plugin/filter_inventory2mdm.rb b/source/code/plugin/filter_inventory2mdm.rb index d9864bc1a..66866fa9d 100644 --- a/source/code/plugin/filter_inventory2mdm.rb +++ b/source/code/plugin/filter_inventory2mdm.rb @@ -77,7 +77,9 @@ class Inventory2MdmFilter < Filter } } }' - + + @@pod_phase_values = ['Running', 'Pending', 'Succeeded', 'Failed', 'Unknown'] + @process_incoming_stream = true def initialize @@ -151,7 +153,7 @@ def process_node_inventory_records(es) def process_pod_inventory_records(es) timestamp = DateTime.now pod_count_hash = Hash.new - + no_phase_dim_values_hash = Hash.new begin records = [] es.each{|time,record| @@ -173,6 +175,29 @@ def process_pod_inventory_records(es) pod_count = 1 pod_count_hash[pod_key] = pod_count end + + # Collect all possible combinations of dimension values other than pod phase + key_without_phase_dim_value = [podNodeDimValue, podNamespaceDimValue, podControllerNameDimValue].join('~~') + if no_phase_dim_values_hash.key?(key_without_phase_dim_value) + @log.info "#{key_without_phase_dim_value} already present in #{no_phase_dim_values_hash}" + next + else + @log.info "Adding #{key_without_phase_dim_value} to #{no_phase_dim_values_hash}" + no_phase_dim_values_hash[key_without_phase_dim_value] = true + end + } + + # generate all possible values of non_phase_dim_values X pod Phases and zero-fill the ones that are not already present + no_phase_dim_values_hash.each {|key, value| + @@pod_phase_values.each{|phase| + pod_key = [key, phase].join('~~') + if !pod_count_hash.key?(pod_key) + pod_count_hash[pod_key] = 0 + @log.info "Zero filled #{pod_key}" + else + next + end + } } pod_count_hash.each {|key, value| From c7f8020b6385c9493fd7a6a61df6fc5576e9b940 Mon Sep 17 00:00:00 2001 From: Dilip Raghunathan Date: Fri, 15 Feb 2019 18:33:09 -0800 Subject: [PATCH 2/2] Change namespace dimension to Kubernetes namespace --- source/code/plugin/filter_inventory2mdm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/code/plugin/filter_inventory2mdm.rb b/source/code/plugin/filter_inventory2mdm.rb index 66866fa9d..8aaa5ff01 100644 --- a/source/code/plugin/filter_inventory2mdm.rb +++ b/source/code/plugin/filter_inventory2mdm.rb @@ -56,7 +56,7 @@ class Inventory2MdmFilter < Filter "namespace": "insights.container/pods", "dimNames": [ "phase", - "namespace", + "Kubernetes namespace", "node", "controllerName" ],