appsignal 2.8.4.beta.1 → 2.9.18.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
  3. data/.github/ISSUE_TEMPLATE/chore.md +14 -0
  4. data/.gitignore +2 -3
  5. data/.rubocop.yml +3 -0
  6. data/.rubocop_todo.yml +7 -16
  7. data/.travis.yml +28 -27
  8. data/CHANGELOG.md +657 -533
  9. data/README.md +31 -3
  10. data/Rakefile +128 -129
  11. data/SUPPORT.md +16 -0
  12. data/appsignal.gemspec +17 -4
  13. data/build_matrix.yml +21 -9
  14. data/ext/Rakefile +23 -17
  15. data/ext/agent.yml +40 -37
  16. data/ext/base.rb +116 -31
  17. data/ext/extconf.rb +34 -28
  18. data/gemfiles/capistrano2.gemfile +5 -0
  19. data/gemfiles/capistrano3.gemfile +5 -0
  20. data/gemfiles/grape.gemfile +5 -0
  21. data/gemfiles/no_dependencies.gemfile +5 -0
  22. data/gemfiles/padrino.gemfile +5 -0
  23. data/gemfiles/que.gemfile +5 -0
  24. data/gemfiles/que_beta.gemfile +10 -0
  25. data/gemfiles/rails-3.2.gemfile +5 -0
  26. data/gemfiles/rails-4.0.gemfile +5 -0
  27. data/gemfiles/rails-4.1.gemfile +5 -0
  28. data/gemfiles/rails-4.2.gemfile +5 -0
  29. data/gemfiles/rails-6.0.gemfile +5 -0
  30. data/gemfiles/resque.gemfile +5 -0
  31. data/lib/appsignal.rb +14 -492
  32. data/lib/appsignal/cli/demo.rb +5 -2
  33. data/lib/appsignal/cli/diagnose.rb +84 -4
  34. data/lib/appsignal/cli/diagnose/paths.rb +0 -5
  35. data/lib/appsignal/cli/diagnose/utils.rb +19 -0
  36. data/lib/appsignal/cli/helpers.rb +6 -0
  37. data/lib/appsignal/cli/install.rb +45 -15
  38. data/lib/appsignal/cli/notify_of_deploy.rb +10 -0
  39. data/lib/appsignal/config.rb +1 -2
  40. data/lib/appsignal/event_formatter.rb +4 -5
  41. data/lib/appsignal/event_formatter/action_view/render_formatter.rb +10 -8
  42. data/lib/appsignal/event_formatter/moped/query_formatter.rb +60 -59
  43. data/lib/appsignal/extension.rb +2 -2
  44. data/lib/appsignal/helpers/instrumentation.rb +494 -0
  45. data/lib/appsignal/helpers/metrics.rb +54 -0
  46. data/lib/appsignal/hooks.rb +11 -8
  47. data/lib/appsignal/hooks/active_support_notifications.rb +2 -5
  48. data/lib/appsignal/hooks/puma.rb +74 -11
  49. data/lib/appsignal/hooks/sequel.rb +1 -1
  50. data/lib/appsignal/hooks/sidekiq.rb +115 -0
  51. data/lib/appsignal/integrations/mongo_ruby_driver.rb +7 -0
  52. data/lib/appsignal/integrations/que.rb +9 -8
  53. data/lib/appsignal/integrations/railtie.rb +2 -1
  54. data/lib/appsignal/marker.rb +2 -3
  55. data/lib/appsignal/minutely.rb +188 -19
  56. data/lib/appsignal/rack/sinatra_instrumentation.rb +1 -1
  57. data/lib/appsignal/system.rb +16 -18
  58. data/lib/appsignal/transaction.rb +8 -0
  59. data/lib/appsignal/utils/rails_helper.rb +20 -0
  60. data/lib/appsignal/version.rb +1 -1
  61. data/lib/puma/plugin/appsignal.rb +26 -0
  62. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +40 -0
  63. data/spec/lib/appsignal/cli/diagnose_spec.rb +129 -22
  64. data/spec/lib/appsignal/cli/install_spec.rb +57 -8
  65. data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +10 -0
  66. data/spec/lib/appsignal/config_spec.rb +13 -11
  67. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +38 -28
  68. data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +6 -0
  69. data/spec/lib/appsignal/event_formatter_spec.rb +168 -69
  70. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +104 -25
  71. data/spec/lib/appsignal/hooks/puma_spec.rb +251 -34
  72. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +209 -0
  73. data/spec/lib/appsignal/hooks_spec.rb +4 -0
  74. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +24 -1
  75. data/spec/lib/appsignal/minutely_spec.rb +318 -26
  76. data/spec/lib/appsignal/system_spec.rb +0 -35
  77. data/spec/lib/appsignal/transaction_spec.rb +68 -10
  78. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +39 -31
  79. data/spec/lib/appsignal/utils/json_spec.rb +7 -3
  80. data/spec/lib/appsignal_spec.rb +98 -22
  81. data/spec/lib/puma/appsignal_spec.rb +91 -0
  82. data/spec/spec_helper.rb +13 -0
  83. data/spec/support/{project_fixture → fixtures/projects/valid}/config/application.rb +0 -0
  84. data/spec/support/{project_fixture → fixtures/projects/valid}/config/appsignal.yml +1 -0
  85. data/spec/support/{project_fixture → fixtures/projects/valid}/config/environments/development.rb +0 -0
  86. data/spec/support/{project_fixture → fixtures/projects/valid}/config/environments/production.rb +0 -0
  87. data/spec/support/{project_fixture → fixtures/projects/valid}/config/environments/test.rb +0 -0
  88. data/spec/support/{project_fixture → fixtures/projects/valid}/log/.gitkeep +0 -0
  89. data/spec/support/helpers/config_helpers.rb +1 -1
  90. data/spec/support/helpers/log_helpers.rb +6 -0
  91. data/spec/support/helpers/wait_for_helper.rb +28 -0
  92. data/spec/support/mocks/mock_probe.rb +11 -0
  93. data/spec/support/stubs/sidekiq/api.rb +4 -0
  94. metadata +43 -31
  95. data/spec/support/fixtures/containers/cgroups/docker +0 -14
  96. data/spec/support/fixtures/containers/cgroups/docker_systemd +0 -8
  97. data/spec/support/fixtures/containers/cgroups/lxc +0 -10
  98. data/spec/support/fixtures/containers/cgroups/no_permission +0 -0
  99. data/spec/support/fixtures/containers/cgroups/none +0 -1
