Skip to content
28 changes: 20 additions & 8 deletions source/code/plugin/ApplicationInsightsUtility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class ApplicationInsightsUtility
@@Exception = 'ExceptionEvent'
@@AcsClusterType = 'ACS'
@@AksClusterType = 'AKS'
@@DaemonsetControllerType = 'DaemonSet'
@OmsAdminFilePath = '/etc/opt/microsoft/omsagent/conf/omsadmin.conf'
@@EnvAcsResourceName = 'ACS_RESOURCE_NAME'
@@EnvAksRegion = 'AKS_REGION'
@@EnvAgentVersion = 'AGENT_VERSION'
@@EnvApplicationInsightsKey = 'APPLICATIONINSIGHTS_AUTH'
@@EnvControllerType = 'CONTROLLER_TYPE'
@@CustomProperties = {}
@@Tc = nil
@@hostName = (OMS::Common.get_hostname)
Expand Down Expand Up @@ -54,12 +54,10 @@ def initializeUtility()
@@CustomProperties["ClusterName"] = clusterName
@@CustomProperties["Region"] = ENV[@@EnvAksRegion]
end
@@CustomProperties['ControllerType'] = @@DaemonsetControllerType
dockerInfo = DockerApiClient.dockerInfo
@@CustomProperties['DockerVersion'] = dockerInfo['Version']
@@CustomProperties['DockerApiVersion'] = dockerInfo['ApiVersion']
getDockerInfo()
@@CustomProperties['WorkspaceID'] = getWorkspaceId
@@CustomProperties['AgentVersion'] = ENV[@@EnvAgentVersion]
@@CustomProperties['ControllerType'] = ENV[@@EnvControllerType]
encodedAppInsightsKey = ENV[@@EnvApplicationInsightsKey]
if !encodedAppInsightsKey.nil?
decodedAppInsightsKey = Base64.decode64(encodedAppInsightsKey)
Expand All @@ -70,6 +68,14 @@ def initializeUtility()
end
end

def getDockerInfo()
dockerInfo = DockerApiClient.dockerInfo
if (!dockerInfo.nil? && !dockerInfo.empty?)
@@CustomProperties['DockerVersion'] = dockerInfo['Version']
@@CustomProperties['DockerApiVersion'] = dockerInfo['ApiVersion']
end
end

def sendHeartBeatEvent(pluginName)
begin
eventName = pluginName + @@HeartBeat
Expand Down Expand Up @@ -100,7 +106,9 @@ def sendCustomMetric(pluginName, properties)
def sendExceptionTelemetry(errorStr)
begin
if @@CustomProperties.empty? || @@CustomProperties.nil?
initializeUtility
initializeUtility()
elsif @@CustomProperties['DockerVersion'].nil?
getDockerInfo()
end
if !(@@Tc.nil?)
@@Tc.track_exception errorStr , :properties => @@CustomProperties
Expand All @@ -116,7 +124,9 @@ def sendExceptionTelemetry(errorStr)
def sendTelemetry(pluginName, properties)
begin
if @@CustomProperties.empty? || @@CustomProperties.nil?
initializeUtility
initializeUtility()
elsif @@CustomProperties['DockerVersion'].nil?
getDockerInfo()
end
@@CustomProperties['Computer'] = properties['Computer']
sendHeartBeatEvent(pluginName)
Expand All @@ -134,7 +144,9 @@ def sendMetricTelemetry(metricName, metricValue, properties)
return
end
if @@CustomProperties.empty? || @@CustomProperties.nil?
initializeUtility
initializeUtility()
elsif @@CustomProperties['DockerVersion'].nil?
getDockerInfo()
end
telemetryProps = {}
telemetryProps["Computer"] = @@hostName
Expand Down
3 changes: 2 additions & 1 deletion source/code/plugin/DockerApiClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class DockerApiClient
require_relative 'DockerApiRestHelper'
require_relative 'ApplicationInsightsUtility'

@@SocketPath = "/var/run/docker.sock"
@@SocketPath = "/var/run/host/docker.sock"
@@ChunkSize = 4096
@@TimeoutInSeconds = 5
@@PluginName = 'ContainerInventory'

def initialize
end

Expand Down
1 change: 1 addition & 0 deletions source/code/plugin/in_containerinventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize
require_relative 'ContainerInventoryState'
require_relative 'ApplicationInsightsUtility'
require_relative 'omslog'

end

config_param :run_interval, :time, :default => '1m'
Expand Down
6 changes: 6 additions & 0 deletions source/code/plugin/in_kube_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def initialize
require_relative 'KubernetesApiClient'
require_relative 'oms_common'
require_relative 'omslog'
require_relative 'ApplicationInsightsUtility'

