observed-http 0.1.0 → 0.2.0.rc1

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGI2ODA0ZmI1YzJlZTRlMjZjMTQ1M2ZjMDQ0ZTgxOWY2OWY5ZWViMw==
4
+ OTEzNTdjYzM4NDkwNDRhZmUzMmMyNWJmZjk2NTQ4NWEwNTkwZGZjYQ==
5
5
  data.tar.gz: !binary |-
6
- ZmY0MGMzZTRiYTljMjQzZjg0NjgzZTY1ZTdkN2UzMGQ3ODM5NDAyZA==
7
- !binary "U0hBNTEy":
6
+ NWFlYzNlNDFjNjRkNTFjZmMwYTRiMjNjMWI4NWE5NWUwY2RhNGRmYg==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- YzdiMmVlNjExYmY2NDQ4ZmViOTI3NzEwODFjMGI5NzFiYTA1MTBmZThiNzQ4
10
- ODk4MzdiNzI0NTlmM2IzNWYxNDVkY2MzNjQzMWEzNGI0MTk1OWE3YTZhM2Zk
11
- YjJhNjBmMGQxYWIwZmQ1MmQwODExMTk0OTc3YmNiZDkwNjgyYjY=
9
+ MzQzMTc3ODQ0NGQwZmM1ZDY1ODc3OGYwNmJlYmQyYjc5NDc0N2RmOTEyZmFj
10
+ ODY2OTU3MzQ3NGY4MmJlMDJkOGYwOTAzZTQ2Y2Y1NDYzYzYzM2UxZGNkOWU3
11
+ YWI0MTQ4YzNmZmMzOWE1NTdiYWM3M2ZhZmYwZWZkYmZjZjZmMjE=
12
12
  data.tar.gz: !binary |-
13
- NzUyNTViNzE0ZGI2MjU1OTMxNmI4NjYxNzhkNjhmNzljNmUxOWZjYjI3YTI5
14
- YjkyM2Q2NTY3ZTNiNTc1NjA4Y2YzYmFjNzBkZjQwNjYwNjJlZWIxNDg2YjM4
15
- YTcxMDY2NTdlOGU3ZWU5MmY2NzE1NDFjZGQ4MGVkZThiZjM1MzY=
13
+ ZWEyZGU5YzI0NmEwN2RjZmEzMTU5M2I3M2U1ZWE2YjZiZTdjZmUxMTgwN2Fi
14
+ ZDFiMTk1ZWE4YjRhYjcyNmMzOGJlNDdjMjE5NmFhZWUyMzU3OGUwYTJhYzlh
15
+ ZTdiNWJkMTRlYjU3MzM0ZDBlMTg3NWI1NWViMWVlNDBkZWVmZTc=
@@ -1,5 +1,5 @@
1
1
  module Observed
2
2
  module Http
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0.rc1"
4
4
  end
5
5
  end
data/lib/observed/http.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'observed/http/version'
2
+ require 'observed/observer'
2
3
  require 'observed/observer_helpers/timer'
4
+ require 'observed/logging'
3
5
  require 'timeout'
4
6
  require 'net/http'
5
7
 
@@ -8,18 +10,22 @@ module Observed
8
10
  class HTTP < Observed::Observer
9
11
 
10
12
  include Observed::ObserverHelpers::Timer
13
+ include Observed::Logging
11
14
 
12
15
  attribute :timeout_in_milliseconds, default: 5000
13
16
 
14
17
  attribute :method
15
18
  attribute :url
19
+ attribute :logger
16
20
 
17
21
  def observe
18
- logger.debug "method: #{method}, url: #{url}"
22
+ method = get_attribute_value(:method)
23
+
24
+ log_debug "method: #{method}, url: #{url}"
19
25
 
20
26
  uri = URI.parse(url)
21
27
 
22
- logger.debug "uri: #{uri}, uri.host: #{uri.host}, uri.port:#{uri.port}, uri.path: #{uri.path}"
28
+ log_debug "uri: #{uri}, uri.host: #{uri.host}, uri.port:#{uri.port}, uri.path: #{uri.path}"
23
29
 
24
30
  http_method = method.capitalize
25
31
  path = if uri.path.size == 0
@@ -36,23 +42,19 @@ module Observed
36
42
 
37
43
  time_and_report(tag: self.tag, timeout_in_seconds: timeout_in_seconds) do
38
44
 
39
- logger.debug "Sending a HTTP request with the timeout of #{timeout_in_seconds} seconds"
45
+ log_debug "Sending a HTTP request with the timeout of #{timeout_in_seconds} seconds"
40
46
 
