vault-tools 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,11 +26,20 @@ module Vault
26
26
  ENV['TZ'] = 'UTC'
27
27
  end
28
28
 
29
+ def self.hack_time_class
30
+ $stderr.puts "Modifying Time#to_s to use #iso8601"
31
+ # use send to call private method
32
+ Time.send(:define_method, :to_s) do
33
+ self.iso8601
34
+ end
35
+ end
36
+
29
37
  # all in one go
30
38
  def self.setup
31
39
  self.require
32
40
  self.load_path
33
41
  self.set_timezones
42
+ self.hack_time_class
34
43
  end
35
44
  end
36
45
 
@@ -5,7 +5,7 @@ module Vault
5
5
  # @param name [String] The name of the metric.
6
6
  def self.count(name)
7
7
  name = "#{Config.app_name}.#{name}" if Config.app_name
8
- log(measure: name)
8
+ log("count##{name}" => 1)
9
9
  end
10
10
 
11
11
  # Log an HTTP status code. Two log metrics are written each time this
@@ -36,8 +36,8 @@ module Vault
36
36
  name.gsub(/\/:\w+/, ''). # Remove param names from path.
37
37
  gsub("/", "_"). # Replace slash with underscore.
38
38
  gsub(/[^A-Za-z0-9\-\_]/, ''). # Only keep subset of chars.
39
- slice(1..-1).
40
- tap { |name| log(measure: name, val: duration) }
39
+ slice(1..-1). # Strip the leading underscore.
40
+ tap { |name| log("measure##{name}" => "#{duration}ms") }
41
41
  end
42
42
  end
43
43
 
@@ -1,5 +1,5 @@
1
1
  module Vault
2
2
  module Tools
3
- VERSION = '0.3.8'
3
+ VERSION = '0.3.9'
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ class LogTest < Vault::TestCase
6
6
  def test_count
7
7
  set_env('APP_NAME', nil)
8
8
  Vault::Log.count('countable')
