Skip to content

Commit

Permalink
Read extension details from Ruby file
Browse files Browse the repository at this point in the history
Instead of writing a YAML file for every agent release, and then reading
and parsing it on installation, directly write a Ruby file that can be
more easily imported.

This reduces our dependency on YAML library during installation.

Add "stringio" import. That appears to have been loaded by the YAML
require, but now needs to be required manually on Ruby 2.5 and newer.

Part of #904
Closes appsignal/appsignal-agent#736
  • Loading branch information
tombruijn committed Jan 20, 2023
1 parent e20f4e2 commit d1b960f
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 113 deletions.
6 changes: 6 additions & 0 deletions .changesets/reduce-dependency-on-yaml-during-installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "change"
---

Reduce our dependency on YAML during installation. Instead of a YAML file with details about the extension download location, use a pure Ruby file. This is a partial fix for the installation issue involving psych version 5.
144 changes: 144 additions & 0 deletions ext/agent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# DO NOT EDIT
# This is a generated file by the `rake ship` family of tasks in the
# appsignal-agent repository.
# Modifications to this file will be overwritten with the next agent release.

APPSIGNAL_AGENT_CONFIG = {
"version" => "c0e80b9",
"mirrors" => [
"https://appsignal-agent-releases.global.ssl.fastly.net",
"https://d135dj0rjqvssy.cloudfront.net"
],
"triples" => {
"x86_64-darwin" => {
"static" => {
"checksum" => "c0e1fc966eff49dd942ed07b44f5c5db6be41676f4e35530c300bac8f99e03c4",
"filename" => "appsignal-x86_64-darwin-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "38805c50262c9dbc5c4e7479d274b5e41d6df6e86e6c09d76b9f3f471dcf8787",
"filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz"
}
},
"universal-darwin" => {
"static" => {
"checksum" => "c0e1fc966eff49dd942ed07b44f5c5db6be41676f4e35530c300bac8f99e03c4",
"filename" => "appsignal-x86_64-darwin-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "38805c50262c9dbc5c4e7479d274b5e41d6df6e86e6c09d76b9f3f471dcf8787",
"filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz"
}
},
"aarch64-darwin" => {
"static" => {
"checksum" => "37fcdf17250ce9e2149f28a8492074f5957691636ab542c7073b323a1b9dbdd8",
"filename" => "appsignal-aarch64-darwin-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "0fe962abf0885888f38d1767b959ea25ea8c4b38813d7a23fbebe2aa62873341",
"filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz"
}
},
"arm64-darwin" => {
"static" => {
"checksum" => "37fcdf17250ce9e2149f28a8492074f5957691636ab542c7073b323a1b9dbdd8",
"filename" => "appsignal-aarch64-darwin-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "0fe962abf0885888f38d1767b959ea25ea8c4b38813d7a23fbebe2aa62873341",
"filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz"
}
},
"arm-darwin" => {
"static" => {
"checksum" => "37fcdf17250ce9e2149f28a8492074f5957691636ab542c7073b323a1b9dbdd8",
"filename" => "appsignal-aarch64-darwin-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "0fe962abf0885888f38d1767b959ea25ea8c4b38813d7a23fbebe2aa62873341",
"filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz"
}
},
"aarch64-linux" => {
"static" => {
"checksum" => "ce9075ee5bc14ea786b734793b6bb6331567398cab6a21f2ceaa9062cfbdb373",
"filename" => "appsignal-aarch64-linux-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "eb798538e0e32b19de0afba924c3cb8979a5e57433de4b1a12a6aeaf7233929b",
"filename" => "appsignal-aarch64-linux-all-dynamic.tar.gz"
}
},
"i686-linux" => {
"static" => {
"checksum" => "ea3d1a29cf1534293738f2bd27ae29b8addf8dbe34dde77dc4ae150e109e2e4f",
"filename" => "appsignal-i686-linux-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "add159ec5bcf1b1a3362c08f9f765230d99c0431c567d845e31c51389792a51c",
"filename" => "appsignal-i686-linux-all-dynamic.tar.gz"
}
},
"x86-linux" => {
"static" => {
"checksum" => "ea3d1a29cf1534293738f2bd27ae29b8addf8dbe34dde77dc4ae150e109e2e4f",
"filename" => "appsignal-i686-linux-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "add159ec5bcf1b1a3362c08f9f765230d99c0431c567d845e31c51389792a51c",
"filename" => "appsignal-i686-linux-all-dynamic.tar.gz"
}
},
"x86_64-linux" => {
"static" => {
"checksum" => "adeceb091c4ed277c29eda018ffc61fd064e5c486b2b0a239b26873168a7fdb0",
"filename" => "appsignal-x86_64-linux-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "121abc5d34db302c130cf49ce1dad032025e6717efd63f5cf04ba0b55b5fc863",
"filename" => "appsignal-x86_64-linux-all-dynamic.tar.gz"
}
},
"x86_64-linux-musl" => {
"static" => {
"checksum" => "b57aec8c334b1d3646c80d87f20372287e4e2bdbd798c195e0e36ceeb2aac68a",
"filename" => "appsignal-x86_64-linux-musl-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "67a918b1848f979afe01eb56ce1661fb5b5910d4c7d691fcf0e304203bd7bd7a",
"filename" => "appsignal-x86_64-linux-musl-all-dynamic.tar.gz"
}
},
"aarch64-linux-musl" => {
"static" => {
"checksum" => "fc780524942fc7aeaa4cabec64dfc104c82969df7e8b5cd0fa8eae24c1c9b304",
"filename" => "appsignal-aarch64-linux-musl-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "92ed33ca9f402f9e822e5777b291f7a062545767ea92dea7eaa94db4f82d8130",
"filename" => "appsignal-aarch64-linux-musl-all-dynamic.tar.gz"
}
},
"x86_64-freebsd" => {
"static" => {
"checksum" => "574137de415487afe8d2cc29eac3b1fda2c8e1001474b8f25ebee0cbb32fb1ca",
"filename" => "appsignal-x86_64-freebsd-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "9dcc3454c14e8a7a0d7250b35864b6f0f205d5c730ca510e7b77628e024a703f",
"filename" => "appsignal-x86_64-freebsd-all-dynamic.tar.gz"
}
},
"amd64-freebsd" => {
"static" => {
"checksum" => "574137de415487afe8d2cc29eac3b1fda2c8e1001474b8f25ebee0cbb32fb1ca",
"filename" => "appsignal-x86_64-freebsd-all-static.tar.gz"
},
"dynamic" => {
"checksum" => "9dcc3454c14e8a7a0d7250b35864b6f0f205d5c730ca510e7b77628e024a703f",
"filename" => "appsignal-x86_64-freebsd-all-dynamic.tar.gz"
}
}
}
}.freeze
101 changes: 0 additions & 101 deletions ext/agent.yml

