metrician 0.0.6 → 0.0.7

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: cb5521c138568656b191ac64370ca87b9bfe3668
4
- data.tar.gz: e513db08fd32887b149d03488cff036fe46efcf5
3
+ metadata.gz: 9cf863462aef4c2b2425233de2c527f3b1286bdf
4
+ data.tar.gz: 461a4cafdc0255467e2b7cbf9c236c49575a2a6b
5
5
  SHA512:
6
- metadata.gz: 4400530ab9c2158937cd8f09ee45ad05db2483879dbc8217eb8f2541368fbcf088388adf408b3383be432eb941046f6ff571d4bc31fc5f18528e124a0c925145
7
- data.tar.gz: 2f8b7d7e207ff7aa166c0a3c254eff20f33e2958e9331a797e732da4b927679f19e314875410f890660b0839ea8379a321d7a4c3f81705d85a4456d8f6cf787b
6
+ metadata.gz: 8f98d615943e39c4f1257420c7bb7f301c9d3c9ecf25bdea95b6c4c083b9b4c63b85519218385b468240c550790f126b06d8355764d13f912d708d678e91ba37
7
+ data.tar.gz: cf46b4c1638fd04ec00d3565e6650b511ea60e37b21edbfa38248ba796b06b9f00c42998903d36bba11928182427c45b823956bb88c9402ee328c20aee0a825f
@@ -17,7 +17,7 @@ matrix:
17
17
  - gemfile: gemfiles/Gemfile.5.0.pg
18
18
  rvm: 2.1.5
19
19
 
20
- before_script:
20
+ before_install:
21
21
  - psql -c 'create database metrician_test;' -U postgres
22
22
  - mysql -e 'create database IF NOT EXISTS metrician_test;'
23
23
 
@@ -1,3 +1,10 @@
1
+ ### 0.0.7 [August 3, 2017]
2
+ * Allow partial config files
3
+ * Officially require Ruby 2
4
+ * Add separate DB command and table configs
5
+ * Don't add method tracing function by default
6
+ * Add example config file
7
+
1
8
  ### 0.0.6 [July 25, 2017]
2
9
  * Fix edge case in web error tracking
