metrician 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a83deae6837d2eb16e8f36b352bfeebeccc41138
4
- data.tar.gz: 3b698ec7a2b20f6afc688ba8f3b7d904316dface
3
+ metadata.gz: 4ea4543ca702d54b9c5b3b98da80914d17c4804e
4
+ data.tar.gz: 923cd68e6fd20feb0b1a786c83b53dec87e629a7
5
5
  SHA512:
6
- metadata.gz: 28d988ff9268492fa52801cac87ec8760a7989f3aae0c6d86d47c67b57f4339255740c7803e95cf302f0ac9caaa5c5e15d16f2a0f25c96fd2d3f601e72a7ed48
7
- data.tar.gz: 6c928de3e629ca94e4f79837aae9281ebeb9b6c84610cd28030defb0309c0d75e5c1736e1faaede4fcf8071116d193c0c838ac3bc161910f740bc4486d8314b8
6
+ metadata.gz: 8c3ef47ea845363d1c5d581435de855b4c115397523aa71d4632489a70dbed294e51779d05582a3d2119ad88800037760348f8acfb4ad1d469753c5df325c454
7
+ data.tar.gz: f29e315bffa5fa8ccd9dd86d0f39782f174eab18278f4c98ed09e5d898ca6597c4dbcd87efcf97c39ca91a08d62114a833bbbcde1052821d62545f10b13788be
@@ -12,6 +12,7 @@ gemfile:
12
12
  - gemfiles/Gemfile.4.2.sidekiq-4
13
13
  - gemfiles/Gemfile.5.0.pg
14
14
  - gemfiles/Gemfile.dalli_not_memcached
15
+ - gemfiles/Gemfile.minimal
15
16
 
16
17
  matrix:
17
18
  exclude:
@@ -1,3 +1,6 @@
1
+ ### 0.0.11 [August 18, 2017]
2
+ * Remove dependence on ActiveSupport
3
+
1
4
  ### 0.0.10 [August 17, 2017]
2
5
  * Fix issue with cache lib detection
3
6
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.10)
4
+ metrician (0.0.11)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.10)
4
+ metrician (0.0.11)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.10)
4
+ metrician (0.0.11)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Differentiated development dependencies
4
+ gem 'rspec', '~> 3.4'
5
+
6
+ # Development dependencies
7
+ gem 'instrumental_agent'
8
+ gem 'rake'
9
+ gem 'byebug'
10
+ gem 'gemika'
11
+ gem 'simplecov', :require => false, :group => :test
12
+
13
+ # Gem under test
14
+ gem 'metrician', :path => '..'
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ metrician (0.0.11)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (9.0.6)
10
+ diff-lcs (1.3)
11
+ docile (1.1.5)
12
+ gemika (0.3.2)
13
+ instrumental_agent (1.0.1)
14
+ json (2.1.0)
15
+ rake (12.0.0)
16
+ rspec (3.6.0)
17
+ rspec-core (~> 3.6.0)
18
+ rspec-expectations (~> 3.6.0)
19
+ rspec-mocks (~> 3.6.0)
20
+ rspec-core (3.6.0)
21
+ rspec-support (~> 3.6.0)
22
+ rspec-expectations (3.6.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.6.0)
25
+ rspec-mocks (3.6.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.6.0)
28
+ rspec-support (3.6.0)
29
+ simplecov (0.15.0)
30
+ docile (~> 1.1.0)
31
+ json (>= 1.8, < 3)
32
+ simplecov-html (~> 0.10.0)
33
+ simplecov-html (0.10.2)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ byebug
40
+ gemika
41
+ instrumental_agent
42
+ metrician!
43
+ rake
44
+ rspec (~> 3.4)
45
+ simplecov
46
+
47
+ BUNDLED WITH
48
+ 1.14.2
@@ -1,4 +1,5 @@
1
1
  require "English"
2
+ require "metrician/core_ext"
2
3
  require "metrician/configuration"
3
4
  require "metrician/reporter"
4
5
  require "metrician/jobs"
@@ -9,7 +9,7 @@ module Metrician
9
9
 
10
10
  config = {}
11
11
  config_locations.reverse.each do |location|
12
- deep_merge!(config, YAML.load_file(location)) if File.exist?(location)
12
+ config.deep_merge!(YAML.load_file(location)) if File.exist?(location)
13
13
  end
14
14
  config
15
15
  end
@@ -42,24 +42,5 @@ module Metrician
42
42
  Metrician::Jobs.reset
43
43
  Metrician::Middleware.reset
