This allows to enable/disable and list probes either internally or through REST.
* GET /instrumentation_probes/all Will return the list of currently defined probes in the running instance * PUT /instrumentation_probes/unused Will enable all probes * DELETE /instrumentation_probes/unused Will disable all probes Signed-off-by: Brice Figureau <[email protected]> --- lib/puppet/indirector/instrumentation_probe.rb | 3 + .../indirector/instrumentation_probe/local.rb | 24 +++++++ .../indirector/instrumentation_probe/rest.rb | 5 ++ lib/puppet/util/instrumentation.rb | 2 + .../util/instrumentation/indirection_probe.rb | 24 +++++++ .../indirector/instrumentation_probe/local_spec.rb | 64 ++++++++++++++++++++ .../indirector/instrumentation_probe/rest_spec.rb | 12 ++++ 7 files changed, 134 insertions(+), 0 deletions(-) create mode 100644 lib/puppet/indirector/instrumentation_probe.rb create mode 100644 lib/puppet/indirector/instrumentation_probe/local.rb create mode 100644 lib/puppet/indirector/instrumentation_probe/rest.rb create mode 100644 lib/puppet/util/instrumentation/indirection_probe.rb create mode 100644 spec/unit/indirector/instrumentation_probe/local_spec.rb create mode 100644 spec/unit/indirector/instrumentation_probe/rest_spec.rb diff --git a/lib/puppet/indirector/instrumentation_probe.rb b/lib/puppet/indirector/instrumentation_probe.rb new file mode 100644 index 0000000..3e51444 --- /dev/null +++ b/lib/puppet/indirector/instrumentation_probe.rb @@ -0,0 +1,3 @@ +# A stub class, so our constants work. +class Puppet::Indirector::InstrumentationProbe +end diff --git a/lib/puppet/indirector/instrumentation_probe/local.rb b/lib/puppet/indirector/instrumentation_probe/local.rb new file mode 100644 index 0000000..6adf48c --- /dev/null +++ b/lib/puppet/indirector/instrumentation_probe/local.rb @@ -0,0 +1,24 @@ +require 'puppet/indirector/instrumentation_probe' +require 'puppet/indirector/code' +require 'puppet/util/instrumentation/indirection_probe' + +class Puppet::Indirector::InstrumentationProbe::Local < Puppet::Indirector::Code + def find(request) + end + + def search(request) + probes = [] + Puppet::Util::Instrumentation::Instrumentable.each_probes do |probe| + probes << Puppet::Util::Instrumentation::IndirectionProbe.new("#{probe.klass}.#{probe.method}") + end + probes + end + + def save(request) + Puppet::Util::Instrumentation::Instrumentable.enable_probes + end + + def destroy(request) + Puppet::Util::Instrumentation::Instrumentable.disable_probes + end +end diff --git a/lib/puppet/indirector/instrumentation_probe/rest.rb b/lib/puppet/indirector/instrumentation_probe/rest.rb new file mode 100644 index 0000000..57e6fcf --- /dev/null +++ b/lib/puppet/indirector/instrumentation_probe/rest.rb @@ -0,0 +1,5 @@ +require 'puppet/indirector/rest' +require 'puppet/indirector/instrumentation_probe' + +class Puppet::Indirector::InstrumentationProbe::Rest < Puppet::Indirector::REST +end diff --git a/lib/puppet/util/instrumentation.rb b/lib/puppet/util/instrumentation.rb index 90cd856..60b44d4 100644 --- a/lib/puppet/util/instrumentation.rb +++ b/lib/puppet/util/instrumentation.rb @@ -113,6 +113,8 @@ class Puppet::Util::Instrumentation end def self.init + # let's init our probe indirection + require 'puppet/util/instrumentation/indirection_probe' synchronize { @listeners ||= {} @listeners_of ||= {} diff --git a/lib/puppet/util/instrumentation/indirection_probe.rb b/lib/puppet/util/instrumentation/indirection_probe.rb new file mode 100644 index 0000000..f013571 --- /dev/null +++ b/lib/puppet/util/instrumentation/indirection_probe.rb @@ -0,0 +1,24 @@ +require 'puppet/indirector' + +# We need to use a distinct class than Probe for the indirector because +# the Indirection class declares some probe, and this would be giant +# dependency cycle. +class Puppet::Util::Instrumentation::IndirectionProbe + extend Puppet::Indirector + + indirects :instrumentation_probe, :terminus_class => :local + + attr_reader :probe_name + + def initialize(probe_name) + @probe_name = probe_name + end + + def to_pson + { :name => probe_name }.to_pson + end + + def self.from_pson(data) + self.new("dummy") + end +end \ No newline at end of file diff --git a/spec/unit/indirector/instrumentation_probe/local_spec.rb b/spec/unit/indirector/instrumentation_probe/local_spec.rb new file mode 100644 index 0000000..2dbab2c --- /dev/null +++ b/spec/unit/indirector/instrumentation_probe/local_spec.rb @@ -0,0 +1,64 @@ + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/util/instrumentation/indirection_probe' +require 'puppet/indirector/instrumentation_probe/local' + +describe Puppet::Indirector::InstrumentationProbe::Local do + it "should be a subclass of the Code terminus" do + Puppet::Indirector::InstrumentationProbe::Local.superclass.should equal(Puppet::Indirector::Code) + end + + it "should be registered with the configuration store indirection" do + indirection = Puppet::Indirector::Indirection.instance(:instrumentation_probe) + Puppet::Indirector::InstrumentationProbe::Local.indirection.should equal(indirection) + end + + it "should have its name set to :local" do + Puppet::Indirector::InstrumentationProbe::Local.name.should == :local + end +end + +describe Puppet::Indirector::InstrumentationProbe::Local do + before :each do + Puppet::Util::Instrumentation.stubs(:listener) + @probe = Puppet::Indirector::InstrumentationProbe::Local.new + @name = "me" + @request = stub 'request', :key => @name + end + + describe "when finding probes" do + it "should do nothing" do + @probe.find(@request).should be_nil + end + end + + describe "when searching probes" do + it "should return a list of all loaded probes irregardless of the given key" do + instance1 = stub 'instance1', :method => "probe1", :klass => "Klass1" + instance2 = stub 'instance2', :method => "probe2", :klass => "Klass2" + Puppet::Util::Instrumentation::IndirectionProbe.expects(:new).with("Klass1.probe1").returns(:instance1) + Puppet::Util::Instrumentation::IndirectionProbe.expects(:new).with("Klass2.probe2").returns(:instance2) + Puppet::Util::Instrumentation::Instrumentable.expects(:each_probes).multiple_yields(instance1, instance2) + @probe.search(@request).should == [ :instance1, :instance2] + end + end + + describe "when saving probes" do + it "should enable probes" do + newprobe = stub 'probe', :name => @name + @request.stubs(:instance).returns(newprobe) + Puppet::Util::Instrumentation::Instrumentable.expects(:enable_probes) + @probe.save(@request) + end + end + + describe "when destroying probes" do + it "should disable probes" do + newprobe = stub 'probe', :name => @name + @request.stubs(:instance).returns(newprobe) + Puppet::Util::Instrumentation::Instrumentable.expects(:disable_probes) + @probe.destroy(@request) + end + end +end diff --git a/spec/unit/indirector/instrumentation_probe/rest_spec.rb b/spec/unit/indirector/instrumentation_probe/rest_spec.rb new file mode 100644 index 0000000..bc51ffa --- /dev/null +++ b/spec/unit/indirector/instrumentation_probe/rest_spec.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +require 'puppet/util/instrumentation/indirection_probe' +require 'puppet/indirector/instrumentation_probe/rest' + +describe Puppet::Indirector::InstrumentationProbe::Rest do + it "should be a subclass of Puppet::Indirector::REST" do + Puppet::Indirector::InstrumentationProbe::Rest.superclass.should equal(Puppet::Indirector::REST) + end +end -- 1.7.2.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