@@ -1,28 +1,34 @@
1
- require File.expand_path("../../lib/appsignal/version.rb", __FILE__)
2
1
  require File.expand_path("../base.rb", __FILE__)
3
2
 
3
+ def local_build?
4
+ File.exist?(ext_path("appsignal-agent")) &&
5
+ (
6
+ File.exist?(ext_path("libappsignal.dylib")) ||
7
+ File.exist?(ext_path("libappsignal.so"))
8
+ ) &&
9
+ File.exist?(ext_path("appsignal.h"))
10
+ end
11
+
4
12
  task :default do
5
13
  begin
6
- logger.info "Installing appsignal agent #{Appsignal::VERSION} for Ruby #{RUBY_VERSION} on #{RUBY_PLATFORM}"
7
- write_agent_architecture
14
+ library_type = "dynamic"
15
+ report["language"]["implementation"] = "jruby"
16
+ report["build"]["library_type"] = library_type
8
17
  next unless check_architecture
9
- arch_config = AGENT_CONFIG["triples"][ARCH]
10
18
 
11
- unless File.exist?(ext_path("appsignal-agent")) &&
12
- (
13
- File.exist?(ext_path("libappsignal.dylib")) ||
14
- File.exist?(ext_path("libappsignal.so"))
15
- ) &&
16
- File.exist?(ext_path("appsignal.h"))
17
- archive = download_archive(arch_config, "dynamic")
19
+ if local_build?
20
+ report["build"]["source"] = "local"
21
+ else
22
+ archive = download_archive(library_type)
18
23
  next unless archive
19
- next unless verify_archive(archive, arch_config, "dynamic")
24
+ next unless verify_archive(archive, library_type)
20
25
  unarchive(archive)
21
26
  end
22
- rescue => ex
23
- installation_failed "Exception while installing: #{ex}"
24
- ex.backtrace.each do |line|
25
- logger.error line
26
- end
27
+ successful_installation
28
+ rescue => error
29
+ fail_installation_with_error(error)
30
+ ensure
31
+ create_dummy_makefile unless installation_succeeded?
32
+ write_report
27
33
  end
