-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathalloy.rb
118 lines (96 loc) · 3.43 KB
/
alloy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
class Alloy < Formula
desc "Vendor-agnostic OpenTelemetry Collector distribution with programmable pipelines"
homepage "https://grafana.com/docs/alloy/latest"
url "https://github.com/grafana/alloy/archive/refs/tags/v1.5.1.tar.gz"
sha256 "1f12521b7b64db19a4ed7aab6d8b053225943fa89d72635dd2665aad7e444a83"
license "Apache-2.0"
depends_on "[email protected]" => :build
depends_on "node@20" => :build
depends_on "yarn" => :build
on_linux do
depends_on "systemd" => :build
end
def install
ldflags = %W[
-s -w
-X github.com/grafana/alloy/internal/build.Branch=HEAD
-X github.com/grafana/alloy/internal/build.Version=v#{version}
-X github.com/grafana/alloy/internal/build.BuildUser=#{tap.user}
-X github.com/grafana/alloy/internal/build.BuildDate=#{time.iso8601}
]
args = std_go_args(ldflags: ldflags) + %w[-tags=builtinassets,noebpf]
# Build the UI, which is baked into the final binary when the builtinassets
# tag is set.
cd "internal/web/ui" do
system "yarn"
system "yarn", "run", "build"
end
system "go", "build", *args, "-o", bin/"alloy", "."
# Create a config.alloy file with default Alloy configuration
(buildpath/"config.alloy").write <<~EOS
logging {
level = "info"
format = "logfmt"
}
EOS
(etc/"alloy").install "config.alloy"
# Create an empty config.env file for environment variables
(buildpath/"config.env").write ""
(etc/"alloy").install "config.env"
# Create an empty extra-args.txt file for extra command line arguments
(buildpath/"extra-args.txt").write ""
(etc/"alloy").install "extra-args.txt"
# Create a wrapper script to run Alloy using the config in config.alloy,
# env vars in config.env, and extra args in extra-args.txt
(buildpath/"alloy-wrapper").write <<~SH
#!/usr/bin/env sh
source "#{etc}/alloy/config.env"
COMMAND="#{opt_bin}/alloy run #{etc}/alloy/config.alloy \
--server.http.listen-addr=0.0.0.0:12345 \
--storage.path=#{var}/lib/alloy/data"
EXTRA_ARGS=$(cat "#{etc}/alloy/extra-args.txt")
if [ -z "$EXTRA_ARGS" ]; then
exec $COMMAND
else
exec $COMMAND $EXTRA_ARGS
fi
SH
bin.install "alloy-wrapper"
(bin/"alloy-wrapper").chmod 0755
mkdir_p (var/"lib/alloy/data")
end
def caveats
<<~EOS
Alloy uses a set of files that you can customize before running:
Configuration:
#{etc}/alloy/config.alloy
Environment variables:
#{etc}/alloy/config.env
Extra command line arguments:
#{etc}/alloy/extra-args.txt
EOS
end
service do
run ["#{opt_bin}/alloy-wrapper"]
keep_alive true
log_path var/"log/alloy.log"
error_log_path var/"log/alloy.err.log"
end
test do
assert_match version.to_s, shell_output("#{bin}/alloy --version")
port = free_port
(testpath/"config.alloy").write <<~EOS
logging {
level = "info"
}
EOS
fork do
exec bin/"alloy", "run", "#{testpath}/config.alloy",
"--server.http.listen-addr=127.0.0.1:#{port}",
"--storage.path=#{testpath}/data"
end
sleep 10
output = shell_output("curl -s 127.0.0.1:#{port}/metrics")
assert_match "alloy_build_info", output
end
end