scout_apm 2.4.16 → 2.4.17

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3f60117002c54a06a541a4b23f585aa84ac6b71
4
- data.tar.gz: 1452280fc1a2c1a9804d79a853dfbc34f1ab957e
3
+ metadata.gz: ed58dbdb3101d5cdc2b60a89a65e4c32b6917ca8
4
+ data.tar.gz: 7f9b855b1ccfb592f6b86c912a32d9ef22d64eba
5
5
  SHA512:
6
- metadata.gz: 693a5899262d98f0b78902f7694840ba6543643ae8ac4ad947fec3e5857470d9dee86842b5be970f6c7c1d93c4352c5cd0aec3c7688af096773d8a734659f163
7
- data.tar.gz: b1861d620b74275e6387fe0b3ecce55a9596bc79f7499edcf6a216434afe252b724e596309a6bfac7b1293f3a4c69e881e64697803459b48ff0c263fd427687a
6
+ metadata.gz: 782a5955c3cea0f7a8004d7cded41421463fc61d68dfcba15ea814be6f5b8dd9ba092e8ced672457a572bc841cdc97682f51739a27d5896177ce0da9caf7938a
7
+ data.tar.gz: dee4aba092de66d99fc91e9507568f2037352b3c2362a936404949f306296b0616e087a8f6b1b13d072b1ad77a47e49f139d577400450747d8f15c5186114b0d
@@ -1,3 +1,8 @@
1
+ # 2.4.17
2
+
3
+ * Renames SQL `BEGIN` and `COMMIT` statements from `SQL#other` to `SQL#begin` and `SQL#commit`, respectively.
4
+ * Makes naming between transaction and database metrics consistent. Previously, database metrics lacking a provided ActiveRecord label were named `SQL#other`.
5
+
1
6
  # 2.4.16
2
7
 
3
8
  * Fix synchronization bug in Store (#205, PR #210)
@@ -13,7 +13,6 @@ module ScoutApm
13
13
 
14
14
  walker.on do |layer|
15
15
  next if skip_layer?(layer)
16
-
17
16
  stat = DbQueryMetricStats.new(
18
17
  model_name(layer),
19
18
  operation_name(layer),
@@ -52,23 +51,11 @@ module ScoutApm
52
51
  DEFAULT_OPERATION = "other"
53
52
 
54
53
  def model_name(layer)
55
- if layer.name.respond_to?(:model)
56
- layer.name.model || DEFAULT_MODEL
57
- else
58
- DEFAULT_MODEL
59
- end
60
- rescue
61
- DEFAULT_MODEL
54
+ layer.name.to_s.split("/").first || DEFAULT_MODEL
62
55
  end
63
56
 
64
57
  def operation_name(layer)
65
- if layer.name.respond_to?(:normalized_operation)
66
- layer.name.normalized_operation || DEFAULT_OPERATION
67
- else
68
- DEFAULT_OPERATION
69
- end
70
- rescue
71
- DEFAULT_OPERATION
58
+ layer.name.to_s.split("/")[1] || DEFAULT_OPERATION
72
59
  end
73
60
 
74
61
  def records_returned(layer)
@@ -12,22 +12,27 @@ module ScoutApm
12
12
  # Converts an SQL string and the name (typically assigned automatically
13
13
  # by rails) into a Scout metric_name.
14
14
  #
15
+ # This prefers to use the ActiveRecord-provided name over parsing SQL as parsing is slower.
16
+ #
15
17
  # sql: SELECT "places".* FROM "places" ORDER BY "places"."position" ASC
16
18
  # name: Place Load
17
19
  # metric_name: Place/find
18
20
  def to_s
21
+ return @to_s if @to_s
19
22
  parsed = parse_operation
20
23
  if parsed
21
- "#{model}/#{parsed}"
24
+ @to_s = "#{model}/#{parsed}"
22
25
  else
23
- regex_name(sql)
26
+ @to_s = regex_name(sql)
24
27
  end
25
28
  end
26
29
 
30
+ # This only returns a value if a name is provided via +initialize+.
27
31
  def model
28
32
  parts.first
29
33
  end
30
34
 
35
+ # This only returns a value if a name is provided via +initialize+.
31
36
  def normalized_operation
32
37
  parse_operation
33
38
  end
@@ -49,12 +54,14 @@ module ScoutApm
49
54
 
50
55
  private
51
56
 
57
+ # This only returns a value if a name is provided via +initialize+.
52
58
  def operation
53
59
  if parts.length >= 2
54
60
  parts[1].downcase
55
61
  end
56
62
  end
57
63
 
64
+ # This only returns a value if a name is provided via +initialize+.
58
65
  def parts
59
66
  name.split(" ")
60
67
  end
@@ -86,6 +93,8 @@ module ScoutApm
86
93
  NON_GREEDY_CONSUME = '.*?'
87
94
  TABLE = '(?:"|`)?(.*?)(?:"|`)?\s'
88
95
  COUNT = 'COUNT\(.*?\)'
96
+ BEGIN_STATEMENT = 'BEGIN'.freeze # BEGIN is a reserved keyword
97
+ COMMIT = 'COMMIT'.freeze
89
98
 
90
99
  SELECT_REGEX = /\A#{WHITE_SPACE}(SELECT)#{WHITE_SPACE}(#{COUNT})?#{NON_GREEDY_CONSUME}#{FROM}#{WHITE_SPACE}#{TABLE}/i.freeze
91
100
  UPDATE_REGEX = /\A#{WHITE_SPACE}(UPDATE)#{WHITE_SPACE}#{TABLE}/i.freeze
@@ -121,13 +130,17 @@ module ScoutApm
121
130
  else
122
131
  SELECT_LABEL
123
132
  end
124
- "#{match[3].classify}/#{operation}"
133
+ "#{match[3].gsub(/\W/,'').classify}/#{operation}"
125
134
  elsif match = UPDATE_REGEX.match(sql)
126
135
  "#{match[2].classify}/#{UPDATE_LABEL}"
127
136
  elsif match = INSERT_REGEX.match(sql)
128
137
  "#{match[2].classify}/#{INSERT_LABEL}"
129
138
  elsif match = DELETE_REGEX.match(sql)
130
139
  "#{match[2].classify}/#{DELETE_LABEL}"
140
+ elsif sql == BEGIN_STATEMENT
141
+ "SQL/#{BEGIN_STATEMENT.downcase}"
142
+ elsif sql == COMMIT
143
+ "SQL/#{COMMIT.downcase}"
131
144
  else
132
145
  UNKNOWN_LABEL
133
146
  end
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "2.4.16"
2
+ VERSION = "2.4.17"
3
3
  end
4
4
 
@@ -64,6 +64,16 @@ class ActiveRecordMetricNameTest < Minitest::Test
64
64
  assert_equal "User/find", mn.to_s
65
65
  end
66
66
 
67
+ def test_begin_statement
68
+ mn = ScoutApm::Utils::ActiveRecordMetricName.new("BEGIN", nil)
69
+ assert_equal "SQL/begin", mn.to_s
70
+ end
71
+
72
+ def test_commit
73
+ mn = ScoutApm::Utils::ActiveRecordMetricName.new("COMMIT", nil)
74
+ assert_equal "SQL/commit", mn.to_s
75
+ end
76
+
67
77
 
68
78
  # Regex test cases, pass these in w/ "SQL" as the AR provided name field
69
79
  [
@@ -89,8 +99,6 @@ class ActiveRecordMetricNameTest < Minitest::Test
89
99
  # Stuff we don't care about in SQL
90
100
  ["SQL/other", 'SET SESSION statement_timeout = ?'],
91
101
  ["SQL/other", 'SHOW TIME ZONE'],
92
- ["SQL/other", 'BEGIN'],
93
- ["SQL/other", 'COMMIT'],
94
102
 
95
103
  # Empty strings, or invalid SQL
96
104
  ["SQL/other", ''],
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: 2.4.16
4
+ version: 2.4.17
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: 2018-08-16 00:00:00.000000000 Z
12
+ date: 2018-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -390,7 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
390
  version: '0'
391
391
  requirements: []
392
392
  rubyforge_project: scout_apm
393
- rubygems_version: 2.4.5.2
393
+ rubygems_version: 2.4.6
394
394
  signing_key:
395
395
  specification_version: 4
396
396
  summary: Ruby application performance monitoring