28
34
  end
@@ -1,67 +1,70 @@
1
1
  ---
2
- version: 4c4acdf
2
+ version: c348132
3
+ mirrors:
4
+ - https://appsignal-agent-releases.global.ssl.fastly.net
5
+ - https://d135dj0rjqvssy.cloudfront.net
3
6
  triples:
4
7
  x86_64-darwin:
5
8
  static:
6
- checksum: 33117d6fc3db70a87b6c643762d13f0ed2e961003952beb97fb86a6d528a8af2
7
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-darwin-all-static.tar.gz
9
+ checksum: cb287c8e2072fe5b8cf14449bd6892989c392d0c651ce339895ae0302cb69785
10
+ filename: appsignal-x86_64-darwin-all-static.tar.gz
8
11
  dynamic:
9
- checksum: a9eca0b19c1863560cf402b5171eb7d8b3aee134d9a11cd52ddb5facd9192242
10
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-darwin-all-dynamic.tar.gz
12
+ checksum: af1ed2e9d29859ffbfc8e6903e4c51764dee94d7b4877ca8d30270b6f133a10f
13
+ filename: appsignal-x86_64-darwin-all-dynamic.tar.gz
11
14
  universal-darwin:
12
15
  static:
13
- checksum: 33117d6fc3db70a87b6c643762d13f0ed2e961003952beb97fb86a6d528a8af2
14
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-darwin-all-static.tar.gz
16
+ checksum: cb287c8e2072fe5b8cf14449bd6892989c392d0c651ce339895ae0302cb69785
17
+ filename: appsignal-x86_64-darwin-all-static.tar.gz
15
18
  dynamic:
16
- checksum: a9eca0b19c1863560cf402b5171eb7d8b3aee134d9a11cd52ddb5facd9192242
17
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-darwin-all-dynamic.tar.gz
19
+ checksum: af1ed2e9d29859ffbfc8e6903e4c51764dee94d7b4877ca8d30270b6f133a10f
20
+ filename: appsignal-x86_64-darwin-all-dynamic.tar.gz
18
21
  i686-linux:
19
22
  static:
20
- checksum: a75c82ead6c0e31662d58ee1e2824e09f80c96a483c8fb00c8a622013bb531db
21
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-i686-linux-all-static.tar.gz
23
+ checksum: 2c3bcd102592bf38fbdb27e7c70502dccbe54a0dc2739a9d54aaa694fcfb41fb
24
+ filename: appsignal-i686-linux-all-static.tar.gz
22
25
  dynamic:
23
- checksum: f18cf71eed0921ee1ae423fb2cf4f980ec16c270ffab9cd9b8201a5c222c7448
24
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-i686-linux-all-dynamic.tar.gz
26
+ checksum: 1c037b8370b755d706340e25d3e4b2f4acb279dd03873cc53bcf0a6ec0832653
27
+ filename: appsignal-i686-linux-all-dynamic.tar.gz
25
28
  x86-linux:
26
29
  static:
27
- checksum: a75c82ead6c0e31662d58ee1e2824e09f80c96a483c8fb00c8a622013bb531db
28
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-i686-linux-all-static.tar.gz
30
+ checksum: 2c3bcd102592bf38fbdb27e7c70502dccbe54a0dc2739a9d54aaa694fcfb41fb
31
+ filename: appsignal-i686-linux-all-static.tar.gz
29
32
  dynamic:
30
- checksum: f18cf71eed0921ee1ae423fb2cf4f980ec16c270ffab9cd9b8201a5c222c7448
31
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-i686-linux-all-dynamic.tar.gz
33
+ checksum: 1c037b8370b755d706340e25d3e4b2f4acb279dd03873cc53bcf0a6ec0832653
34
+ filename: appsignal-i686-linux-all-dynamic.tar.gz
32
35
  i686-linux-musl:
33
36
  static:
34
- checksum: 2776672dfc380c30cceaa8274addf880d54a39cc803e515b0ba00dbcbd36b044
35
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-i686-linux-musl-all-static.tar.gz
37
+ checksum: 0add9eed4452feda7fc5e1bbd0acdff32c353e4ea0b5d527959df57deb1bdcb2
38
+ filename: appsignal-i686-linux-musl-all-static.tar.gz
36
39
  x86-linux-musl:
37
40
  static:
