homebrew-core/Formula/loki.rb

74 lines
2.2 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.0.0.tar.gz"
sha256 "e7ab246d98be52caf7b475245f5ea2cf62fb00f61d6e5377f31423414847556b"
license "Apache-2.0"
bottle do
cellar :any_skip_relocation
sha256 "cdafcfbd3692972dfbb0830e3c57f4cfbd325292783d7f96fde9894c9983c2ec" => :catalina
sha256 "c9e1ad411938e2f224d5b6c6b68c93c9b8405eece3a9fd2e29e3628f03c09708" => :mojave
sha256 "0177decc1efb4cb56c78a5aa8cc91405800c3e428fead5a53afe18cde8553994" => :high_sierra
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