scout_apm 1.2.5 → 1.2.6

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: 103d9ad8a0cf748a92bf2283463ced16af225ec6
4
- data.tar.gz: d941ca86450397e2499805ae3e7d6a717aa26bbb
3
+ metadata.gz: 24f14f22f07f52ef204f8547d5f253f32858f390
4
+ data.tar.gz: 61475d574d1b89429625733f3e5ad1ed21103bc4
5
5
  SHA512:
6
- metadata.gz: 8402634e74e3153e3031bcb1ccd3854b32f496761b1634e5434afcf5444e7155d1f44e52f549c208ceb32b88aad601bced8b27b9e80d386a424f0397567411bf
7
- data.tar.gz: dcee383d2769bbb15d0be63a8c7de47f8f025553fd10ee48375a2e4ef52f4f843bd7107e168cf40b4fedcaece40aed3b0915c7646091b900e0067c0a8592168e
6
+ metadata.gz: 4fad8d97c3f0421337a36cd6ca6734bfc882bd9ab2a56a9c1ec39359811a3b26d59b50e2e19630b6ae7e21583f1b2273135bf1d9153c902dfa7af4f4daf68817
7
+ data.tar.gz: 437750875a372707bcc412bcdd42196fd13281b8462dc87d74466b1cb1b938cc98f3afd044cc001f48f77fe63ba288d16c0a7040d9d8299fba4c4bf6eb779ec9
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.2.6
2
+
3
+ * Fix a bug when determining the name of metrics for ActiveRecord queries
4
+
1
5
  # 1.2.5
2
6
 
3
7
  * Instrument ActionController::Base instead of ::Metal. This allows us to
data/lib/scout_apm.rb CHANGED
@@ -74,6 +74,7 @@ require 'scout_apm/instruments/process/process_memory'
74
74
  require 'scout_apm/app_server_load'
75
75
 
76
76
  require 'scout_apm/utils/sql_sanitizer'
77
+ require 'scout_apm/utils/active_record_metric_name'
77
78
  require 'scout_apm/utils/null_logger'
78
79
  require 'scout_apm/utils/installed_gems'
79
80
  require 'scout_apm/utils/time'
@@ -58,34 +58,12 @@ module ScoutApm
58
58
 
59
59
  def log_with_scout_instruments(*args, &block)
60
60
  sql, name = args
61
- self.class.instrument("ActiveRecord", scout_ar_metric_name(sql, name), :desc => Utils::SqlSanitizer.new(sql).to_s ) do
61
+ self.class.instrument("ActiveRecord",
62
+ Utils::ActiveRecordMetricName.new(sql, name).metric_name,
63
+ :desc => Utils::SqlSanitizer.new(sql).to_s ) do
62
64
  log_without_scout_instruments(sql, name, &block)
63
65
  end
64
66
  end
65
-
66
- def scout_ar_metric_name(sql, name)
67
- # sql: SELECT "places".* FROM "places" ORDER BY "places"."position" ASC
68
- # name: Place Load
69
- if name && (parts = name.split(" ")) && parts.size == 2
70
- model = parts.first
71
- operation = parts.last.downcase
72
- metric_name = case operation
73
- when 'load' then 'find'
74
- when 'indexes', 'columns' then nil # not under developer control
75
- when 'destroy', 'find', 'save', 'create', 'exists' then operation
76
- when 'update' then 'save'
77
- else
78
- if model == 'Join'
79
- operation
80
- end
81
- end
82
- metric = "#{model}/#{metric_name}" if metric_name
83
- metric = "SQL/other" if metric.nil?
84
- else
85
- metric = "SQL/Unknown"
86
- end
87
- metric
88
- end
89
67
  end # module ActiveRecordInstruments
90
68
  end
91
69
  end
@@ -0,0 +1,62 @@
1
+ module ScoutApm
2
+ module Utils
3
+ class ActiveRecordMetricName
4
+ DEFAULT_METRIC = "SQL/Unknown"
5
+
6
+ attr_reader :sql, :name
7
+
8
+ def initialize(sql, name)
9
+ @sql = sql
10
+ @name = name.to_s
11
+ end
12
+
13
+ # Converts an SQL string and the name (typically assigned automatically
14
+ # by rails) into a Scout metric_name.
15
+ #
16
+ # sql: SELECT "places".* FROM "places" ORDER BY "places"."position" ASC
17
+ # name: Place Load
18
+ # metric_name: Place/find
19
+ def metric_name
20
+ return DEFAULT_METRIC unless name
21
+ return DEFAULT_METRIC unless model && operation
22
+
23
+ if parsed = parse_operation
24
+ "#{model}/#{parsed}"
25
+ else
26
+ "SQL/other"
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def model
33
+ parts.first
34
+ end
35
+
36
+ def operation
37
+ if parts.length >= 2
38
+ parts[1].downcase
39
+ end
40
+ end
41
+
42
+ def parts
43
+ name.split(" ")
44
+ end
45
+
46
+ # Returns nil if no match
47
+ # Returns nil if the operation wasn't under developer control (and hence isn't interesting to report)
48
+ def parse_operation
49
+ case operation
50
+ when 'indexes', 'columns' then nil # not under developer control
51
+ when 'load' then 'find'
52
+ when 'destroy', 'find', 'save', 'create', 'exists' then operation
53
+ when 'update' then 'save'
54
+ else
55
+ if model == 'Join'
56
+ operation
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "1.2.5"
2
+ VERSION = "1.2.6"
3
3
  end
4
4
 
data/test/test_helper.rb CHANGED
@@ -19,6 +19,7 @@ end
19
19
  class Minitest::Test
20
20
  def setup
21
21
  reopen_logger
22
+ FileUtils.mkdir_p(DATA_FILE_DIR)
22
23
  ENV['SCOUT_DATA_FILE'] = DATA_FILE_PATH
