From 61039a8e53baf1180cea93beb1d12ccb3802ce9e Mon Sep 17 00:00:00 2001 From: rashmy Date: Wed, 4 Sep 2019 17:58:58 -0700 Subject: [PATCH 01/10] changes --- installer/conf/telegraf-rs.conf | 4 +- .../scripts/tomlparser-prom-customconfig.rb | 66 +++++++++++++++++-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/installer/conf/telegraf-rs.conf b/installer/conf/telegraf-rs.conf index ce60bfa04..2eb454f43 100644 --- a/installer/conf/telegraf-rs.conf +++ b/installer/conf/telegraf-rs.conf @@ -552,7 +552,8 @@ ## 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 + # monitor_kubernetes_pods = $AZMON_RS_PROM_MONITOR_PODS + $AZMON_RS_PROM_MONITOR_PODS fieldpass = $AZMON_RS_PROM_FIELDPASS fielddrop = $AZMON_RS_PROM_FIELDDROP @@ -579,6 +580,7 @@ insecure_skip_verify = true #tagexclude = ["AgentVersion","AKS_RESOURCE_ID","ACS_RESOURCE_NAME", "Region", "ClusterName", "ClusterType", "Computer", "ControllerType"] +$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER # [[inputs.exec]] # ## Commands array # interval = "15m" diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index d9fdf1cc2..6f2e45b8c 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -18,6 +18,14 @@ @defaultRsK8sServices = [] @defaultRsMonitorPods = false +#Configurations to be used for the auto-generated input prometheus plugins for namespace filtering +@metricVersion = 2 +@urlTag = "scrapeUrl" +@bearerToken = "/var/run/secrets/kubernetes.io/serviceaccount/token" +@responseTimeout = "15s" +@tlsCa = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" +@insecureSkipVerify = true + # Use parser to parse the configmap toml file to a ruby structure def parseConfigMap begin @@ -53,6 +61,33 @@ def checkForType(variable, varType) end end +def replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) + new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", ("monitor_kubernetes_pods = #{monitorKubernetesPods}")) + new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "") +end + +def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) + begin + new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", "# Commenting this out since new plugins will be created per namespace\n # $AZMON_RS_PROM_MONITOR_PODS") + monitorKubernetesPodsNamespaces.each do |namespace| + new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "[[inputs.prometheus]]\n interval = #{interval}\n + monitor_kubernetes_pods = true\n + monitor_kubernetes_pods_namespaces = #{namespace}\n + fieldpass = #{fieldPassSetting}\n + fielddrop = #{fieldDropSetting}\n + metric_version = #{@metricVersion}\n + url_tag = #{@urlTag}\n + bearer_token = #{@bearerToken}\n + response_timeout = #{@responseTimeout}\n + tls_ca = #{@tlsCa}\n + insecure_skip_verify = #{@insecureSkipVerify}\n") + end + rescue => errorStr + puts "config::error::Exception while creating prometheus input plugins to filter namespaces: #{errorStr}, using defaults" + replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) + end +end + # Use the ruby structure created after config parsing to set the right values to be used as environment variables def populateSettingValuesFromConfigMap(parsedConfig) # Checking to see if this is the daemonset or replicaset to parse config accordingly @@ -68,6 +103,10 @@ def populateSettingValuesFromConfigMap(parsedConfig) 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] + monitorKubernetesPodsNamespaces = parsedConfig[:prometheus_data_collection_settings][:cluster][:monitor_kubernetes_pods_namespaces] + + # Setting this to false by default, will be set to true/false based on the setting evaluation for 'monitor_kubernetes_pods_namespaces' + #namespaceFilterForMonitorPods = false # Check for the right datattypes to enforce right setting values if checkForType(interval, String) && @@ -75,7 +114,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) checkForTypeArray(fieldDrop, String) && checkForTypeArray(kubernetesServices, String) && checkForTypeArray(urls, String) && - !monitorKubernetesPods.nil? && (!!monitorKubernetesPods == monitorKubernetesPods) #Checking for Boolean type, since 'Boolean' is not defined as a type in ruby + (monitorKubernetesPods.nil? || (!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" #if setting is nil assign default values interval = (interval.nil?) ? @defaultRsInterval : interval @@ -83,7 +122,10 @@ def populateSettingValuesFromConfigMap(parsedConfig) fieldDrop = (fieldDrop.nil?) ? @defaultRsFieldDrop : fieldDrop kubernetesServices = (kubernetesServices.nil?) ? @defaultRsK8sServices : kubernetesServices urls = (urls.nil?) ? @defaultRsPromUrls : urls - monitorKubernetesPods = (kubernetesServices.nil?) ? @defaultRsMonitorPods : monitorKubernetesPods + monitorKubernetesPods = (monitorKubernetesPods.nil?) ? @defaultRsMonitorPods : monitorKubernetesPods + # if monitorKubernetesPods && checkForTypeArray(monitorKubernetesPodsNamespaces, String) + # namespaceFilterForMonitorPods = true + # end file_name = "/opt/telegraf-test-rs.conf" # Copy the telegraf config file to a temp file to run telegraf in test mode with this config @@ -93,11 +135,25 @@ def populateSettingValuesFromConfigMap(parsedConfig) #Replace the placeholder config values with values from custom config text = File.read(file_name) new_contents = text.gsub("$AZMON_RS_PROM_INTERVAL", interval) - new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDPASS", ((fieldPass.length > 0) ? ("[\"" + fieldPass.join("\",\"") + "\"]") : "[]")) - new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDDROP", ((fieldDrop.length > 0) ? ("[\"" + fieldDrop.join("\",\"") + "\"]") : "[]")) + fieldPassSetting = (fieldPass.length > 0) ? ("[\"" + fieldPass.join("\",\"") + "\"]") : "[]" + new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDPASS", fieldPassSetting) + fieldDropSetting = (fieldDrop.length > 0) ? ("[\"" + fieldDrop.join("\",\"") + "\"]") : "[]" + new_contents = new_contents.gsub("$AZMON_RS_PROM_FIELDDROP", fieldDropSetting) new_contents = new_contents.gsub("$AZMON_RS_PROM_URLS", ((urls.length > 0) ? ("[\"" + urls.join("\",\"") + "\"]") : "[]")) new_contents = new_contents.gsub("$AZMON_RS_PROM_K8S_SERVICES", ((kubernetesServices.length > 0) ? ("[\"" + kubernetesServices.join("\",\"") + "\"]") : "[]")) - new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", (monitorKubernetesPods ? "true" : "false")) + + # Check to see if monitor_kubernetes_pods is set to true with a valid setting for monitor_kubernetes_namespaces to enable scraping for specific namespaces + # Adding nil check here as well since checkForTypeArray returns true even if setting is nil to accomodate for other settings to be able - + # - to use defaults in case of nil settings + if monitorKubernetesPods && !monitorKubernetesPodsNamespaces.nil? && checkForTypeArray(monitorKubernetesPodsNamespaces, String) + createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) + else + #new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", (monitorKubernetesPods ? "monitor_kubernetes_pods = true" : "monitor_kubernetes_pods = false")) + replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) + # new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", ("monitor_kubernetes_pods = #{monitorKubernetesPods}")) + # new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "") + end + File.open(file_name, "w") { |file| file.puts new_contents } puts "config::Successfully substituted the placeholders in telegraf conf file for replicaset" #Set environment variables for telemetry From 84df0812e7c7865cd72a593f9131b6084758b206 Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 5 Sep 2019 17:18:21 -0700 Subject: [PATCH 02/10] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 6f2e45b8c..e55222770 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -62,8 +62,13 @@ def checkForType(variable, varType) end def replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) - new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", ("monitor_kubernetes_pods = #{monitorKubernetesPods}")) - new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "") + begin + new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", ("monitor_kubernetes_pods = #{monitorKubernetesPods}")) + new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "") + rescue => errorStr + puts "config::error::Exception while replacing default pod monitor settings: #{errorStr}" + end + return new_contents end def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) @@ -82,6 +87,7 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu tls_ca = #{@tlsCa}\n insecure_skip_verify = #{@insecureSkipVerify}\n") end + return new_contents rescue => errorStr puts "config::error::Exception while creating prometheus input plugins to filter namespaces: #{errorStr}, using defaults" replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) @@ -146,10 +152,10 @@ def populateSettingValuesFromConfigMap(parsedConfig) # Adding nil check here as well since checkForTypeArray returns true even if setting is nil to accomodate for other settings to be able - # - to use defaults in case of nil settings if monitorKubernetesPods && !monitorKubernetesPodsNamespaces.nil? && checkForTypeArray(monitorKubernetesPodsNamespaces, String) - createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) + new_contents = createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) else #new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", (monitorKubernetesPods ? "monitor_kubernetes_pods = true" : "monitor_kubernetes_pods = false")) - replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) + new_contents = replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) # new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", ("monitor_kubernetes_pods = #{monitorKubernetesPods}")) # new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "") end From f095350949f922016dc4ff1f5d25817fb141e8f7 Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 5 Sep 2019 21:40:38 -0700 Subject: [PATCH 03/10] changes --- .../scripts/tomlparser-prom-customconfig.rb | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index e55222770..1eb434f08 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -75,17 +75,18 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu begin new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", "# Commenting this out since new plugins will be created per namespace\n # $AZMON_RS_PROM_MONITOR_PODS") monitorKubernetesPodsNamespaces.each do |namespace| - new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "[[inputs.prometheus]]\n interval = #{interval}\n - monitor_kubernetes_pods = true\n - monitor_kubernetes_pods_namespaces = #{namespace}\n - fieldpass = #{fieldPassSetting}\n - fielddrop = #{fieldDropSetting}\n - metric_version = #{@metricVersion}\n - url_tag = #{@urlTag}\n - bearer_token = #{@bearerToken}\n - response_timeout = #{@responseTimeout}\n - tls_ca = #{@tlsCa}\n - insecure_skip_verify = #{@insecureSkipVerify}\n") + new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "[[inputs.prometheus]]\n + interval = \"#{interval}\"\n + monitor_kubernetes_pods = true\n + monitor_kubernetes_pods_namespaces = \"#{namespace}\"\n + fieldpass = #{fieldPassSetting}\n + fielddrop = #{fieldDropSetting}\n + metric_version = #{@metricVersion}\n + url_tag = \"#{@urlTag}\"\n + bearer_token = \"#{@bearerToken}\"\n + response_timeout = \"#{@responseTimeout}\"\n + tls_ca = \"#{@tlsCa}\"\n + insecure_skip_verify = #{@insecureSkipVerify}\n") end return new_contents rescue => errorStr From f5db92469d9eefdc814ac5ab9a528ca0f2a8593e Mon Sep 17 00:00:00 2001 From: rashmy Date: Thu, 5 Sep 2019 21:56:16 -0700 Subject: [PATCH 04/10] 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 1eb434f08..85dbcb01b 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -78,7 +78,7 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "[[inputs.prometheus]]\n interval = \"#{interval}\"\n monitor_kubernetes_pods = true\n - monitor_kubernetes_pods_namespaces = \"#{namespace}\"\n + monitor_kubernetes_pods_namespace = \"#{namespace}\"\n fieldpass = #{fieldPassSetting}\n fielddrop = #{fieldDropSetting}\n metric_version = #{@metricVersion}\n From 5b46836a8418410792ceb370beea206345d117e4 Mon Sep 17 00:00:00 2001 From: rashmy Date: Fri, 6 Sep 2019 15:07:43 -0700 Subject: [PATCH 05/10] changes --- installer/conf/telegraf-rs.conf | 1 - .../scripts/tomlparser-prom-customconfig.rb | 26 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/installer/conf/telegraf-rs.conf b/installer/conf/telegraf-rs.conf index 2eb454f43..3450ab88f 100644 --- a/installer/conf/telegraf-rs.conf +++ b/installer/conf/telegraf-rs.conf @@ -552,7 +552,6 @@ ## 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 $AZMON_RS_PROM_MONITOR_PODS fieldpass = $AZMON_RS_PROM_FIELDPASS diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 85dbcb01b..c15bd0838 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -74,20 +74,22 @@ def replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) begin new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", "# Commenting this out since new plugins will be created per namespace\n # $AZMON_RS_PROM_MONITOR_PODS") + pluginConfigsWithNamespaces = "" monitorKubernetesPodsNamespaces.each do |namespace| - new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "[[inputs.prometheus]]\n - interval = \"#{interval}\"\n - monitor_kubernetes_pods = true\n - monitor_kubernetes_pods_namespace = \"#{namespace}\"\n - fieldpass = #{fieldPassSetting}\n - fielddrop = #{fieldDropSetting}\n - metric_version = #{@metricVersion}\n - url_tag = \"#{@urlTag}\"\n - bearer_token = \"#{@bearerToken}\"\n - response_timeout = \"#{@responseTimeout}\"\n - tls_ca = \"#{@tlsCa}\"\n - insecure_skip_verify = #{@insecureSkipVerify}\n") + pluginConfigsWithNamespaces += "\n[[inputs.prometheus]]\n + interval = \"#{interval}\"\n + monitor_kubernetes_pods = true\n + monitor_kubernetes_pods_namespace = \"#{namespace}\"\n + fieldpass = #{fieldPassSetting}\n + fielddrop = #{fieldDropSetting}\n + metric_version = #{@metricVersion}\n + url_tag = \"#{@urlTag}\"\n + bearer_token = \"#{@bearerToken}\"\n + response_timeout = \"#{@responseTimeout}\"\n + tls_ca = \"#{@tlsCa}\"\n + insecure_skip_verify = #{@insecureSkipVerify}\n" end + new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", pluginConfigsWithNamespaces) return new_contents rescue => errorStr puts "config::error::Exception while creating prometheus input plugins to filter namespaces: #{errorStr}, using defaults" From 653cc0b5422ce15d233e2411bc38be0750e878ea Mon Sep 17 00:00:00 2001 From: rashmy Date: Fri, 6 Sep 2019 15:30:26 -0700 Subject: [PATCH 06/10] changes --- .../scripts/tomlparser-prom-customconfig.rb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index c15bd0838..cf4c42a5c 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -77,17 +77,17 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu pluginConfigsWithNamespaces = "" monitorKubernetesPodsNamespaces.each do |namespace| pluginConfigsWithNamespaces += "\n[[inputs.prometheus]]\n - interval = \"#{interval}\"\n - monitor_kubernetes_pods = true\n - monitor_kubernetes_pods_namespace = \"#{namespace}\"\n - fieldpass = #{fieldPassSetting}\n - fielddrop = #{fieldDropSetting}\n - metric_version = #{@metricVersion}\n - url_tag = \"#{@urlTag}\"\n - bearer_token = \"#{@bearerToken}\"\n - response_timeout = \"#{@responseTimeout}\"\n - tls_ca = \"#{@tlsCa}\"\n - insecure_skip_verify = #{@insecureSkipVerify}\n" + interval = \"#{interval}\" + monitor_kubernetes_pods = true + monitor_kubernetes_pods_namespace = \"#{namespace}\" + fieldpass = #{fieldPassSetting} + fielddrop = #{fieldDropSetting} + metric_version = #{@metricVersion} + url_tag = \"#{@urlTag}\" + bearer_token = \"#{@bearerToken}\" + response_timeout = \"#{@responseTimeout}\" + tls_ca = \"#{@tlsCa}\" + insecure_skip_verify = #{@insecureSkipVerify}\n" end new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", pluginConfigsWithNamespaces) return new_contents From c058b51b3f44368666c9d1acba0e9a045fce0eee Mon Sep 17 00:00:00 2001 From: rashmy Date: Fri, 6 Sep 2019 21:11:45 -0700 Subject: [PATCH 07/10] chnages --- 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 cf4c42a5c..09a427bbf 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -76,7 +76,7 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", "# Commenting this out since new plugins will be created per namespace\n # $AZMON_RS_PROM_MONITOR_PODS") pluginConfigsWithNamespaces = "" monitorKubernetesPodsNamespaces.each do |namespace| - pluginConfigsWithNamespaces += "\n[[inputs.prometheus]]\n + pluginConfigsWithNamespaces += "\n[[inputs.prometheus]] interval = \"#{interval}\" monitor_kubernetes_pods = true monitor_kubernetes_pods_namespace = \"#{namespace}\" From ab3133a1fd7e76a5d6cfd91656383fe03739dc5f Mon Sep 17 00:00:00 2001 From: rashmy Date: Fri, 6 Sep 2019 21:16:30 -0700 Subject: [PATCH 08/10] changes --- installer/scripts/tomlparser-prom-customconfig.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index 09a427bbf..b3346b5fc 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -114,9 +114,6 @@ def populateSettingValuesFromConfigMap(parsedConfig) monitorKubernetesPods = parsedConfig[:prometheus_data_collection_settings][:cluster][:monitor_kubernetes_pods] monitorKubernetesPodsNamespaces = parsedConfig[:prometheus_data_collection_settings][:cluster][:monitor_kubernetes_pods_namespaces] - # Setting this to false by default, will be set to true/false based on the setting evaluation for 'monitor_kubernetes_pods_namespaces' - #namespaceFilterForMonitorPods = false - # Check for the right datattypes to enforce right setting values if checkForType(interval, String) && checkForTypeArray(fieldPass, String) && @@ -132,9 +129,6 @@ def populateSettingValuesFromConfigMap(parsedConfig) kubernetesServices = (kubernetesServices.nil?) ? @defaultRsK8sServices : kubernetesServices urls = (urls.nil?) ? @defaultRsPromUrls : urls monitorKubernetesPods = (monitorKubernetesPods.nil?) ? @defaultRsMonitorPods : monitorKubernetesPods - # if monitorKubernetesPods && checkForTypeArray(monitorKubernetesPodsNamespaces, String) - # namespaceFilterForMonitorPods = true - # end file_name = "/opt/telegraf-test-rs.conf" # Copy the telegraf config file to a temp file to run telegraf in test mode with this config @@ -157,10 +151,7 @@ def populateSettingValuesFromConfigMap(parsedConfig) if monitorKubernetesPods && !monitorKubernetesPodsNamespaces.nil? && checkForTypeArray(monitorKubernetesPodsNamespaces, String) new_contents = createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) else - #new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", (monitorKubernetesPods ? "monitor_kubernetes_pods = true" : "monitor_kubernetes_pods = false")) new_contents = replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) - # new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", ("monitor_kubernetes_pods = #{monitorKubernetesPods}")) - # new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "") end File.open(file_name, "w") { |file| file.puts new_contents } From 73d72580af4b58cbdb126b23a7d9eecb34ae0db5 Mon Sep 17 00:00:00 2001 From: rashmy Date: Mon, 9 Sep 2019 14:15:12 -0700 Subject: [PATCH 09/10] telemetry changes --- installer/scripts/tomlparser-prom-customconfig.rb | 4 ++++ source/code/plugin/in_kube_nodes.rb | 2 ++ 2 files changed, 6 insertions(+) diff --git a/installer/scripts/tomlparser-prom-customconfig.rb b/installer/scripts/tomlparser-prom-customconfig.rb index b3346b5fc..c2e4fa50f 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -150,8 +150,10 @@ def populateSettingValuesFromConfigMap(parsedConfig) # - to use defaults in case of nil settings if monitorKubernetesPods && !monitorKubernetesPodsNamespaces.nil? && checkForTypeArray(monitorKubernetesPodsNamespaces, String) new_contents = createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKubernetesPodsNamespaces, new_contents, interval, fieldPassSetting, fieldDropSetting) + monitorKubernetesPodsNamespacesLength = monitorKubernetesPodsNamespaces.length else new_contents = replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods) + monitorKubernetesPodsNamespacesLength = 0 end File.open(file_name, "w") { |file| file.puts new_contents } @@ -166,6 +168,8 @@ def populateSettingValuesFromConfigMap(parsedConfig) file.write("export TELEMETRY_RS_PROM_K8S_SERVICES_LENGTH=#{kubernetesServices.length}\n") file.write("export TELEMETRY_RS_PROM_URLS_LENGTH=#{urls.length}\n") file.write("export TELEMETRY_RS_PROM_MONITOR_PODS=\"#{monitorKubernetesPods}\"\n") + file.write("export TELEMETRY_RS_PROM_MONITOR_PODS_NS_LENGTH=\"#{monitorKubernetesPodsNamespacesLength}\"\n") + # Close file after writing all environment variables file.close puts "config::Successfully created telemetry file for replicaset" diff --git a/source/code/plugin/in_kube_nodes.rb b/source/code/plugin/in_kube_nodes.rb index 24ab51d4c..7249957ab 100644 --- a/source/code/plugin/in_kube_nodes.rb +++ b/source/code/plugin/in_kube_nodes.rb @@ -15,6 +15,7 @@ class Kube_nodeInventory_Input < Input @@rsPromK8sServiceCount = ENV["TELEMETRY_RS_PROM_K8S_SERVICES_LENGTH"] @@rsPromUrlCount = ENV["TELEMETRY_RS_PROM_URLS_LENGTH"] @@rsPromMonitorPods = ENV["TELEMETRY_RS_PROM_MONITOR_PODS"] + @@rsPromMonitorPodsNamespaceLength = ENV["TELEMETRY_RS_PROM_MONITOR_PODS_NS_LENGTH"] def initialize super @@ -150,6 +151,7 @@ def enumerate properties["rsPromServ"] = @@rsPromK8sServiceCount properties["rsPromUrl"] = @@rsPromUrlCount properties["rsPromMonPods"] = @@rsPromMonitorPods + properties["rsPromMonPodsNs"] = @@rsPromMonitorPodsNamespaceLength end ApplicationInsightsUtility.sendMetricTelemetry("NodeCoreCapacity", capacityInfo["cpu"], properties) telemetrySent = true From 68add7a3fee23c3dadf1cf0ac4501d53b6248e31 Mon Sep 17 00:00:00 2001 From: rashmy Date: Tue, 10 Sep 2019 16:30:01 -0700 Subject: [PATCH 10/10] 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 c2e4fa50f..d44bf3342 100644 --- a/installer/scripts/tomlparser-prom-customconfig.rb +++ b/installer/scripts/tomlparser-prom-customconfig.rb @@ -76,7 +76,11 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", "# Commenting this out since new plugins will be created per namespace\n # $AZMON_RS_PROM_MONITOR_PODS") pluginConfigsWithNamespaces = "" monitorKubernetesPodsNamespaces.each do |namespace| - pluginConfigsWithNamespaces += "\n[[inputs.prometheus]] + if !namespace.nil? + #Stripping namespaces to remove leading and trailing whitespaces + namespace.strip! + if namespace.length > 0 + pluginConfigsWithNamespaces += "\n[[inputs.prometheus]] interval = \"#{interval}\" monitor_kubernetes_pods = true monitor_kubernetes_pods_namespace = \"#{namespace}\" @@ -88,6 +92,8 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu response_timeout = \"#{@responseTimeout}\" tls_ca = \"#{@tlsCa}\" insecure_skip_verify = #{@insecureSkipVerify}\n" + end + end end new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", pluginConfigsWithNamespaces) return new_contents