instrumental_agent 0.9.11 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +3 -0
 - data/lib/instrumental/agent.rb +1 -3
 - data/lib/instrumental/version.rb +1 -1
 - data/spec/agent_spec.rb +1 -114
 - metadata +3 -3
 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/instrumental/agent.rb
    CHANGED
    
    | 
         @@ -88,14 +88,12 @@ module Instrumental 
     | 
|
| 
       88 
88 
     | 
    
         
             
                  # host:        instrumentalapp.com
         
     | 
| 
       89 
89 
     | 
    
         
             
                  # port:        8000
         
     | 
| 
       90 
90 
     | 
    
         
             
                  # enabled:     true
         
     | 
| 
       91 
     | 
    
         
            -
                  # test_mode:   false
         
     | 
| 
       92 
91 
     | 
    
         
             
                  # synchronous: false
         
     | 
| 
       93 
92 
     | 
    
         
             
                  @api_key         = api_key
         
     | 
| 
       94 
93 
     | 
    
         
             
                  @host, @port     = options[:collector].to_s.split(':')
         
     | 
| 
       95 
94 
     | 
    
         
             
                  @host          ||= 'instrumentalapp.com'
         
     | 
| 
       96 
95 
     | 
    
         
             
                  @port            = (@port || 8000).to_i
         
     | 
| 
       97 
96 
     | 
    
         
             
                  @enabled         = options.has_key?(:enabled) ? !!options[:enabled] : true
         
     | 
| 
       98 
     | 
    
         
            -
                  @test_mode       = !!options[:test_mode]
         
     | 
| 
       99 
97 
     | 
    
         
             
                  @synchronous     = !!options[:synchronous]
         
     | 
| 
       100 
98 
     | 
    
         
             
                  @pid             = Process.pid
         
     | 
| 
       101 
99 
     | 
    
         
             
                  @allow_reconnect = true
         
     | 
| 
         @@ -360,7 +358,7 @@ module Instrumental 
     | 
|
| 
       360 
358 
     | 
    
         
             
                  logger.info "connecting to collector"
         
     | 
| 
       361 
359 
     | 
    
         
             
                  @socket = with_timeout(CONNECT_TIMEOUT) { TCPSocket.new(host, port) }
         
     | 
| 
       362 
360 
     | 
    
         
             
                  logger.info "connected to collector at #{host}:#{port}"
         
     | 
| 
       363 
     | 
    
         
            -
                  send_with_reply_timeout "hello version #{Instrumental::VERSION}  
     | 
| 
      
 361 
     | 
    
         
            +
                  send_with_reply_timeout "hello version #{Instrumental::VERSION} hostname #{Socket.gethostname}"
         
     | 
| 
       364 
362 
     | 
    
         
             
                  send_with_reply_timeout "authenticate #{@api_key}"
         
     | 
| 
       365 
363 
     | 
    
         
             
                  @failures = 0
         
     | 
| 
       366 
364 
     | 
    
         
             
                  loop do
         
     | 
    
        data/lib/instrumental/version.rb
    CHANGED
    
    
    
        data/spec/agent_spec.rb
    CHANGED
    
    | 
         @@ -50,119 +50,6 @@ describe Instrumental::Agent, "disabled" do 
     | 
|
| 
       50 
50 
     | 
    
         
             
              end
         
     | 
| 
       51 
51 
     | 
    
         
             
            end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
            describe Instrumental::Agent, "enabled in test_mode" do
         
     | 
| 
       54 
     | 
    
         
            -
              before(:each) do
         
     | 
| 
       55 
     | 
    
         
            -
                @server = TestServer.new
         
     | 
| 
       56 
     | 
    
         
            -
                @agent = Instrumental::Agent.new('test_token', :collector => @server.host_and_port, :test_mode => true)
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
              after(:each) do
         
     | 
| 
       60 
     | 
    
         
            -
                @agent.stop
         
     | 
| 
       61 
     | 
    
         
            -
                @agent = nil
         
     | 
| 
       62 
     | 
    
         
            -
                @server.stop
         
     | 
| 
       63 
     | 
    
         
            -
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
              it "should not connect to the server" do
         
     | 
| 
       66 
     | 
    
         
            -
                wait
         
     | 
| 
       67 
     | 
    
         
            -
                @server.connect_count.should == 0
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
              it "should connect to the server when the user sends a metric" do
         
     | 
| 
       71 
     | 
    
         
            -
                @agent.increment("test.foo")
         
     | 
| 
       72 
     | 
    
         
            -
                wait
         
     | 
