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

package info (click to toggle)
prometheus 2.53.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 25,388 kB
  • sloc: javascript: 2,423; yacc: 758; sh: 431; makefile: 231; lex: 189
file content (160 lines) | stat: -rw-r--r-- 7,089 bytes parent folder | download | duplicates (2)
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
From: Martina Ferrari <tina@debian.org>
Date: Sat, 20 Jun 2020 15:32:33 -0300
Subject: Do not embed blobs

Forwarded: not-needed
Last-Update: Mon, 14 Mar 2022 23:20:08 +0000

Avoid embedding blobs into the prometheus binary, instead use files
installed on disk.
---
 cmd/prometheus/main.go     |  3 +++
 console_libraries/prom.lib | 16 ++++++++--------
 web/ui/ui.go               |  3 ++-
 web/web.go                 | 29 ++++++++++-------------------
 4 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go
index 9829125..a7d5600 100644
--- a/cmd/prometheus/main.go
+++ b/cmd/prometheus/main.go
@@ -313,6 +313,9 @@ func main() {
 		"Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.").
 		PlaceHolder("<path>").StringVar(&cfg.web.RoutePrefix)
 
+	a.Flag("web.local-assets", "Path to static asset/templates directory.").
+		Default("/usr/share/prometheus/web/").StringVar(&cfg.web.LocalAssets)
+
 	a.Flag("web.user-assets", "Path to user asset directory, available at /user.").
 		PlaceHolder("<path>").StringVar(&cfg.web.UserAssetsPath)
 
diff --git a/console_libraries/prom.lib b/console_libraries/prom.lib
index d7d436f..802810a 100644
--- a/console_libraries/prom.lib
+++ b/console_libraries/prom.lib
@@ -1,16 +1,16 @@
 {{/* vim: set ft=html: */}}
 {{/* Load Prometheus console library JS/CSS. Should go in <head> */}}
 {{ define "prom_console_head" }}
-<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/classic/static/vendor/rickshaw/rickshaw.min.css">
-<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/classic/static/vendor/bootstrap-4.5.2/css/bootstrap.min.css">
+<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/classic/static/rickshaw/rickshaw.min.css">
+<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/classic/static/bootstrap4/css/bootstrap.min.css">
 <link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/classic/static/css/prom_console.css">
-<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/classic/static/vendor/bootstrap4-glyphicons/css/bootstrap-glyphicons.min.css">
-<script src="{{ pathPrefix }}/classic/static/vendor/rickshaw/vendor/d3.v3.js"></script>
+<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/classic/static/vendor/bootstrap4-glyphicons/css/bootstrap-glyphicons.css">
+<script src="{{ pathPrefix }}/classic/static/d3/d3.min.js"></script>
 <script src="{{ pathPrefix }}/classic/static/vendor/rickshaw/vendor/d3.layout.min.js"></script>
-<script src="{{ pathPrefix }}/classic/static/vendor/rickshaw/rickshaw.min.js"></script>
-<script src="{{ pathPrefix }}/classic/static/vendor/js/jquery-3.5.1.min.js"></script>
-<script src="{{ pathPrefix }}/classic/static/vendor/js/popper.min.js"></script>
-<script src="{{ pathPrefix }}/classic/static/vendor/bootstrap-4.5.2/js/bootstrap.min.js"></script>
+<script src="{{ pathPrefix }}/classic/static/rickshaw/rickshaw.min.js"></script>
+<script src="{{ pathPrefix }}/classic/static/jquery/jquery.min.js"></script>
+<script src="{{ pathPrefix }}/classic/static/popper.js"></script>
+<script src="{{ pathPrefix }}/classic/static/bootstrap4/js/bootstrap.min.js"></script>
 
 <script>
 var PATH_PREFIX = "{{ pathPrefix }}";
diff --git a/web/ui/ui.go b/web/ui/ui.go
index 2585951..842dd4a 100644
--- a/web/ui/ui.go
+++ b/web/ui/ui.go
@@ -11,7 +11,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-//go:build !builtinassets
+//go:build ignore
+// +build ignore
 
 package ui
 