44
44
  end
45
-
46
- def self.deep_merge!(this_hash, other_hash, &block)
47
- return this_hash unless other_hash
48
- other_hash.each_pair do |current_key, other_value|
49
- this_value = this_hash[current_key]
50
-
51
- this_hash[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
52
- this_value.deep_merge(other_value, &block)
53
- else
54
- if block_given? && this_hash.key?(current_key)
55
- block.call(current_key, this_value, other_value)
56
- else
57
- other_value
58
- end
59
- end
60
- end
61
-
62
- this_hash
63
- end
64
45
  end
65
46
  end
@@ -0,0 +1,48 @@
1
+ begin
2
+ require 'active_support/core_ext/hash/deep_merge'
3
+ rescue LoadError
4
+ class Hash
5
+ # active_support
6
+ def deep_merge(other_hash, &block)
7
+ dup.deep_merge!(other_hash, &block)
8
+ end if !{}.respond_to?(:deep_merge)
9
+
10
+ def deep_merge!(other_hash, &block)
11
+ other_hash.each_pair do |current_key, other_value|
12
+ this_value = self[current_key]
13
+
14
+ self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
15
+ this_value.deep_merge(other_value, &block)
16
+ else
17
+ if block_given? && key?(current_key)
18
+ block.call(current_key, this_value, other_value)
19
+ else
20
+ other_value
21
+ end
22
+ end
23
+ end
24
+
25
+ self
26
+ end if !{}.respond_to?(:deep_merge!)
27
+ end
28
+ end
29
+
30
+ begin
31
+ require 'active_support/core_ext/string/inflections'
32
+ rescue LoadError
33
+ class String
34
+ # active_support
35
+ def underscore
36
+ camel_cased_word = self
37
+ return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
38
+ word = camel_cased_word.to_s.gsub(/::/, '/')
39
+ # word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" }
40
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
41
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
42
+ word.tr!("-", "_")
43
+ word.downcase!
44
+ word end
45
+ end if !"".respond_to?(:underscore)
46
+ end
47
+
48
+
@@ -1,5 +1,5 @@
1
1
  module Metrician
2
2
 
3
- VERSION = "0.0.10".freeze
3
+ VERSION = "0.0.11".freeze
4
4
 
5
5
  end
@@ -19,6 +19,14 @@ for ruby_version in `ruby -ryaml -e 'puts YAML.load(File.read(".travis.yml"))["r
19
19
  } || success="false"
20
20
  done
21
21
 
22
+ minimum_coverage="90"
23
+ if ! bundle exec ruby -e "require 'simplecov'; exit SimpleCov::LastRun.read['result']['covered_percent'] >= ${minimum_coverage}"; then
24
+ success="false"
25
+ echo
26
+ echo "Coverage fell below minimum of ${minimum_coverage}:"
27
+ cat coverage/.last_run.json
28
+ fi
29
+
22
30
  if [ $success == "true" ]; then
23
31
  tput bold # bold text
24
32
  tput setaf 2 # green text
@@ -1,5 +1,6 @@
1
1
  require "spec_helper"
2
2
  require "instrumental_agent"
3
+ require "tempfile"
3
4
 
4
5
  module Metrician
5
6
  def self.null_agent(agent_class: Instrumental::Agent)
@@ -7,6 +8,12 @@ module Metrician
7
8
  end
8
9
  end
9
10
 
11
+ def should_skip?(gem_name)
12
+ unless Gemika::Env.gem?(gem_name)
13
+ "Skipping tests because gem '#{gem_name}' isn't loaded. Make sure this is correct for the current Gemfile."
14
+ end
15
+ end
16
+
10
17
  RSpec.describe Metrician do
11
18
  before(:each) do
12
19
  Metrician.reset
@@ -63,14 +70,17 @@ RSpec.describe Metrician do
63
70
  describe "exception tracking" do
64
71
  before do
65
72
  Metrician.configuration[:exception][:enabled] = true
66
- Honeybadger.configure do |config|
67
- config.disabled = true
68
- end
69
73
  @agent = Metrician.null_agent
70
74
  Metrician.activate(@agent)
71
75
  end
72
76
 
73
- describe "honeybadger" do
77
+ describe "honeybadger", skip: should_skip?('honeybadger') do
78
+ before do
79
+ Honeybadger.configure do |config|
80
+ config.disabled = true
81
+ end
82
+ end
83
+
74
84
  specify "exceptions are instrumented" do
75
85
  @agent.stub(:increment)
76
86
  @agent.should_receive(:increment).with("app.tracked_exception", 1)
@@ -105,7 +115,7 @@ RSpec.describe Metrician do
105
115
  end
106
116
  end
107
117
 
108
- describe "ActiveRecord" do
118
+ describe "ActiveRecord", skip: should_skip?('activerecord') do
109
119
  before do
110
120
  @agent = Metrician.null_agent
111
121
  Metrician.activate(@agent)
@@ -144,7 +154,7 @@ RSpec.describe Metrician do
144
154
  end
145
155
 
146
156
  describe "job systems" do
147
- describe "delayed_job" do
157
+ describe "delayed_job", skip: should_skip?('delayed_job') do
148
158
  before do
149
159
  @agent = Metrician.null_agent
150
160
  Metrician.activate(@agent)
@@ -176,7 +186,7 @@ RSpec.describe Metrician do
176
186
  end
177
187
  end
178
188
 
179
- describe "resque" do
189
+ describe "resque", skip: should_skip?('resque') do
180
190
  before do
181
191
  Resque.inline = true
182
192
  @agent = Metrician.null_agent
@@ -202,7 +212,7 @@ RSpec.describe Metrician do
202
212
  end
203
213
  end
204
214
 
205
- describe "sidekiq" do
215
+ describe "sidekiq", skip: should_skip?('sidekiq') do
206
216
  before do
207
217
  Sidekiq::Testing.inline!
208
218
  @agent = Metrician.null_agent
@@ -260,7 +270,7 @@ RSpec.describe Metrician do
260
270
  end
261
271
 
262
272
  describe "cache systems" do
263
- specify "redis is instrumented" do
273
+ specify "redis is instrumented", skip: should_skip?('redis') do
264
274
  agent = Metrician.null_agent
265
275
  Metrician.activate(agent)
266
276
  client = Redis.new
@@ -269,13 +279,8 @@ RSpec.describe Metrician do
269
279
  client.get("foo-#{rand(100_000)}")
270
280
  end
271
281
 
272
- memcached_clients = [
273
- Gemika::Env.gem?('memcached') ? ::Memcached.new("localhost:11211") : nil, # allow testing only one for Gemfile.dalli_not_memcached
274
- ::Dalli::Client.new("localhost:11211"),
275
- ].compact
276
-
277
- memcached_clients.each do |client|
278
- specify "memcached is instrumented (#{client.class.name})" do
282
+ shared_examples "memcache libs" do
283
+ it "is instrumented" do
279
284
  agent = Metrician.null_agent
280
285
  Metrician.activate(agent)
281
286
  agent.stub(:gauge)
@@ -289,6 +294,16 @@ RSpec.describe Metrician do
289
294
  end
290
295
  end
291
296
  end
297
+
298
+ describe "memcached gem", skip: should_skip?('memcached') do
299
+ let(:client) { ::Memcached.new("localhost:11211") }
300
+ it_behaves_like "memcache libs"
301
+ end
302
+
303
+ describe "dalli gem", skip: should_skip?('dalli') do
304
+ let(:client) { ::Dalli::Client.new("localhost:11211") }
305
+ it_behaves_like "memcache libs"
306
+ end
292
307
  end
293
308
 
294
309
  describe "external service timing" do
@@ -302,8 +317,8 @@ RSpec.describe Metrician do
302
317
  end
303
318
  end
304
319
 
305
- describe "request timing" do
306
- include Rack::Test::Methods
320
+ describe "request timing", skip: should_skip?('rack') do
321
+ include Rack::Test::Methods if Gemika::Env.gem?('rack')
307
322
 
308
323
  let(:agent) { Metrician.null_agent }
309
324
 
@@ -1,8 +1,6 @@
1
1
  require 'simplecov'
2
2
  SimpleCov.start
3
3
  SimpleCov.command_name "#{RUBY_VERSION}_#{File.basename(ENV["BUNDLE_GEMFILE"])}"
4
- SimpleCov.minimum_coverage 90
5
- SimpleCov.refuse_coverage_drop
6
4
 
7
5
  ENV["RAILS_ENV"] = "test"
8
6
 
@@ -1,33 +1,35 @@
1
- database = Gemika::Database.new
2
- database.connect
1
+ if Gemika::Env.gem?('activerecord')
2
+ database = Gemika::Database.new
3
+ database.connect
3
4
 
4
- if Gemika::Env.gem?('activerecord', '< 5')
5
- class ActiveRecord::ConnectionAdapters::Mysql2Adapter
6
- NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
5
+ if Gemika::Env.gem?('activerecord', '< 5')
6
+ class ActiveRecord::ConnectionAdapters::Mysql2Adapter
7
+ NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
8
+ end
7
9
  end
8
- end
9
10
 
10
- database.rewrite_schema! do
11
+ database.rewrite_schema! do
11
12
 
12
- create_table :users do |t|
13
- t.string :name
14
- t.string :email
15
- t.string :city
16
- end
13
+ create_table :users do |t|
14
+ t.string :name
15
+ t.string :email
16
+ t.string :city
17
+ end
17
18
 
18
- create_table :delayed_jobs, force: true do |table|
19
- table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
20
- table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
21
- table.text :handler, null: false # YAML-encoded string of the object that will do work
22
- table.text :last_error # reason for last failure (See Note below)
23
- table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
24
- table.datetime :locked_at # Set when a client is working on this object
25
- table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
26
- table.string :locked_by # Who is working on this object (if locked)
27
- table.string :queue # The name of the queue this job is in
28
- table.timestamps null: true
29
- end
19
+ create_table :delayed_jobs, force: true do |table|
20
+ table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
21
+ table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
22
+ table.text :handler, null: false # YAML-encoded string of the object that will do work
23
+ table.text :last_error # reason for last failure (See Note below)
24
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
25
+ table.datetime :locked_at # Set when a client is working on this object
26
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
27
+ table.string :locked_by # Who is working on this object (if locked)
28
+ table.string :queue # The name of the queue this job is in
29
+ table.timestamps null: true
30
+ end
30
31
 
31
- add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
32
+ add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
32
33
 
34
+ end
33
35
  end
@@ -1,2 +1,4 @@
1
- class User < ActiveRecord::Base
1
+ if Gemika::Env.gem?('activerecord')
2
+ class User < ActiveRecord::Base
3
+ end
2
4
  end
@@ -1,21 +1,23 @@
1
- require "rails/all"
1
+ if Gemika::Env.gem?('activerecord')
2
+ require "rails/all"
2
3
 
3
- class TestRailsApp < Rails::Application
4
- secrets.secret_token = "secret_token"
5
- secrets.secret_key_base = "secret_key_base"
4
+ class TestRailsApp < Rails::Application
5
+ secrets.secret_token = "secret_token"
6
+ secrets.secret_key_base = "secret_key_base"
6
7
 
7
- config.logger = Logger.new($stdout)
8
- Rails.logger = config.logger
8
+ config.logger = Logger.new($stdout)
9
+ Rails.logger = config.logger
9
10
 
10
- routes.draw do
11
- get "/", to: "foobars#index"
11
+ routes.draw do
12
+ get "/", to: "foobars#index"
13
+ end
12
14
  end
13
- end
14
15
 
15
- class FoobarsController < ActionController::Base
16
- include Rails.application.routes.url_helpers
16
+ class FoobarsController < ActionController::Base
17
+ include Rails.application.routes.url_helpers
17
18
 
18
- def index
19
- render inline: "foobar response"
19
+ def index
20
+ render inline: "foobar response"
21
+ end
20
22
  end
21
- end
23
+ end
@@ -1,8 +1,10 @@
1
- class TestSidekiqWorker
2
- include Sidekiq::Worker
1
+ if Gemika::Env.gem?('sidekiq')
2
+ class TestSidekiqWorker
3
+ include Sidekiq::Worker
3
4
 
4
- def perform(options = {})
5
- return if options["success"]
6
- raise "suck it nerd" if options["error"]
5
+ def perform(options = {})
6
+ return if options["success"]
7
+ raise "suck it nerd" if options["error"]
8
+ end
7
9
  end
8
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrician
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Expected Behavior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-17 00:00:00.000000000 Z
11
+ date: 2017-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: instrumental_agent
@@ -133,8 +133,11 @@ files:
133
133
  - gemfiles/Gemfile.5.0.pg.lock
134
134
  - gemfiles/Gemfile.dalli_not_memcached
135
135
  - gemfiles/Gemfile.dalli_not_memcached.lock
136
+ - gemfiles/Gemfile.minimal
137
+ - gemfiles/Gemfile.minimal.lock
136
138
  - lib/metrician.rb
137
139
  - lib/metrician/configuration.rb
140
+ - lib/metrician/core_ext.rb
138
141
  - lib/metrician/jobs.rb
139
142
  - lib/metrician/jobs/delayed_job_callbacks.rb
140
143
  - lib/metrician/jobs/resque_plugin.rb