| 
       73 
     | 
    
         
            -
                @server.connect_count.should == 1
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
              it "should announce itself, and include version and test_mode flag" do
         
     | 
| 
       77 
     | 
    
         
            -
                @agent.increment("test.foo")
         
     | 
| 
       78 
     | 
    
         
            -
                wait
         
     | 
| 
       79 
     | 
    
         
            -
                @server.commands[0].should =~ /hello .*version .*test_mode true/
         
     | 
| 
       80 
     | 
    
         
            -
              end
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
              it "should authenticate using the token" do
         
     | 
| 
       83 
     | 
    
         
            -
                @agent.increment("test.foo")
         
     | 
| 
       84 
     | 
    
         
            -
                wait
         
     | 
| 
       85 
     | 
    
         
            -
                @server.commands[1].should == "authenticate test_token"
         
     | 
| 
       86 
     | 
    
         
            -
              end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
              it "should report a gauge" do
         
     | 
| 
       89 
     | 
    
         
            -
                now = Time.now
         
     | 
| 
       90 
     | 
    
         
            -
                @agent.gauge('gauge_test', 123)
         
     | 
| 
       91 
     | 
    
         
            -
                wait
         
     | 
| 
       92 
     | 
    
         
            -
                @server.commands.last.should == "gauge gauge_test 123 #{now.to_i}"
         
     | 
| 
       93 
     | 
    
         
            -
              end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
              it "should report a time as gauge and return the block result" do
         
     | 
| 
       96 
     | 
    
         
            -
                now = Time.now
         
     | 
| 
       97 
     | 
    
         
            -
                @agent.time("time_value_test") do
         
     | 
| 
       98 
     | 
    
         
            -
                  sleep 0.1
         
     | 
| 
       99 
     | 
    
         
            -
                  1 + 1
         
     | 
| 
       100 
     | 
    
         
            -
                end.should == 2
         
     | 
| 
       101 
     | 
    
         
            -
                wait
         
     | 
| 
       102 
     | 
    
         
            -
                @server.commands.last.should =~ /gauge time_value_test .* #{now.to_i}/
         
     | 