38
- checksum: 2776672dfc380c30cceaa8274addf880d54a39cc803e515b0ba00dbcbd36b044
39
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-i686-linux-musl-all-static.tar.gz
41
+ checksum: 0add9eed4452feda7fc5e1bbd0acdff32c353e4ea0b5d527959df57deb1bdcb2
42
+ filename: appsignal-i686-linux-musl-all-static.tar.gz
40
43
  x86_64-linux:
41
44
  static:
42
- checksum: d0ced9bf5ccbfa407dbdf7d3528e7976059f08da340728dcd2b76c4ab2012ed2
43
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-linux-all-static.tar.gz
45
+ checksum: d11221c127c00128da16b419c503281407e429c0ea6f5bfe1691640b8e995e4e
46
+ filename: appsignal-x86_64-linux-all-static.tar.gz
44
47
  dynamic:
45
- checksum: 6ae9c20c3c51961a90476034ad54e26353f6f07d96ba4b3c568a5690be02cc0c
46
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-linux-all-dynamic.tar.gz
48
+ checksum: 6869ab461fde55487d55805c396d55f36cb881998556f44236035b949939b0af
49
+ filename: appsignal-x86_64-linux-all-dynamic.tar.gz
47
50
  x86_64-linux-musl:
48
51
  static:
49
- checksum: a8420232884339e4857fbdce76ecd7fbba2da893094b5f676e46b931f6767ec2
50
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-linux-musl-all-static.tar.gz
52
+ checksum: 7ce44dc23c578933ca37a79d244bc367fdc2438408c2a61558adb92bcfebb1fa
53
+ filename: appsignal-x86_64-linux-musl-all-static.tar.gz
51
54
  dynamic:
52
- checksum: d447ae2422cf405d21efc5f3ebf96050e53feb86be7509462942d8ec51734dc9
53
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-linux-musl-all-dynamic.tar.gz
55
+ checksum: 78d98f468e3a12cc09baff9e68bc4d9cd3b79f4a3bbe744036bff685415546a4
56
+ filename: appsignal-x86_64-linux-musl-all-dynamic.tar.gz
54
57
  x86_64-freebsd:
55
58
  static:
56
- checksum: 457e191e72af77f082c788c5a87eac253342f7238c54a325ea09881106fc8476
57
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-freebsd-all-static.tar.gz
59
+ checksum: df5f8b61e6ecca40f349cf5c83d5f37f031850d367793dee90dc56f13974431d
60
+ filename: appsignal-x86_64-freebsd-all-static.tar.gz
58
61
  dynamic:
59
- checksum: f789a7f7c4d3453b2ff23af734bb084dc6bc1372ab23e46453519ea436f4111b
60
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-freebsd-all-dynamic.tar.gz
62
+ checksum: 30d0303e97386014640c5b8194b777a5741e08ab5497ba58a7d8229bd4890fc5
63
+ filename: appsignal-x86_64-freebsd-all-dynamic.tar.gz
61
64
  amd64-freebsd:
62
65
  static:
63
- checksum: 457e191e72af77f082c788c5a87eac253342f7238c54a325ea09881106fc8476
64
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-freebsd-all-static.tar.gz
66
+ checksum: df5f8b61e6ecca40f349cf5c83d5f37f031850d367793dee90dc56f13974431d
67
+ filename: appsignal-x86_64-freebsd-all-static.tar.gz
65
68
  dynamic:
66
- checksum: f789a7f7c4d3453b2ff23af734bb084dc6bc1372ab23e46453519ea436f4111b
67
- download_url: https://appsignal-agent-releases.global.ssl.fastly.net/4c4acdf/appsignal-x86_64-freebsd-all-dynamic.tar.gz
69
+ checksum: 30d0303e97386014640c5b8194b777a5741e08ab5497ba58a7d8229bd4890fc5
70
+ filename: appsignal-x86_64-freebsd-all-dynamic.tar.gz
@@ -1,77 +1,156 @@
1
1
  require "digest"
2
- require "logger"
3
2
  require "fileutils"
4
3
  require "open-uri"
5
4
  require "zlib"
6
5
  require "yaml"
7
6
  require "rubygems/package"
7
+ require File.expand_path("../../lib/appsignal/version.rb", __FILE__)
8
8
  require File.expand_path("../../lib/appsignal/system.rb", __FILE__)
