harness-activesupport 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f9b12610642ef62bb0afca73f85a81da83890ef
4
+ data.tar.gz: e82e680ce9d291cb793b17efdf88bcd67c368e7c
5
+ SHA512:
6
+ metadata.gz: ba1b3354ec41132767228bfc952493bf82bf97dd7985275645a97c396b2f4d7f6ae2d41055b00bddb25a72f439cf2ddf8449f590cb55310ffae49dc822ba5508
7
+ data.tar.gz: 3167a32e954e629d67a59a5efb9fc63ed840cd46263c1dd2e17c58b7516938c84ac206601561f9d37f98fb2ee181330b561278bee43f0cc569552928451d1867
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in harness-varnish.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ahawkins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Harness::ActiveSupport
2
+
3
+ Collect metrics from ActiveSupport and forward them to Harness
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'harness-activesupport'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install harness-activesupport
18
+
19
+ ## Usage
20
+
21
+ All you need to do is require the gem:
22
+
23
+ ```ruby
24
+ require 'harness-activesupport'
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'harness/active_support/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "harness-activesupport"
8
+ spec.version = Harness::ActiveSupport::VERSION
9
+ spec.authors = ["ahawkins"]
10
+ spec.email = ["adam@hawkins.io"]
11
+ spec.description = %q{ActiveSupport internal performance metrics logged to Harness}
12
+ spec.summary = %q{}
13
+ spec.homepage = "http://github.com/ahawkins/harness-activesupport"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "harness"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1 @@
1
+ require 'harness/active_support'
@@ -0,0 +1,31 @@
1
+ require "harness/active_support/version"
2
+
3
+ require 'harness'
4
+
5
+ events = %w(cache_read cache_generate cache_fetch_hit cache_write cache_delete)
6
+
7
+ events.each do |name|
8
+ ActiveSupport::Notifications.subscribe "#{name}.active_support" do |*args|
9
+ event = ActiveSupport::Notifications::Event.new(*args)
10
+ Harness.timing "active_support.#{name}", event.duration
11
+ end
12
+ end
13
+
14
+ ActiveSupport::Notifications.subscribe "cache_read.active_support" do |*args|
15
+ payload = args.last
16
+ next if payload[:super_operation] == :fetch
17
+
18
+ if payload[:hit]
19
+ Harness.increment 'cache.hit'
20
+ else
21
+ Harness.increment 'cache.miss'
22
+ end
23
+ end
24
+
25
+ ActiveSupport::Notifications.subscribe "cache_fetch_hit.active_support" do |*args|
26
+ Harness.increment 'cache.hit'
27
+ end
28
+
29
+ ActiveSupport::Notifications.subscribe "cache_generate.active_support" do |*args|
30
+ Harness.increment 'cache.miss'
31
+ end
@@ -0,0 +1,5 @@
1
+ module Harness
2
+ module ActiveSupport
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'test_helper'
2
+ require 'active_support/cache'
3
+
4
+ class ActiveSupportCacheIntegration < MiniTest::Unit::TestCase
5
+ attr_reader :cache
6
+
7
+ class InstrumentedCache < ActiveSupport::Cache::MemoryStore
8
+ self.instrument = true
9
+ end
10
+
11
+ def setup
12
+ super
13
+ @cache = InstrumentedCache.new
14
+ end
15
+
16
+ def test_fetch_counts_as_misses
17
+ cache.fetch 'foo' do
18
+ 'bar'
19
+ end
20
+
21
+ assert_increment 'cache.miss'
22
+ end
23
+
24
+ def test_fetch_hits_count_as_hits
25
+ cache.fetch 'foo' do
26
+ 'bar'
27
+ end
28
+
29
+ cache.fetch 'foo' do
30
+ 'bar'
31
+ end
32
+
33
+ assert_increment 'cache.hit'
34
+ end
35
+
36
+ def test_reads_and_writes_count_correctly
37
+ cache.read 'foo'
38
+ assert_increment 'cache.miss'
39
+
40
+ cache.write 'foo', 'bar'
41
+ cache.read 'foo'
42
+ assert_increment 'cache.hit'
43
+ end
44
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'test_helper'
2
+
3
+ class ActiveSupportIntegration < MiniTest::Unit::TestCase
4
+ def test_logs_cache_read
5
+ instrument "cache_read"
6
+ assert_timer "active_support.cache_read"
7
+ end
8
+
9
+ def test_logs_cache_generate
10
+ instrument "cache_generate"
11
+ assert_timer "active_support.cache_generate"
12
+ end
13
+
14
+ def test_logs_cache_fetch_hit
15
+ instrument "cache_fetch_hit"
16
+ assert_timer "active_support.cache_fetch_hit"
17
+ end
18
+
19
+ def test_logs_cache_write
20
+ instrument "cache_write"
21
+ assert_timer "active_support.cache_write"
22
+ end
23
+
24
+ def test_logs_cache_delete
25
+ instrument "cache_delete"
26
+ assert_timer "active_support.cache_delete"
27
+ end
28
+
29
+ private
30
+ def instrument(event)
31
+ super "#{event}.active_support", { }
32
+ end
33
+ end
@@ -0,0 +1,63 @@
1
+ require 'bundler/setup'
2
+ require 'harness/active_support'
3
+ require 'minitest/unit'
4
+ require 'minitest/autorun'
5
+
6
+ class MiniTest::Unit::TestCase
7
+ def setup
8
+ Harness.config.collector = Harness::FakeCollector.new
9
+ Harness.config.queue = Harness::SyncQueue.new
10
+ end
11
+
12
+ def assert_timer(name)
13
+ refute_empty timers
14
+ timer = timers.find { |t| t.name == name }
15
+ assert timer, "Timer #{name} not logged!"
16
+ end
17
+
18
+ def assert_increment(name)
19
+ refute_empty increments
20
+ increment = increments.find { |i| i.name == name }
21
+ assert increment, "Increment #{name} not logged!"
22
+ end
23
+
24
+ def assert_decrement(name)
25
+ refute_empty decrements
26
+ decrement = decrements.find { |i| i.name == name }
27
+ assert decrement, "decrement #{name} not logged!"
28
+ end
29
+
30
+ def assert_gauge(name)
31
+ refute_empty gauges
32
+ gauge = gauges.find { |g| g.name == name }
33
+ assert gauge, "gauge #{name} not logged!"
34
+ end
35
+
36
+ def instrument(name, data = {}, &block)
37
+ ActiveSupport::Notifications.instrument name, data, &block
38
+ end
39
+
40
+ def collector
41
+ Harness.config.collector
42
+ end
43
+
44
+ def timers
45
+ collector.timers
46
+ end
47
+
48
+ def increments
49
+ collector.increments
50
+ end
51
+
52
+ def decrements
53
+ collector.decrements
54
+ end
55
+
56
+ def counters
57
+ collector.counters
58
+ end
59
+
60
+ def gauges
61
+ collector.gauges
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harness-activesupport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ahawkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: harness
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ActiveSupport internal performance metrics logged to Harness
56
+ email:
57
+ - adam@hawkins.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - harness-activesupport.gemspec
68
+ - lib/harness-activesupport.rb
69
+ - lib/harness/active_support.rb
70
+ - lib/harness/active_support/version.rb
71
+ - test/active_support_cache_test.rb
72
+ - test/active_support_test.rb
73
+ - test/test_helper.rb
74
+ homepage: http://github.com/ahawkins/harness-activesupport
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: ''
98
+ test_files:
99
+ - test/active_support_cache_test.rb
100
+ - test/active_support_test.rb
101
+ - test/test_helper.rb