23
24
  end
24
25
 
@@ -38,5 +39,6 @@ class Minitest::Test
38
39
  ScoutApm::Agent.instance.instance_variable_set("@logger", @logger)
39
40
  end
40
41
 
41
- DATA_FILE_PATH = File.dirname(__FILE__) + '/tmp/scout_apm.db'
42
+ DATA_FILE_DIR = File.dirname(__FILE__) + '/tmp'
43
+ DATA_FILE_PATH = "#{DATA_FILE_DIR}/scout_apm.db"
42
44
  end
@@ -12,14 +12,14 @@ class AgentTest < Minitest::Test
12
12
  def test_start_with_lock_on_layaway_file
13
13
  # setup the file, putting a lock on it.
14
14
  File.open(DATA_FILE_PATH, "w") {}
15
- f=File.open(DATA_FILE_PATH, File::RDWR | File::CREAT)
15
+ f = File.open(DATA_FILE_PATH, File::RDWR | File::CREAT)
16
16
  f.flock(File::LOCK_EX)
17
17
 
18
18
  agent = ScoutApm::Agent.instance
19
19
 
20
20
  no_timeout = true
21
21
  begin
22
- Timeout::timeout(3) { agent.start({:monitor => true,:force => true}) }
22
+ Timeout::timeout(3) { agent.start({:monitor => true, :force => true}) }
23
23
  rescue Timeout::Error
24
24
  no_timeout = false
25
25
  ensure
@@ -55,4 +55,4 @@ class AgentTest < Minitest::Test
55
55
  ## TODO - adds tests to ensure other potentially long-running things don't sneak in, like HTTP calls.
56
56
 
57
57
  OLD_FORMAT = {1452533280 => {:metrics => {}, :slow_transactions => {}} } # Pre 1.2 agents used a different file format to store data.
58
- end
58
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+ require 'scout_apm/utils/active_record_metric_name'
3
+
4
+ class ActiveRecordMetricNameTest < Minitest::Test
5
+ # This is a bug report from Андрей Филиппов <tmn.sun@gmail.com>
6
+ # The code that triggered the bug was: ActiveRecord::Base.connection.execute("%some sql%", :skip_logging)
7
+ def test_symbol_name
8
+ sql = "SELECT * FROM users /*application:Testapp,controller:public,action:index*/"
9
+ name = :skip_logging
10
+
11
+ mn = ScoutApm::Utils::ActiveRecordMetricName.new(sql, name)
12
+ assert_equal "SQL/Unknown", mn.metric_name
13
+ end
14
+
15
+ def test_postgres_column_lookup
16
+ sql = <<-EOF
17
+ SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
18
+ FROM pg_type as t
19
+ LEFT JOIN pg_range as r ON oid = rngtypid
20
+ WHERE
21
+ t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'time', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'timestamp', 'numeric')
22
+ OR t.typtype IN ('r', 'e', 'd')
23
+ OR t.typinput::varchar = 'array_in'
24
+ OR t.typelem != 0
25
+ EOF
26
+
27
+ name = "SCHEMA"
28
+
29
+ mn = ScoutApm::Utils::ActiveRecordMetricName.new(sql, name)
30
+ assert_equal "SQL/Unknown", mn.metric_name
31
+ end
32
+
33
+
34
+ def test_user_find
35
+ sql = %q|SELECT "users".* FROM "users" /*application:Testapp,controller:public,action:index*/|
36
+ name = "User Load"
37
+
38
+ mn = ScoutApm::Utils::ActiveRecordMetricName.new(sql, name)
39
+ assert_equal "User/find", mn.metric_name
40
+ end
41
+
42
+ def test_without_name
43
+ sql = %q|SELECT "users".* FROM "users" /*application:Testapp,controller:public,action:index*/|
44
+ name = nil
45
+
46
+ mn = ScoutApm::Utils::ActiveRecordMetricName.new(sql, name)
47
+ assert_equal "SQL/Unknown", mn.metric_name
48
+ end
49
+
50
+ # TODO: Determine if there should be a distinction between Unknown and Other.
51
+ def test_with_custom_name
52
+ sql = %q|SELECT "users".* FROM "users" /*application:Testapp,controller:public,action:index*/|
53
+ name = "A whole sentance describing what's what"
54
+
55
+ mn = ScoutApm::Utils::ActiveRecordMetricName.new(sql, name)
56
+ assert_equal "SQL/other", mn.metric_name
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-13 00:00:00.000000000 Z
12
+ date: 2016-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -133,6 +133,7 @@ files:
133
133
  - lib/scout_apm/store.rb
134
134
  - lib/scout_apm/tracer.rb
135
135
  - lib/scout_apm/tracked_request.rb
136
+ - lib/scout_apm/utils/active_record_metric_name.rb
136
137
  - lib/scout_apm/utils/fake_stack_prof.rb
137
138
  - lib/scout_apm/utils/installed_gems.rb
138
139
  - lib/scout_apm/utils/null_logger.rb
@@ -153,6 +154,7 @@ files:
153
154
  - test/unit/serializers/payload_serializer_test.rb
154
155
  - test/unit/slow_transaction_set_test.rb
155
156
  - test/unit/sql_sanitizer_test.rb
157
+ - test/unit/utils/active_record_metric_name_test.rb
156
158
  homepage: https://github.com/scoutapp/scout_apm_ruby
157
159
  licenses: []
158
160
  metadata: {}
@@ -188,3 +190,4 @@ test_files:
188
190
  - test/unit/serializers/payload_serializer_test.rb
189
191
  - test/unit/slow_transaction_set_test.rb
190
192
  - test/unit/sql_sanitizer_test.rb
193
+ - test/unit/utils/active_record_metric_name_test.rb