9
9
 
10
10
  EXT_PATH = File.expand_path("..", __FILE__).freeze
11
11
  AGENT_CONFIG = YAML.load(File.read(File.join(EXT_PATH, "agent.yml"))).freeze
12
12
 
13
- PLATFORM = Appsignal::System.agent_platform
14
- ARCH = "#{RbConfig::CONFIG["host_cpu"]}-#{PLATFORM}".freeze
13
+ AGENT_PLATFORM = Appsignal::System.agent_platform
14
+ ARCH = "#{RbConfig::CONFIG["host_cpu"]}-#{AGENT_PLATFORM}".freeze
15
+ ARCH_CONFIG = AGENT_CONFIG["triples"][ARCH].freeze
15
16
  CA_CERT_PATH = File.join(EXT_PATH, "../resources/cacert.pem").freeze
16
17
 
17
18
  def ext_path(path)
18
19
  File.join(EXT_PATH, path)
19
20
  end
20
21
 
21
- def logger
22
- @logger ||= Logger.new(File.join(EXT_PATH, "install.log"))
22
+ def report
23
+ @report ||=
24
+ begin
25
+ rbconfig = RbConfig::CONFIG
26
+ {
27
+ "result" => {
28
+ "status" => "incomplete"
29
+ },
30
+ "language" => {
31
+ "name" => "ruby",
32
+ "version" => "#{rbconfig["ruby_version"]}-p#{rbconfig["PATCHLEVEL"]}"
33
+ },
34
+ "download" => {
35
+ "checksum" => "unverified"
36
+ },
37
+ "build" => {
38
+ "time" => Time.now.utc,
39
+ "package_path" => File.dirname(EXT_PATH),
40
+ "architecture" => rbconfig["host_cpu"],
41
+ "target" => AGENT_PLATFORM,
42
+ "musl_override" => Appsignal::System.force_musl_build?,
43
+ "dependencies" => {},
44
+ "flags" => {}
45
+ },
46
+ "host" => {
47
+ "root_user" => Process.uid.zero?,
48
+ "dependencies" => {}.tap do |d|
49
+ ldd_output = Appsignal::System.ldd_version_output
50
+ ldd_version = Appsignal::System.extract_ldd_version(ldd_output)
51
+ d["libc"] = ldd_version if ldd_version
52
+ end
53
+ }
54
+ }
55
+ end
56
+ end
57
+
58
+ def write_report
59
+ File.open(File.join(EXT_PATH, "install.report"), "w") do |file|
60
+ file.write YAML.dump(report)
61
+ end
23
62
  end
24
63
 
25
- def installation_failed(reason)
26
- logger.error "Installation failed: #{reason}"
64
+ def create_dummy_makefile
27
65
  File.open(File.join(EXT_PATH, "Makefile"), "w") do |file|
28
66
  file.write "default:\nclean:\ninstall:"
29
67
  end
30
68
  end
31
69
 
32
- def write_agent_architecture
33
- File.open(File.join(EXT_PATH, "appsignal.architecture"), "w") do |file|
34
- file.write ARCH
35
- end
70
+ def successful_installation
71
+ report["result"] = { "status" => "success" }
72
+ end
73
+
74
+ def abort_installation(reason)
75
+ report["result"] = {
76
+ "status" => "failed",
77
+ "message" => reason
78
+ }
79
+ false
80
+ end
81
+
82
+ def fail_installation_with_error(error)
83
+ report["result"] = {
84
+ "status" => "error",
85
+ "error" => "#{error.class}: #{error}",
86
+ "backtrace" => error.backtrace
87
+ }
88
+ false
89
+ end
90
+
91
+ def installation_succeeded?
92
+ report["result"]["status"] == "success"
36
93
  end
37
94
 
38
95
  def check_architecture
39
96
  if AGENT_CONFIG["triples"].key?(ARCH)
40
97
  true
41
98
  else
