From cdfe3e59370af0b7d7b05aa99b219c7488080230 Mon Sep 17 00:00:00 2001 From: Grace Wehner Date: Mon, 28 Dec 2020 11:53:35 -0800 Subject: [PATCH 1/7] use env var for log tail path for windows --- build/windows/installer/conf/fluent.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/windows/installer/conf/fluent.conf b/build/windows/installer/conf/fluent.conf index c96300b1e..79df7fad5 100644 --- a/build/windows/installer/conf/fluent.conf +++ b/build/windows/installer/conf/fluent.conf @@ -6,7 +6,7 @@ @type tail - path /var/log/containers/*.log + path "#{ENV['AZMON_LOG_TAIL_PATH']}" pos_file /var/opt/microsoft/fluent/fluentd-containers.log.pos tag oms.container.log.la @log_level trace From 3d0f484e3becbc2105f38cc696670192ffd06ecb Mon Sep 17 00:00:00 2001 From: Grace Wehner Date: Mon, 28 Dec 2020 15:04:31 -0800 Subject: [PATCH 2/7] error handling for get_node_capacity --- source/plugins/ruby/filter_cadvisor2mdm.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/plugins/ruby/filter_cadvisor2mdm.rb b/source/plugins/ruby/filter_cadvisor2mdm.rb index 2423ad024..08745ab67 100644 --- a/source/plugins/ruby/filter_cadvisor2mdm.rb +++ b/source/plugins/ruby/filter_cadvisor2mdm.rb @@ -308,8 +308,13 @@ def ensure_cpu_memory_capacity_set end elsif controller_type.downcase == "daemonset" capacity_from_kubelet = KubeletUtils.get_node_capacity - @cpu_capacity = capacity_from_kubelet[0] - @memory_capacity = capacity_from_kubelet[1] + + if !capacity_from_kubelet.nil? && capacity_from_kubelet.length > 1 + @cpu_capacity = capacity_from_kubelet[0] + @memory_capacity = capacity_from_kubelet[1] + else + @log.info "Error getting capacity_from_kubelet: cpu_capacity and memory_capacity" + end end end From fab079894f51c3c6df0e01d0457ac6f201d80feb Mon Sep 17 00:00:00 2001 From: Grace Wehner Date: Tue, 29 Dec 2020 16:55:52 -0800 Subject: [PATCH 3/7] do not use env var for ws key - windows agent --- build/windows/installer/certificategenerator/Program.cs | 9 +++++---- kubernetes/windows/main.ps1 | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build/windows/installer/certificategenerator/Program.cs b/build/windows/installer/certificategenerator/Program.cs index 43063c4be..45a68b48d 100644 --- a/build/windows/installer/certificategenerator/Program.cs +++ b/build/windows/installer/certificategenerator/Program.cs @@ -414,10 +414,11 @@ static void Main(string[] args) try { - if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSKEY"))) - { - logAnalyticsWorkspaceSharedKey = Environment.GetEnvironmentVariable("WSKEY"); - } + logAnalyticsWorkspaceSharedKey = File.ReadAllText("C:/etc/omsagent-secret/KEY"); + //if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSKEY"))) + //{ + //logAnalyticsWorkspaceSharedKey = Environment.GetEnvironmentVariable("WSKEY"); + //} } catch (Exception ex) { diff --git a/kubernetes/windows/main.ps1 b/kubernetes/windows/main.ps1 index d32e5068a..b3f32e8c1 100644 --- a/kubernetes/windows/main.ps1 +++ b/kubernetes/windows/main.ps1 @@ -75,8 +75,8 @@ function Set-EnvironmentVariables { } # Set KEY - [System.Environment]::SetEnvironmentVariable("WSKEY", $wsKey, "Process") - [System.Environment]::SetEnvironmentVariable("WSKEY", $wsKey, "Machine") + #[System.Environment]::SetEnvironmentVariable("", $wsKey, "Process") + #[System.Environment]::SetEnvironmentVariable("WSKEY", $wsKey, "Machine") $proxy = "" if (Test-Path /etc/omsagent-secret/PROXY) { From 4017ed22d86b2fade6287a02045bf9131c58a610 Mon Sep 17 00:00:00 2001 From: Grace Wehner Date: Tue, 29 Dec 2020 17:20:01 -0800 Subject: [PATCH 4/7] fix commented out code --- kubernetes/windows/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/windows/main.ps1 b/kubernetes/windows/main.ps1 index b3f32e8c1..e0a392cbb 100644 --- a/kubernetes/windows/main.ps1 +++ b/kubernetes/windows/main.ps1 @@ -75,7 +75,7 @@ function Set-EnvironmentVariables { } # Set KEY - #[System.Environment]::SetEnvironmentVariable("", $wsKey, "Process") + #[System.Environment]::SetEnvironmentVariable("WSKEY", $wsKey, "Process") #[System.Environment]::SetEnvironmentVariable("WSKEY", $wsKey, "Machine") $proxy = "" From 4155b79420b9ed8be66c21783a44fa5ab7951d91 Mon Sep 17 00:00:00 2001 From: Grace Wehner Date: Thu, 31 Dec 2020 16:35:32 -0800 Subject: [PATCH 5/7] windows log filtering fix and comments --- build/common/installer/scripts/tomlparser.rb | 2 +- .../installer/certificategenerator/Program.cs | 11 ++++------- build/windows/installer/conf/fluent.conf | 9 +++++++++ kubernetes/windows/main.ps1 | 12 ++---------- source/plugins/ruby/filter_cadvisor2mdm.rb | 3 +++ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/build/common/installer/scripts/tomlparser.rb b/build/common/installer/scripts/tomlparser.rb index 7235ee0c3..decebc624 100644 --- a/build/common/installer/scripts/tomlparser.rb +++ b/build/common/installer/scripts/tomlparser.rb @@ -228,7 +228,7 @@ def get_command_windows(env_variable_name, env_variable_value) file.write(commands) commands = get_command_windows('AZMON_LOG_TAIL_PATH', @logTailPath) file.write(commands) - commands = get_command_windows('AZMON_LOG_EXCLUSION_REGEX_PATTERN', @stdoutExcludeNamespaces) + commands = get_command_windows('AZMON_LOG_EXCLUSION_REGEX_PATTERN', @logExclusionRegexPattern) file.write(commands) commands = get_command_windows('AZMON_STDOUT_EXCLUDED_NAMESPACES', @stdoutExcludeNamespaces) file.write(commands) diff --git a/build/windows/installer/certificategenerator/Program.cs b/build/windows/installer/certificategenerator/Program.cs index 45a68b48d..c0f5334af 100644 --- a/build/windows/installer/certificategenerator/Program.cs +++ b/build/windows/installer/certificategenerator/Program.cs @@ -364,7 +364,7 @@ public static X509Certificate2 RegisterAgentWithOMS(string logAnalyticsWorkspace try { - agentCert = CreateSelfSignedCertificate(agentGuid, logAnalyticsWorkspaceId); + agentCert = CreateSelfSignedCertificate(agentGuid, logAnalyticsWorkspaceId); if (agentCert == null) { @@ -414,15 +414,12 @@ static void Main(string[] args) try { - logAnalyticsWorkspaceSharedKey = File.ReadAllText("C:/etc/omsagent-secret/KEY"); - //if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WSKEY"))) - //{ - //logAnalyticsWorkspaceSharedKey = Environment.GetEnvironmentVariable("WSKEY"); - //} + // WSKEY isn't stored as an environment variable + logAnalyticsWorkspaceSharedKey = File.ReadAllText("C:/etc/omsagent-secret/KEY").Trim(); } catch (Exception ex) { - Console.WriteLine("Failed to read env variables (WSKEY)" + ex.Message); + Console.WriteLine("Failed to read secret (WSKEY)" + ex.Message); } try diff --git a/build/windows/installer/conf/fluent.conf b/build/windows/installer/conf/fluent.conf index 79df7fad5..5597d4241 100644 --- a/build/windows/installer/conf/fluent.conf +++ b/build/windows/installer/conf/fluent.conf @@ -7,6 +7,7 @@ @type tail path "#{ENV['AZMON_LOG_TAIL_PATH']}" + exclude_path "#{ENV['AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH']}" pos_file /var/opt/microsoft/fluent/fluentd-containers.log.pos tag oms.container.log.la @log_level trace @@ -37,6 +38,14 @@ + + @type grep + + key stream + pattern "#{ENV['AZMON_LOG_EXCLUSION_REGEX_PATTERN']}" + + + @type forward diff --git a/kubernetes/windows/main.ps1 b/kubernetes/windows/main.ps1 index e0a392cbb..a297e3801 100644 --- a/kubernetes/windows/main.ps1 +++ b/kubernetes/windows/main.ps1 @@ -64,19 +64,11 @@ function Set-EnvironmentVariables { $wsID = Get-Content /etc/omsagent-secret/WSID } - # Set DOMAIN + # Set WSID [System.Environment]::SetEnvironmentVariable("WSID", $wsID, "Process") [System.Environment]::SetEnvironmentVariable("WSID", $wsID, "Machine") - $wsKey = "" - if (Test-Path /etc/omsagent-secret/KEY) { - # TODO: Change to omsagent-secret before merging - $wsKey = Get-Content /etc/omsagent-secret/KEY - } - - # Set KEY - #[System.Environment]::SetEnvironmentVariable("WSKEY", $wsKey, "Process") - #[System.Environment]::SetEnvironmentVariable("WSKEY", $wsKey, "Machine") + # Don't store WSKEY as environment variable $proxy = "" if (Test-Path /etc/omsagent-secret/PROXY) { diff --git a/source/plugins/ruby/filter_cadvisor2mdm.rb b/source/plugins/ruby/filter_cadvisor2mdm.rb index 08745ab67..3425c2359 100644 --- a/source/plugins/ruby/filter_cadvisor2mdm.rb +++ b/source/plugins/ruby/filter_cadvisor2mdm.rb @@ -309,12 +309,15 @@ def ensure_cpu_memory_capacity_set elsif controller_type.downcase == "daemonset" capacity_from_kubelet = KubeletUtils.get_node_capacity + # Error handling in case /metrics/cadvsior endpoint fails if !capacity_from_kubelet.nil? && capacity_from_kubelet.length > 1 @cpu_capacity = capacity_from_kubelet[0] @memory_capacity = capacity_from_kubelet[1] else + # cpu_capacity and memory_capacity keep initialized value of 0.0 @log.info "Error getting capacity_from_kubelet: cpu_capacity and memory_capacity" end + end end From aabca1c7b2863d05ade5ab593c65b1cff0efa6a7 Mon Sep 17 00:00:00 2001 From: Grace Wehner Date: Thu, 31 Dec 2020 16:37:23 -0800 Subject: [PATCH 6/7] fix whitespace --- build/windows/installer/certificategenerator/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/windows/installer/certificategenerator/Program.cs b/build/windows/installer/certificategenerator/Program.cs index c0f5334af..e24d0e303 100644 --- a/build/windows/installer/certificategenerator/Program.cs +++ b/build/windows/installer/certificategenerator/Program.cs @@ -364,7 +364,7 @@ public static X509Certificate2 RegisterAgentWithOMS(string logAnalyticsWorkspace try { - agentCert = CreateSelfSignedCertificate(agentGuid, logAnalyticsWorkspaceId); + agentCert = CreateSelfSignedCertificate(agentGuid, logAnalyticsWorkspaceId); if (agentCert == null) { From a02109985cb91ef729cad91e8f07e7cbf159fe29 Mon Sep 17 00:00:00 2001 From: Grace Wehner Date: Mon, 4 Jan 2021 13:28:38 -0800 Subject: [PATCH 7/7] feedback changes --- build/windows/installer/conf/fluent.conf | 17 ++++++++--------- source/plugins/ruby/filter_cadvisor2mdm.rb | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/build/windows/installer/conf/fluent.conf b/build/windows/installer/conf/fluent.conf index 5597d4241..d5eb475ca 100644 --- a/build/windows/installer/conf/fluent.conf +++ b/build/windows/installer/conf/fluent.conf @@ -29,15 +29,6 @@ @include fluent-docker-parser.conf - - @type record_transformer - # fluent-plugin-record-modifier more light-weight but needs to be installed (dependency worth it?) - remove_keys tailed_path - - filepath ${record["tailed_path"]} - - - @type grep @@ -46,6 +37,14 @@ + + @type record_transformer + # fluent-plugin-record-modifier more light-weight but needs to be installed (dependency worth it?) + remove_keys tailed_path + + filepath ${record["tailed_path"]} + + @type forward diff --git a/source/plugins/ruby/filter_cadvisor2mdm.rb b/source/plugins/ruby/filter_cadvisor2mdm.rb index 3425c2359..8d7e729c8 100644 --- a/source/plugins/ruby/filter_cadvisor2mdm.rb +++ b/source/plugins/ruby/filter_cadvisor2mdm.rb @@ -315,7 +315,7 @@ def ensure_cpu_memory_capacity_set @memory_capacity = capacity_from_kubelet[1] else # cpu_capacity and memory_capacity keep initialized value of 0.0 - @log.info "Error getting capacity_from_kubelet: cpu_capacity and memory_capacity" + @log.error "Error getting capacity_from_kubelet: cpu_capacity and memory_capacity" end end