Andrew Bogott has submitted this change and it was merged.

Change subject: Fix race condition in puppet_statsd by deferring config file 
check
......................................................................


Fix race condition in puppet_statsd by deferring config file check

Deferring the configuration file loading to the actual report callback ensures
that (a) it runs at the end of the Puppet run, and thus after
/etc/puppet/statsd.yaml would have been populated, and (b) that it doesn't run
at all if the statsd reporter isn't configured.

Change-Id: I4cea6f54ebac80e7ab580beb9d9134808b808012
---
M modules/puppet_statsd/lib/puppet/reports/statsd.rb
1 file changed, 10 insertions(+), 12 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/puppet_statsd/lib/puppet/reports/statsd.rb 
b/modules/puppet_statsd/lib/puppet/reports/statsd.rb
index 8aa6310..bd0d65d 100644
--- a/modules/puppet_statsd/lib/puppet/reports/statsd.rb
+++ b/modules/puppet_statsd/lib/puppet/reports/statsd.rb
@@ -7,26 +7,24 @@
 Puppet::Reports.register_report(:statsd) do
     desc = 'Send Puppet metrics to StatsD'
 
-    config_file = File.join Puppet.settings[:confdir], 'statsd.yaml'
 
-    unless File.exist? config_file
-        raise Puppet::ParseError, "Required StatsD reporter configuration file 
#{config_file} is missing"
+    def load_config
+        config_file = File.join Puppet.settings[:confdir], 'statsd.yaml'
+        raise Puppet::ParseError, "#{config_file} is missing" unless 
File.exists? config_file
+        YAML.load_file(config_file)
     end
 
-    config = YAML.load_file(config_file)
-
-    STATSD_HOST = config[:statsd_host]
-    STATSD_PORT = config[:statsd_port]
-    METRIC_FORMAT = config[:metric_format]
-
     def process
-        Puppet.notice "Sending metrics for #{self.host} to 
#{STATSD_HOST}:#{STATSD_PORT}."
+        config = load_config
         hostname = self.host
+        Puppet.notice "Sending metrics for #{self.host} to "\
+            "#{config[:statsd_host]}:#{config[:statsd_port]}.."
+
         socket = UDPSocket.new
         self.metrics['time'].values.each do |metric,description,value|
             value = (value * 1000).round  # Convert fractional seconds to 
whole miliseconds
-            name = ERB.new(METRIC_FORMAT).result(binding)
-            socket.send("#{name}:#{value}|ms", 0, STATSD_HOST, STATSD_PORT)
+            name = ERB.new(config[:metric_format]).result(binding)
+            socket.send("#{name}:#{value}|ms", 0, config[:statsd_host], 
config[:statsd_port])
         end
         socket.close
     end

-- 
To view, visit https://gerrit.wikimedia.org/r/89112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4cea6f54ebac80e7ab580beb9d9134808b808012
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Andrew Bogott <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to