homebrew-core/Formula/apm-server.rb
2019-09-05 08:24:27 +02:00

120 lines
3.8 KiB
Ruby

class ApmServer < Formula
desc "Server for shipping APM metrics to Elasticsearch"
homepage "https://www.elastic.co/"
# Pinned at 6.2.x because of a licencing issue
# See: https://github.com/Homebrew/homebrew-core/pull/28995
url "https://github.com/elastic/apm-server/archive/v6.2.4.tar.gz"
sha256 "b0d85f62851dd0cc7cb7a54c8549d36fb7c29bdb8f83c91b3a6487a8e9acba39"
head "https://github.com/elastic/apm-server.git"
bottle do
cellar :any_skip_relocation
rebuild 1
sha256 "270e7d9dc45e547f4a98e592286e93182eecc0fa0744cec167987bd37d5fbaf6" => :mojave
sha256 "1bd89339bcdd9474d1baf7011dee653e23ed1e3cab4d164646fdd59acdc892d0" => :high_sierra
sha256 "62bcad59f0b04ea4db8c180e4dae2166ec921561a978d726b8c2aba86fa55870" => :sierra
end
depends_on "go" => :build
depends_on "python@2" => :build # does not support Python 3
resource "virtualenv" do
url "https://files.pythonhosted.org/packages/b1/72/2d70c5a1de409ceb3a27ff2ec007ecdd5cc52239e7c74990e32af57affe9/virtualenv-15.2.0.tar.gz"
sha256 "1d7e241b431e7afce47e77f8843a276f652699d1fa4f93b9d8ce0076fd7b0b54"
end
def install
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/elastic/apm-server").install buildpath.children
ENV.prepend_create_path "PYTHONPATH", buildpath/"vendor/lib/python2.7/site-packages"
resource("virtualenv").stage do
system "python", *Language::Python.setup_install_args(buildpath/"vendor")
end
ENV.prepend_path "PATH", buildpath/"vendor/bin"
cd "src/github.com/elastic/apm-server" do
system "make"
system "make", "PIP_INSTALL_COMMANDS=--no-binary :all", "python-env"
system "make", "update"
(libexec/"bin").install "apm-server"
libexec.install "_meta/kibana"
(etc/"apm-server").install Dir["apm-server*.yml"]
(etc/"apm-server").install "fields.yml"
prefix.install_metafiles
end
(bin/"apm-server").write <<~EOS
#!/bin/sh
exec #{libexec}/bin/apm-server \
-path.config #{etc}/apm-server \
-path.home #{libexec} \
-path.logs #{var}/log/apm-server \
-path.data #{var}/lib/apm-server \
"$@"
EOS
end
def post_install
(var/"lib/apm-server").mkpath
(var/"log/apm-server").mkpath
end
plist_options :manual => "apm-server"
def plist; <<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>Program</key>
<string>#{opt_bin}/apm-server</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOS
end
test do
require "socket"
server = TCPServer.new(0)
port = server.addr[1]
server.close
(testpath/"config/apm-server.yml").write <<~EOS
apm-server:
host: localhost:#{port}
output.file:
path: "#{testpath}/apm-server"
filename: apm-server
codec.format:
string: '%{[transaction]}'
EOS
pid = fork do
exec bin/"apm-server", "-path.config", testpath/"config", "-path.data", testpath/"data"
end
sleep 1
begin
system "curl", "-H", "Content-Type: application/json", "-XPOST", "localhost:#{port}/v1/transactions", "-d",
'{"service":{"name":"app1","agent":{"name":"python","version":"1.0"}},' \
'"transactions":[{"id":"945254c5-67a5-417e-8a4e-aa29efcbfb79","name":"GET /api/types", ' \
'"type":"request","duration":32.592981,"timestamp":"2017-05-09T15:04:05.999999Z"}]}'
sleep 1
s = (testpath/"apm-server/apm-server").read
assert_match '"id":"945254c5-67a5-417e-8a4e-aa29efcbfb79"', s
assert_match '"name":"GET /api/types"', s
ensure
Process.kill "SIGINT", pid
Process.wait pid
end
end
end