This file was deleted.

13 changes: 6 additions & 7 deletions ext/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
require "open-uri"
require "zlib"
require "json"
require "yaml"
require "rubygems/package"
require File.expand_path("../../lib/appsignal/version.rb", __FILE__)
require File.expand_path("../../lib/appsignal/system.rb", __FILE__)
require_relative "./agent"

EXT_PATH = File.expand_path("..", __FILE__).freeze
AGENT_CONFIG = YAML.load(File.read(File.join(EXT_PATH, "agent.yml"))).freeze
EXT_PATH = File.expand_path("..", __FILE__).freeze

AGENT_PLATFORM = Appsignal::System.agent_platform
AGENT_ARCHITECTURE = Appsignal::System.agent_architecture
TARGET_TRIPLE = "#{AGENT_ARCHITECTURE}-#{AGENT_PLATFORM}".freeze
ARCH_CONFIG = AGENT_CONFIG["triples"][TARGET_TRIPLE].freeze
ARCH_CONFIG = APPSIGNAL_AGENT_CONFIG["triples"][TARGET_TRIPLE].freeze
CA_CERT_PATH = File.join(EXT_PATH, "../resources/cacert.pem").freeze

def ext_path(path)
Expand Down Expand Up @@ -97,7 +96,7 @@ def installation_succeeded?
end

def check_architecture
if AGENT_CONFIG["triples"].key?(TARGET_TRIPLE)
if APPSIGNAL_AGENT_CONFIG["triples"].key?(TARGET_TRIPLE)
true
else
abort_installation(
Expand All @@ -120,11 +119,11 @@ def download_archive(type)
return
end

version = AGENT_CONFIG["version"]
version = APPSIGNAL_AGENT_CONFIG["version"]
filename = ARCH_CONFIG[type]["filename"]
download_errors = []

AGENT_CONFIG["mirrors"].each do |mirror|
APPSIGNAL_AGENT_CONFIG["mirrors"].each do |mirror|
download_url = [mirror, version, filename].join("/")
report["download"]["download_url"] = download_url

Expand Down
1 change: 1 addition & 0 deletions lib/appsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "json"
require "securerandom"
require "stringio"

require "appsignal/logger"
require "appsignal/utils/deprecation_message"
Expand Down
7 changes: 2 additions & 5 deletions lib/appsignal/extension.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "yaml"

begin
if Appsignal::System.jruby?
require "appsignal/extension/jruby"
Expand All @@ -24,9 +22,8 @@ module Appsignal
class Extension
class << self
def agent_config
@agent_config ||= YAML.load(
File.read(File.join(File.dirname(__FILE__), "../../ext/agent.yml"))
)
require_relative "../../ext/agent"
::APPSIGNAL_AGENT_CONFIG
end

def agent_version
Expand Down

0 comments on commit d1b960f

Please sign in to comment.