| 
       103 
     | 
    
         
            -
                time = @server.commands.last.scan(/gauge time_value_test (.*) #{now.to_i}/)[0][0].to_f
         
     | 
| 
       104 
     | 
    
         
            -
                time.should > 0.1
         
     | 
| 
       105 
     | 
    
         
            -
              end
         
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
              it "should allow a block used in .time to throw an exception and still be timed" do
         
     | 
| 
       108 
     | 
    
         
            -
                now = Time.now
         
     | 
| 
       109 
     | 
    
         
            -
                lambda {
         
     | 
| 
       110 
     | 
    
         
            -
                  @agent.time("time_value_test") do
         
     | 
| 
       111 
     | 
    
         
            -
                    sleep 0.1
         
     | 
| 
       112 
     | 
    
         
            -
                    throw :an_exception
         
     | 
| 
       113 
     | 
    
         
            -
                    sleep 1
         
     | 
| 
       114 
     | 
    
         
            -
                  end
         
     | 
| 
       115 
     | 
    
         
            -
                }.should raise_error
         
     | 
| 
       116 
     | 
    
         
            -
                wait
         
     | 
| 
       117 
     | 
    
         
            -
                @server.commands.last.should =~ /gauge time_value_test .* #{now.to_i}/
         
     | 
| 
       118 
     | 
    
         
            -
                time = @server.commands.last.scan(/gauge time_value_test (.*) #{now.to_i}/)[0][0].to_f
         
     | 
| 
       119 
     | 
    
         
            -
                time.should > 0.1
         
     | 
| 
       120 
     | 
    
         
            -
              end
         
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
              it "should report a time as a millisecond gauge and return the block result" do
         
     | 
| 
       123 
     | 
    
         
            -
                now = Time.now
         
     | 
| 
       124 
     | 
    
         
            -
                @agent.time_ms("time_ms_test") do
         
     | 
| 
       125 
     | 
    
         
            -
                  sleep 0.1
         
     | 
| 
       126 
     | 
    
         
            -
                  1 + 1
         
     | 
| 
       127 
     | 
    
         
            -
                end.should == 2
         
     | 
| 
       128 
     | 
    
         
            -
                wait
         
     | 
| 
       129 
     | 
    
         
            -
                @server.commands.last.should =~ /gauge time_ms_test .* #{now.to_i}/
         
     | 
| 
       130 
     | 
    
         
            -
                time = @server.commands.last.scan(/gauge time_ms_test (.*) #{now.to_i}/)[0][0].to_f
         
     | 
| 
       131 
     | 
    
         
            -
                time.should > 100.0
         
     | 
| 
       132 
     | 
    
         
            -
              end
         
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
              it "should report an increment" do
         
     | 
| 
       135 
     | 
    
         
            -
                now = Time.now
         
     | 
| 
       136 
     | 
    
         
            -
                @agent.increment("increment_test")
         
     | 
| 
       137 
     | 
    
         
            -
                wait
         
     | 
| 
       138 
     | 
    
         
            -
                @server.commands.last.should == "increment increment_test 1 #{now.to_i}"
         
     | 
| 
       139 
     | 
    
         
            -
              end
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
              it "should send notices to the server" do
         
     | 
| 
       142 
     | 
    
         
            -
                tm = Time.now
         
     | 
| 
       143 
     | 
    
         
            -
                @agent.notice("Test note", tm)
         
     | 
| 
       144 
     | 
    
         
            -
                wait
         
     | 
| 
       145 
     | 
    
         
            -
                @server.commands.join("\n").should include("notice #{tm.to_i} 0 Test note")
         
     | 
| 
       146 
     | 
    
         
            -
              end
         
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
              it "should allow outgoing metrics to be stopped" do
         
     | 
| 
       149 
     | 
    
         
            -
                tm = Time.now
         
     | 
| 
       150 
     | 
    
         
            -
                @agent.increment("foo.bar", 1, tm)
         
     | 
| 
       151 
     | 
    
         
            -
                @agent.stop
         
     | 
| 
       152 
     | 
    
         
            -
                wait
         
     | 
| 
       153 
     | 
    
         
            -
                @agent.increment("foo.baz", 1, tm)
         
     | 
| 
       154 
     | 
    
         
            -
                wait
         
     | 
| 
       155 
     | 
    
         
            -
                @server.commands.join("\n").should include("increment foo.baz 1 #{tm.to_i}")
         
     | 
| 
       156 
     | 
    
         
            -
                @server.commands.join("\n").should_not include("increment foo.bar 1 #{tm.to_i}")
         
     | 
| 
       157 
     | 
    
         
            -
              end
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
              it "should no op on an empty flush" do
         
     | 
| 
       160 
     | 
    
         
            -
                @agent.flush(true)
         
     | 
| 
       161 
     | 
    
         
            -
                wait
         
     | 
| 
       162 
     | 
    
         
            -
                @server.commands.should be_empty
         
     | 
| 
       163 
     | 
    
         
            -
              end
         
     | 
| 
       164 
     | 
    
         
            -
            end
         
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
53 
     | 
    
         
             
            describe Instrumental::Agent, "enabled" do
         
     | 
| 
       167 
54 
     | 
    
         
             
              before do
         
     | 
| 
       168 
55 
     | 
    
         
             
                @server = TestServer.new
         
     | 
| 
         @@ -189,7 +76,7 @@ describe Instrumental::Agent, "enabled" do 
     | 
|
| 
       189 
76 
     | 
    
         
             
              it "should announce itself, and include version" do
         
     | 
| 
       190 
77 
     | 
    
         
             
                @agent.increment("test.foo")
         
     | 
| 
       191 
78 
     | 
    
         
             
                wait
         
     | 
| 
       192 
     | 
    
         
            -
                @server.commands[0].should =~ /hello .*version  
     | 
| 
      
 79 
     | 
    
         
            +
                @server.commands[0].should =~ /hello .*version .* hostname .*/
         
     | 
| 
       193 
80 
     | 
    
         
             
              end
         
     | 
| 
       194 
81 
     | 
    
         | 
| 
       195 
82 
     | 
    
         
             
              it "should authenticate using the token" do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: instrumental_agent
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.10.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       163 
163 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       164 
164 
     | 
    
         
             
                  segments:
         
     | 
| 
       165 
165 
     | 
    
         
             
                  - 0
         
     | 
| 
       166 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 166 
     | 
    
         
            +
                  hash: -983056145287653998
         
     | 
| 
       167 
167 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       168 
168 
     | 
    
         
             
              none: false
         
     | 
| 
       169 
169 
     | 
    
         
             
              requirements:
         
     | 
| 
         @@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       172 
172 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       173 
173 
     | 
    
         
             
                  segments:
         
     | 
| 
       174 
174 
     | 
    
         
             
                  - 0
         
     | 
| 
       175 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 175 
     | 
    
         
            +
                  hash: -983056145287653998
         
     | 
| 
       176 
176 
     | 
    
         
             
            requirements: []
         
     | 
| 
       177 
177 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       178 
178 
     | 
    
         
             
            rubygems_version: 1.8.21
         
     |