File: 0001-Do-not-embed-blobs.patch

package info (click to toggle)
prometheus-alertmanager 0.28.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 8,736 kB
  • sloc: makefile: 216; sh: 211; javascript: 86
file content (278 lines) | stat: -rw-r--r-- 10,060 bytes parent folder | download
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
From: Martina Ferrari <tina@debian.org>
Date: Tue, 12 Jul 2016 03:23:14 +0000
Subject: Do not embed blobs

Forwarded: not-needed
Last-Update: 2023-02-03

Upstream is interested in keeping the resources embedded, this patch is to
comply with Debian policy.
---
 cli/check_config.go        |  2 +-
 cli/template_render.go     |  2 +-
 cmd/alertmanager/main.go   |  5 +++--
 notify/email/email_test.go |  2 +-
 notify/sns/sns_test.go     |  2 +-
 notify/test/test.go        |  2 +-
 template/template.go       |  9 +++++----
 template/template_test.go  |  6 +++---
 ui/app/src/Views.elm       |  4 ++--
 ui/web.go                  | 26 ++++++++++----------------
 10 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/cli/check_config.go b/cli/check_config.go
index c024c27..f3b5ae2 100644
--- a/cli/check_config.go
+++ b/cli/check_config.go
@@ -84,7 +84,7 @@ func CheckConfig(args []string) error {
 			fmt.Printf(" - %d receivers\n", len(cfg.Receivers))
 			fmt.Printf(" - %d templates\n", len(cfg.Templates))
 			if len(cfg.Templates) > 0 {
-				_, err = template.FromGlobs(cfg.Templates)
+				_, err = template.FromGlobs("", cfg.Templates)
 				if err != nil {
 					fmt.Printf("  FAILED: %s\n", err)
 					failed++
diff --git a/cli/template_render.go b/cli/template_render.go
index b02df7c..11a7d20 100644
--- a/cli/template_render.go
+++ b/cli/template_render.go
@@ -108,7 +108,7 @@ func configureTemplateRenderCmd(cc *kingpin.CmdClause) {
 }
 
 func (c *templateRenderCmd) render(ctx context.Context, _ *kingpin.ParseContext) error {
-	tmpl, err := template.FromGlobs(c.templateFilesGlobs)
+	tmpl, err := template.FromGlobs("", c.templateFilesGlobs)
 	if err != nil {
 		return err
 	}
diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go
index 87cdab8..872ad1d 100644
--- a/cmd/alertmanager/main.go
+++ b/cmd/alertmanager/main.go
@@ -156,6 +156,7 @@ func run() int {
 		routePrefix    = kingpin.Flag("web.route-prefix", "Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.").String()
 		getConcurrency = kingpin.Flag("web.get-concurrency", "Maximum number of GET requests processed concurrently. If negative or zero, the limit is GOMAXPROC or 8, whichever is larger.").Default("0").Int()
 		httpTimeout    = kingpin.Flag("web.timeout", "Timeout for HTTP requests. If negative or zero, no timeout is set.").Default("0").Duration()
+		uiPath = kingpin.Flag("web.ui-path", "Path to static UI directory.").Default("/usr/share/prometheus/alertmanager/ui/").String()
 
 		memlimitRatio = kingpin.Flag("auto-gomemlimit.ratio", "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value must be greater than 0 and less than or equal to 1.").
 				Default("0.9").Float64()
@@ -415,7 +416,7 @@ func run() int {
 		configLogger,
 	)
 	configCoordinator.Subscribe(func(conf *config.Config) error {
-		tmpl, err = template.FromGlobs(conf.Templates)
+		tmpl, err = template.FromGlobs("/usr/share/prometheus/alertmanager", conf.Templates)
 		if err != nil {
 			return fmt.Errorf("failed to parse templates: %w", err)
 		}
@@ -546,7 +547,7 @@ func run() int {
 
 	webReload := make(chan chan error)
 
-	ui.Register(router, webReload, logger)
+	ui.Register(router, webReload, *uiPath)
 	reactapp.Register(router, logger)
 
 	mux := api.Register(router, *routePrefix)
diff --git a/notify/email/email_test.go b/notify/email/email_test.go
index 0eec715..ff24451 100644
--- a/notify/email/email_test.go
+++ b/notify/email/email_test.go
@@ -209,7 +209,7 @@ func prepare(cfg *config.EmailConfig) (*template.Template, *types.Alert, error)
 		cfg.Headers = make(map[string]string)
 	}
 
-	tmpl, err := template.FromGlobs([]string{})
+	tmpl, err := template.FromGlobs("../../template", []string{})
 	if err != nil {
 		return nil, nil, err
 	}
diff --git a/notify/sns/sns_test.go b/notify/sns/sns_test.go
index bb64b11..a4c2baa 100644
--- a/notify/sns/sns_test.go
+++ b/notify/sns/sns_test.go
@@ -143,7 +143,7 @@ func TestNotifyWithInvalidTemplate(t *testing.T) {
 
 // CreateTmpl returns a ready-to-use template.
 func createTmpl(t *testing.T) *template.Template {
-	tmpl, err := template.FromGlobs([]string{})
+	tmpl, err := template.FromGlobs("", []string{})
 	require.NoError(t, err)
 	tmpl.ExternalURL, _ = url.Parse("http://am")
 	return tmpl
diff --git a/notify/test/test.go b/notify/test/test.go
index 75729b2..c13e417 100644
--- a/notify/test/test.go
+++ b/notify/test/test.go
@@ -128,7 +128,7 @@ func DefaultRetryCodes() []int {
 
 // CreateTmpl returns a ready-to-use template.
 func CreateTmpl(t *testing.T) *template.Template {
-	tmpl, err := template.FromGlobs([]string{})
+	tmpl, err := template.FromGlobs("../../template", []string{})
 	require.NoError(t, err)
 	tmpl.ExternalURL, _ = url.Parse("http://am")
 	return tmpl
diff --git a/template/template.go b/template/template.go
index 92f8323..e0d308e 100644
--- a/template/template.go
+++ b/template/template.go
@@ -18,7 +18,7 @@ import (
 	tmplhtml "html/template"
 	"io"
 	"net/url"
-	"path"
+	"os"
 	"path/filepath"
 	"regexp"
 	"sort"
@@ -31,7 +31,6 @@ import (
 	"golang.org/x/text/cases"
 	"golang.org/x/text/language"
 
-	"github.com/prometheus/alertmanager/asset"
 	"github.com/prometheus/alertmanager/types"
 )
 
@@ -67,16 +66,17 @@ func New(options ...Option) (*Template, error) {
 
 // FromGlobs calls ParseGlob on all path globs provided and returns the
 // resulting Template.
-func FromGlobs(paths []string, options ...Option) (*Template, error) {
+func FromGlobs(defaultTemplatePath string, paths []string, options ...Option) (*Template, error) {
 	t, err := New(options...)
 	if err != nil {
 		return nil, err
 	}
 
+	if defaultTemplatePath != "" {
 	defaultTemplates := []string{"default.tmpl", "email.tmpl"}
 
 	for _, file := range defaultTemplates {
-		f, err := asset.Assets.Open(path.Join("/templates", file))
+		f, err := os.Open(filepath.Join(defaultTemplatePath, file))
 		if err != nil {
 			return nil, err
 		}
@@ -86,6 +86,7 @@ func FromGlobs(paths []string, options ...Option) (*Template, error) {
 		}
 		f.Close()
 	}
+	}
 
 	for _, tp := range paths {
 		if err := t.FromGlob(tp); err != nil {
diff --git a/template/template_test.go b/template/template_test.go
index ea8915b..f306bae 100644
--- a/template/template_test.go
+++ b/template/template_test.go
@@ -287,7 +287,7 @@ func TestData(t *testing.T) {
 }
 
 func TestTemplateExpansion(t *testing.T) {
-	tmpl, err := FromGlobs([]string{})
+	tmpl, err := FromGlobs("../template", []string{})
 	require.NoError(t, err)
 
 	for _, tc := range []struct {
@@ -450,7 +450,7 @@ func TestTemplateExpansionWithOptions(t *testing.T) {
 	} {
 		tc := tc
 		t.Run(tc.title, func(t *testing.T) {
-			tmpl, err := FromGlobs([]string{}, tc.options...)
+			tmpl, err := FromGlobs("../template", []string{}, tc.options...)
 			require.NoError(t, err)
 			f := tmpl.ExecuteTextString
 			if tc.html {
@@ -469,7 +469,7 @@ func TestTemplateExpansionWithOptions(t *testing.T) {
 
 // This test asserts that template functions are thread-safe.
 func TestTemplateFuncs(t *testing.T) {
-	tmpl, err := FromGlobs([]string{})
+	tmpl, err := FromGlobs("../template", []string{})
 	require.NoError(t, err)
 
 	for _, tc := range []struct {
diff --git a/ui/app/src/Views.elm b/ui/app/src/Views.elm
index 4bbcd06..ce29db8 100644
--- a/ui/app/src/Views.elm
+++ b/ui/app/src/Views.elm
@@ -55,8 +55,8 @@ failureView model err =
 renderCSS : String -> Html Msg
 renderCSS assetsUrl =
     div []
-        [ cssNode (assetsUrl ++ "lib/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.min.css") BootstrapCSSLoaded
-        , cssNode (assetsUrl ++ "lib/font-awesome-4.7.0/css/font-awesome.min.css") FontAwesomeCSSLoaded
+        [ cssNode (assetsUrl ++ "lib/bootstrap/css/bootstrap.min.css") BootstrapCSSLoaded
+        , cssNode (assetsUrl ++ "lib/font-awesome/css/font-awesome.min.css") FontAwesomeCSSLoaded
         , cssNode (assetsUrl ++ "lib/elm-datepicker/css/elm-datepicker.css") ElmDatepickerCSSLoaded
         ]
 
diff --git a/ui/web.go b/ui/web.go
index 3b81135..aab56b4 100644
--- a/ui/web.go
+++ b/ui/web.go
@@ -15,51 +15,45 @@ package ui
 
 import (
 	"fmt"
-	"log/slog"
 	"net/http"
 	_ "net/http/pprof" // Comment this line to disable pprof endpoint.
 	"path"
+	"os"
 
 	"github.com/prometheus/client_golang/prometheus/promhttp"
 	"github.com/prometheus/common/route"
-
-	"github.com/prometheus/alertmanager/asset"
 )
 
 // Register registers handlers to serve files for the web interface.
-func Register(r *route.Router, reloadCh chan<- chan error, logger *slog.Logger) {
+func Register(r *route.Router, reloadCh chan<- chan error, uiPath string) {
+	if _, err := os.Stat(path.Join(uiPath, "index.html")); os.IsNotExist(err) {
+		// UI not installed, use stub site.
+		uiPath = "/usr/share/prometheus/alertmanager/no-ui"
+	}
 	r.Get("/metrics", promhttp.Handler().ServeHTTP)
 
 	r.Get("/", func(w http.ResponseWriter, req *http.Request) {
 		disableCaching(w)
 
-		req.URL.Path = "/static/"
-		fs := http.FileServer(asset.Assets)
-		fs.ServeHTTP(w, req)
+		http.ServeFile(w, req, path.Join(uiPath, "index.html"))
 	})
 
 	r.Get("/script.js", func(w http.ResponseWriter, req *http.Request) {
 		disableCaching(w)
 
-		req.URL.Path = "/static/script.js"
-		fs := http.FileServer(asset.Assets)
-		fs.ServeHTTP(w, req)
+		http.ServeFile(w, req, path.Join(uiPath, "script.js"))
 	})
 
 	r.Get("/favicon.ico", func(w http.ResponseWriter, req *http.Request) {
 		disableCaching(w)
 
-		req.URL.Path = "/static/favicon.ico"
-		fs := http.FileServer(asset.Assets)
-		fs.ServeHTTP(w, req)
+		http.ServeFile(w, req, path.Join(uiPath, "favicon.ico"))
 	})
 
 	r.Get("/lib/*path", func(w http.ResponseWriter, req *http.Request) {
 		disableCaching(w)
 
-		req.URL.Path = path.Join("/static/lib", route.Param(req.Context(), "path"))
-		fs := http.FileServer(asset.Assets)
-		fs.ServeHTTP(w, req)
+		http.ServeFile(w, req, path.Join(uiPath, "/lib", route.Param(req.Context(), "path")))
 	})
 
 	r.Post("/-/reload", func(w http.ResponseWriter, req *http.Request) {