From 3d385ca6411fb1603ebceeb7e65aa2e1a3c23581 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Wed, 11 Sep 2019 16:23:48 -0700 Subject: [PATCH 1/6] add telemetry to detect the cloud, distro and kernel version --- source/code/plugin/in_kube_nodes.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/code/plugin/in_kube_nodes.rb b/source/code/plugin/in_kube_nodes.rb index 7249957ab..2d321a2f4 100644 --- a/source/code/plugin/in_kube_nodes.rb +++ b/source/code/plugin/in_kube_nodes.rb @@ -83,6 +83,7 @@ def enumerate record["CreationTimeStamp"] = items["metadata"]["creationTimestamp"] record["Labels"] = [items["metadata"]["labels"]] record["Status"] = "" + record["ProviderID"] = items["spec"]["providerID"] # Refer to https://kubernetes.io/docs/concepts/architecture/nodes/#condition for possible node conditions. # We check the status of each condition e.g. {"type": "OutOfDisk","status": "False"} . Based on this we @@ -139,6 +140,9 @@ def enumerate properties["KubeletVersion"] = record["KubeletVersion"] properties["OperatingSystem"] = nodeInfo["operatingSystem"] properties["DockerVersion"] = dockerVersion + properties["ProviderID"] = record["ProviderID"] + properties["KernelVersion"] = nodeInfo["kernelVersion"] + properties["OSImage"] = nodeInfo["osImage"] capacityInfo = items["status"]["capacity"] ApplicationInsightsUtility.sendMetricTelemetry("NodeMemory", capacityInfo["memory"], properties) From 55d8b0c41ecffb95a48b93db0a2634f67d5c9f62 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Wed, 11 Sep 2019 17:20:51 -0700 Subject: [PATCH 2/6] add null check since providerId optional --- source/code/plugin/in_kube_nodes.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/code/plugin/in_kube_nodes.rb b/source/code/plugin/in_kube_nodes.rb index 2d321a2f4..224d555b3 100644 --- a/source/code/plugin/in_kube_nodes.rb +++ b/source/code/plugin/in_kube_nodes.rb @@ -83,7 +83,13 @@ def enumerate record["CreationTimeStamp"] = items["metadata"]["creationTimestamp"] record["Labels"] = [items["metadata"]["labels"]] record["Status"] = "" - record["ProviderID"] = items["spec"]["providerID"] + + if !items["spec"]["providerID"].nil? && !items["spec"]["providerID"].empty? + record["ProviderID"] = items["spec"]["providerID"] + else + record["ProviderID"] = "onprem" + end + # Refer to https://kubernetes.io/docs/concepts/architecture/nodes/#condition for possible node conditions. # We check the status of each condition e.g. {"type": "OutOfDisk","status": "False"} . Based on this we From e42a51336fc7cb1d614b0ccdd9ba6494114549af Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Thu, 12 Sep 2019 14:08:31 -0700 Subject: [PATCH 3/6] detect azurestack cloud --- source/code/plugin/in_kube_nodes.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/code/plugin/in_kube_nodes.rb b/source/code/plugin/in_kube_nodes.rb index 224d555b3..dca5d12e6 100644 --- a/source/code/plugin/in_kube_nodes.rb +++ b/source/code/plugin/in_kube_nodes.rb @@ -8,6 +8,7 @@ class Kube_nodeInventory_Input < Input @@ContainerNodeInventoryTag = "oms.containerinsights.ContainerNodeInventory" @@MDMKubeNodeInventoryTag = "mdm.kubenodeinventory" @@promConfigMountPath = "/etc/config/settings/prometheus-data-collection-settings" + @@AzStackCloudFileName = "/etc/kubernetes/host/azurestackcloud.json" @@rsPromInterval = ENV["TELEMETRY_RS_PROM_INTERVAL"] @@rsPromFieldPassCount = ENV["TELEMETRY_RS_PROM_FIELDPASS_LENGTH"] @@ -85,7 +86,11 @@ def enumerate record["Status"] = "" if !items["spec"]["providerID"].nil? && !items["spec"]["providerID"].empty? - record["ProviderID"] = items["spec"]["providerID"] + if File.file?(@@AzStackCloudFileName) # existence of this file indicates agent running on azstack + record["ProviderID"] = "azurestack" + else + record["ProviderID"] = items["spec"]["providerID"] + end else record["ProviderID"] = "onprem" end From e4be8affe643a5227a2ce6f3d8bc996caf1b4b86 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Mon, 16 Sep 2019 12:41:30 -0700 Subject: [PATCH 4/6] rename to KubernetesProviderID since ProviderID name already used in LA --- source/code/plugin/in_kube_nodes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/code/plugin/in_kube_nodes.rb b/source/code/plugin/in_kube_nodes.rb index dca5d12e6..42bc13b68 100644 --- a/source/code/plugin/in_kube_nodes.rb +++ b/source/code/plugin/in_kube_nodes.rb @@ -87,12 +87,12 @@ def enumerate if !items["spec"]["providerID"].nil? && !items["spec"]["providerID"].empty? if File.file?(@@AzStackCloudFileName) # existence of this file indicates agent running on azstack - record["ProviderID"] = "azurestack" + record["KubernetesProviderID"] = "azurestack" else - record["ProviderID"] = items["spec"]["providerID"] + record["KubernetesProviderID"] = items["spec"]["providerID"] end else - record["ProviderID"] = "onprem" + record["KubernetesProviderID"] = "onprem" end @@ -151,7 +151,7 @@ def enumerate properties["KubeletVersion"] = record["KubeletVersion"] properties["OperatingSystem"] = nodeInfo["operatingSystem"] properties["DockerVersion"] = dockerVersion - properties["ProviderID"] = record["ProviderID"] + properties["KubernetesProviderID"] = record["KubernetesProviderID"] properties["KernelVersion"] = nodeInfo["kernelVersion"] properties["OSImage"] = nodeInfo["osImage"] From 3ee760df5f286d50fa51edc0cee379f133e00960 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Tue, 17 Sep 2019 19:27:56 -0700 Subject: [PATCH 5/6] capture workspaceCloud to the telemetry --- .../code/plugin/ApplicationInsightsUtility.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/code/plugin/ApplicationInsightsUtility.rb b/source/code/plugin/ApplicationInsightsUtility.rb index bb4831701..d4d0a3d70 100644 --- a/source/code/plugin/ApplicationInsightsUtility.rb +++ b/source/code/plugin/ApplicationInsightsUtility.rb @@ -64,6 +64,7 @@ def initializeUtility() @@CustomProperties["ControllerType"] = ENV[@@EnvControllerType] encodedAppInsightsKey = ENV[@@EnvApplicationInsightsKey] appInsightsEndpoint = ENV[@@EnvApplicationInsightsEndpoint] + @@CustomProperties["WorkspaceCloud"] = getWorkspaceCloud #Check if telemetry is turned off telemetryOffSwitch = ENV["DISABLE_TELEMETRY"] @@ -230,5 +231,32 @@ def getWorkspaceId() $log.warn("Exception in AppInsightsUtility: getWorkspaceId - error: #{errorStr}") end end + + def getWorkspaceCloud() + begin + adminConf = {} + confFile = File.open(@OmsAdminFilePath, "r") + confFile.each_line do |line| + splitStrings = line.split("=") + adminConf[splitStrings[0]] = splitStrings[1] + end + workspaceDomain = adminConf["URL_TLD"] + workspaceCloud = "AzureCloud" + if workspaceDomain.casecmp("opinsights.azure.com") == 0 + workspaceCloud = "AzureCloud" + elsif wokrspaceDomain.casecmp("opinsights.azure.cn") == 0 + workspaceCloud = "AzureChinaCloud" + elsif wokrspaceDomain.casecmp("opinsights.azure.us") == 0 + workspaceCloud = "AzureUSGovernment" + elsif wokrspaceDomain.casecmp("opinsights.azure.de") == 0 + workspaceCloud = "AzureGermanCloud" + else + workspaceCloud = "Unknown" + end + return workspaceCloud + rescue => errorStr + $log.warn("Exception in AppInsightsUtility: getWorkspaceCloud - error: #{errorStr}") + end + end end end From 5c1c98dc0d5ebf9e2aafbe94f62f0b981064a09d Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Mon, 23 Sep 2019 14:00:21 -0700 Subject: [PATCH 6/6] trim the domain read from file --- source/code/plugin/ApplicationInsightsUtility.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/code/plugin/ApplicationInsightsUtility.rb b/source/code/plugin/ApplicationInsightsUtility.rb index d4d0a3d70..85b424e69 100644 --- a/source/code/plugin/ApplicationInsightsUtility.rb +++ b/source/code/plugin/ApplicationInsightsUtility.rb @@ -240,15 +240,15 @@ def getWorkspaceCloud() splitStrings = line.split("=") adminConf[splitStrings[0]] = splitStrings[1] end - workspaceDomain = adminConf["URL_TLD"] + workspaceDomain = adminConf["URL_TLD"].strip workspaceCloud = "AzureCloud" if workspaceDomain.casecmp("opinsights.azure.com") == 0 workspaceCloud = "AzureCloud" - elsif wokrspaceDomain.casecmp("opinsights.azure.cn") == 0 + elsif workspaceDomain.casecmp("opinsights.azure.cn") == 0 workspaceCloud = "AzureChinaCloud" - elsif wokrspaceDomain.casecmp("opinsights.azure.us") == 0 + elsif workspaceDomain.casecmp("opinsights.azure.us") == 0 workspaceCloud = "AzureUSGovernment" - elsif wokrspaceDomain.casecmp("opinsights.azure.de") == 0 + elsif workspaceDomain.casecmp("opinsights.azure.de") == 0 workspaceCloud = "AzureGermanCloud" else workspaceCloud = "Unknown"