9
- assert_match(/measure=countable/, Scrolls.stream.string)
9
+ assert_match(/count#countable=1/, Scrolls.stream.string)
10
10
  end
11
11
 
12
12
  # Vault::Log.count emits a metric that represents a countable event. If an
@@ -15,7 +15,7 @@ class LogTest < Vault::TestCase
15
15
  def test_count_with_app_name
16
16
  set_env('APP_NAME', 'vault_app')
17
17
  Vault::Log.count('countable')
18
- assert_match(/measure=vault_app.countable/, Scrolls.stream.string)
18
+ assert_match(/count#vault_app.countable=1/, Scrolls.stream.string)
19
19
  end
20
20
 
21
21
  # Vault::Log.count_status emits metrics to measure HTTP responses. The
@@ -23,8 +23,8 @@ class LogTest < Vault::TestCase
23
23
  def test_count_status
24
24
  set_env('APP_NAME', nil)
25
25
  Vault::Log.count_status(201)
26
- assert_match(/measure=http_201/, Scrolls.stream.string)
27
- assert_match(/measure=http_2xx/, Scrolls.stream.string)
26
+ assert_match(/count#http_201=1/, Scrolls.stream.string)
27
+ assert_match(/count#http_2xx=1/, Scrolls.stream.string)
28
28
  end
29
29
 
30
30
  # Vault::Log.count_status emits metrics to measure HTTP responses. If an
@@ -33,30 +33,27 @@ class LogTest < Vault::TestCase
33
33
  def test_count_status_with_app_name
34
34
  set_env('APP_NAME', 'vault_app')
35
35
  Vault::Log.count_status(201)
36
- assert_match(/measure=vault_app.http_201/, Scrolls.stream.string)
37
- assert_match(/measure=vault_app.http_2xx/, Scrolls.stream.string)
36
+ assert_match(/count#vault_app.http_201=1/, Scrolls.stream.string)
37
+ assert_match(/count#vault_app.http_2xx=1/, Scrolls.stream.string)
38
38
  end
39
39
 
40
40
  # Vault::Log.time emits a metric to measure the duration of an HTTP request.
41
41
  # It converts slashes to underscores.
42
42
  def test_time_replaces_slash_with_underscore
43
43
  Vault::Log.time('/some/web/path', 123.4)
44
- assert_match(/measure=some_web_path val=123.400/, Scrolls.stream.string)
45
- assert_match(/val=123.4/, Scrolls.stream.string)
44
+ assert_match(/measure#some_web_path=123.4ms/, Scrolls.stream.string)
46
45
  end
47
46
 
48
47
  # Vault::Log.time removes parameters.
49
48
  def test_time_removes_parameters
50
49
  Vault::Log.time('/some/:web/path', 123.4)
51
- assert_match(/measure=some_path val=123.400/, Scrolls.stream.string)
52
- assert_match(/val=123.4/, Scrolls.stream.string)
50
+ assert_match(/measure#some_path=123.4ms/, Scrolls.stream.string)
53
51
  end
54
52
 
55
53
  # Vault::Log.time removes non-alphanumeric characters.
56
54
  def test_time_removes_non_alphanumeric_characters
57
55
  Vault::Log.time('/some/web+path', 123.4)
58
- assert_match(/measure=some_webpath val=123.400/, Scrolls.stream.string)
59
- assert_match(/val=123.4/, Scrolls.stream.string)
56
+ assert_match(/measure#some_webpath=123.4ms/, Scrolls.stream.string)
60
57
  end
61
58
 
62
59
  # Vault::Log.time is a no-op if a nil name is provided.
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class TimeTest < Vault::TestCase
4
+
5
+ # We're always using UTC time
6
+ def test_now_is_utc
7
+ local = Time.local(2012,1,1)
8
+ utc = Time.utc(2012,1,1)
9
+ assert_equal(utc, local)
10
+ end
11
+
12
+ # Default time format is iso8601
13
+ def test_to_s_is_iso8601
14
+ t = Time.utc(2012,1,1)
15
+ assert_equal(t.to_s, t.iso8601)
16
+ end
17
+ end
@@ -42,8 +42,8 @@ class WebTest < Vault::TestCase
42
42
  # requests.
43
43
  def test_head_status_check
44
44
  head '/'
45
- assert_match(/measure=http_200/, Scrolls.stream.string)
46
- assert_match(/measure=http_2xx/, Scrolls.stream.string)
45
+ assert_match(/count#http_200=1/, Scrolls.stream.string)
46
+ assert_match(/count#http_2xx=1/, Scrolls.stream.string)
47
47
  assert_equal(200, last_response.status)
48
48
  end
49
49
 
@@ -51,8 +51,8 @@ class WebTest < Vault::TestCase
51
51
  # response body.
52
52
  def test_get_health_check
53
53
  get '/health'
54
- assert_match(/measure=http_200/, Scrolls.stream.string)
55
- assert_match(/measure=http_2xx/, Scrolls.stream.string)
54
+ assert_match(/count#http_200=1/, Scrolls.stream.string)
55
+ assert_match(/count#http_2xx=1/, Scrolls.stream.string)
56
56
  assert_equal(200, last_response.status)
57
57
  assert_equal('OK', last_response.body)
58
58
  end
@@ -61,8 +61,8 @@ class WebTest < Vault::TestCase
61
61
  # match a known resource.
62
62
  def test_head_with_unknown_endpoint
63
63
  head '/unknown'
64
- assert_match(/measure=http_404/, Scrolls.stream.string)
65
- assert_match(/measure=http_4xx/, Scrolls.stream.string)
64
+ assert_match(/count#http_404=1/, Scrolls.stream.string)
65
+ assert_match(/count#http_4xx=1/, Scrolls.stream.string)
66
66
  assert_equal(404, last_response.status)
67
67
  end
68
68
 
@@ -70,8 +70,8 @@ class WebTest < Vault::TestCase
70
70
  # traceback is also written to the response body to ease debugging.
71
71
  def test_error_logs_500
72
72
  get '/boom'
73
- assert_match(/measure=http_500/, Scrolls.stream.string)
74
- assert_match(/measure=http_5xx/, Scrolls.stream.string)
73
+ assert_match(/count#http_500=1/, Scrolls.stream.string)
74
+ assert_match(/count#http_5xx=1/, Scrolls.stream.string)
75
75
  assert_match(/^RuntimeError: An expected error occurred.$/m,
76
76
  last_response.body)
77
77
  assert_equal(500, last_response.status)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-14 00:00:00.000000000 Z
13
+ date: 2013-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: scrolls
@@ -130,7 +130,7 @@ files:
130
130
  - test/log_test.rb
131
131
  - test/pipeline_test.rb
132
132
  - test/product_test.rb
133
- - test/test_spec.rb
133
+ - test/time_test.rb
134
134
  - test/user_test.rb
135
135
  - test/web_test.rb
136
136
  - vault-tools.gemspec
@@ -146,15 +146,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  - - ! '>='
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
+ segments:
150
+ - 0
151
+ hash: 4182790357412636502
149
152
  required_rubygems_version: !ruby/object:Gem::Requirement
150
153
  none: false
151
154
  requirements:
152
155
  - - ! '>='
153
156
  - !ruby/object:Gem::Version
154
157
  version: '0'
158
+ segments:
159
+ - 0
160
+ hash: 4182790357412636502
155
161
  requirements: []
156
162
  rubyforge_project:
157
- rubygems_version: 1.8.25
163
+ rubygems_version: 1.8.23
158
164
  signing_key:
159
165
  specification_version: 3
160
166
  summary: Test classes, base web classes, and helpers - oh my!
@@ -1,7 +0,0 @@
1
- class TestSpec < MiniTest::Unit::TestCase
2
-
3
- def test_default_spec_class_is_vault_spec
4
- assert_equal Vault::Spec, MiniTest::Spec.spec_type('')
5
- end
6
-
7
- end