diff --git a/web/web.go b/web/web.go
index a87759f..620c356 100644
--- a/web/web.go
+++ b/web/web.go
@@ -19,6 +19,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"io"
+	"io/fs"
 	stdlog "log"
 	"math"
 	"net"
@@ -45,7 +46,6 @@ import (
 	io_prometheus_client "github.com/prometheus/client_model/go"
 	"github.com/prometheus/common/model"
 	"github.com/prometheus/common/route"
-	"github.com/prometheus/common/server"
 	toolkit_web "github.com/prometheus/exporter-toolkit/web"
 	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
 	"go.uber.org/atomic"
@@ -60,7 +60,6 @@ import (
 	"github.com/prometheus/prometheus/template"
 	"github.com/prometheus/prometheus/util/httputil"
 	api_v1 "github.com/prometheus/prometheus/web/api/v1"
-	"github.com/prometheus/prometheus/web/ui"
 )
 
 // Paths that are handled by the React / Reach router that should all be served the main React app's index.html.
@@ -250,7 +249,7 @@ type Options struct {
 	MaxConnections             int
 	ExternalURL                *url.URL
 	RoutePrefix                string
-	UseLocalAssets             bool
+	LocalAssets                string
 	UserAssetsPath             string
 	ConsoleTemplatesPath       string
 	ConsoleLibrariesPath       string
@@ -376,11 +375,7 @@ func New(logger log.Logger, o *Options) *Handler {
 	})
 
 	// The console library examples at 'console_libraries/prom.lib' still depend on old asset files being served under `classic`.
-	router.Get("/classic/static/*filepath", func(w http.ResponseWriter, r *http.Request) {
-		r.URL.Path = path.Join("/static", route.Param(r.Context(), "filepath"))
-		fs := server.StaticFileServer(ui.Assets)
-		fs.ServeHTTP(w, r)
-	})
+	router.Get("/classic/static/*filepath", route.FileServe(filepath.Join(o.LocalAssets, "static")))
 
 	router.Get("/version", h.version)
 	router.Get("/metrics", promhttp.Handler().ServeHTTP)
@@ -392,8 +387,11 @@ func New(logger log.Logger, o *Options) *Handler {
 	router.Get("/consoles/*filepath", readyf(h.consoles))
 
 	serveReactApp := func(w http.ResponseWriter, r *http.Request) {
-		f, err := ui.Assets.Open("/static/react/index.html")
-		if err != nil {
+		f, err := os.Open(filepath.Join(o.LocalAssets, "static/react/index.html"))
+		if errors.Is(err, fs.ErrNotExist) {
+			http.ServeFile(w, r, "/usr/share/prometheus/web/no-ui/index.html")
+			return
+		} else if err != nil {
 			w.WriteHeader(http.StatusInternalServerError)
 			fmt.Fprintf(w, "Error opening React index.html: %v", err)
 			return
@@ -430,20 +428,13 @@ func New(logger log.Logger, o *Options) *Handler {
 	// The favicon and manifest are bundled as part of the React app, but we want to serve
 	// them on the root.
 	for _, p := range []string{"/favicon.ico", "/manifest.json"} {
-		assetPath := "/static/react" + p
 		router.Get(p, func(w http.ResponseWriter, r *http.Request) {
-			r.URL.Path = assetPath
-			fs := server.StaticFileServer(ui.Assets)
-			fs.ServeHTTP(w, r)
+			http.ServeFile(w, r, filepath.Join(o.LocalAssets, "static/react", p))
 		})
 	}
 
 	// Static files required by the React app.
-	router.Get("/static/*filepath", func(w http.ResponseWriter, r *http.Request) {
-		r.URL.Path = path.Join("/static/react/static", route.Param(r.Context(), "filepath"))
-		fs := server.StaticFileServer(ui.Assets)
-		fs.ServeHTTP(w, r)
-	})
+	router.Get("/static/*filepath", route.FileServe(filepath.Join(o.LocalAssets, "static/react/static")))
 
 	if o.UserAssetsPath != "" {
 		router.Get("/user/*filepath", route.FileServe(o.UserAssetsPath))