42
- installation_failed(
99
+ abort_installation(
43
100
  "AppSignal currently does not support your system architecture (#{ARCH})." \
44
- "Please let us know at support@appsignal.com, we aim to support everything our customers run."
101
+ "Please let us know at support@appsignal.com, we aim to support everything our customers run."
45
102
  )
46
- false
47
103
  end
48
104
  end
49
105
 
50
- def download_archive(arch_config, type)
51
- if arch_config.key?(type)
52
- logger.info "Downloading agent release from #{arch_config[type]["download_url"]}"
53
- open(arch_config[type]["download_url"], :ssl_ca_cert => CA_CERT_PATH)
54
- else
55
- installation_failed(
106
+ def download_archive(type)
107
+ report["build"]["source"] = "remote"
108
+
109
+ unless ARCH_CONFIG.key?(type)
110
+ abort_installation(
56
111
  "AppSignal currently does not support your system. " \
57
- "Expected config for architecture '#{ARCH}' and package type '#{type}', but none found. " \
58
- "For a full list of supported systems visit: " \
59
- "https://docs.appsignal.com/support/operating-systems.html"
112
+ "Expected config for architecture '#{arch}' and package type '#{type}', but none found. " \
113
+ "For a full list of supported systems visit: " \
114
+ "https://docs.appsignal.com/support/operating-systems.html"
60
115
  )
61
- false
116
+ return
117
+ end
118
+
119
+ version = AGENT_CONFIG["version"]
120
+ filename = ARCH_CONFIG[type]["filename"]
121
+ attempted_mirror_urls = []
122
+
123
+ AGENT_CONFIG["mirrors"].each do |mirror|
124
+ download_url = [mirror, version, filename].join("/")
125
+ attempted_mirror_urls << download_url
126
+ report["download"]["download_url"] = download_url
127
+
128
+ begin
129
+ return open(download_url, :ssl_ca_cert => CA_CERT_PATH)
130
+ rescue
131
+ next
132
+ end
62
133
  end
134
+
135
+ attempted_mirror_urls_mapped = attempted_mirror_urls.map { |mirror| "- #{mirror}" }
136
+ abort_installation(
137
+ "Could not download archive from any of our mirrors. " \
138
+ "Attempted to download the archive from the following urls:\n" \
139
+ "#{attempted_mirror_urls_mapped.join("\n")}\n" \
140
+ "Please make sure your network allows access to any of these mirrors."
141
+ )
63
142
  end
64
143
 
65
- def verify_archive(archive, arch_config, type)
66
- if Digest::SHA256.hexdigest(archive.read) == arch_config[type]["checksum"]
67
- logger.info "Checksum of downloaded archive verified, extracting archive"
144
+ def verify_archive(archive, type)
145
+ if Digest::SHA256.hexdigest(archive.read) == ARCH_CONFIG[type]["checksum"]
146
+ report["download"]["checksum"] = "verified"
68
147
  true
69
148
  else
70
- installation_failed(
71
- "Aborting installation, checksum of downloaded archive could not be verified: " \
72
- "Expected '#{arch_config[type]["checksum"]}', got '#{checksum}'."
149
+ report["download"]["checksum"] = "invalid"
150
+ abort_installation(
151
+ "Checksum of downloaded archive could not be verified: " \
152
+ "Expected '#{ARCH_CONFIG[type]["checksum"]}', got '#{checksum}'."
73
153
  )
74
- false
75
154
  end
76
155
  end
77
156
 
@@ -85,5 +164,11 @@ def unarchive(archive)
85
164
  end
86
165
  end
87
166
  end
167
+ store_download_version_on_report
88
168
  FileUtils.chmod(0o755, ext_path("appsignal-agent"))
89
169
  end
170
+
171
+ def store_download_version_on_report
172
+ path = File.expand_path(File.join(File.dirname(__FILE__), "appsignal.version"))
173
+ report["build"]["agent_version"] = File.read(path).strip
174
+ end
@@ -1,35 +1,38 @@
1
- require File.expand_path("../../lib/appsignal/version.rb", __FILE__)
2
1
  require File.expand_path("../base.rb", __FILE__)
3
2
 
4
- def install # rubocop:disable Metrics/CyclomaticComplexity
5
- logger.info "Installing appsignal agent #{Appsignal::VERSION} for Ruby #{RUBY_VERSION} on #{RUBY_PLATFORM}"
6
- write_agent_architecture
3
+ def local_build?
4
+ File.exist?(ext_path("appsignal-agent")) &&
5
+ File.exist?(ext_path("libappsignal.a")) &&
6
+ File.exist?(ext_path("appsignal.h"))
7
+ end
8
+
9
+ def install
10
+ library_type = "static"
11
+ report["language"]["implementation"] = "ruby"
12
+ report["build"]["library_type"] = library_type
7
13
  return unless check_architecture
8
- arch_config = AGENT_CONFIG["triples"][ARCH]
9
14
 
10
- unless File.exist?(ext_path("appsignal-agent")) &&
11
- File.exist?(ext_path("libappsignal.a")) &&
12
- File.exist?(ext_path("appsignal.h"))
13
- archive = download_archive(arch_config, "static")
15
+ if local_build?
16
+ report["build"]["source"] = "local"
17
+ else
18
+ archive = download_archive(library_type)
14
19
  return unless archive
15
- return unless verify_archive(archive, arch_config, "static")
20
+ return unless verify_archive(archive, library_type)
16
21
  unarchive(archive)
17
22
  end
18
23
 
19
24
  is_linux_system = [
20
25
  Appsignal::System::LINUX_TARGET,
21
26
  Appsignal::System::MUSL_TARGET
22
- ].include?(PLATFORM)
27
+ ].include?(AGENT_PLATFORM)
23
28
 
24
- logger.info "Creating makefile"
25
29
  require "mkmf"
26
-
27
30
  link_libraries if is_linux_system
28
31
 
29
32
  if !have_library("appsignal", "appsignal_start", "appsignal.h")
30
- installation_failed "Aborting installation, libappsignal.a or appsignal.h not found"
33
+ abort_installation("Library libappsignal.a or appsignal.h not found")
31
34
  elsif !find_executable("appsignal-agent", EXT_PATH)
32
- installation_failed "Aborting installation, appsignal-agent not found"
35
+ abort_installation("File appsignal-agent not found")
33
36
  else
34
37
  if is_linux_system
35
38
  # Statically link libgcc and libgcc_s libraries.
@@ -38,15 +41,16 @@ def install # rubocop:disable Metrics/CyclomaticComplexity
38
41
  # run on one that isn't the missing libraries will cause the extension
39
42
  # to fail on start.
40
43
  $LDFLAGS += " -static-libgcc" # rubocop:disable Style/GlobalVars
44
+ report["build"]["flags"]["LDFLAGS"] = $LDFLAGS # rubocop:disable Style/GlobalVars
41
45
  end
42
46
  create_makefile "appsignal_extension"
43
- logger.info "Successfully created Makefile for appsignal extension"
44
- end
45
- rescue => ex
46
- installation_failed "Exception while installing: #{ex}"
47
- ex.backtrace.each do |line|
48
- logger.error line
47
+ successful_installation
49
48
  end
49
+ rescue => error
50
+ fail_installation_with_error(error)
51
+ ensure
52
+ create_dummy_makefile unless installation_succeeded?
53
+ write_report
50
54
  end
51
55
 
52
56
  # Ruby 2.6 requires us to statically link more libraries we use in our
@@ -54,26 +58,28 @@ end
54
58
  # and musl builds.
55
59
  def link_libraries
56
60
  if RbConfig::CONFIG["THREAD_MODEL"] == "pthread"
57
- logger.info "Linking extension against 'pthread' library"
58
61
  # Link gem extension against pthread library
59
62
  have_library "pthread"
60
- have_required_function "pthread_create"
63
+ have_required_function "pthread", "pthread_create"
61
64
  end
62
65
 
63
66
  # Links gem extension against the `dl` library. This is needed when Ruby is
64
67
  # not linked against `dl` itself, so link it on the gem extension.
65
- logger.info "Linking extension against 'dl' library"
66
68
  have_library "dl"
67
69
  # Check if functions are available now from the linked library
68
70
  %w[dlopen dlclose dlsym].each do |func|
69
- have_required_function func
71
+ have_required_function "dl", func
70
72
  end
71
73
  end
72
74
 
73
- def have_required_function(func) # rubocop:disable Naming/PredicateName
74
- return if have_func(func)
75
+ def have_required_function(library, func) # rubocop:disable Naming/PredicateName
76
+ if have_func(func)
77
+ report["build"]["dependencies"][library] = "linked"
78
+ return
79
+ end
75
80
 
76
- installation_failed "Aborting installation, missing function '#{func}'"
81
+ report["build"]["dependencies"][library] = "not linked"
82
+ abort_installation("Missing function '#{func}'")
77
83
  # Exit with true/0/success because the AppSignal installation should never
78
84
  # break a build
79
85
  exit