41
47
  body = Net::HTTP.start(uri.host, uri.port) {|http|
42
48
  http.request(req)
43
49
  }.body
44
50
 
45
- logger.debug "Response body: #{body}"
51
+ log_debug "Response body: #{body}"
46
52
 
47
53
  "#{http_method} #{uri}"
48
54
  end
49
55
 
50
56
  end
51
57
 
52
- def logger
53
- @logger ||= Logger.new(STDOUT)
54
- end
55
-
56
58
  plugin_name 'http'
57
59
 
58
60
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "observed", "~> 0.1.0"
21
+ spec.add_dependency "observed", "~> 0.2.0.rc1"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
data/spec/http_spec.rb CHANGED
@@ -1,14 +1,69 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'observed/application/oneshot'
3
+ require 'observed/http'
4
+
5
+ describe Observed::Plugins::HTTP do
4
6
 
5
- describe Observed::Application::Oneshot do
6
7
  subject {
7
- Observed::Application::Oneshot.create(
8
- config_file: 'spec/fixtures/observed.conf'
9
- )
8
+ Observed::Plugins::HTTP.new
9
+ }
10
+
11
+ before {
12
+ subject.configure config
13
+ }
14
+
15
+ let(:config) {
16
+ {
17
+ timeout_in_milliseconds: 1000,
18
+ method: 'get',
19
+ url: 'http://google.com/',
20
+ tag: 'test',
21
+ system: sys
22
+ }
23
+ }
24
+
25
+ let(:sys) {
26
+ sys = mock('system')
27
+ sys.stubs(:now).returns(before).then.returns(after)
28
+ sys
29
+ }
30
+
31
+ let(:before) {
32
+ Time.now
33
+ }
34
+
35
+ let(:after) {
36
+ Time.now + 1
10
37
  }
11
- it 'initializes' do
12
- expect(subject.run.size).not_to eq(0)
38
+
39
+ let(:response) {
40
+ res = stub('response')
41
+ res.stubs(body: 'the response body')
42
+ res
43
+ }
44
+
45
+ context 'when timed out' do
46
+ before {
47
+ Timeout.expects(:timeout).raises(Timeout::Error)
48
+
49
+ sys.expects(:report).with('test.error', {status: :error, error: {message: 'Timed out.'}, timed_out: true})
50
+ }
51
+
52
+ it 'reports an error' do
53
+ expect { subject.observe }.to_not raise_error
54
+ end
13
55
  end
56
+
57
+ context 'when not timed out' do
58
+ before {
59
+ Timeout.expects(:timeout).returns({ status: :success, result: 'Get http://google.com/' })
60
+
61
+ sys.expects(:report).with('test.success', {status: :success, result: 'Get http://google.com/', elapsed_time: after - before})
62
+ }
63
+
64
+ it 'reports an success' do
65
+ expect { subject.observe }.to_not raise_error
66
+ end
67
+ end
68
+
14
69
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ require 'observed/application/oneshot'
4
+
5
+ describe Observed::Application::Oneshot do
6
+ subject {
7
+ Observed::Application::Oneshot.create(
8
+ config_file: 'spec/fixtures/observed.conf'
9
+ )
10
+ }
11
+ it 'initializes' do
12
+ expect(subject.run.size).not_to eq(0)
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: observed-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - KUOKA Yusuke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-11 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: observed
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.2.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.2.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +155,7 @@ files:
155
155
  - observed-http.gemspec
156
156
  - spec/fixtures/observed.conf
157
157
  - spec/http_spec.rb
158
+ - spec/integration_spec.rb
158
159
  - spec/spec_helper.rb
159
160
  homepage: ''
160
161
  licenses:
@@ -171,12 +172,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
172
  version: '0'
172
173
  required_rubygems_version: !ruby/object:Gem::Requirement
173
174
  requirements:
174
- - - ! '>='
175
+ - - ! '>'
175
176
  - !ruby/object:Gem::Version
176
- version: '0'
177
+ version: 1.3.1
177
178
  requirements: []
178
179
  rubyforge_project:
179
- rubygems_version: 2.0.5
180
+ rubygems_version: 2.1.10
180
181
  signing_key:
181
182
  specification_version: 4
182
183
  summary: observed-http is a plugin for Observed to run health-check against Web services
@@ -186,4 +187,5 @@ test_files:
186
187
  - features/support/env.rb
187
188
  - spec/fixtures/observed.conf
188
189
  - spec/http_spec.rb
190
+ - spec/integration_spec.rb
189
191
  - spec/spec_helper.rb