Skip to content

Instantly share code, notes, and snippets.

@kbarber
Last active December 18, 2015 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbarber/5767525 to your computer and use it in GitHub Desktop.
Save kbarber/5767525 to your computer and use it in GitHub Desktop.
Patch for timing the puppetdb terminus
diff --git a/indirector/catalog/puppetdb.rb b/indirector/catalog/puppetdb.rb
index 227eeab..6eb6ed0 100644
--- a/indirector/catalog/puppetdb.rb
+++ b/indirector/catalog/puppetdb.rb
@@ -7,9 +7,15 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
include Puppet::Util::Puppetdb::CommandNames
def save(request)
+ start = Time.now
+
catalog = munge_catalog(request.instance)
- submit_command(request.key, catalog, CommandReplaceCatalog, 2)
+ result = submit_command(request.key, catalog, CommandReplaceCatalog, 2)
+
+ Puppet.warning("catalog/puppetdb#save timing is #{(Time.now-start) * 1000000}")
+
+ result
end
def find(request)
diff --git a/indirector/resource/puppetdb.rb b/indirector/resource/puppetdb.rb
index 0c6c59b..32c16ce 100644
--- a/indirector/resource/puppetdb.rb
+++ b/indirector/resource/puppetdb.rb
@@ -5,6 +5,8 @@ class Puppet::Resource::Puppetdb < Puppet::Indirector::REST
include Puppet::Util::Puppetdb
def search(request)
+ start = Time.now
+
type = request.key
host = request.options[:host]
filter = request.options[:filter]
@@ -36,7 +38,7 @@ class Puppet::Resource::Puppetdb < Puppet::Indirector::REST
resources = PSON.load(response.body)
- resources.map do |res|
+ result = resources.map do |res|
params = res['parameters'] || {}
params = params.map do |name,value|
Puppet::Parser::Resource::Param.new(:name => name, :value => value)
@@ -46,6 +48,10 @@ class Puppet::Resource::Puppetdb < Puppet::Indirector::REST
result.collector_id = "#{res['certname']}|#{res['type']}|#{res['title']}"
result
end
+
+ Puppet.warning("resource/puppetdb#search time for #{request.key} collection is: #{(Time.now-start)*1000000.0}")
+
+ result
end
def build_expression(filter)
Expected output:
Jun 12 18:47:18 puppetdb1 puppet-master[64698]: resource/puppetdb#search time for Notify collection is: 77485.0
Jun 12 18:47:18 puppetdb1 puppet-master[64698]: resource/puppetdb#search time for Whit collection is: 68959.0
Jun 12 18:47:18 puppetdb1 puppet-master[64698]: catalog/puppetdb#save timing is 135567.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment