appmap 0.23.0 → 0.25.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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +17 -8
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +19 -0
  6. data/README.md +29 -12
  7. data/Rakefile +3 -3
  8. data/appmap.gemspec +3 -1
  9. data/exe/appmap +6 -18
  10. data/lib/appmap.rb +47 -6
  11. data/lib/appmap/algorithm/prune_class_map.rb +2 -0
  12. data/lib/appmap/algorithm/stats.rb +4 -2
  13. data/lib/appmap/class_map.rb +143 -0
  14. data/lib/appmap/command/record.rb +8 -6
  15. data/lib/appmap/command/stats.rb +2 -0
  16. data/lib/appmap/command/upload.rb +4 -2
  17. data/lib/appmap/event.rb +168 -0
  18. data/lib/appmap/hook.rb +151 -0
  19. data/lib/appmap/middleware/remote_recording.rb +14 -20
  20. data/lib/appmap/rails/action_handler.rb +10 -6
  21. data/lib/appmap/rails/sql_handler.rb +10 -8
  22. data/lib/appmap/railtie.rb +31 -18
  23. data/lib/appmap/rspec.rb +238 -261
  24. data/lib/appmap/trace.rb +88 -0
  25. data/lib/appmap/version.rb +1 -1
  26. data/package-lock.json +90 -92
  27. data/spec/abstract_controller4_base_spec.rb +1 -1
  28. data/spec/abstract_controller_base_spec.rb +7 -3
  29. data/spec/config_spec.rb +25 -0
  30. data/spec/fixtures/hook/attr_accessor.rb +5 -0
  31. data/spec/fixtures/hook/class_method.rb +17 -0
  32. data/spec/fixtures/hook/constructor.rb +7 -0
  33. data/spec/fixtures/hook/exception_method.rb +11 -0
  34. data/spec/fixtures/hook/instance_method.rb +23 -0
  35. data/spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb +3 -3
  36. data/spec/fixtures/rails4_users_app/config/database.yml +2 -1
  37. data/spec/fixtures/rails4_users_app/docker-compose.yml +2 -0
  38. data/spec/fixtures/rails_users_app/.ruby-version +1 -1
  39. data/spec/fixtures/rails_users_app/app/controllers/api/users_controller.rb +2 -2
  40. data/spec/fixtures/rails_users_app/config/database.yml +2 -1
  41. data/spec/fixtures/rails_users_app/create_app +1 -0
  42. data/spec/fixtures/rails_users_app/docker-compose.yml +4 -0
  43. data/spec/fixtures/rails_users_app/spec/models/user_spec.rb +1 -1
  44. data/spec/hook_spec.rb +357 -0
  45. data/spec/rails_spec_helper.rb +25 -16
  46. data/spec/railtie_spec.rb +1 -1
  47. data/spec/record_sql_rails_pg_spec.rb +1 -2
  48. data/spec/remote_recording_spec.rb +117 -0
  49. data/spec/spec_helper.rb +1 -0
  50. data/test/cli_test.rb +7 -36
  51. data/test/fixtures/cli_record_test/appmap.yml +2 -1
  52. data/test/fixtures/cli_record_test/lib/cli_record_test/main.rb +4 -2
  53. data/test/test_helper.rb +0 -42
  54. metadata +46 -62
  55. data/exe/_appmap-record-self +0 -49
  56. data/lib/appmap/command/inspect.rb +0 -14
  57. data/lib/appmap/config.rb +0 -65
  58. data/lib/appmap/config/directory.rb +0 -65
  59. data/lib/appmap/config/file.rb +0 -13
  60. data/lib/appmap/config/named_function.rb +0 -21
  61. data/lib/appmap/config/package_dir.rb +0 -52
  62. data/lib/appmap/config/path.rb +0 -25
  63. data/lib/appmap/feature.rb +0 -262
  64. data/lib/appmap/inspect.rb +0 -91
  65. data/lib/appmap/inspect/inspector.rb +0 -99
  66. data/lib/appmap/inspect/parse_node.rb +0 -170
  67. data/lib/appmap/inspect/parser.rb +0 -15
  68. data/lib/appmap/parser.rb +0 -60
  69. data/lib/appmap/rspec/parse_node.rb +0 -41
  70. data/lib/appmap/rspec/parser.rb +0 -15
  71. data/lib/appmap/trace/event_handler/rack_handler_webrick.rb +0 -65
  72. data/lib/appmap/trace/tracer.rb +0 -356
  73. data/spec/fixtures/rails_users_app/bin/_appmap-record-self +0 -29
  74. data/spec/rack_handler_webrick_spec.rb +0 -59
  75. data/test/config_test.rb +0 -149
  76. data/test/explict_inspect_test.rb +0 -29
  77. data/test/fixtures/active_record_like/active_record.rb +0 -2
  78. data/test/fixtures/active_record_like/active_record/aggregations.rb +0 -4
  79. data/test/fixtures/active_record_like/active_record/association.rb +0 -4
  80. data/test/fixtures/active_record_like/active_record/associations/join_dependency.rb +0 -6
  81. data/test/fixtures/active_record_like/active_record/associations/join_dependency/join_base.rb +0 -8
  82. data/test/fixtures/active_record_like/active_record/associations/join_dependency/join_part.rb +0 -8
  83. data/test/fixtures/active_record_like/active_record/caps/caps.rb +0 -4
  84. data/test/fixtures/ignore_non_ruby_file/class.rb +0 -3
  85. data/test/fixtures/ignore_non_ruby_file/non-ruby.txt +0 -1
  86. data/test/fixtures/includes_excludes/lib/a/a_1.rb +0 -6
  87. data/test/fixtures/includes_excludes/lib/a/a_2.rb +0 -6
  88. data/test/fixtures/includes_excludes/lib/a/x/x_1.rb +0 -8
  89. data/test/fixtures/includes_excludes/lib/b/b_1.rb +0 -6
  90. data/test/fixtures/includes_excludes/lib/root_1.rb +0 -4
  91. data/test/fixtures/inspect_multiple_subdirs/module_a.rb +0 -2
  92. data/test/fixtures/inspect_multiple_subdirs/module_a/class_a.rb +0 -5
  93. data/test/fixtures/inspect_multiple_subdirs/module_b.rb +0 -2
  94. data/test/fixtures/inspect_multiple_subdirs/module_b/class_b.rb +0 -5
  95. data/test/fixtures/inspect_multiple_subdirs/module_b/class_c.rb +0 -5
  96. data/test/fixtures/inspect_package/module_a/module_b/class_in_module.rb +0 -6
  97. data/test/fixtures/parse_file/defs_static_function.rb +0 -96
  98. data/test/fixtures/parse_file/function_within_class.rb +0 -36
  99. data/test/fixtures/parse_file/include_public_methods.rb +0 -127
  100. data/test/fixtures/parse_file/instance_function.rb +0 -17
  101. data/test/fixtures/parse_file/modules.rb +0 -71
  102. data/test/fixtures/parse_file/sclass_static_function.rb +0 -88
  103. data/test/fixtures/parse_file/toplevel_class.rb +0 -13
  104. data/test/fixtures/parse_file/toplevel_function.rb +0 -14
  105. data/test/fixtures/trace_test/trace_program_1.rb +0 -44
  106. data/test/implicit_inspect_test.rb +0 -33
  107. data/test/include_exclude_test.rb +0 -48
  108. data/test/prerecorded_trace_test.rb +0 -76
  109. data/test/trace_test.rb +0 -92
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'RackHandlerWebrick' do
4
- around(:each) do |example|
5
- FileUtils.mkdir_p tmpdir
6
- FileUtils.rm_f appmap_json
7
- cmd = "docker run -d -v #{File.absolute_path tmpdir}:/app/tmp -p 9292 rack-users-app:#{ENV['RUBY_VERSION']} bin/rackup -o 0.0.0.0 -s webrick"
8
- container_id = `cd spec/fixtures/rack_users_app && #{cmd}`.strip
9
- raise 'Failed to start rack_users_app container' unless $CHILD_STATUS.exitstatus == 0
10
-
11
- begin
12
- start_time = Time.now
13
- until (cid = `docker ps -q -f id=#{container_id} -f health=healthy`.strip) != '' && container_id.include?(cid)
14
- elapsed = Time.now - start_time
15
- raise "Timeout waiting for container #{container_id} to be ready" if elapsed > 10
16
-
17
- $stderr.write '.' if elapsed > 3
18
- sleep 0.25
19
- end
20
- @container_id = container_id
21
- example.run
22
- ensure
23
- if ENV['NOKILL'] != 'true'
24
- `docker rm -f #{container_id}`
25
- warn 'Failed to remove rack_users_app container' unless $CHILD_STATUS.exitstatus == 0
26
- end
27
- end
28
- end
29
-
30
- let(:tmpdir) { 'tmp/spec/RackHandlerWebrick' }
31
- let(:appmap_json) { File.join(tmpdir, 'appmap.json') }
32
- let(:users_app_host_and_port) { `docker port #{@container_id} 9292`.strip.split(':') }
33
- let(:users_app_port) { users_app_host_and_port[1] }
34
-
35
- describe 'POST /users' do
36
- it 'HTTP request and response are recorded in the appmap' do
37
- uri = URI("http://localhost:#{users_app_port}/users")
38
- res = Net::HTTP.post(uri, { 'login' => 'alice', 'password' => 'foobar' }.to_json)
39
- expect(res.code.to_i).to eq(201)
40
-
41
- `docker stop #{@container_id}`
42
-
43
- expect(File).to exist(appmap_json)
44
- appmap = JSON.parse(File.read(appmap_json)).to_yaml
45
-
46
- expect(appmap).to include(<<-WEB_REQUEST.strip)
47
- http_server_request:
48
- request_method: POST
49
- path_info: "/users"
50
- protocol: HTTP/1.1
51
- WEB_REQUEST
52
-
53
- expect(appmap).to include(<<-WEB_RESPONSE.strip)
54
- http_server_response:
55
- status: 201
56
- WEB_RESPONSE
57
- end
58
- end
59
- end
data/test/config_test.rb DELETED
@@ -1,149 +0,0 @@
1
- require 'test_helper'
2
- require 'appmap/config'
3
- require 'appmap/inspect'
4
-
5
- class ConfigTest < Minitest::Test
6
- include FixtureFile
7
-
8
- def test_explicit_module_path_naming
9
- config = AppMap::Config::PackageDir.new(INSPECT_PACKAGE_FIXTURE_DIR).tap do |c|
10
- c.mode = :explicit
11
- c.exclude = [ 'module_a/ignore_module_c' ]
12
- end
13
- feature = AppMap::Inspect.detect_features(config)
14
-
15
- assert_equal %w[inspect_package module_a module_b], feature_names(feature)
16
- end
17
-
18
- def test_implicit_module_path_naming
19
- config = AppMap::Config::PackageDir.new(INSPECT_PACKAGE_FIXTURE_DIR).tap do |c|
20
- c.exclude = [ 'module_a/ignore_module_c' ]
21
- end
22
- feature = AppMap::Inspect.detect_features(config)
23
-
24
- assert_equal %w[inspect_package module_a module_b A B Main], feature_names(feature)
25
- end
26
-
27
- def test_ignore_non_ruby_file
28
- config = AppMap::Config::PackageDir.new(File.join(FIXTURE_DIR, 'ignore_non_ruby_file'))
29
- feature = AppMap::Inspect.detect_features(config)
30
- assert_equal %w[ignore_non_ruby_file Cls], feature_names(feature)
31
- end
32
-
33
- def test_inspect_multiple_subdirs
34
- config_yaml = <<-YAML
35
- packages:
36
- - path: module_a
37
- - path: module_b
38
- named_functions: []
39
- YAML
40
-
41
- require 'yaml'
42
- config = AppMap::Config.load YAML.safe_load(config_yaml)
43
- features = Dir.chdir File.join(FIXTURE_DIR, 'inspect_multiple_subdirs') do
44
- config.source_locations.map(&AppMap::Inspect.method(:detect_features))
45
- end.flatten
46
- features = features.map(&:reparent)
47
- assert_equal %w[module_a ModuleA ClassA module_b ModuleB ClassB ClassC], features.map(&method(:feature_names)).flatten
48
- end
49
-
50
- def test_active_record_like
51
- config_yaml = <<-YAML
52
- packages:
53
- - path: .
54
- name: ROOT
55
- named_functions: []
56
- YAML
57
-
58
- require 'yaml'
59
- config = AppMap::Config.load YAML.safe_load(config_yaml)
60
- features = Dir.chdir File.join(FIXTURE_DIR, 'active_record_like') do
61
- config.source_locations.map(&AppMap::Inspect.method(:detect_features))
62
- end.flatten
63
- features = features.map(&:reparent)
64
-
65
- assert_equal <<-FEATURES.strip, JSON.pretty_generate(features)
66
- [
67
- {
68
- "name": "ROOT",
69
- "location": ".",
70
- "type": "package",
71
- "children": [
72
- {
73
- "name": "ActiveRecord",
74
- "location": "./active_record.rb:1",
75
- "type": "class",
76
- "children": [
77
- {
78
- "name": "Aggregations",
79
- "location": "./active_record/aggregations.rb:2",
80
- "type": "class"
81
- },
82
- {
83
- "name": "Associations",
84
- "location": "./active_record/association.rb:2",
85
- "type": "class",
86
- "children": [
87
- {
88
- "name": "JoinDependency",
89
- "location": "./active_record/associations/join_dependency.rb:3",
90
- "type": "class",
91
- "children": [
92
- {
93
- "name": "JoinBase",
94
- "location": "./active_record/associations/join_dependency/join_base.rb:4",
95
- "type": "class"
96
- },
97
- {
98
- "name": "JoinPart",
99
- "location": "./active_record/associations/join_dependency/join_part.rb:4",
100
- "type": "class"
101
- }
102
- ]
103
- }
104
- ]
105
- },
106
- {
107
- "name": "CAPS",
108
- "location": "./active_record/caps/caps.rb:2",
109
- "type": "class"
110
- }
111
- ]
112
- },
113
- {
114
- "name": "active_record",
115
- "location": "./active_record",
116
- "type": "package",
117
- "children": [
118
- {
119
- "name": "associations",
120
- "location": "./active_record/associations",
121
- "type": "package",
122
- "children": [
123
- {
124
- "name": "join_dependency",
125
- "location": "./active_record/associations/join_dependency",
126
- "type": "package"
127
- }
128
- ]
129
- },
130
- {
131
- "name": "caps",
132
- "location": "./active_record/caps",
133
- "type": "package"
134
- }
135
- ]
136
- }
137
- ]
138
- }
139
- ]
140
- FEATURES
141
- end
142
-
143
- def feature_names(feature, names = [])
144
- names.tap do |_|
145
- names << feature.name
146
- feature.children.each { |child| feature_names(child, names) }
147
- end
148
- end
149
- end
@@ -1,29 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExplicitInspectTest < Minitest::Test
4
- include FixtureFile
5
-
6
- def test_toplevel_class
7
- assert_fixture_features :explicit, 'toplevel_class.rb'
8
- end
9
-
10
- def test_defs_static_function
11
- assert_fixture_features :explicit, 'defs_static_function.rb'
12
- end
13
-
14
- def test_sclass_static_function
15
- assert_fixture_features :explicit, 'sclass_static_function.rb'
16
- end
17
-
18
- def test_toplevel_function
19
- assert_fixture_features :explicit, 'toplevel_function.rb'
20
- end
21
-
22
- def test_function_within_class
23
- assert_fixture_features :explicit, 'function_within_class.rb'
24
- end
25
-
26
- def test_include_public_methods
27
- assert_fixture_features :explicit, 'include_public_methods.rb'
28
- end
29
- end
@@ -1,2 +0,0 @@
1
- module ActiveRecord
2
- end
@@ -1,4 +0,0 @@
1
- module ActiveRecord
2
- class Aggregations
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- module JoinDependency
4
- end
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- module JoinDependency
4
- class JoinBase
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- module JoinDependency
4
- class JoinPart
5
- end
6
- end
7
- end
8
- end
@@ -1,4 +0,0 @@
1
- module ActiveRecord
2
- module CAPS
3
- end
4
- end
@@ -1,3 +0,0 @@
1
- # @appmap
2
- class Cls
3
- end
@@ -1 +0,0 @@
1
- This is not ruby.
@@ -1,6 +0,0 @@
1
- module A
2
- class A1
3
- def action
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module A
2
- class A2
3
- def action
4
- end
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- module A
2
- module X
3
- class X1
4
- def action
5
- end
6
- end
7
- end
8
- end
@@ -1,6 +0,0 @@
1
- module B
2
- class B1
3
- def action
4
- end
5
- end
6
- end
@@ -1,4 +0,0 @@
1
- class Root1
2
- def action
3
- end
4
- end
@@ -1,2 +0,0 @@
1
- module ModuleA
2
- end
@@ -1,5 +0,0 @@
1
- module ModuleA
2
- # @appmap
3
- class ClassA
4
- end
5
- end
@@ -1,2 +0,0 @@
1
- module ModuleB
2
- end
@@ -1,5 +0,0 @@
1
- module ModuleB
2
- # @appmap
3
- class ClassB
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- module ModuleB
2
- # @appmap
3
- class ClassC
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- module A
2
- module B
3
- class Main
4
- end
5
- end
6
- end
@@ -1,96 +0,0 @@
1
- class Main
2
- # @appmap
3
- def self.main_func; end
4
- end
5
-
6
- class Sub < Main
7
- # @appmap
8
- def self.sub_func; end
9
-
10
- # @appmap
11
- def Main.sub_func_2; end
12
-
13
- # @appmap
14
- def self.sub_func_3; end
15
-
16
- protected
17
-
18
- # TODO: ensure that this is ignored by implicit scan
19
- def self.sub_func_protected; end
20
- end
21
-
22
- puts DATA.read
23
- __END__
24
- {
25
- "explicit": [
26
- {
27
- "name": "main_func",
28
- "location": "$FIXTURE_DIR/defs_static_function.rb:3",
29
- "type": "function",
30
- "class_name": "Main",
31
- "static": true
32
- },
33
- {
34
- "name": "sub_func",
35
- "location": "$FIXTURE_DIR/defs_static_function.rb:8",
36
- "type": "function",
37
- "class_name": "Sub",
38
- "static": true
39
- },
40
- {
41
- "name": "sub_func_2",
42
- "location": "$FIXTURE_DIR/defs_static_function.rb:11",
43
- "type": "function",
44
- "class_name": "Main",
45
- "static": true
46
- },
47
- {
48
- "name": "sub_func_3",
49
- "location": "$FIXTURE_DIR/defs_static_function.rb:14",
50
- "type": "function",
51
- "class_name": "Sub",
52
- "static": true
53
- }
54
- ],
55
- "implicit": [
56
- {
57
- "name": "Main",
58
- "location": "$FIXTURE_DIR/defs_static_function.rb:1",
59
- "type": "class",
60
- "children": [
61
- {
62
- "name": "main_func",
63
- "location": "$FIXTURE_DIR/defs_static_function.rb:3",
64
- "type": "function",
65
- "static": true
66
- }
67
- ]
68
- },
69
- {
70
- "name": "Sub",
71
- "location": "$FIXTURE_DIR/defs_static_function.rb:6",
72
- "type": "class",
73
- "children": [
74
- {
75
- "name": "sub_func",
76
- "location": "$FIXTURE_DIR/defs_static_function.rb:8",
77
- "type": "function",
78
- "static": true
79
- },
80
- {
81
- "name": "sub_func_2",
82
- "location": "$FIXTURE_DIR/defs_static_function.rb:11",
83
- "type": "function",
84
- "class_name": "Main",
85
- "static": true
86
- },
87
- {
88
- "name": "sub_func_3",
89
- "location": "$FIXTURE_DIR/defs_static_function.rb:14",
90
- "type": "function",
91
- "static": true
92
- }
93
- ]
94
- }
95
- ]
96
- }