end

config_param :run_interval, :time, :default => '1m'
Expand Down Expand Up @@ -94,6 +96,7 @@ def enumerate(eventList = nil)
rescue => errorStr
$log.warn line.dump, error: errorStr.to_s
$log.debug_backtrace(errorStr.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end

Expand All @@ -110,6 +113,7 @@ def run_periodic
enumerate
rescue => errorStr
$log.warn "in_kube_events::run_periodic: enumerate Failed to retrieve kube events: #{errorStr}"
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end
@mutex.lock
Expand All @@ -129,6 +133,7 @@ def getEventQueryState
rescue => errorStr
$log.warn $log.warn line.dump, error: errorStr.to_s
$log.debug_backtrace(errorStr.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
return eventQueryState
end
Expand All @@ -144,6 +149,7 @@ def writeEventQueryState(eventQueryState)
rescue => errorStr
$log.warn $log.warn line.dump, error: errorStr.to_s
$log.debug_backtrace(errorStr.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end

Expand Down
3 changes: 3 additions & 0 deletions source/code/plugin/in_kube_nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize
require_relative 'ApplicationInsightsUtility'
require_relative 'oms_common'
require_relative 'omslog'

end

config_param :run_interval, :time, :default => '1m'
Expand Down Expand Up @@ -142,6 +143,7 @@ def enumerate
rescue => errorStr
$log.warn "Failed to retrieve node inventory: #{errorStr}"
$log.debug_backtrace(errorStr.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end

Expand All @@ -158,6 +160,7 @@ def run_periodic
enumerate
rescue => errorStr
$log.warn "in_kube_nodes::run_periodic: enumerate Failed to retrieve node inventory: #{errorStr}"
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end
@mutex.lock
Expand Down
6 changes: 6 additions & 0 deletions source/code/plugin/in_kube_podinventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize
require_relative 'ApplicationInsightsUtility'
require_relative 'oms_common'
require_relative 'omslog'

end

config_param :run_interval, :time, :default => '1m'
Expand Down Expand Up @@ -66,6 +67,7 @@ def enumerate(podList = nil)
rescue => errorStr
$log.warn "Failed in enumerate pod inventory: #{errorStr}"
$log.debug_backtrace(errorStr.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end

Expand Down Expand Up @@ -207,6 +209,7 @@ def parse_and_emit_records(podInventory, serviceList)
end #podInventory block end
router.emit_stream(@tag, eventStream) if eventStream
if telemetryFlush == true
ApplicationInsightsUtility.sendHeartBeatEvent("KubePodInventory")
ApplicationInsightsUtility.sendMetricTelemetry("PodCount", podInventory['items'].length , {})
ApplicationInsightsUtility.sendMetricTelemetry("ControllerCount", controllerSet.length , {})
@@podTelemetryTimeTracker = DateTime.now.to_time.to_i
Expand All @@ -218,6 +221,7 @@ def parse_and_emit_records(podInventory, serviceList)
rescue => errorStr
$log.warn "Failed in parse_and_emit_record pod inventory: #{errorStr}"
$log.debug_backtrace(errorStr.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end #begin block end
end

Expand All @@ -234,6 +238,7 @@ def run_periodic
enumerate
rescue => errorStr
$log.warn "in_kube_podinventory::run_periodic: enumerate Failed to retrieve pod inventory: #{errorStr}"
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end
@mutex.lock
Expand Down Expand Up @@ -268,6 +273,7 @@ def getServiceNameFromLabels(namespace, labels, serviceList)
rescue => errorStr
$log.warn "Failed to retrieve service name from labels: #{errorStr}"
$log.debug_backtrace(errorStr.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
return serviceName
end
Expand Down
4 changes: 4 additions & 0 deletions source/code/plugin/in_kube_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def initialize
require_relative 'KubernetesApiClient'
require_relative 'oms_common'
require_relative 'omslog'
require_relative 'ApplicationInsightsUtility'

end

config_param :run_interval, :time, :default => '1m'
Expand Down Expand Up @@ -70,6 +72,7 @@ def enumerate
rescue => errorStr
$log.warn line.dump, error: errorStr.to_s
$log.debug_backtrace(e.backtrace)
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end

Expand All @@ -86,6 +89,7 @@ def run_periodic
enumerate
rescue => errorStr
$log.warn "in_kube_services::run_periodic: enumerate Failed to kube services: #{errorStr}"
ApplicationInsightsUtility.sendExceptionTelemetry(errorStr)
end
end
@mutex.lock
Expand Down