From 46f6ecd87f68a9e7f212b5fd630da58e6f7d5a55 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Thu, 2 Apr 2020 17:06:05 -0700 Subject: [PATCH 1/3] fix nil exception --- source/code/plugin/in_containerinventory.rb | 4 ++-- .../plugin/kubernetes_container_inventory.rb | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/source/code/plugin/in_containerinventory.rb b/source/code/plugin/in_containerinventory.rb index 8c504467b..c1126aa4e 100644 --- a/source/code/plugin/in_containerinventory.rb +++ b/source/code/plugin/in_containerinventory.rb @@ -83,8 +83,8 @@ def enumerate container = ContainerInventoryState.readContainerState(deletedContainer) if !container.nil? container.each { |k, v| container[k] = v } - container["State"] = "Deleted" - @@containerCGroupCache.delete(container["InstanceID"]) + container["State"] = "Deleted" + KubernetesContainerInventory.deleteCGroupCacheEntryForDeletedContainer(container["InstanceID"]) containerInventory.push container end end diff --git a/source/code/plugin/kubernetes_container_inventory.rb b/source/code/plugin/kubernetes_container_inventory.rb index 6fd63a735..029bfee27 100644 --- a/source/code/plugin/kubernetes_container_inventory.rb +++ b/source/code/plugin/kubernetes_container_inventory.rb @@ -5,6 +5,8 @@ class KubernetesContainerInventory require "yajl/json_gem" require "time" require_relative "omslog" + require_relative "ApplicationInsightsUtility" + # cache the container and cgroup parent process @@containerCGroupCache = Hash.new @@ -116,6 +118,8 @@ def getContainerInventoryRecords(podItem, batchTime, clusterCollectEnvironmentVa end rescue => error @log.warn("KubernetesContainerInventory::getContainerInventoryRecords : Get Container Inventory Records failed: #{error}") + $log.debug_backtrace(error.backtrace) + ApplicationInsightsUtility.sendExceptionTelemetry(error) end return containerInventoryRecords end @@ -157,6 +161,8 @@ def getContainersInfoMap(podItem, isWindows) end rescue => error @log.warn("KubernetesContainerInventory::getContainersInfoMap : Get Container Info Maps failed: #{error}") + $log.debug_backtrace(error.backtrace) + ApplicationInsightsUtility.sendExceptionTelemetry(error) end return containersInfoMap end @@ -292,8 +298,22 @@ def obtainWindowsContainerEnvironmentVars(pod, container) end rescue => error @log.warn("KubernetesContainerInventory::obtainWindowsContainerEnvironmentVars: parsing of EnvVars failed: #{error}") + $log.debug_backtrace(error.backtrace) + ApplicationInsightsUtility.sendExceptionTelemetry(error) end return envValueString end + + def deleteCGroupCacheEntryForDeletedContainer(containerId) + begin + if !containerId.nil? && @@containerCGroupCache.nil && @@containerCGroupCache.length > 0 && @@containerCGroupCache.key?(containerId) + @@containerCGroupCache.delete(containerId) + end + rescue => error + @log.warn("KubernetesContainerInventory::deleteCGroupCacheEntryForDeletedContainer: deleting: #{error}") + $log.debug_backtrace(error.backtrace) + ApplicationInsightsUtility.sendExceptionTelemetry(error) + end + end end end From b03124782392180ba0fbb876ac91361d6b1e53f0 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Thu, 2 Apr 2020 17:14:49 -0700 Subject: [PATCH 2/3] add exception logging message --- source/code/plugin/kubernetes_container_inventory.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/code/plugin/kubernetes_container_inventory.rb b/source/code/plugin/kubernetes_container_inventory.rb index 029bfee27..e54fe656f 100644 --- a/source/code/plugin/kubernetes_container_inventory.rb +++ b/source/code/plugin/kubernetes_container_inventory.rb @@ -221,6 +221,8 @@ def obtainContainerEnvironmentVars(containerId) end rescue => error @log.warn("KubernetesContainerInventory::obtainContainerEnvironmentVars: obtain Container Environment vars failed: #{error} for containerId: #{containerId}") + $log.debug_backtrace(error.backtrace) + ApplicationInsightsUtility.sendExceptionTelemetry(error) end return envValueString end @@ -303,14 +305,14 @@ def obtainWindowsContainerEnvironmentVars(pod, container) end return envValueString end - + def deleteCGroupCacheEntryForDeletedContainer(containerId) begin if !containerId.nil? && @@containerCGroupCache.nil && @@containerCGroupCache.length > 0 && @@containerCGroupCache.key?(containerId) @@containerCGroupCache.delete(containerId) end rescue => error - @log.warn("KubernetesContainerInventory::deleteCGroupCacheEntryForDeletedContainer: deleting: #{error}") + @log.warn("KubernetesContainerInventory::deleteCGroupCacheEntryForDeletedContainer: deleting of cache entry failed: #{error}") $log.debug_backtrace(error.backtrace) ApplicationInsightsUtility.sendExceptionTelemetry(error) end From 572fae9936d0e0336cecab05e8890dfb3d14bfcb Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Fri, 3 Apr 2020 13:57:42 -0700 Subject: [PATCH 3/3] fix npe --- source/code/plugin/kubernetes_container_inventory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/code/plugin/kubernetes_container_inventory.rb b/source/code/plugin/kubernetes_container_inventory.rb index e54fe656f..a95ca59a2 100644 --- a/source/code/plugin/kubernetes_container_inventory.rb +++ b/source/code/plugin/kubernetes_container_inventory.rb @@ -308,7 +308,7 @@ def obtainWindowsContainerEnvironmentVars(pod, container) def deleteCGroupCacheEntryForDeletedContainer(containerId) begin - if !containerId.nil? && @@containerCGroupCache.nil && @@containerCGroupCache.length > 0 && @@containerCGroupCache.key?(containerId) + if !containerId.nil? && !containerId.empty? && !@@containerCGroupCache.nil? && @@containerCGroupCache.length > 0 && @@containerCGroupCache.key?(containerId) @@containerCGroupCache.delete(containerId) end rescue => error