Skip to content
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
3 changes: 3 additions & 0 deletions source/plugins/ruby/ApplicationInsightsUtility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ def sendTelemetry(pluginName, properties)
getContainerRuntimeInfo()
end
@@CustomProperties["Computer"] = properties["Computer"]
if !properties["addonTokenAdapterImageTag"].nil? && !properties["addonTokenAdapterImageTag"].empty?
@@CustomProperties["addonTokenAdapterImageTag"] = properties["addonTokenAdapterImageTag"]
end
sendHeartBeatEvent(pluginName)
sendLastProcessedContainerInventoryCountMetric(pluginName, properties)
rescue => errorStr
Expand Down
13 changes: 13 additions & 0 deletions source/plugins/ruby/in_containerinventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def enumerate
containerInventory = Array.new
eventStream = Fluent::MultiEventStream.new
hostName = ""
addonTokenAdapterImageTag = ""
$log.info("in_container_inventory::enumerate : Begin processing @ #{Time.now.utc.iso8601}")
if ExtensionUtils.isAADMSIAuthMode()
$log.info("in_container_inventory::enumerate: AAD AUTH MSI MODE")
Expand All @@ -82,6 +83,15 @@ def enumerate
if hostName.empty? && !containerRecord["Computer"].empty?
hostName = containerRecord["Computer"]
end
if addonTokenAdapterImageTag.empty? && ExtensionUtils.isAADMSIAuthMode()
Copy link
Member

@vishiy vishiy Sep 29, 2021

Choose a reason for hiding this comment

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

aadonTokenAdapterImageTag is a local variable in enumerate which is being intialized to empty, every time, which means this will be evaluated for all containers in MSI mode every minute, until this container is found. This should be a global, that should be set the first time, and then just use it as the container image for the sidecar wont change during our lifetime until we are redeployed/updated/restarted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologize for missing this feedback. I am just noticing when I am looking at the changes for the release notes. Agree, this should be global and will make PR to address this.

if !containerRecord["ElementName"].nil? && !containerRecord["ElementName"].empty? &&
Copy link
Member

Choose a reason for hiding this comment

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

I also disagree with this approach. Much neater way to do this would be, pass this image as an env variable from yaml. Define a helm variable for sidecar container, and use that for the spec.container.image as well pass the same as env variable to be picked up by our telemetry

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created a task in next agent release to switch the envvar from yaml.

containerRecord["ElementName"].include?("kube-system") &&
Copy link
Member

Choose a reason for hiding this comment

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

so if i have a kube-system-2 or my-kube-system namespace with a pod having same container name, we will pick that image ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are chances to pick the wrong telemetry if the namespace contains kube-system and container name and will add strict check for the namespace.

containerRecord["ElementName"].include?("addon-token-adapter_omsagent")
if !containerRecord["ImageTag"].nil? && !containerRecord["ImageTag"].empty?
addonTokenAdapterImageTag = containerRecord["ImageTag"]
end
end
end
containerIds.push containerRecord["InstanceID"]
containerInventory.push containerRecord
end
Expand Down Expand Up @@ -117,6 +127,9 @@ def enumerate
telemetryProperties = {}
telemetryProperties["Computer"] = hostName
telemetryProperties["ContainerCount"] = containerInventory.length
if !addonTokenAdapterImageTag.empty?
telemetryProperties["addonTokenAdapterImageTag"] = addonTokenAdapterImageTag
end
ApplicationInsightsUtility.sendTelemetry(@@PluginName, telemetryProperties)
end
rescue => errorStr
Expand Down