3
10
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.6)
4
+ metrician (0.0.7)
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.6)
4
+ metrician (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -7,34 +7,59 @@ module Metrician
7
7
  def self.load
8
8
  reset_dependents
9
9
 
10
- if env_location
11
- # this should never raise unless a bad ENV setting has been set
12
- raise(FileMissing.new(env_location)) unless File.exist?(env_location)
13
- return YAML.load(env_location)
14
- end
15
-
16
- if File.exist?(app_location)
17
- return YAML.load_file(app_location)
10
+ config = {}
11
+ config_locations.reverse.each do |location|
12
+ deep_merge!(config, YAML.load_file(location)) if File.exist?(location)
18
13
  end
14
+ config
15
+ end
19
16
 
20
- YAML.load_file(gem_location)
17
+ def self.config_locations
18
+ [env_location, *app_locations, gem_location].compact
21
19
  end
22
20
 
23
21
  def self.env_location
24
- ENV["METRICIAN_CONFIG"]
22
+ path = ENV["METRICIAN_CONFIG"]
23
+ if path && !File.exist?(path)
24
+ # this should never raise unless a bad ENV setting has been set
25
+ raise(FileMissing.new(path))
26
+ end
27
+ path
25
28
  end
26
29
 
27
- def self.app_location
28
- File.join(Dir.pwd, "config", "metrician.yaml")
30
+ def self.app_locations
31
+ [
32
+ File.join(Dir.pwd, "config", "metrician.yaml"),
33
+ File.join(Dir.pwd, "config", "metrician.yml"),
34
+ ]
29
35
  end
30
36
 
31
37
  def self.gem_location
32
- File.expand_path("../../../config/metrician.yaml", __FILE__)
38
+ File.expand_path("../../../metrician.defaults.yaml", __FILE__)
33
39
  end
34
40
 
35
41
  def self.reset_dependents
36
42
  Metrician::Jobs.reset
37
43
  Metrician::Middleware.reset
38
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
39
64
  end
40
65
  end
@@ -37,11 +37,11 @@ module Metrician
37
37
  config = Metrician.configuration[:database]
38
38
  metrics = []
39
39
  metrics << "database.query" if config[:query][:enabled]
40
- if config[:command][:enabled] || config[:table][:enabled]
40
+ if [:command, :table, :command_and_table].any?{ |key| config[key][:enabled] }
41
41
  command, table = parse_sql(sql)
42
42
  metrics << "database.#{command}" if config[:command][:enabled] && command
43
43
  metrics << "database.#{table}" if config[:table][:enabled] && table
44
- metrics << "database.#{command}.#{table}" if config[:command][:enabled] && config[:table] && command && table
44
+ metrics << "database.#{command}.#{table}" if config[:command_and_table][:enabled] && command && table
45
45
  end
46
46
  begin
47
47
  log_without_metrician(*args, &block)
@@ -1,5 +1,5 @@
1
1
  module Metrician
2
2
 
3
- VERSION = "0.0.6".freeze
3
+ VERSION = "0.0.7".freeze
4
4
 
5
5
  end
@@ -65,6 +65,10 @@
65
65
  :table:
66
66
  :enabled: false
67
67
 
68
+ # collect query information about the command issued and table executed against
69
+ :command_and_table:
70
+ :enabled: false
71
+
68
72
 
69
73
  # "external_service" settings control reporting metrics when Net::HTTP
70
74
  # is used to make requests
@@ -133,4 +137,4 @@
133
137
 
134
138
  # hook into Module with add_metrician_method_tracer added as a base
135
139
  # feature of every ruby object
136
- :enabled: true
140
+ :enabled: false
@@ -0,0 +1,136 @@
1
+ # A configuration for Metrician that controls the features of its
2
+ # automated metric reporting
3
+
4
+ ---
5
+
6
+ # # "request_timing" settings control the features of the Request Timing Rack Middleware
7
+ :request_timing:
8
+ # # hook into Rack middleware for request timing
9
+ # :enabled: true
10
+
11
+ # # collect basic request timing for every request
12
+ # :request:
13
+ # :enabled: true
14
+
15
+ # # report 5xx codes as errors
16
+ # :error:
17
+ # :enabled: true
18
+
19
+ # # report time between requests in a server process as idle time
20
+ # :idle:
21
+ # :enabled: false
22
+
23
+ # # report the payload size of requests
24
+ # :response_size:
25
+ # :enabled: false
26
+
27
+ # # report the amount of time spent on middleware per request
28
+ # :middleware:
29
+ # :enabled: false
30
+
31
+ # # report the amount of time a request spent queued at the web layer
32
+ # # before hitting Rack
33
+ # :queue_time:
34
+ # :enabled: false
35
+
36
+ # # report the controller, action, and verb for every request
37
+ # :route_tracking:
38
+ # :enabled: false
39
+
40
+ # # "apdex" controls the recording of metrics to measure apdex
41
+ # # More here: https://en.wikipedia.org/wiki/Apdex
42
+ # # Note this requires "request" tracking to be enabled
43
+ # :apdex:
44
+ # :enabled: true
45
+
46
+ # # set the threshold (seconds), above which a request is no longer
47
+ # # considered "sasifactory". The "tolerates" threshold will be
48
+ # # 4x this number.
49
+ # :satisfied_threshold: 2.5
50
+
51
+ # # "database" settings control ActiveRecord metric reporting features
52
+ :database:
53
+ # # hook into ActiveRecord for db call timing
54
+ # :enabled: true
55
+
56
+ # # collect basic query tracking for every query
57
+ # :query:
58
+ # :enabled: true
59
+
60
+ # # collect generic sql query information (select, update, insert, etc.)
61
+ # :command:
62
+ # :enabled: false
63
+
64
+ # # collect query information for specific tables
65
+ # :table:
66
+ # :enabled: false
67
+
68
+
69
+ # # "external_service" settings control reporting metrics when Net::HTTP
70
+ # # is used to make requests
71
+ :external_service:
72
+ # # hook into Net::HTTP to record timing metrics
73
+ # :enabled: true
74
+
75
+ # # collect basic external request timing information
76
+ # :request:
77
+ # :enabled: true
78
+
79
+
80
+ # # "jobs" settings control reporting metrics when ruby job systems
81
+ # # work through their queues
82
+ :jobs:
83
+
84
+ # # hook into job system middleware when presence detected
85
+ # :enabled: true
86
+
87
+ # # record the basic timing of every job
88
+ # :run:
89
+ # :enabled: true
90
+
91
+ # # record when an error occurs in the a job
92
+ # :error:
93
+ # :enabled: true
94
+
95
+ # # record metrics for each kind of job that is worked from the queue
96
+ # :job_specific:
97
+ # :enabled: false
98
+
99
+ # # "cache" settings control timing of commands to services often used as
100
+ # # application caches like memcached and redis
101
+ :cache:
102
+
103
+ # # hook into caching libraries
104
+ # :enabled: true
105
+
106
+ # # record aggregate timing information for all cache commands
107
+ # :command:
108
+ # :enabled: true
109
+
110
+ # # record the timing of each command as its own metric
111
+ # :command_specific:
112
+ # :enabled: false
113
+
114
+
115
+ # # "exception" settings control reporting when exceptions are caught
116
+ # # by an exception tracker in your application
117
+ :exception:
118
+
119
+ # # hook into exception tracking libraries
120
+ # :enabled: false
121
+
122
+ # # report when an exception is raised and caught by an exception tracker
123
+ # :raise:
124
+ # :enabled: true
125
+
126
+ # # report a metric per exception type raised
127
+ # :exception_specific:
128
+ # :enabled: false
129
+
130
+ # # "method_tracing" settings control hooking into Module and allowing
131
+ # # ruby methods to be timed
132
+ :method_tracer:
133
+
134
+ # # hook into Module with add_metrician_method_tracer added as a base
135
+ # # feature of every ruby object
136
+ # :enabled: true
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.metadata = {
14
14
  "source_code_uri" => "https://github.com/Instrumental/metrician-ruby"
15
15
  }
16
+ s.required_ruby_version = '>= 2.0.0'
16
17
 
17
18
  s.files = `git ls-files`.split("\n")
18
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -15,7 +15,6 @@ brew list mysql > /dev/null 2>&1 || (
15
15
 
16
16
  brew list postgresql > /dev/null 2>&1 || brew install postgresql
17
17
 
18
- # TODO: Install all rubies in .travis
19
18
  rbenv which ruby >/dev/null 2>&1 || (brew upgrade ruby-build || true; rbenv install)
20
19
 
21
20
  # Setup rbenv so we can switch rubies below
@@ -43,7 +42,7 @@ for ruby_version in `ruby -ryaml -e 'puts YAML.load(File.read(".travis.yml"))["r
43
42
 
44
43
  gem list -i gemika >/dev/null || gem install gemika
45
44
 
46
- rake matrix:install
45
+ rake -t matrix:install
47
46
  done
48
47
 
49
48
  if ! psql postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'metrician_test'" | grep -q 1; then
@@ -10,12 +10,32 @@ end
10
10
  RSpec.describe Metrician do
11
11
  before(:each) do
12
12
  Metrician.reset
13
+ ENV.delete("METRICIAN_CONFIG")
13
14
  end
14
15
 
15
16
  it "has a version number" do
16
17
  Metrician::VERSION.should_not be nil
17
18
  end
18
19
 
20
+ it "can load config from ENV" do
21
+ config = {request_timing: {enabled: "test value"}}
22
+ t = Tempfile.new("metrician_config")
23
+ t.write(config.to_yaml)
24
+ t.flush
25
+ ENV["METRICIAN_CONFIG"] = t.path
26
+ Metrician.reset
27
+ Metrician.configuration[:request_timing][:enabled].should == "test value"
28
+ end
29
+
30
+ specify "partially defined config shouldn't error" do
31
+ t = Tempfile.new("metrician_config")
32
+ t.write({request_timing: {enabled: true}}.to_yaml)
33
+ t.flush
34
+ ENV["METRICIAN_CONFIG"] = t.path
35
+ Metrician.reset
36
+ lambda { Metrician::Jobs.run? }.should_not raise_error
37
+ end
38
+
19
39
  describe "Metrician.activate" do
20
40
  it "takes an agent" do
21
41
  # if this excepts, the world changed
@@ -70,8 +90,7 @@ RSpec.describe Metrician do
70
90
  end
71
91
 
72
92
  specify "per command and table instrumentation" do
73
- Metrician.configuration[:database][:command][:enabled] = true
74
- Metrician.configuration[:database][:table][:enabled] = true
93
+ Metrician.configuration[:database][:command_and_table][:enabled] = true
75
94
  @agent.stub(:gauge)
76
95
  @agent.should_receive(:gauge).with("database.select.users", anything)
77
96
 
@@ -1,6 +1,6 @@
1
1
  mysql:
2
2
  database: metrician_test
3
- username: travis
3
+ username: root
4
4
  password:
5
5
 
6
6
  postgresql:
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.6
4
+ version: 0.0.7
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-07-25 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: instrumental_agent
@@ -114,7 +114,6 @@ files:
114
114
  - METRICS.MD
115
115
  - README.md
116
116
  - Rakefile
117
- - config/metrician.yaml
118
117
  - gemfiles/Gemfile.4.2.sidekiq-4
119
118
  - gemfiles/Gemfile.4.2.sidekiq-4.lock
120
119
  - gemfiles/Gemfile.5.0.pg
@@ -140,6 +139,8 @@ files:
140
139
  - lib/metrician/reporters/resque.rb
141
140
  - lib/metrician/reporters/sidekiq.rb
142
141
  - lib/metrician/version.rb
142
+ - metrician.defaults.yaml
143
+ - metrician.example.yaml
143
144
  - metrician.gemspec
144
145
  - script/setup
145
146
  - script/test
@@ -166,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
167
  requirements:
167
168
  - - ">="
168
169
  - !ruby/object:Gem::Version
169
- version: '0'
170
+ version: 2.0.0
170
171
  required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
173
  - - ">="