homebrew-core/Formula/loki.rb

74 lines
2.4 KiB
Ruby

class Loki < Formula
desc "Horizontally-scalable, highly-available log aggregation system"
homepage "https://grafana.com/loki"
url "https://github.com/grafana/loki/archive/v2.1.0.tar.gz"
sha256 "ceccc4e42a7158ca0bc49903a3fbe31c8cd55f85f50bac8a8bba9843b4f8cd6f"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "270a38d251958d692f764a245aabd1e48dce3d0ef9f2fec662703c35e66352b7"
sha256 cellar: :any_skip_relocation, big_sur: "c260accbef2a86c2b07bdcb0a9d301c90e4a777a5ce0a38972d13639c6ee0211"
sha256 cellar: :any_skip_relocation, catalina: "c30784090d993d8fa11e1b7572f7c9bf3bfcca66f14cb90a14e042bbb64cfb07"
sha256 cellar: :any_skip_relocation, mojave: "06264507ae31286df620a0119f24dfc1394735d54d4dcee448ac751b9e7d0d83"
end
depends_on "go" => :build
def install
cd "cmd/loki" do
system "go", "build", *std_go_args
inreplace "loki-local-config.yaml", "/tmp", var
etc.install "loki-local-config.yaml"
end
end
plist_options manual: "loki -config.file=#{HOMEBREW_PREFIX}/etc/loki-local-config.yaml"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/loki</string>
<string>-config.file=#{etc}/loki-local-config.yaml</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/loki.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/loki.log</string>
</dict>
</plist>
EOS
end
test do
port = free_port
cp etc/"loki-local-config.yaml", testpath
inreplace "loki-local-config.yaml" do |s|
s.gsub! "3100", port.to_s
s.gsub! var, testpath
end
fork { exec bin/"loki", "-config.file=loki-local-config.yaml" }
sleep 3
output = shell_output("curl -s localhost:#{port}/metrics")
assert_match "log_messages_total", output
end
end