Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry optimization - Remove unnecessary customDimensions field and shortening some fields #1056

Merged
merged 4 commits into from
Sep 13, 2023
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
35 changes: 12 additions & 23 deletions source/plugins/go/src/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ var (
PromMonitorPodsLabelSelectorLength int
//Tracks the number of monitor kubernetes pods field selectors and sent only from prometheus sidecar (uses ContainerLogTelemetryTicker)
PromMonitorPodsFieldSelectorLength int
jatakiajanvi12 marked this conversation as resolved.
Show resolved Hide resolved
//Map to get the short name for the controller type
ControllerType = map[string]string{
"daemonset": "DS",
"replicaset": "RS",
}
)

const (
Expand Down Expand Up @@ -359,41 +364,25 @@ func InitializeTelemetryClient(agentVersion string) (int, error) {

CommonProperties = make(map[string]string)
CommonProperties["Computer"] = Computer
CommonProperties["WorkspaceID"] = WorkspaceID
CommonProperties["ControllerType"] = os.Getenv("CONTROLLER_TYPE")
CommonProperties["AgentVersion"] = agentVersion
CommonProperties["WSID"] = WorkspaceID
CommonProperties["Controller"] = ControllerType[strings.ToLower(os.Getenv("CONTROLLER_TYPE"))]
CommonProperties["Version"] = agentVersion

aksResourceID := os.Getenv(envAKSResourceID)
// if the aks resource id is not defined, it is most likely an ACS Cluster
if aksResourceID == "" {
CommonProperties["ACSResourceName"] = os.Getenv(envACSResourceName)
CommonProperties["ClusterType"] = clusterTypeACS

CommonProperties["SubscriptionID"] = ""
CommonProperties["ResourceGroupName"] = ""
CommonProperties["ClusterName"] = ""
CommonProperties["Region"] = ""
CommonProperties["AKS_RESOURCE_ID"] = ""

CommonProperties["ID"] = os.Getenv(envACSResourceName)
} else {
CommonProperties["ACSResourceName"] = ""
CommonProperties["AKS_RESOURCE_ID"] = aksResourceID
splitStrings := strings.Split(aksResourceID, "/")
if len(splitStrings) > 0 && len(splitStrings) < 10 {
CommonProperties["SubscriptionID"] = splitStrings[2]
CommonProperties["ResourceGroupName"] = splitStrings[4]
CommonProperties["ClusterName"] = splitStrings[8]
}
CommonProperties["ClusterType"] = clusterTypeAKS
CommonProperties["ID"] = aksResourceID

region := os.Getenv("AKS_REGION")
CommonProperties["Region"] = region
}

if isProxyConfigured == true {
CommonProperties["IsProxyConfigured"] = "true"
CommonProperties["Proxy"] = "true"
} else {
CommonProperties["IsProxyConfigured"] = "false"
CommonProperties["Proxy"] = "false"
}

// Adding container type to telemetry
Expand Down
54 changes: 20 additions & 34 deletions source/plugins/ruby/ApplicationInsightsUtility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ApplicationInsightsUtility
@@proxy = (ProxyUtils.getProxyConfiguration)
end

@@controllerType = {"daemonset" => "DS", "replicaset" => "RS"}

def initialize
end

Expand All @@ -47,59 +49,43 @@ def initializeUtility()
begin
resourceInfo = ENV["AKS_RESOURCE_ID"]
if resourceInfo.nil? || resourceInfo.empty?
@@CustomProperties["ACSResourceName"] = ENV[@@EnvAcsResourceName]
@@CustomProperties["ClusterType"] = @@AcsClusterType
@@CustomProperties["SubscriptionID"] = ""
@@CustomProperties["ResourceGroupName"] = ""
@@CustomProperties["ClusterName"] = ""
@@CustomProperties["ID"] = ENV[@@EnvAcsResourceName]
@@CustomProperties["Region"] = ""
else
@@CustomProperties["AKS_RESOURCE_ID"] = resourceInfo
begin
splitStrings = resourceInfo.split("/")
subscriptionId = splitStrings[2]
resourceGroupName = splitStrings[4]
clusterName = splitStrings[8]
rescue => errorStr
$log.warn("Exception in AppInsightsUtility: parsing AKS resourceId: #{resourceInfo}, error: #{errorStr}")
end
@@CustomProperties["ClusterType"] = @@AksClusterType
@@CustomProperties["SubscriptionID"] = subscriptionId
@@CustomProperties["ResourceGroupName"] = resourceGroupName
@@CustomProperties["ClusterName"] = clusterName
@@CustomProperties["ID"] = resourceInfo
@@CustomProperties["Region"] = ENV[@@EnvAksRegion]
end

#Commenting it for now from initilize method, we need to pivot all telemetry off of kubenode docker version
#getDockerInfo()
@@CustomProperties["WorkspaceID"] = getWorkspaceId
@@CustomProperties["AgentVersion"] = ENV[@@EnvAgentVersion]
@@CustomProperties["ControllerType"] = ENV[@@EnvControllerType]
@@CustomProperties["WSID"] = getWorkspaceId
@@CustomProperties["Version"] = ENV[@@EnvAgentVersion]
@@CustomProperties["Controller"] = @@controllerType[ENV[@@EnvControllerType].downcase]
@@CustomProperties["Computer"] = @@hostName
encodedAppInsightsKey = ENV[@@EnvApplicationInsightsKey]
appInsightsEndpoint = ENV[@@EnvApplicationInsightsEndpoint]
@@CustomProperties["WorkspaceCloud"] = getWorkspaceCloud
@@CustomProperties["WSCloud"] = getWorkspaceCloud
if !@@proxy.nil? && !@@proxy.empty?
$log.info("proxy configured")
@@CustomProperties["IsProxyConfigured"] = "true"
@@CustomProperties["Proxy"] = "true"
isProxyConfigured = true
if ProxyUtils.isProxyCACertConfigured()
@@CustomProperties["ProxyCACertConfigured"] = "true"
end
else
@@CustomProperties["IsProxyConfigured"] = "false"
@@CustomProperties["Proxy"] = "false"
isProxyConfigured = false
if ProxyUtils.isIgnoreProxySettings()
$log.info("proxy configuration ignored since ignoreProxyConfig is true")
@@CustomProperties["IsProxyConfigurationIgnored"] = "true"
end
$log.info("proxy is not configured")
end
aadAuthMSIMode = ENV[@@EnvAADMSIAuthMode]
if !aadAuthMSIMode.nil? && !aadAuthMSIMode.empty? && aadAuthMSIMode.downcase == "true".downcase
@@CustomProperties["aadAuthMSIMode"] = "true"
isMSI = ENV[@@EnvAADMSIAuthMode]
if !isMSI.nil? && !isMSI.empty? && isMSI.downcase == "true".downcase
@@CustomProperties["isMSI"] = "true"
else
@@CustomProperties["aadAuthMSIMode"] = "false"
@@CustomProperties["isMSI"] = "false"
end
addonResizerVPAEnabled = ENV[@@EnvAddonResizerVPAEnabled]
if !addonResizerVPAEnabled.nil? && !addonResizerVPAEnabled.empty? && addonResizerVPAEnabled.downcase == "true".downcase
Expand Down Expand Up @@ -170,14 +156,14 @@ def getContainerRuntimeInfo()
begin
containerRuntime = ENV[@@EnvContainerRuntime]
if !containerRuntime.nil? && !containerRuntime.empty?
# DockerVersion field holds either containerRuntime for non-docker or Dockerversion if its docker
@@CustomProperties["DockerVersion"] = containerRuntime
# cri field holds either containerRuntime for non-docker or Dockerversion if its docker
@@CustomProperties["cri"] = containerRuntime
# Not doing this for windows since docker is being deprecated soon and we dont want to bring in the socket dependency.
if !@@isWindows.nil? && @@isWindows == false
if containerRuntime.casecmp("docker") == 0
dockerInfo = DockerApiClient.dockerInfo
if (!dockerInfo.nil? && !dockerInfo.empty?)
@@CustomProperties["DockerVersion"] = dockerInfo["Version"]
@@CustomProperties["cri"] = dockerInfo["Version"]
end
end
end
Expand Down Expand Up @@ -237,7 +223,7 @@ def sendExceptionTelemetry(errorStr, properties = nil)
begin
if @@CustomProperties.empty? || @@CustomProperties.nil?
initializeUtility()
elsif @@CustomProperties["DockerVersion"].nil?
elsif @@CustomProperties["cri"].nil?
getContainerRuntimeInfo()
end
telemetryProps = {}
Expand All @@ -261,7 +247,7 @@ def sendTelemetry(pluginName, properties)
begin
if @@CustomProperties.empty? || @@CustomProperties.nil?
initializeUtility()
elsif @@CustomProperties["DockerVersion"].nil?
elsif @@CustomProperties["cri"].nil?
getContainerRuntimeInfo()
end
@@CustomProperties["Computer"] = properties["Computer"]
Expand All @@ -284,7 +270,7 @@ def sendMetricTelemetry(metricName, metricValue, properties)
end
if @@CustomProperties.empty? || @@CustomProperties.nil?
initializeUtility()
elsif @@CustomProperties["DockerVersion"].nil?
elsif @@CustomProperties["cri"].nil?
getContainerRuntimeInfo()
end
telemetryProps = {}
Expand Down
6 changes: 3 additions & 3 deletions source/plugins/ruby/CAdvisorMetricsAPIClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def getContainerCpuMetricItems(metricJSON, hostName, cpuMetricNameToCollect, met
if (podName.downcase.start_with?("ama-logs-") && podNamespace.eql?("kube-system") && containerName.downcase.start_with?("ama-logs") && metricNametoReturn.eql?(Constants::CPU_USAGE_NANO_CORES))
if (timeDifferenceInMinutes >= Constants::TELEMETRY_FLUSH_INTERVAL_IN_MINUTES)
telemetryProps = {}
telemetryProps["PodName"] = podName
telemetryProps["Pod"] = podName
telemetryProps["ContainerName"] = containerName
telemetryProps["Computer"] = hostName
telemetryProps["CAdvisorIsSecure"] = @cAdvisorMetricsSecurePort
Expand Down Expand Up @@ -587,7 +587,7 @@ def getContainerCpuMetricItemRate(metricJSON, hostName, cpuMetricNameToCollect,
if (podName.downcase.start_with?("ama-logs-") && podNamespace.eql?("kube-system") && containerName.downcase.start_with?("ama-logs"))
if (timeDifferenceInMinutes >= 10)
telemetryProps = {}
telemetryProps["PodName"] = podName
telemetryProps["Pod"] = podName
telemetryProps["ContainerName"] = containerName
telemetryProps["Computer"] = hostName
telemetryProps["CAdvisorIsSecure"] = @cAdvisorMetricsSecurePort
Expand Down Expand Up @@ -683,7 +683,7 @@ def getContainerMemoryMetricItems(metricJSON, hostName, memoryMetricNameToCollec
if (podName.downcase.start_with?("ama-logs-") && podNamespace.eql?("kube-system") && containerName.downcase.start_with?("ama-logs") && ((metricNametoReturn.eql?(Constants::MEMORY_RSS_BYTES) && operatingSystem == "Linux") || (metricNametoReturn.eql?(Constants::MEMORY_WORKING_SET_BYTES) && operatingSystem == "Windows")))
if (timeDifferenceInMinutes >= Constants::TELEMETRY_FLUSH_INTERVAL_IN_MINUTES)
telemetryProps = {}
telemetryProps["PodName"] = podName
telemetryProps["Pod"] = podName
telemetryProps["ContainerName"] = containerName
telemetryProps["Computer"] = hostName
ApplicationInsightsUtility.sendMetricTelemetry(metricNametoReturn, metricValue, telemetryProps)
Expand Down
2 changes: 1 addition & 1 deletion source/plugins/ruby/KubernetesApiClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ def sendReplicasetAgentRequestsAndLimitsTelemetry(podName, podNameSpace, contain
begin
if (!podName.nil? && podName.downcase.start_with?("ama-logs-rs-") && podNameSpace.eql?("kube-system") && containerName.eql?("ama-logs"))
telemetryProps = {}
telemetryProps["PodName"] = podName
telemetryProps["Pod"] = podName
telemetryProps["ContainerName"] = containerName
case metricName
when "cpuLimitNanoCores"
Expand Down
2 changes: 1 addition & 1 deletion source/plugins/ruby/out_mdm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_access_token
if @cached_access_token.to_s.empty? || (Time.now + 5 * 60 > @token_expiry_time) # Refresh token 5 minutes from expiration
@log.info "Refreshing access token for out_mdm plugin.."
if (!!@isAADMSIAuth)
properties["aadAuthMSIMode"] = "true"
properties["isMSI"] = "true"
end
if @isAADMSIAuth && @isWindows
@log.info "reading the token from IMDS token file since its windows.."
Expand Down
Loading