Skip to content

Commit d9b592a

Browse files
KubeMonAgentEvents changes to collect configuration events (#267)
* changes * changes * changes * changes * changes * changes * env changes * changes * changes * changes * reverting * changes * cahnges * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * chnages * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes
1 parent 421a41e commit d9b592a

File tree

9 files changed

+378
-38
lines changed

9 files changed

+378
-38
lines changed

installer/conf/td-agent-bit.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Path /var/log/containers/omsagent*.log
2929
DB /var/opt/microsoft/docker-cimprov/state/omsagent-ai.db
3030
DB.Sync Off
31+
Parser docker
3132
Mem_Buf_Limit 1m
3233
Path_Key filepath
3334
Skip_Long_Lines On
@@ -51,7 +52,6 @@
5152
[FILTER]
5253
Name grep
5354
Match oms.container.log.flbplugin.*
54-
Exclude log E! [\[]inputs.prometheus[\]]
5555

5656
[OUTPUT]
5757
Name oms

installer/datafiles/base_container.data

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ MAINTAINER: 'Microsoft Corporation'
116116
/opt/tomlparser.rb; installer/scripts/tomlparser.rb; 755; root; root
117117
/opt/tomlparser-prom-customconfig.rb; installer/scripts/tomlparser-prom-customconfig.rb; 755; root; root
118118
/opt/td-agent-bit-conf-customizer.rb; installer/scripts/td-agent-bit-conf-customizer.rb; 755; root; root
119+
/opt/ConfigParseErrorLogger.rb; installer/scripts/ConfigParseErrorLogger.rb; 755; root; root
119120

120121

121122

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/local/bin/ruby
2+
# frozen_string_literal: true
3+
4+
class ConfigParseErrorLogger
5+
require "json"
6+
7+
def initialize
8+
end
9+
10+
class << self
11+
def logError(message)
12+
begin
13+
errorMessage = "config::error::" + message
14+
jsonMessage = errorMessage.to_json
15+
STDERR.puts jsonMessage
16+
rescue => errorStr
17+
puts "Error in ConfigParserErrorLogger::logError: #{errorStr}"
18+
end
19+
end
20+
end
21+
end

installer/scripts/td-agent-bit-conf-customizer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/local/bin/ruby
2+
require_relative "ConfigParseErrorLogger"
23

34
@td_agent_bit_conf_path = "/etc/opt/microsoft/docker-cimprov/td-agent-bit.conf"
45

@@ -40,7 +41,7 @@ def substituteFluentBitPlaceHolders
4041
File.open(@td_agent_bit_conf_path, "w") { |file| file.puts new_contents }
4142
puts "config::Successfully substituted the placeholders in td-agent-bit.conf file"
4243
rescue => errorStr
43-
puts "td-agent-bit-config-customizer: error while substituting values: #{errorStr}"
44+
ConfigParseErrorLogger.logError("td-agent-bit-config-customizer: error while substituting values in td-agent-bit.conf file: #{errorStr}")
4445
end
4546
end
4647

installer/scripts/tomlparser-prom-customconfig.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/local/bin/ruby
22

33
require_relative "tomlrb"
4+
require_relative "ConfigParseErrorLogger"
45
require "fileutils"
56

67
@promConfigMapMountPath = "/etc/config/settings/prometheus-data-collection-settings"
@@ -40,7 +41,7 @@ def parseConfigMap
4041
return nil
4142
end
4243
rescue => errorStr
43-
puts "config::error::Exception while parsing toml config file for prometheus config: #{errorStr}, using defaults"
44+
ConfigParseErrorLogger.logError("Exception while parsing config map for prometheus config: #{errorStr}, using defaults, please check config map for errors")
4445
return nil
4546
end
4647
end
@@ -66,7 +67,7 @@ def replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods)
6667
new_contents = new_contents.gsub("$AZMON_RS_PROM_MONITOR_PODS", ("monitor_kubernetes_pods = #{monitorKubernetesPods}"))
6768
new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", "")
6869
rescue => errorStr
69-
puts "config::error::Exception while replacing default pod monitor settings: #{errorStr}"
70+
puts "Exception while replacing default pod monitor settings: #{errorStr}"
7071
end
7172
return new_contents
7273
end
@@ -98,7 +99,7 @@ def createPrometheusPluginsWithNamespaceSetting(monitorKubernetesPods, monitorKu
9899
new_contents = new_contents.gsub("$AZMON_RS_PROM_PLUGINS_WITH_NAMESPACE_FILTER", pluginConfigsWithNamespaces)
99100
return new_contents
100101
rescue => errorStr
101-
puts "config::error::Exception while creating prometheus input plugins to filter namespaces: #{errorStr}, using defaults"
102+
puts "Exception while creating prometheus input plugins to filter namespaces: #{errorStr}, using defaults"
102103
replaceDefaultMonitorPodSettings(new_contents, monitorKubernetesPods)
103104
end
104105
end
@@ -181,10 +182,10 @@ def populateSettingValuesFromConfigMap(parsedConfig)
181182
puts "config::Successfully created telemetry file for replicaset"
182183
end
183184
else
184-
puts "config::Typecheck failed for prometheus config settings for replicaset, using defaults"
185+
ConfigParseErrorLogger.logError("Typecheck failed for prometheus config settings for replicaset, using defaults, please use right types for all settings")
185186
end # end of type check condition
186187
rescue => errorStr
187-
puts "config::error::Exception while parsing config file for prometheus config for replicaset: #{errorStr}, using defaults"
188+
ConfigParseErrorLogger.logError("Exception while parsing config file for prometheus config for replicaset: #{errorStr}, using defaults")
188189
setRsPromDefaults
189190
puts "****************End Prometheus Config Processing********************"
190191
end
@@ -236,16 +237,16 @@ def populateSettingValuesFromConfigMap(parsedConfig)
236237
puts "config::Successfully created telemetry file for daemonset"
237238
end
238239
else
239-
puts "config::Typecheck failed for prometheus config settings for daemonset, using defaults"
240+
ConfigParseErrorLogger.logError("Typecheck failed for prometheus config settings for daemonset, using defaults, please use right types for all settings")
240241
end # end of type check condition
241242
rescue => errorStr
242-
puts "config::error::Exception while parsing config file for prometheus config for daemonset: #{errorStr}, using defaults"
243+
ConfigParseErrorLogger.logError("Exception while parsing config file for prometheus config for daemonset: #{errorStr}, using defaults, please check correctness of configmap")
243244
puts "****************End Prometheus Config Processing********************"
244245
end
245246
end # end of controller type check
246247
end
247248
else
248-
puts "config::error:: Controller undefined while processing prometheus config, using defaults"
249+
ConfigParseErrorLogger.logError("Controller undefined while processing prometheus config, using defaults")
249250
end
250251
end
251252

@@ -258,7 +259,7 @@ def populateSettingValuesFromConfigMap(parsedConfig)
258259
end
259260
else
260261
if (File.file?(@promConfigMapMountPath))
261-
puts "config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults"
262+
ConfigParseErrorLogger.logError("config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults, please use supported version")
262263
else
263264
puts "config::No configmap mounted for prometheus custom config, using defaults"
264265
end

installer/scripts/tomlparser.rb

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/local/bin/ruby
22

33
require_relative "tomlrb"
4-
require 'json'
4+
require_relative "ConfigParseErrorLogger"
5+
require "json"
56

67
@log_settings_config_map_mount_path = "/etc/config/settings/log-data-collection-settings"
78
@agent_settings_config_map_mount_path = "/etc/config/settings/agent-settings"
@@ -33,7 +34,7 @@ def parseConfigMap(path)
3334
return nil
3435
end
3536
rescue => errorStr
36-
puts "config::error::Exception while parsing toml config file: #{errorStr}, using defaults"
37+
ConfigParseErrorLogger.logError("Exception while parsing config map for log collection/env variable settings: #{errorStr}, using defaults, please check config map for errors")
3738
@excludePath = "*_kube-system_*.log"
3839
return nil
3940
end
@@ -70,7 +71,7 @@ def populateSettingValuesFromConfigMap(parsedConfig)
7071
end
7172
end
7273
rescue => errorStr
73-
puts "config::error::Exception while reading config settings for stdout log collection - #{errorStr}, using defaults"
74+
ConfigParseErrorLogger.logError("Exception while reading config map settings for stdout log collection - #{errorStr}, using defaults, please check config map for errors")
7475
end
7576

7677
#Get stderr log config settings
@@ -107,7 +108,7 @@ def populateSettingValuesFromConfigMap(parsedConfig)
107108
end
108109
end
109110
rescue => errorStr
110-
puts "config::error:Exception while reading config settings for stderr log collection - #{errorStr}, using defaults"
111+
ConfigParseErrorLogger.logError("Exception while reading config map settings for stderr log collection - #{errorStr}, using defaults, please check config map for errors")
111112
end
112113

113114
#Get environment variables log config settings
@@ -117,42 +118,43 @@ def populateSettingValuesFromConfigMap(parsedConfig)
117118
puts "config::Using config map setting for cluster level environment variable collection"
118119
end
119120
rescue => errorStr
120-
puts "config::error::Exception while reading config settings for cluster level environment variable collection - #{errorStr}, using defaults"
121+
ConfigParseErrorLogger.logError("Exception while reading config map settings for cluster level environment variable collection - #{errorStr}, using defaults, please check config map for errors")
121122
end
122123
end
123124

124125
begin
125126
if !parsedConfig.nil? && !parsedConfig[:agent_settings].nil? && !parsedConfig[:agent_settings][:health_model].nil? && !parsedConfig[:agent_settings][:health_model][:enabled].nil?
126-
@enable_health_model = parsedConfig[:agent_settings][:health_model][:enabled]
127+
@enable_health_model = parsedConfig[:agent_settings][:health_model][:enabled]
127128
else
128-
@enable_health_model = false
129+
@enable_health_model = false
129130
end
130131
puts "enable_health_model = #{@enable_health_model}"
131132
rescue => errorStr
132-
puts "config::error:Exception while reading config settings for health_model enabled setting - #{errorStr}, using defaults"
133+
ConfigParseErrorLogger.logError("Exception while reading config map settings for health_model enabled setting - #{errorStr}, using defaults, please check config map for errors")
133134
@enable_health_model = false
134135
end
135136
end
136137

137138
@configSchemaVersion = ENV["AZMON_AGENT_CFG_SCHEMA_VERSION"]
138139
puts "****************Start Config Processing********************"
140+
139141
if !@configSchemaVersion.nil? && !@configSchemaVersion.empty? && @configSchemaVersion.strip.casecmp("v1") == 0 #note v1 is the only supported schema version , so hardcoding it
140-
configMapSettings = {}
142+
configMapSettings = {}
141143

142-
#iterate over every *settings file and build a hash of settings
143-
Dir["/etc/config/settings/*settings"].each{|file|
144-
puts "Parsing File #{file}"
145-
settings = parseConfigMap(file)
146-
if !settings.nil?
147-
configMapSettings = configMapSettings.merge(settings)
148-
end
149-
}
144+
#iterate over every *settings file and build a hash of settings
145+
Dir["/etc/config/settings/*settings"].each { |file|
146+
puts "Parsing File #{file}"
147+
settings = parseConfigMap(file)
148+
if !settings.nil?
149+
configMapSettings = configMapSettings.merge(settings)
150+
end
151+
}
150152

151153
if !configMapSettings.nil?
152154
populateSettingValuesFromConfigMap(configMapSettings)
153155
end
154156
else
155-
puts "config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults"
157+
ConfigParseErrorLogger.logError("config::unsupported/missing config schema version - '#{@configSchemaVersion}' , using defaults, please use supported schema version")
156158
@excludePath = "*_kube-system_*.log"
157159
end
158160

@@ -178,13 +180,13 @@ def populateSettingValuesFromConfigMap(parsedConfig)
178180
file.write("export AZMON_STDERR_EXCLUDED_NAMESPACES=#{@stderrExcludeNamespaces}\n")
179181
file.write("export AZMON_CLUSTER_COLLECT_ENV_VAR=#{@collectClusterEnvVariables}\n")
180182
file.write("export AZMON_CLUSTER_LOG_TAIL_EXCLUDE_PATH=#{@excludePath}\n")
181-
#health_model settings
183+
#health_model settings
182184
file.write("export AZMON_CLUSTER_ENABLE_HEALTH_MODEL=#{@enable_health_model}\n")
183185
# Close file after writing all environment variables
184186
file.close
185187
puts "Both stdout & stderr log collection are turned off for namespaces: '#{@excludePath}' "
186188
puts "****************End Config Processing********************"
187189
else
188-
puts "config::error::Exception while opening file for writing config environment variables"
190+
puts "Exception while opening file for writing config environment variables"
189191
puts "****************End Config Processing********************"
190192
end

0 commit comments

Comments
 (0)