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..a95ca59a2 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 @@ -215,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 @@ -292,8 +300,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? && !containerId.empty? && !@@containerCGroupCache.nil? && @@containerCGroupCache.length > 0 && @@containerCGroupCache.key?(containerId) + @@containerCGroupCache.delete(containerId) + end + rescue => error + @log.warn("KubernetesContainerInventory::deleteCGroupCacheEntryForDeletedContainer: deleting of cache entry failed: #{error}") + $log.debug_backtrace(error.backtrace) + ApplicationInsightsUtility.sendExceptionTelemetry(error) + end + end end end