From 7807b12b2fb9d70bacc6ebfc7a61400c68bde29c Mon Sep 17 00:00:00 2001 From: rashmy Date: Tue, 25 Jun 2019 15:57:48 -0700 Subject: [PATCH 01/20] changes --- .../scripts/tomlparser-prom-customconfig.rb | 186 ++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 installer/scripts/tomlparser-prom-customconfig.rb diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb new file mode 100644 index 000000000..ae735a835 --- /dev/null +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -0,0 +1,186 @@ +#!/usr/local/bin/ruby + +require_relative "tomlrb" + +@promConfigMapMountPath = "/etc/config/settings/prometheus-data-collection-settings" +@replicaset = "replicaset" +@daemonset = "daemonset" +# @cnfigVersion = "" +@promConfigSchemaVersion = "" +# Setting default values which will be used in case they are not set in the configmap or if configmap doesnt exist +# @collectStdoutLogs = true +# @stdoutExcludeNamespaces = "kube-system" +# @collectStderrLogs = true +# @stderrExcludeNamespaces = "kube-system" +# @collectClusterEnvVariables = true +# @logTailPath = "/var/log/containers/*.log" +# @logExclusionRegexPattern = "(^((?!stdout|stderr).)*$)" +# @excludePath = "*.csv2" #some invalid path + +# Use parser to parse the configmap toml file to a ruby structure +def parseConfigMap + begin + # Check to see if config map is created + if (File.file?(@promConfigMapMountPath)) + puts "config::configmap container-azm-ms-agentconfig for settings mounted, parsing values for prometheus config map" + parsedConfig = Tomlrb.load_file(@promConfigMapMountPath, symbolize_keys: true) + puts "config::Successfully parsed mounted prometheus config map" + return parsedConfig + else + puts "config::configmap container-azm-ms-agentconfig for settings not mounted, using defaults for prometheus scraping" + # @excludePath = "*_kube-system_*.log" + return nil + end + rescue => errorStr + puts "config::error::Exception while parsing toml config file for prometheus config: #{errorStr}, using defaults" + # @excludePath = "*_kube-system_*.log" + return nil + end +end + +def checkForTypeArray(arrayValue, arrayType) + if !arrayValue.nil? && arrayValue.kind_of?(Array) && arrayValue.length > 0 && arrayValue[0].kind_of?(arrayType) + return true + else + return false + end +end + +def checkForType(variable, varType) + if !variable.nil? && variable.kind_of?(varType) + return true + else + return false + end +end + +# Use the ruby structure created after config parsing to set the right values to be used as environment variables +def populateSettingValuesFromConfigMap(parsedConfig) +puts "****************Start Prometheus Config Processing********************" + # Checking to see if this is the daemonset or replicaset to parse config accordingly + controller = ENV["CONTROLLER_TYPE"] + if !controller.nil? + if !parsedConfig.nil? && !parsedConfig[:prometheus_data_collection_settings].nil? + if controller.casecmp(@replicaset) == 0 && !parsedConfig[:prometheus_data_collection_settings][:cluster].nil? + #Get prometheus replicaset custom config settings + begin + interval = parsedConfig[:prometheus_data_collection_settings][:cluster][:interval] + fieldPass = parsedConfig[:prometheus_data_collection_settings][:cluster][:fieldpass] + fieldDrop = parsedConfig[:prometheus_data_collection_settings][:cluster][:fielddrop] + urls = parsedConfig[:prometheus_data_collection_settings][:cluster][:urls] + kubernetesServices = parsedConfig[:prometheus_data_collection_settings][:cluster][:kubernetes_services] + monitorKubernetesPods = parsedConfig[:prometheus_data_collection_settings][:cluster][:monitor_kubernetes_pods] + + if checkForType(interval, String) + && checkForTypeArray(fieldPass, String) + && checkForTypeArray(fieldDrop, String) + && checkForTypeArray(kubernetesServices, String) + && checkForTypeArray(urls, String) + && checkForType(monitorKubernetesPods, Boolean) + + # Write the settings to file, so that they can be set as environment variables +file = File.open("prom_config_env_var", "w") + +if !file.nil? + file.write("export AZMON_RS_PROM_INTERVAL=#{interval}\n") + file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + file.write("export AZMON_RS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export AZMON_RS_PROM_K8S_SERVICES=#{kubernetesServices}\n") + file.write("export AZMON_RS_PROM_URLS=#{urls}\n") + file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") + # Close file after writing all environment variables + file.close + puts "****************End Prometheus Config Processing********************" +else + puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" + puts "****************End Prometheus Config Processing********************" +end + + end + rescue => errorStr + # error handling code + end + elsif controller.casecmp(@daemonset) == 0 && !parsedConfig[:prometheus_data_collection_settings][:node].nil? + #Get prometheus daemonset custom config settings + begin + interval = parsedConfig[:prometheus_data_collection_settings][:node][:interval] + fieldPass = parsedConfig[:prometheus_data_collection_settings][:node][:fieldpass] + fieldDrop = parsedConfig[:prometheus_data_collection_settings][:node][:fielddrop] + urls = parsedConfig[:prometheus_data_collection_settings][:node][:urls] + + if checkForType(interval, String) + && checkForTypeArray(fieldPass, String) + && checkForTypeArray(fieldDrop, String) + && checkForTypeArray(urls, String) + + # Write the settings to file, so that they can be set as environment variables +file = File.open("prom_config_env_var", "w") + +if !file.nil? + file.write("export AZMON_DS_PROM_INTERVAL=#{interval}\n") + file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + file.write("export AZMON_DS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export AZMON_DS_PROM_URLS=#{urls}\n") + # Close file after writing all environment variables + file.close + puts "****************End Prometheus Config Processing********************" +else + puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" + puts "****************End Prometheus Config Processing********************" +end + + end + rescue => errorStr + # error handling code + end + end + end + end + + end + end + +@promConfigSchemaVersion = ENV["AZMON_AGENT_PROM_CFG_SCHEMA_VERSION"] +puts "****************Start Prometheus Config Processing********************" +if !@promConfigSchemaVersion.nil? && !@promConfigSchemaVersion.empty? && @promConfigSchemaVersion.strip.casecmp("v1") == 0 #note v1 is the only supported schema version , so hardcoding it + promConfigMapSettings = parseConfigMap + if !promConfigMapSettings.nil? + populateSettingValuesFromConfigMap(promConfigMapSettings) + end +else + if (File.file?(@promConfigMapMountPath)) + puts "config::unsupported/missing config schema version for prometheus config - '#{@promConfigSchemaVersion}' , using defaults" + end + # @excludePath = "*_kube-system_*.log" +end + +# Write the settings to file, so that they can be set as environment variables +file = File.open("prom_config_env_var", "w") + +if !file.nil? + # This will be used in td-agent-bit.conf file to filter out logs + if (!@collectStdoutLogs && !@collectStderrLogs) + #Stop log tailing completely + @logTailPath = "/opt/nolog*.log" + @logExclusionRegexPattern = "stdout|stderr" + elsif !@collectStdoutLogs + @logExclusionRegexPattern = "stdout" + elsif !@collectStderrLogs + @logExclusionRegexPattern = "stderr" + end + file.write("export AZMON_COLLECT_STDOUT_LOGS=#{@collectStdoutLogs}\n") + file.write("export AZMON_LOG_TAIL_PATH=#{@logTailPath}\n") + file.write("export AZMON_LOG_EXCLUSION_REGEX_PATTERN=\"#{@logExclusionRegexPattern}\"\n") + file.write("export AZMON_STDOUT_EXCLUDED_NAMESPACES=#{@stdoutExcludeNamespaces}\n") + file.write("export AZMON_COLLECT_STDERR_LOGS=#{@collectStderrLogs}\n") + file.write("export AZMON_STDERR_EXCLUDED_NAMESPACES=#{@stderrExcludeNamespaces}\n") + file.write("export AZMON_CLUSTER_COLLECT_ENV_VAR=#{@collectClusterEnvVariables}\n") + file.write("export AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH=#{@excludePath}\n") + # Close file after writing all environment variables + file.close + puts "Both stdout & stderr log collection are turned off for namespaces: '#{@excludePath}' " + puts "****************End Config Processing********************" +else + puts "config::error::Exception while opening file for writing prometheus config environment variables" + puts "****************End Prometheus Config Processing********************" +end From d9f641c6b08657125eff76c7470a839d3e54dd70 Mon Sep 17 00:00:00 2001 From: rashmy Date: Tue, 25 Jun 2019 16:07:20 -0700 Subject: [PATCH 02/20] formatting changes --- .../scripts/tomlparser-prom-customconfig.rb | 126 ++++++------------ 1 file changed, 42 insertions(+), 84 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index ae735a835..6e34b0b08 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -56,12 +56,12 @@ def checkForType(variable, varType) # Use the ruby structure created after config parsing to set the right values to be used as environment variables def populateSettingValuesFromConfigMap(parsedConfig) -puts "****************Start Prometheus Config Processing********************" + puts "****************Start Prometheus Config Processing********************" # Checking to see if this is the daemonset or replicaset to parse config accordingly controller = ENV["CONTROLLER_TYPE"] if !controller.nil? - if !parsedConfig.nil? && !parsedConfig[:prometheus_data_collection_settings].nil? - if controller.casecmp(@replicaset) == 0 && !parsedConfig[:prometheus_data_collection_settings][:cluster].nil? + if !parsedConfig.nil? && !parsedConfig[:prometheus_data_collection_settings].nil? + if controller.casecmp(@replicaset) == 0 && !parsedConfig[:prometheus_data_collection_settings][:cluster].nil? #Get prometheus replicaset custom config settings begin interval = parsedConfig[:prometheus_data_collection_settings][:cluster][:interval] @@ -71,36 +71,30 @@ def populateSettingValuesFromConfigMap(parsedConfig) kubernetesServices = parsedConfig[:prometheus_data_collection_settings][:cluster][:kubernetes_services] monitorKubernetesPods = parsedConfig[:prometheus_data_collection_settings][:cluster][:monitor_kubernetes_pods] - if checkForType(interval, String) - && checkForTypeArray(fieldPass, String) - && checkForTypeArray(fieldDrop, String) - && checkForTypeArray(kubernetesServices, String) - && checkForTypeArray(urls, String) - && checkForType(monitorKubernetesPods, Boolean) + if checkForType(interval, String) && checkForTypeArray(fieldPass, String) && checkForTypeArray(fieldDrop, String) && checkForTypeArray(kubernetesServices, String) && checkForTypeArray(urls, String) && checkForType(monitorKubernetesPods, Boolean) # Write the settings to file, so that they can be set as environment variables -file = File.open("prom_config_env_var", "w") - -if !file.nil? - file.write("export AZMON_RS_PROM_INTERVAL=#{interval}\n") - file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass}\"\n") - file.write("export AZMON_RS_PROM_FIELDDROP=#{fieldDrop}\n") - file.write("export AZMON_RS_PROM_K8S_SERVICES=#{kubernetesServices}\n") - file.write("export AZMON_RS_PROM_URLS=#{urls}\n") - file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") - # Close file after writing all environment variables - file.close - puts "****************End Prometheus Config Processing********************" -else - puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" - puts "****************End Prometheus Config Processing********************" -end - + file = File.open("prom_config_env_var", "w") + + if !file.nil? + file.write("export AZMON_RS_PROM_INTERVAL=#{interval}\n") + file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + file.write("export AZMON_RS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export AZMON_RS_PROM_K8S_SERVICES=#{kubernetesServices}\n") + file.write("export AZMON_RS_PROM_URLS=#{urls}\n") + file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") + # Close file after writing all environment variables + file.close + puts "****************End Prometheus Config Processing********************" + else + puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" + puts "****************End Prometheus Config Processing********************" + end end rescue => errorStr - # error handling code + puts "config::error::Exception while reading config file for prometheus config for replicaset: #{errorStr}, using defaults" end - elsif controller.casecmp(@daemonset) == 0 && !parsedConfig[:prometheus_data_collection_settings][:node].nil? + elsif controller.casecmp(@daemonset) == 0 && !parsedConfig[:prometheus_data_collection_settings][:node].nil? #Get prometheus daemonset custom config settings begin interval = parsedConfig[:prometheus_data_collection_settings][:node][:interval] @@ -108,37 +102,32 @@ def populateSettingValuesFromConfigMap(parsedConfig) fieldDrop = parsedConfig[:prometheus_data_collection_settings][:node][:fielddrop] urls = parsedConfig[:prometheus_data_collection_settings][:node][:urls] - if checkForType(interval, String) - && checkForTypeArray(fieldPass, String) - && checkForTypeArray(fieldDrop, String) - && checkForTypeArray(urls, String) - + if checkForType(interval, String) && checkForTypeArray(fieldPass, String) && checkForTypeArray(fieldDrop, String) && checkForTypeArray(urls, String) # Write the settings to file, so that they can be set as environment variables -file = File.open("prom_config_env_var", "w") - -if !file.nil? - file.write("export AZMON_DS_PROM_INTERVAL=#{interval}\n") - file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass}\"\n") - file.write("export AZMON_DS_PROM_FIELDDROP=#{fieldDrop}\n") - file.write("export AZMON_DS_PROM_URLS=#{urls}\n") - # Close file after writing all environment variables - file.close - puts "****************End Prometheus Config Processing********************" -else - puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" - puts "****************End Prometheus Config Processing********************" -end - + file = File.open("prom_config_env_var", "w") + + if !file.nil? + file.write("export AZMON_DS_PROM_INTERVAL=#{interval}\n") + file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + file.write("export AZMON_DS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export AZMON_DS_PROM_URLS=#{urls}\n") + # Close file after writing all environment variables + file.close + puts "****************End Prometheus Config Processing********************" + else + puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" + puts "****************End Prometheus Config Processing********************" + end end rescue => errorStr - # error handling code + puts "config::error::Exception while reading config file for prometheus config for daemonset: #{errorStr}, using defaults" end - end - end - end - + end # end for controller type check end + else + puts "config::error:: Controller undefined, using defaults" end +end @promConfigSchemaVersion = ENV["AZMON_AGENT_PROM_CFG_SCHEMA_VERSION"] puts "****************Start Prometheus Config Processing********************" @@ -153,34 +142,3 @@ def populateSettingValuesFromConfigMap(parsedConfig) end # @excludePath = "*_kube-system_*.log" end - -# Write the settings to file, so that they can be set as environment variables -file = File.open("prom_config_env_var", "w") - -if !file.nil? - # This will be used in td-agent-bit.conf file to filter out logs - if (!@collectStdoutLogs && !@collectStderrLogs) - #Stop log tailing completely - @logTailPath = "/opt/nolog*.log" - @logExclusionRegexPattern = "stdout|stderr" - elsif !@collectStdoutLogs - @logExclusionRegexPattern = "stdout" - elsif !@collectStderrLogs - @logExclusionRegexPattern = "stderr" - end - file.write("export AZMON_COLLECT_STDOUT_LOGS=#{@collectStdoutLogs}\n") - file.write("export AZMON_LOG_TAIL_PATH=#{@logTailPath}\n") - file.write("export AZMON_LOG_EXCLUSION_REGEX_PATTERN=\"#{@logExclusionRegexPattern}\"\n") - file.write("export AZMON_STDOUT_EXCLUDED_NAMESPACES=#{@stdoutExcludeNamespaces}\n") - file.write("export AZMON_COLLECT_STDERR_LOGS=#{@collectStderrLogs}\n") - file.write("export AZMON_STDERR_EXCLUDED_NAMESPACES=#{@stderrExcludeNamespaces}\n") - file.write("export AZMON_CLUSTER_COLLECT_ENV_VAR=#{@collectClusterEnvVariables}\n") - file.write("export AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH=#{@excludePath}\n") - # Close file after writing all environment variables - file.close - puts "Both stdout & stderr log collection are turned off for namespaces: '#{@excludePath}' " - puts "****************End Config Processing********************" -else - puts "config::error::Exception while opening file for writing prometheus config environment variables" - puts "****************End Prometheus Config Processing********************" -end From 3a996d6499652a70ec65d36b1c0544e662ec5555 Mon Sep 17 00:00:00 2001 From: rashmy Date: Tue, 25 Jun 2019 16:15:04 -0700 Subject: [PATCH 03/20] changes --- .../scripts/tomlparser-prom-customconfig.rb | 21 +++-- installer/scripts/tomlparser.rb | 82 +++++++++---------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 6e34b0b08..8ef708c43 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -71,8 +71,12 @@ def populateSettingValuesFromConfigMap(parsedConfig) kubernetesServices = parsedConfig[:prometheus_data_collection_settings][:cluster][:kubernetes_services] monitorKubernetesPods = parsedConfig[:prometheus_data_collection_settings][:cluster][:monitor_kubernetes_pods] - if checkForType(interval, String) && checkForTypeArray(fieldPass, String) && checkForTypeArray(fieldDrop, String) && checkForTypeArray(kubernetesServices, String) && checkForTypeArray(urls, String) && checkForType(monitorKubernetesPods, Boolean) - + if checkForType(interval, String) && + checkForTypeArray(fieldPass, String) && + checkForTypeArray(fieldDrop, String) && + checkForTypeArray(kubernetesServices, String) && + checkForTypeArray(urls, String) && + checkForType(monitorKubernetesPods, Boolean) # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") @@ -90,7 +94,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" puts "****************End Prometheus Config Processing********************" end - end + end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for replicaset: #{errorStr}, using defaults" end @@ -102,7 +106,10 @@ def populateSettingValuesFromConfigMap(parsedConfig) fieldDrop = parsedConfig[:prometheus_data_collection_settings][:node][:fielddrop] urls = parsedConfig[:prometheus_data_collection_settings][:node][:urls] - if checkForType(interval, String) && checkForTypeArray(fieldPass, String) && checkForTypeArray(fieldDrop, String) && checkForTypeArray(urls, String) + if checkForType(interval, String) && + checkForTypeArray(fieldPass, String) && + checkForTypeArray(fieldDrop, String) && + checkForTypeArray(urls, String) # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") @@ -118,14 +125,14 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" puts "****************End Prometheus Config Processing********************" end - end + end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for daemonset: #{errorStr}, using defaults" end - end # end for controller type check + end # end of controller type check end else - puts "config::error:: Controller undefined, using defaults" + puts "config::error:: Controller undefined while processing prometheus config, using defaults" end end diff --git a/installer/scripts/tomlparser.rb b/installer/scripts/tomlparser.rb index 3e7f48045..c72e64127 100644 --- a/installer/scripts/tomlparser.rb +++ b/installer/scripts/tomlparser.rb @@ -82,7 +82,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) if @collectStderrLogs && !stderrNamespaces.nil? if stderrNamespaces.kind_of?(Array) if !@stdoutExcludeNamespaces.nil? && !@stdoutExcludeNamespaces.empty? - stdoutNamespaces = @stdoutExcludeNamespaces.split(',') + stdoutNamespaces = @stdoutExcludeNamespaces.split(",") end # Checking only for the first element to be string because toml enforces the arrays to contain elements of same type if stderrNamespaces.length > 0 && stderrNamespaces[0].kind_of?(String) @@ -119,47 +119,47 @@ def populateSettingValuesFromConfigMap(parsedConfig) end end - @configSchemaVersion = ENV['AZMON_AGENT_CFG_SCHEMA_VERSION'] - puts "****************Start Config Processing********************" - if !@configSchemaVersion.nil? && !@configSchemaVersion.empty? && @configSchemaVersion.strip.casecmp('v1') == 0 #note v1 is the only supported schema version , so hardcoding it - configMapSettings = parseConfigMap - if !configMapSettings.nil? - populateSettingValuesFromConfigMap(configMapSettings) - end - else - if (File.file?(@configMapMountPath)) - puts "config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults" - end - @excludePath = "*_kube-system_*.log" +@configSchemaVersion = ENV["AZMON_AGENT_CFG_SCHEMA_VERSION"] +puts "****************Start Config Processing********************" +if !@configSchemaVersion.nil? && !@configSchemaVersion.empty? && @configSchemaVersion.strip.casecmp("v1") == 0 #note v1 is the only supported schema version , so hardcoding it + configMapSettings = parseConfigMap + if !configMapSettings.nil? + populateSettingValuesFromConfigMap(configMapSettings) + end +else + if (File.file?(@configMapMountPath)) + puts "config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults" end + @excludePath = "*_kube-system_*.log" +end - # Write the settings to file, so that they can be set as environment variables - file = File.open("config_env_var", "w") +# Write the settings to file, so that they can be set as environment variables +file = File.open("config_env_var", "w") - if !file.nil? - # This will be used in td-agent-bit.conf file to filter out logs - if (!@collectStdoutLogs && !@collectStderrLogs) - #Stop log tailing completely - @logTailPath = "/opt/nolog*.log" - @logExclusionRegexPattern = "stdout|stderr" - elsif !@collectStdoutLogs - @logExclusionRegexPattern = "stdout" - elsif !@collectStderrLogs - @logExclusionRegexPattern = "stderr" - end - file.write("export AZMON_COLLECT_STDOUT_LOGS=#{@collectStdoutLogs}\n") - file.write("export AZMON_LOG_TAIL_PATH=#{@logTailPath}\n") - file.write("export AZMON_LOG_EXCLUSION_REGEX_PATTERN=\"#{@logExclusionRegexPattern}\"\n") - file.write("export AZMON_STDOUT_EXCLUDED_NAMESPACES=#{@stdoutExcludeNamespaces}\n") - file.write("export AZMON_COLLECT_STDERR_LOGS=#{@collectStderrLogs}\n") - file.write("export AZMON_STDERR_EXCLUDED_NAMESPACES=#{@stderrExcludeNamespaces}\n") - file.write("export AZMON_CLUSTER_COLLECT_ENV_VAR=#{@collectClusterEnvVariables}\n") - file.write("export AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH=#{@excludePath}\n") - # Close file after writing all environment variables - file.close - puts "Both stdout & stderr log collection are turned off for namespaces: '#{@excludePath}' " - puts "****************End Config Processing********************" - else - puts "config::error::Exception while opening file for writing config environment variables" - puts "****************End Config Processing********************" +if !file.nil? + # This will be used in td-agent-bit.conf file to filter out logs + if (!@collectStdoutLogs && !@collectStderrLogs) + #Stop log tailing completely + @logTailPath = "/opt/nolog*.log" + @logExclusionRegexPattern = "stdout|stderr" + elsif !@collectStdoutLogs + @logExclusionRegexPattern = "stdout" + elsif !@collectStderrLogs + @logExclusionRegexPattern = "stderr" end + file.write("export AZMON_COLLECT_STDOUT_LOGS=#{@collectStdoutLogs}\n") + file.write("export AZMON_LOG_TAIL_PATH=#{@logTailPath}\n") + file.write("export AZMON_LOG_EXCLUSION_REGEX_PATTERN=\"#{@logExclusionRegexPattern}\"\n") + file.write("export AZMON_STDOUT_EXCLUDED_NAMESPACES=#{@stdoutExcludeNamespaces}\n") + file.write("export AZMON_COLLECT_STDERR_LOGS=#{@collectStderrLogs}\n") + file.write("export AZMON_STDERR_EXCLUDED_NAMESPACES=#{@stderrExcludeNamespaces}\n") + file.write("export AZMON_CLUSTER_COLLECT_ENV_VAR=#{@collectClusterEnvVariables}\n") + file.write("export AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH=#{@excludePath}\n") + # Close file after writing all environment variables + file.close + puts "Both stdout & stderr log collection are turned off for namespaces: '#{@excludePath}' " + puts "****************End Config Processing********************" +else + puts "config::error::Exception while opening file for writing config environment variables" + puts "****************End Config Processing********************" +end From 1333077d0ff41bd0114da8eb284b0bff90879a7a Mon Sep 17 00:00:00 2001 From: rashmy Date: Tue, 25 Jun 2019 16:22:52 -0700 Subject: [PATCH 04/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 8ef708c43..08289569f 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -71,6 +71,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) kubernetesServices = parsedConfig[:prometheus_data_collection_settings][:cluster][:kubernetes_services] monitorKubernetesPods = parsedConfig[:prometheus_data_collection_settings][:cluster][:monitor_kubernetes_pods] + # Check for the right datattypes to enforce right setting values if checkForType(interval, String) && checkForTypeArray(fieldPass, String) && checkForTypeArray(fieldDrop, String) && @@ -79,7 +80,6 @@ def populateSettingValuesFromConfigMap(parsedConfig) checkForType(monitorKubernetesPods, Boolean) # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") - if !file.nil? file.write("export AZMON_RS_PROM_INTERVAL=#{interval}\n") file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass}\"\n") @@ -91,7 +91,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.close puts "****************End Prometheus Config Processing********************" else - puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" + puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" puts "****************End Prometheus Config Processing********************" end end # end of type check condition @@ -106,13 +106,13 @@ def populateSettingValuesFromConfigMap(parsedConfig) fieldDrop = parsedConfig[:prometheus_data_collection_settings][:node][:fielddrop] urls = parsedConfig[:prometheus_data_collection_settings][:node][:urls] + # Check for the right datattypes to enforce right setting values if checkForType(interval, String) && checkForTypeArray(fieldPass, String) && checkForTypeArray(fieldDrop, String) && checkForTypeArray(urls, String) # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") - if !file.nil? file.write("export AZMON_DS_PROM_INTERVAL=#{interval}\n") file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass}\"\n") @@ -144,8 +144,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) populateSettingValuesFromConfigMap(promConfigMapSettings) end else - if (File.file?(@promConfigMapMountPath)) - puts "config::unsupported/missing config schema version for prometheus config - '#{@promConfigSchemaVersion}' , using defaults" - end - # @excludePath = "*_kube-system_*.log" + #Do we need this - if (File.file?(@promConfigMapMountPath)) + puts "config::unsupported/missing config schema version for prometheus config - '#{@promConfigSchemaVersion}' , using defaults" + # end end From ac11c8bc98d32d3fcc53c3a0ed1407c6a0eba698 Mon Sep 17 00:00:00 2001 From: rashmy Date: Tue, 25 Jun 2019 17:44:52 -0700 Subject: [PATCH 05/20] changes --- installer/conf/telegraf-rs.conf | 2 +- installer/conf/telegraf-test-rs.conf | 113 ++++++++++++++++++ installer/conf/telegraf-test.conf | 100 ++++++++++++++++ .../scripts/tomlparser-prom-customconfig.rb | 22 ++++ 4 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 installer/conf/telegraf-test-rs.conf create mode 100644 installer/conf/telegraf-test.conf diff --git a/installer/conf/telegraf-rs.conf b/installer/conf/telegraf-rs.conf index bde27f279..8e8665104 100644 --- a/installer/conf/telegraf-rs.conf +++ b/installer/conf/telegraf-rs.conf @@ -542,7 +542,7 @@ ## An array of urls to scrape metrics from. #urls = ["http://$NODE_IP:10255/metrics", "http://$NODE_IP:10255/metrics/cadvisor", "http://$NODE_IP:10254/metrics", "http://$NODE_IP:9100/metrics"] #fieldpass = ["kubelet_docker_operations", "kubelet_docker_operations_errors"] - interval: "$AZMON_RS_PROM_INTERVAL" + interval = "$AZMON_RS_PROM_INTERVAL" ## An array of urls to scrape metrics from. urls = ["$AZMON_RS_PROM_URLS"] diff --git a/installer/conf/telegraf-test-rs.conf b/installer/conf/telegraf-test-rs.conf new file mode 100644 index 000000000..4ece2bf8c --- /dev/null +++ b/installer/conf/telegraf-test-rs.conf @@ -0,0 +1,113 @@ +# Telegraf Configuration +# +# Telegraf is entirely plugin driven. All metrics are gathered from the +# declared inputs, and sent to the declared outputs. +# +# Plugins must be declared in here to be active. +# To deactivate a plugin, comment out the name and any variables. +# +# Use 'telegraf -config telegraf.conf -test' to see what metrics a config +# file would generate. +# +# Environment variables can be used anywhere in this config file, simply prepend +# them with $. For strings the variable must be within quotes (ie, "$STR_VAR"), +# for numbers and booleans they should be plain (ie, $INT_VAR, $BOOL_VAR) + +# Configuration for telegraf agent +[agent] + ## Default data collection interval for all inputs + interval = "60s" + ## Rounds collection interval to 'interval' + ## ie, if interval="10s" then always collect on :00, :10, :20, etc. + round_interval = true + + ## Telegraf will send metrics to outputs in batches of at most + ## metric_batch_size metrics. + ## This controls the size of writes that Telegraf sends to output plugins. + metric_batch_size = 1000 + + ## For failed writes, telegraf will cache metric_buffer_limit metrics for each + ## output, and will flush this buffer on a successful write. Oldest metrics + ## are dropped first when this buffer fills. + ## This buffer only fills when writes fail to output plugin(s). + metric_buffer_limit = 10000 + + ## Collection jitter is used to jitter the collection by a random amount. + ## Each plugin will sleep for a random time within jitter before collecting. + ## This can be used to avoid many plugins querying things like sysfs at the + ## same time, which can have a measurable effect on the system. + collection_jitter = "0s" + + ## Default flushing interval for all outputs. You shouldn't set this below + ## interval. Maximum flush_interval will be flush_interval + flush_jitter + flush_interval = "60s" + ## Jitter the flush interval by a random amount. This is primarily to avoid + ## large write spikes for users running a large number of telegraf instances. + ## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s + flush_jitter = "0s" + + ## By default or when set to "0s", precision will be set to the same + ## timestamp order as the collection interval, with the maximum being 1s. + ## ie, when interval = "10s", precision will be "1s" + ## when interval = "250ms", precision will be "1ms" + ## Precision will NOT be used for service inputs. It is up to each individual + ## service input to set the timestamp at the appropriate precision. + ## Valid time units are "ns", "us" (or "µs"), "ms", "s". + precision = "" + + ## Logging configuration: + ## Run telegraf with debug log messages. + debug = false + ## Run telegraf in quiet mode (error log messages only). + quiet = false + ## Specify the log file name. The empty string means to log to stderr. + logfile = "/var/opt/microsoft/docker-cimprov/log/telegraf.log" + + ## Override default hostname, if empty use os.Hostname() + #hostname = "placeholder_hostname" + ## If set to true, do no set the "host" tag in the telegraf agent. + omit_hostname = true + + +############################################################################### +# INPUT PLUGINS # +############################################################################### + +#Prometheus Custom Metrics +[[inputs.prometheus]] + ## An array of urls to scrape metrics from. + interval = "$AZMON_RS_PROM_INTERVAL" + + ## An array of urls to scrape metrics from. + #urls = ["http://$NODE_IP:10255/metrics", "http://$NODE_IP:10255/metrics/cadvisor", "http://$NODE_IP:10254/metrics", "http://$NODE_IP:9100/metrics"] + urls = ["$AZMON_RS_PROM_URLS"] + + #fieldpass = ["kubelet_docker_operations", "kubelet_docker_operations_errors"] + fieldpass = ["$AZMON_RS_PROM_FIELDPASS"] + fielddrop = ["$AZMON_RS_PROM_FIELDDROP"] + + ## An array of Kubernetes services to scrape metrics from. + #kubernetes_services = ["https://kube-state-metrics.monitoring:8443/metrics","https://kube-state-metrics.monitoring:9443/metrics","http://oce-scc-template-nginx-ingress-controller.oce-nginx:10254/metrics"] + kubernetes_services = ["$AZMON_RS_PROM_K8S_SERVICES"] + + ## Scrape Kubernetes pods for the following prometheus annotations: + ## - prometheus.io/scrape: Enable scraping for this pod + ## - prometheus.io/scheme: If the metrics endpoint is secured then you will need to + ## set this to `https` & most likely set the tls config. + ## - prometheus.io/path: If the metrics path is not /metrics, define it with this annotation. + ## - prometheus.io/port: If port is not 9102 use this annotation + monitor_kubernetes_pods = $AZMON_RS_PROM_MONITOR_PODS + + metric_version = 2 + url_tag = "scrapeUrl" + + ## Use bearer token for authorization. ('bearer_token' takes priority) + bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token" + + ## Specify timeout duration for slower prometheus clients (default is 3s) + response_timeout = "15s" + + ## Optional TLS Config + tls_ca = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" + ## Use TLS but skip chain & host verification + insecure_skip_verify = true diff --git a/installer/conf/telegraf-test.conf b/installer/conf/telegraf-test.conf new file mode 100644 index 000000000..f1a7880ad --- /dev/null +++ b/installer/conf/telegraf-test.conf @@ -0,0 +1,100 @@ +# Telegraf Configuration +# +# Telegraf is entirely plugin driven. All metrics are gathered from the +# declared inputs, and sent to the declared outputs. +# +# Plugins must be declared in here to be active. +# To deactivate a plugin, comment out the name and any variables. +# +# Use 'telegraf -config telegraf.conf -test' to see what metrics a config +# file would generate. +# +# Environment variables can be used anywhere in this config file, simply prepend +# them with $. For strings the variable must be within quotes (ie, "$STR_VAR"), +# for numbers and booleans they should be plain (ie, $INT_VAR, $BOOL_VAR) + +# Configuration for telegraf agent +[agent] + ## Default data collection interval for all inputs + interval = "60s" + ## Rounds collection interval to 'interval' + ## ie, if interval="10s" then always collect on :00, :10, :20, etc. + round_interval = true + + ## Telegraf will send metrics to outputs in batches of at most + ## metric_batch_size metrics. + ## This controls the size of writes that Telegraf sends to output plugins. + metric_batch_size = 1000 + + ## For failed writes, telegraf will cache metric_buffer_limit metrics for each + ## output, and will flush this buffer on a successful write. Oldest metrics + ## are dropped first when this buffer fills. + ## This buffer only fills when writes fail to output plugin(s). + metric_buffer_limit = 10000 + + ## Collection jitter is used to jitter the collection by a random amount. + ## Each plugin will sleep for a random time within jitter before collecting. + ## This can be used to avoid many plugins querying things like sysfs at the + ## same time, which can have a measurable effect on the system. + collection_jitter = "0s" + + ## Default flushing interval for all outputs. You shouldn't set this below + ## interval. Maximum flush_interval will be flush_interval + flush_jitter + flush_interval = "60s" + ## Jitter the flush interval by a random amount. This is primarily to avoid + ## large write spikes for users running a large number of telegraf instances. + ## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s + flush_jitter = "0s" + + ## By default or when set to "0s", precision will be set to the same + ## timestamp order as the collection interval, with the maximum being 1s. + ## ie, when interval = "10s", precision will be "1s" + ## when interval = "250ms", precision will be "1ms" + ## Precision will NOT be used for service inputs. It is up to each individual + ## service input to set the timestamp at the appropriate precision. + ## Valid time units are "ns", "us" (or "µs"), "ms", "s". + precision = "" + + ## Logging configuration: + ## Run telegraf with debug log messages. + debug = false + ## Run telegraf in quiet mode (error log messages only). + quiet = false + ## Specify the log file name. The empty string means to log to stderr. + logfile = "/var/opt/microsoft/docker-cimprov/log/telegraf.log" + + ## Override default hostname, if empty use os.Hostname() + #hostname = "placeholder_hostname" + ## If set to true, do no set the "host" tag in the telegraf agent. + omit_hostname = true + + +############################################################################### +# INPUT PLUGINS # +############################################################################### + +#Prometheus Custom Metrics +[[inputs.prometheus]] + ## An array of urls to scrape metrics from. + interval = "$AZMON_DS_PROM_INTERVAL" + + ## An array of urls to scrape metrics from. + #urls = ["http://$NODE_IP:10255/metrics", "http://$NODE_IP:10255/metrics/cadvisor", "http://$NODE_IP:10254/metrics", "http://$NODE_IP:9100/metrics"] + urls = ["$AZMON_DS_PROM_URLS"] + + fieldpass = ["$AZMON_DS_PROM_FIELDPASS"] + fielddrop = ["$AZMON_DS_PROM_FIELDDROP"] + + metric_version = 2 + url_tag = "scrapeUrl" + + ## Use bearer token for authorization. ('bearer_token' takes priority) + bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token" + + ## Specify timeout duration for slower prometheus clients (default is 3s) + response_timeout = "15s" + + ## Optional TLS Config + tls_ca = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" + ## Use TLS but skip chain & host verification + insecure_skip_verify = true diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 08289569f..c129e6d78 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -94,6 +94,18 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" puts "****************End Prometheus Config Processing********************" end + #Also substitute these values in the test config file for telegraf + file_name = "telegraf-test-rs.conf" + text = File.read(file_name) + new_contents = text.gsub(/$AZMON_RS_PROM_INTERVAL/, "interval") + new_contents = text.gsub(/$AZMON_RS_PROM_FIELDPASS/, "fieldPass") + new_contents = text.gsub(/$AZMON_RS_PROM_FIELDDROP/, "fieldDrop") + new_contents = text.gsub(/$AZMON_RS_PROM_URLS /, "urls") + new_contents = text.gsub(/$AZMON_RS_PROM_K8S_SERVICES /, "kubernetesServices") + new_contents = text.gsub(/$AZMON_RS_PROM_MONITOR_PODS /, "monitorKubernetesPods") + + # To write changes to the file, use: + File.open(file_name, "w") { |file| file.puts new_contents } end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for replicaset: #{errorStr}, using defaults" @@ -125,6 +137,16 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" puts "****************End Prometheus Config Processing********************" end + + #Also substitute these values in the test config file for telegraf + file_name = "telegraf-test.conf" + text = File.read(file_name) + new_contents = text.gsub(/$AZMON_DS_PROM_INTERVAL/, "interval") + new_contents = text.gsub(/$AZMON_DS_PROM_FIELDPASS/, "fieldPass") + new_contents = text.gsub(/$AZMON_DS_PROM_FIELDDROP/, "fieldDrop") + new_contents = text.gsub(/$AZMON_DS_PROM_URLS /, "urls") + # To write changes to the file, use: + File.open(file_name, "w") { |file| file.puts new_contents } end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for daemonset: #{errorStr}, using defaults" From 0bfed65340caa79da6c09b1b27046134f09cfea2 Mon Sep 17 00:00:00 2001 From: rashmy Date: Tue, 25 Jun 2019 17:46:32 -0700 Subject: [PATCH 06/20] changes --- installer/datafiles/base_container.data | 2 ++ 1 file changed, 2 insertions(+) diff --git a/installer/datafiles/base_container.data b/installer/datafiles/base_container.data index 58a74aa0a..be19b2733 100644 --- a/installer/datafiles/base_container.data +++ b/installer/datafiles/base_container.data @@ -110,6 +110,8 @@ MAINTAINER: 'Microsoft Corporation' /etc/opt/microsoft/docker-cimprov/out_oms.conf; installer/conf/out_oms.conf; 644; root; root /etc/opt/microsoft/docker-cimprov/telegraf.conf; installer/conf/telegraf.conf; 644; root; root /etc/opt/microsoft/docker-cimprov/telegraf-rs.conf; installer/conf/telegraf-rs.conf; 644; root; root +/opt/telegraf-test.conf; installer/conf/telegraf-test.conf; 644; root; root +/opt/telegraf-test-rs.conf; installer/conf/telegraf-test-rs.conf; 644; root; root /opt/microsoft/docker-cimprov/bin/TelegrafTCPErrorTelemetry.sh; installer/scripts/TelegrafTCPErrorTelemetry.sh; 755; root; root /opt/livenessprobe.sh; installer/scripts/livenessprobe.sh; 755; root; root /opt/tomlparser.rb; installer/scripts/tomlparser.rb; 755; root; root From 7ed0dcf4ace7bbf112179171932240f57643dff8 Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 11:34:59 -0700 Subject: [PATCH 07/20] changes --- .../scripts/tomlparser-prom-customconfig.rb | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index c129e6d78..b9484fb44 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -6,7 +6,7 @@ @replicaset = "replicaset" @daemonset = "daemonset" # @cnfigVersion = "" -@promConfigSchemaVersion = "" +@configSchemaVersion = "" # Setting default values which will be used in case they are not set in the configmap or if configmap doesnt exist # @collectStdoutLogs = true # @stdoutExcludeNamespaces = "kube-system" @@ -89,26 +89,26 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") # Close file after writing all environment variables file.close - puts "****************End Prometheus Config Processing********************" + + #Also substitute these values in the test config file for telegraf + file_name = "telegraf-test-rs.conf" + text = File.read(file_name) + new_contents = text.gsub(/$AZMON_RS_PROM_INTERVAL/, "interval") + new_contents = text.gsub(/$AZMON_RS_PROM_FIELDPASS/, "fieldPass") + new_contents = text.gsub(/$AZMON_RS_PROM_FIELDDROP/, "fieldDrop") + new_contents = text.gsub(/$AZMON_RS_PROM_URLS /, "urls") + new_contents = text.gsub(/$AZMON_RS_PROM_K8S_SERVICES /, "kubernetesServices") + new_contents = text.gsub(/$AZMON_RS_PROM_MONITOR_PODS /, "monitorKubernetesPods") + + File.open(file_name, "w") { |file| file.puts new_contents } else puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" puts "****************End Prometheus Config Processing********************" end - #Also substitute these values in the test config file for telegraf - file_name = "telegraf-test-rs.conf" - text = File.read(file_name) - new_contents = text.gsub(/$AZMON_RS_PROM_INTERVAL/, "interval") - new_contents = text.gsub(/$AZMON_RS_PROM_FIELDPASS/, "fieldPass") - new_contents = text.gsub(/$AZMON_RS_PROM_FIELDDROP/, "fieldDrop") - new_contents = text.gsub(/$AZMON_RS_PROM_URLS /, "urls") - new_contents = text.gsub(/$AZMON_RS_PROM_K8S_SERVICES /, "kubernetesServices") - new_contents = text.gsub(/$AZMON_RS_PROM_MONITOR_PODS /, "monitorKubernetesPods") - - # To write changes to the file, use: - File.open(file_name, "w") { |file| file.puts new_contents } end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for replicaset: #{errorStr}, using defaults" + puts "****************End Prometheus Config Processing********************" end elsif controller.casecmp(@daemonset) == 0 && !parsedConfig[:prometheus_data_collection_settings][:node].nil? #Get prometheus daemonset custom config settings @@ -132,24 +132,24 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.write("export AZMON_DS_PROM_URLS=#{urls}\n") # Close file after writing all environment variables file.close - puts "****************End Prometheus Config Processing********************" + + #Also substitute these values in the test config file for telegraf + file_name = "telegraf-test.conf" + text = File.read(file_name) + new_contents = text.gsub(/$AZMON_DS_PROM_INTERVAL/, "interval") + new_contents = text.gsub(/$AZMON_DS_PROM_FIELDPASS/, "fieldPass") + new_contents = text.gsub(/$AZMON_DS_PROM_FIELDDROP/, "fieldDrop") + new_contents = text.gsub(/$AZMON_DS_PROM_URLS /, "urls") + # To write changes to the file, use: + File.open(file_name, "w") { |file| file.puts new_contents } else puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" puts "****************End Prometheus Config Processing********************" end - - #Also substitute these values in the test config file for telegraf - file_name = "telegraf-test.conf" - text = File.read(file_name) - new_contents = text.gsub(/$AZMON_DS_PROM_INTERVAL/, "interval") - new_contents = text.gsub(/$AZMON_DS_PROM_FIELDPASS/, "fieldPass") - new_contents = text.gsub(/$AZMON_DS_PROM_FIELDDROP/, "fieldDrop") - new_contents = text.gsub(/$AZMON_DS_PROM_URLS /, "urls") - # To write changes to the file, use: - File.open(file_name, "w") { |file| file.puts new_contents } end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for daemonset: #{errorStr}, using defaults" + puts "****************End Prometheus Config Processing********************" end end # end of controller type check end @@ -158,15 +158,16 @@ def populateSettingValuesFromConfigMap(parsedConfig) end end -@promConfigSchemaVersion = ENV["AZMON_AGENT_PROM_CFG_SCHEMA_VERSION"] -puts "****************Start Prometheus Config Processing********************" -if !@promConfigSchemaVersion.nil? && !@promConfigSchemaVersion.empty? && @promConfigSchemaVersion.strip.casecmp("v1") == 0 #note v1 is the only supported schema version , so hardcoding it - promConfigMapSettings = parseConfigMap - if !promConfigMapSettings.nil? - populateSettingValuesFromConfigMap(promConfigMapSettings) +@configSchemaVersion = ENV["AZMON_AGENT_CFG_SCHEMA_VERSION"] +puts "****************Start Config Processing********************" +if !@configSchemaVersion.nil? && !@configSchemaVersion.empty? && @configSchemaVersion.strip.casecmp("v1") == 0 #note v1 is the only supported schema version , so hardcoding it + configMapSettings = parseConfigMap + if !configMapSettings.nil? + populateSettingValuesFromConfigMap(configMapSettings) end else - #Do we need this - if (File.file?(@promConfigMapMountPath)) - puts "config::unsupported/missing config schema version for prometheus config - '#{@promConfigSchemaVersion}' , using defaults" - # end + if (File.file?(@configMapMountPath)) + puts "config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults" + end end +puts "****************End Prometheus Config Processing********************" From 1c22e0ed2b25ade4515821e4ffb10d30534e7f45 Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 15:23:18 -0700 Subject: [PATCH 08/20] changes --- installer/datafiles/base_container.data | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/installer/datafiles/base_container.data b/installer/datafiles/base_container.data index be19b2733..5a18805be 100644 --- a/installer/datafiles/base_container.data +++ b/installer/datafiles/base_container.data @@ -110,11 +110,12 @@ MAINTAINER: 'Microsoft Corporation' /etc/opt/microsoft/docker-cimprov/out_oms.conf; installer/conf/out_oms.conf; 644; root; root /etc/opt/microsoft/docker-cimprov/telegraf.conf; installer/conf/telegraf.conf; 644; root; root /etc/opt/microsoft/docker-cimprov/telegraf-rs.conf; installer/conf/telegraf-rs.conf; 644; root; root -/opt/telegraf-test.conf; installer/conf/telegraf-test.conf; 644; root; root -/opt/telegraf-test-rs.conf; installer/conf/telegraf-test-rs.conf; 644; root; root -/opt/microsoft/docker-cimprov/bin/TelegrafTCPErrorTelemetry.sh; installer/scripts/TelegrafTCPErrorTelemetry.sh; 755; root; root +/opt/telegraf-test.conf; installer/conf/telegraf-test.conf; 644; root; root +/opt/telegraf-test-rs.conf; installer/conf/telegraf-test-rs.conf; 644; root; root +/opt/microsoft/docker-cimprov/bin/TelegrafTCPErrorTelemetry.sh; installer/scripts/TelegrafTCPErrorTelemetry.sh; 755; root; root /opt/livenessprobe.sh; installer/scripts/livenessprobe.sh; 755; root; root /opt/tomlparser.rb; installer/scripts/tomlparser.rb; 755; root; root +/opt/tomlparser-prom-customconfig.rb; installer/scripts/tomlparser-prom-customconfig.rb; 755; root; root %Links /opt/omi/lib/libcontainer.${{SHLIB_EXT}}; /opt/microsoft/docker-cimprov/lib/libcontainer.${{SHLIB_EXT}}; 644; root; root From f8e30fab28cee721fffdc08a0b3159fdb0fde6df Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 15:44:53 -0700 Subject: [PATCH 09/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index b9484fb44..66e706bd8 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -78,6 +78,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) checkForTypeArray(kubernetesServices, String) && checkForTypeArray(urls, String) && checkForType(monitorKubernetesPods, Boolean) + puts "config::Successfully passed typecheck for config settings for replicaset" # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") if !file.nil? @@ -89,6 +90,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") # Close file after writing all environment variables file.close + puts "config::Successfully created custom config environment variable file for replicaset" #Also substitute these values in the test config file for telegraf file_name = "telegraf-test-rs.conf" @@ -101,6 +103,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) new_contents = text.gsub(/$AZMON_RS_PROM_MONITOR_PODS /, "monitorKubernetesPods") File.open(file_name, "w") { |file| file.puts new_contents } + puts "config::Successfully replaced the settings in test telegraf config file for replicaset" else puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" puts "****************End Prometheus Config Processing********************" @@ -123,6 +126,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) checkForTypeArray(fieldPass, String) && checkForTypeArray(fieldDrop, String) && checkForTypeArray(urls, String) + puts "config::Successfully passed typecheck for config settings for daemonset" # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") if !file.nil? @@ -132,6 +136,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.write("export AZMON_DS_PROM_URLS=#{urls}\n") # Close file after writing all environment variables file.close + puts "config::Successfully created custom config environment variable file for daemonset" #Also substitute these values in the test config file for telegraf file_name = "telegraf-test.conf" @@ -142,6 +147,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) new_contents = text.gsub(/$AZMON_DS_PROM_URLS /, "urls") # To write changes to the file, use: File.open(file_name, "w") { |file| file.puts new_contents } + puts "config::Successfully replaced the settings in test telegraf config file for daemonset" else puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" puts "****************End Prometheus Config Processing********************" @@ -166,7 +172,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) populateSettingValuesFromConfigMap(configMapSettings) end else - if (File.file?(@configMapMountPath)) + if (File.file?(@promConfigMapMountPath)) puts "config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults" end end From 8d17d8ce3a91864197ff3a47e5cefda667ba3d59 Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 16:43:10 -0700 Subject: [PATCH 10/20] changes --- installer/conf/telegraf.conf | 2 +- installer/scripts/tomlparser-prom-customconfig.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/conf/telegraf.conf b/installer/conf/telegraf.conf index fa1d72ea7..a83db55cf 100644 --- a/installer/conf/telegraf.conf +++ b/installer/conf/telegraf.conf @@ -572,7 +572,7 @@ ## prometheus custom metrics [[inputs.prometheus]] - interval: "$AZMON_DS_PROM_INTERVAL" + interval = "$AZMON_DS_PROM_INTERVAL" ## An array of urls to scrape metrics from. urls = ["$AZMON_DS_PROM_URLS"] diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 66e706bd8..32cf2e96b 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -165,7 +165,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) end @configSchemaVersion = ENV["AZMON_AGENT_CFG_SCHEMA_VERSION"] -puts "****************Start Config Processing********************" +puts "****************Start Prometheus Config Processing********************" if !@configSchemaVersion.nil? && !@configSchemaVersion.empty? && @configSchemaVersion.strip.casecmp("v1") == 0 #note v1 is the only supported schema version , so hardcoding it configMapSettings = parseConfigMap if !configMapSettings.nil? From 7dbafb068379dcd9449349b1eb3b61413a546845 Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 17:57:43 -0700 Subject: [PATCH 11/20] adding telemetry --- installer/scripts/tomlparser-prom-customconfig.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 32cf2e96b..2e2e5bdcf 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -84,9 +84,14 @@ def populateSettingValuesFromConfigMap(parsedConfig) if !file.nil? file.write("export AZMON_RS_PROM_INTERVAL=#{interval}\n") file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + #Setting array lengths as environment variables for telemetry purposes + file.write("export TELEMETRY_RS_PROM_FIELDPASS_LENGTH=\"#{fieldPass.length}\"\n") file.write("export AZMON_RS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export TELEMETRY_RS_PROM_FIELDDROP_LENGTH=\"#{fieldDrop.length}\"\n") file.write("export AZMON_RS_PROM_K8S_SERVICES=#{kubernetesServices}\n") + file.write("export TELEMETRY_RS_PROM_K8S_SERVICES_LENGTH=#{kubernetesServices.length}\n") file.write("export AZMON_RS_PROM_URLS=#{urls}\n") + file.write("export TELEMETRY_RS_PROM_URLS_LENGTH=#{urls.length}\n") file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") # Close file after writing all environment variables file.close @@ -132,8 +137,12 @@ def populateSettingValuesFromConfigMap(parsedConfig) if !file.nil? file.write("export AZMON_DS_PROM_INTERVAL=#{interval}\n") file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + #Setting array lengths as environment variables for telemetry purposes + file.write("export TELEMETRY_DS_PROM_FIELDPASS_LENGTH=\"#{fieldPass.length}\"\n") file.write("export AZMON_DS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export TELEMETRY_DS_PROM_FIELDDROP_LENGTH=\"#{fieldDrop.length}\"\n") file.write("export AZMON_DS_PROM_URLS=#{urls}\n") + file.write("export TELEMETRY_DS_PROM_URLS_LENGTH=#{urls.length}\n") # Close file after writing all environment variables file.close puts "config::Successfully created custom config environment variable file for daemonset" From fe12fccca96f98c73e0d2b4358d20f7376f7791a Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 18:57:25 -0700 Subject: [PATCH 12/20] changes --- .../scripts/tomlparser-prom-customconfig.rb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 2e2e5bdcf..70aa1d952 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -100,12 +100,12 @@ def populateSettingValuesFromConfigMap(parsedConfig) #Also substitute these values in the test config file for telegraf file_name = "telegraf-test-rs.conf" text = File.read(file_name) - new_contents = text.gsub(/$AZMON_RS_PROM_INTERVAL/, "interval") - new_contents = text.gsub(/$AZMON_RS_PROM_FIELDPASS/, "fieldPass") - new_contents = text.gsub(/$AZMON_RS_PROM_FIELDDROP/, "fieldDrop") - new_contents = text.gsub(/$AZMON_RS_PROM_URLS /, "urls") - new_contents = text.gsub(/$AZMON_RS_PROM_K8S_SERVICES /, "kubernetesServices") - new_contents = text.gsub(/$AZMON_RS_PROM_MONITOR_PODS /, "monitorKubernetesPods") + new_contents = text.gsub("$AZMON_RS_PROM_INTERVAL", interval) + new_contents = text.gsub("$AZMON_RS_PROM_FIELDPASS", fieldPass) + new_contents = text.gsub("$AZMON_RS_PROM_FIELDDROP", fieldDrop) + new_contents = text.gsub("$AZMON_RS_PROM_URLS", urls) + new_contents = text.gsub("$AZMON_RS_PROM_K8S_SERVICES", kubernetesServices) + new_contents = text.gsub("$AZMON_RS_PROM_MONITOR_PODS", monitorKubernetesPods) File.open(file_name, "w") { |file| file.puts new_contents } puts "config::Successfully replaced the settings in test telegraf config file for replicaset" @@ -150,10 +150,10 @@ def populateSettingValuesFromConfigMap(parsedConfig) #Also substitute these values in the test config file for telegraf file_name = "telegraf-test.conf" text = File.read(file_name) - new_contents = text.gsub(/$AZMON_DS_PROM_INTERVAL/, "interval") - new_contents = text.gsub(/$AZMON_DS_PROM_FIELDPASS/, "fieldPass") - new_contents = text.gsub(/$AZMON_DS_PROM_FIELDDROP/, "fieldDrop") - new_contents = text.gsub(/$AZMON_DS_PROM_URLS /, "urls") + new_contents = text.gsub("$AZMON_DS_PROM_INTERVAL", interval) + new_contents = text.gsub("$AZMON_DS_PROM_FIELDPASS", fieldPass) + new_contents = text.gsub("$AZMON_DS_PROM_FIELDDROP", fieldDrop) + new_contents = text.gsub("$AZMON_DS_PROM_URLS", urls) # To write changes to the file, use: File.open(file_name, "w") { |file| file.puts new_contents } puts "config::Successfully replaced the settings in test telegraf config file for daemonset" From 476a4771e42ffc5cd5aa9555d79c241ff61478a2 Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 19:59:48 -0700 Subject: [PATCH 13/20] changes --- .../scripts/tomlparser-prom-customconfig.rb | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 70aa1d952..232b0e410 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -83,14 +83,14 @@ def populateSettingValuesFromConfigMap(parsedConfig) file = File.open("prom_config_env_var", "w") if !file.nil? file.write("export AZMON_RS_PROM_INTERVAL=#{interval}\n") - file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass.join("\",\"")}\"\n") #Setting array lengths as environment variables for telemetry purposes file.write("export TELEMETRY_RS_PROM_FIELDPASS_LENGTH=\"#{fieldPass.length}\"\n") - file.write("export AZMON_RS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export AZMON_RS_PROM_FIELDDROP=#{fieldDrop.join("\",\"")}\n") file.write("export TELEMETRY_RS_PROM_FIELDDROP_LENGTH=\"#{fieldDrop.length}\"\n") - file.write("export AZMON_RS_PROM_K8S_SERVICES=#{kubernetesServices}\n") + file.write("export AZMON_RS_PROM_K8S_SERVICES=#{kubernetesServices.join("\",\"")}\n") file.write("export TELEMETRY_RS_PROM_K8S_SERVICES_LENGTH=#{kubernetesServices.length}\n") - file.write("export AZMON_RS_PROM_URLS=#{urls}\n") + file.write("export AZMON_RS_PROM_URLS=#{urls.join("\",\"")}\n") file.write("export TELEMETRY_RS_PROM_URLS_LENGTH=#{urls.length}\n") file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") # Close file after writing all environment variables @@ -101,11 +101,11 @@ def populateSettingValuesFromConfigMap(parsedConfig) file_name = "telegraf-test-rs.conf" text = File.read(file_name) new_contents = text.gsub("$AZMON_RS_PROM_INTERVAL", interval) - new_contents = text.gsub("$AZMON_RS_PROM_FIELDPASS", fieldPass) - new_contents = text.gsub("$AZMON_RS_PROM_FIELDDROP", fieldDrop) - new_contents = text.gsub("$AZMON_RS_PROM_URLS", urls) - new_contents = text.gsub("$AZMON_RS_PROM_K8S_SERVICES", kubernetesServices) - new_contents = text.gsub("$AZMON_RS_PROM_MONITOR_PODS", monitorKubernetesPods) + new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDPASS", fieldPass.join("\",\"")) + new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDDROP", fieldDrop.join("\",\"")) + new_contents = new_contents.gsub("$AZMON_RS_PROM_URLS", urls.join("\",\"")) + new_contents = new_contents.gsub("$AZMON_RS_PROM_K8S_SERVICES", kubernetesServices.join("\",\"")) + new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", monitorKubernetesPods.join("\",\"")) File.open(file_name, "w") { |file| file.puts new_contents } puts "config::Successfully replaced the settings in test telegraf config file for replicaset" @@ -136,12 +136,12 @@ def populateSettingValuesFromConfigMap(parsedConfig) file = File.open("prom_config_env_var", "w") if !file.nil? file.write("export AZMON_DS_PROM_INTERVAL=#{interval}\n") - file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass}\"\n") + file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass.join("\",\"")}\"\n") #Setting array lengths as environment variables for telemetry purposes file.write("export TELEMETRY_DS_PROM_FIELDPASS_LENGTH=\"#{fieldPass.length}\"\n") - file.write("export AZMON_DS_PROM_FIELDDROP=#{fieldDrop}\n") + file.write("export AZMON_DS_PROM_FIELDDROP=#{fieldDrop.join("\",\"")}\n") file.write("export TELEMETRY_DS_PROM_FIELDDROP_LENGTH=\"#{fieldDrop.length}\"\n") - file.write("export AZMON_DS_PROM_URLS=#{urls}\n") + file.write("export AZMON_DS_PROM_URLS=#{urls.join("\",\"")}\n") file.write("export TELEMETRY_DS_PROM_URLS_LENGTH=#{urls.length}\n") # Close file after writing all environment variables file.close @@ -151,9 +151,9 @@ def populateSettingValuesFromConfigMap(parsedConfig) file_name = "telegraf-test.conf" text = File.read(file_name) new_contents = text.gsub("$AZMON_DS_PROM_INTERVAL", interval) - new_contents = text.gsub("$AZMON_DS_PROM_FIELDPASS", fieldPass) - new_contents = text.gsub("$AZMON_DS_PROM_FIELDDROP", fieldDrop) - new_contents = text.gsub("$AZMON_DS_PROM_URLS", urls) + new_contents = new_contents.gsub("$AZMON_DS_PROM_FIELDPASS", fieldPass.join("\",\"")) + new_contents = new_contents.gsub("$AZMON_DS_PROM_FIELDDROP", fieldDrop.join("\",\"")) + new_contents = new_contents.gsub("$AZMON_DS_PROM_URLS", urls.join("\",\"")) # To write changes to the file, use: File.open(file_name, "w") { |file| file.puts new_contents } puts "config::Successfully replaced the settings in test telegraf config file for daemonset" From 8801b0366ca6bf4491c274bdb1199c307ad5b4d4 Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 26 Jun 2019 20:14:58 -0700 Subject: [PATCH 14/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 232b0e410..0fef31dad 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -77,7 +77,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) checkForTypeArray(fieldDrop, String) && checkForTypeArray(kubernetesServices, String) && checkForTypeArray(urls, String) && - checkForType(monitorKubernetesPods, Boolean) + !monitorKubernetesPods.nil? && monitorKubernetesPods.is_a?(Boolean) puts "config::Successfully passed typecheck for config settings for replicaset" # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") From 54c04b2ee18bbc3d21f38d6d4d013a346cbe5322 Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 27 Jun 2019 11:39:13 -0700 Subject: [PATCH 15/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 0fef31dad..7042734bf 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -77,12 +77,13 @@ def populateSettingValuesFromConfigMap(parsedConfig) checkForTypeArray(fieldDrop, String) && checkForTypeArray(kubernetesServices, String) && checkForTypeArray(urls, String) && - !monitorKubernetesPods.nil? && monitorKubernetesPods.is_a?(Boolean) + !monitorKubernetesPods.nil? && (!!monitorKubernetesPods == monitorKubernetesPods) #Checking for Boolean type, since 'Boolean' is not defined as a type in ruby puts "config::Successfully passed typecheck for config settings for replicaset" # Write the settings to file, so that they can be set as environment variables file = File.open("prom_config_env_var", "w") if !file.nil? file.write("export AZMON_RS_PROM_INTERVAL=#{interval}\n") + file.write("export TELEMETRY_RS_PROM_INTERVAL=\"#{interval}\"\n") file.write("export AZMON_RS_PROM_FIELDPASS=\"#{fieldPass.join("\",\"")}\"\n") #Setting array lengths as environment variables for telemetry purposes file.write("export TELEMETRY_RS_PROM_FIELDPASS_LENGTH=\"#{fieldPass.length}\"\n") @@ -93,6 +94,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.write("export AZMON_RS_PROM_URLS=#{urls.join("\",\"")}\n") file.write("export TELEMETRY_RS_PROM_URLS_LENGTH=#{urls.length}\n") file.write("export AZMON_RS_PROM_MONITOR_PODS=#{monitorKubernetesPods}\n") + file.write("export TELEMETRY_RS_PROM_MONITOR_PODS=\"#{monitorKubernetesPods}\"\n") # Close file after writing all environment variables file.close puts "config::Successfully created custom config environment variable file for replicaset" @@ -136,6 +138,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) file = File.open("prom_config_env_var", "w") if !file.nil? file.write("export AZMON_DS_PROM_INTERVAL=#{interval}\n") + file.write("export TELEMETRY_DS_PROM_INTERVAL=\"#{interval}\"\n") file.write("export AZMON_DS_PROM_FIELDPASS=\"#{fieldPass.join("\",\"")}\"\n") #Setting array lengths as environment variables for telemetry purposes file.write("export TELEMETRY_DS_PROM_FIELDPASS_LENGTH=\"#{fieldPass.length}\"\n") From 6d07c7b19e46929c514ec4ed8dab5f19db42c30e Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 27 Jun 2019 11:45:21 -0700 Subject: [PATCH 16/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 7042734bf..005751d8d 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -5,17 +5,7 @@ @promConfigMapMountPath = "/etc/config/settings/prometheus-data-collection-settings" @replicaset = "replicaset" @daemonset = "daemonset" -# @cnfigVersion = "" @configSchemaVersion = "" -# Setting default values which will be used in case they are not set in the configmap or if configmap doesnt exist -# @collectStdoutLogs = true -# @stdoutExcludeNamespaces = "kube-system" -# @collectStderrLogs = true -# @stderrExcludeNamespaces = "kube-system" -# @collectClusterEnvVariables = true -# @logTailPath = "/var/log/containers/*.log" -# @logExclusionRegexPattern = "(^((?!stdout|stderr).)*$)" -# @excludePath = "*.csv2" #some invalid path # Use parser to parse the configmap toml file to a ruby structure def parseConfigMap @@ -28,12 +18,10 @@ def parseConfigMap return parsedConfig else puts "config::configmap container-azm-ms-agentconfig for settings not mounted, using defaults for prometheus scraping" - # @excludePath = "*_kube-system_*.log" return nil end rescue => errorStr puts "config::error::Exception while parsing toml config file for prometheus config: #{errorStr}, using defaults" - # @excludePath = "*_kube-system_*.log" return nil end end From 697bb4b94b084e4896d5474beb70842b6eaa376c Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 27 Jun 2019 12:37:25 -0700 Subject: [PATCH 17/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 005751d8d..577124cf6 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -44,7 +44,6 @@ def checkForType(variable, varType) # Use the ruby structure created after config parsing to set the right values to be used as environment variables def populateSettingValuesFromConfigMap(parsedConfig) - puts "****************Start Prometheus Config Processing********************" # Checking to see if this is the daemonset or replicaset to parse config accordingly controller = ENV["CONTROLLER_TYPE"] if !controller.nil? @@ -95,7 +94,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDDROP", fieldDrop.join("\",\"")) new_contents = new_contents.gsub("$AZMON_RS_PROM_URLS", urls.join("\",\"")) new_contents = new_contents.gsub("$AZMON_RS_PROM_K8S_SERVICES", kubernetesServices.join("\",\"")) - new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", monitorKubernetesPods.join("\",\"")) + new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", monitorKubernetesPods) File.open(file_name, "w") { |file| file.puts new_contents } puts "config::Successfully replaced the settings in test telegraf config file for replicaset" @@ -174,6 +173,8 @@ def populateSettingValuesFromConfigMap(parsedConfig) else if (File.file?(@promConfigMapMountPath)) puts "config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults" + else + puts "config::No configmap mounted for prometheus custom config, using defaults" end end puts "****************End Prometheus Config Processing********************" From cd9a62cc18c47ef6e515bbed2934a491ba6180df Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 27 Jun 2019 14:11:04 -0700 Subject: [PATCH 18/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 577124cf6..17ed865fb 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -94,7 +94,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDDROP", fieldDrop.join("\",\"")) new_contents = new_contents.gsub("$AZMON_RS_PROM_URLS", urls.join("\",\"")) new_contents = new_contents.gsub("$AZMON_RS_PROM_K8S_SERVICES", kubernetesServices.join("\",\"")) - new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", monitorKubernetesPods) + new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", (monitorKubernetesPods ? "true" : "false")) File.open(file_name, "w") { |file| file.puts new_contents } puts "config::Successfully replaced the settings in test telegraf config file for replicaset" From fa993844f4ed92ab492513ee5732891d3c01c7a1 Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 27 Jun 2019 14:39:43 -0700 Subject: [PATCH 19/20] cahnges --- installer/scripts/tomlparser-prom-customconfig.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 17ed865fb..b9c1f256f 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -102,6 +102,8 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "config::error::Exception while opening file for writing prometheus replicaset config environment variables" puts "****************End Prometheus Config Processing********************" end + else + puts "config::Typecheck failed for prometheus config settings for replicaset" end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for replicaset: #{errorStr}, using defaults" @@ -151,6 +153,8 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "config::error::Exception while opening file for writing prometheus daemonset config environment variables" puts "****************End Prometheus Config Processing********************" end + else + puts "config::Typecheck failed for prometheus config settings for daemonset" end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for daemonset: #{errorStr}, using defaults" From e4a467c1b792846ea9c2d1c626c7a9f8056a42b5 Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 27 Jun 2019 14:41:09 -0700 Subject: [PATCH 20/20] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index b9c1f256f..5df83c89a 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -103,7 +103,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "****************End Prometheus Config Processing********************" end else - puts "config::Typecheck failed for prometheus config settings for replicaset" + puts "config::Typecheck failed for prometheus config settings for replicaset, using defaults" end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for replicaset: #{errorStr}, using defaults" @@ -154,7 +154,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) puts "****************End Prometheus Config Processing********************" end else - puts "config::Typecheck failed for prometheus config settings for daemonset" + puts "config::Typecheck failed for prometheus config settings for daemonset, using defaults" end # end of type check condition rescue => errorStr puts "config::error::Exception while reading config file for prometheus config for daemonset: #{errorStr}, using defaults"