From a3ce58dc859bdbc36acd8519525b77125ab3cf78 Mon Sep 17 00:00:00 2001 From: Zach Leslie Date: Sun, 21 Jun 2015 21:57:56 -0700 Subject: [PATCH 1/2] Improve debugging, add timing information Ldap has the potential to slow down compiles if a search takes too long. Here we add timing information to the debug output, so that in case of question, we can at least have a method of determining the time a given search took. --- lib/puppet_x/ldapquery.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/puppet_x/ldapquery.rb b/lib/puppet_x/ldapquery.rb index 2880ca7..e0ce787 100644 --- a/lib/puppet_x/ldapquery.rb +++ b/lib/puppet_x/ldapquery.rb @@ -59,7 +59,6 @@ module PuppetX } end - Puppet.debug(conf) return conf end @@ -73,8 +72,7 @@ module PuppetX conf = self.get_config() - Puppet.debug("Searching ldap base #{base} using #{@filter} for #{@attributes}") - + start_time = Time.now.to_i ldap = Net::LDAP.new(conf) ldapfilter = Net::LDAP::Filter.construct(@filter) @@ -87,9 +85,12 @@ module PuppetX :time => 10) do |entry| entries << entry end - Puppet.debug(entries) + end_time = Time.now.to_i + Puppet.debug("Searching #{@base} for #{@attributes} using #{@filter} took #{end_time - start_time} seconds") return entries - rescue + rescue Exception => e + Puppet.debug('There was an error searching LDAP #{e.message}') + Puppet.debug('Returning empty array') return [] end end From 9969f16a60082452367d7857634d075eb85972f2 Mon Sep 17 00:00:00 2001 From: Zach Leslie Date: Thu, 20 Aug 2015 10:05:54 -0700 Subject: [PATCH 2/2] Increase granularity --- lib/puppet_x/ldapquery.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/puppet_x/ldapquery.rb b/lib/puppet_x/ldapquery.rb index e0ce787..411c5db 100644 --- a/lib/puppet_x/ldapquery.rb +++ b/lib/puppet_x/ldapquery.rb @@ -72,7 +72,7 @@ module PuppetX conf = self.get_config() - start_time = Time.now.to_i + start_time = Time.now ldap = Net::LDAP.new(conf) ldapfilter = Net::LDAP::Filter.construct(@filter) @@ -85,8 +85,10 @@ module PuppetX :time => 10) do |entry| entries << entry end - end_time = Time.now.to_i - Puppet.debug("Searching #{@base} for #{@attributes} using #{@filter} took #{end_time - start_time} seconds") + end_time = Time.now + time_delta = sprintf('%.3f', end_time - start_time) + + Puppet.debug("Searching #{@base} for #{@attributes} using #{@filter} took #{time_delta} seconds") return entries rescue Exception => e Puppet.debug('There was an error searching LDAP #{e.message}')