Skip to content

Commit 8be52ef

Browse files
committed
app/vlselect: handle vmui at /select/vmui path instead of /vmui
This simplifies routing at auth proxies such as vmauth to vlselect component, which serves VMUI - just route all the requests, which start with /select/, to vlselect.
1 parent df83b43 commit 8be52ef

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

app/victoria-logs/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
7878
fmt.Fprintf(w, "See docs at <a href='https://docs.victoriametrics.com/VictoriaLogs/'>https://docs.victoriametrics.com/VictoriaLogs/</a></br>")
7979
fmt.Fprintf(w, "Useful endpoints:</br>")
8080
httpserver.WriteAPIHelp(w, [][2]string{
81-
{"vmui", "Web UI for VictoriaLogs"},
81+
{"select/vmui", "Web UI for VictoriaLogs"},
8282
{"metrics", "available service metrics"},
8383
{"flags", "command-line flags"},
8484
})

app/vlinsert/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func Stop() {
2020
func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
2121
path := r.URL.Path
2222
if !strings.HasPrefix(path, "/insert/") {
23+
// Skip requests, which do not start with /insert/, since these aren't our requests.
2324
return false
2425
}
2526
path = strings.TrimPrefix(path, "/insert")

app/vlselect/main.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,29 @@ var vmuiFileServer = http.FileServer(http.FS(vmuiFiles))
7171
// RequestHandler handles select requests for VictoriaLogs
7272
func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
7373
path := r.URL.Path
74+
if !strings.HasPrefix(path, "/select/") {
75+
// Skip requests, which do not start with /select/, since these aren't our requests.
76+
return false
77+
}
7478
path = strings.TrimPrefix(path, "/select")
7579
path = strings.ReplaceAll(path, "//", "/")
7680

77-
// Limit the number of concurrent queries.
81+
if path == "/vmui" {
82+
// VMUI access via incomplete url without `/` in the end. Redirect to complete url.
83+
// Use relative redirect, since the hostname and path prefix may be incorrect if VictoriaMetrics
84+
// is hidden behind vmauth or similar proxy.
85+
_ = r.ParseForm()
86+
newURL := "vmui/?" + r.Form.Encode()
87+
httpserver.Redirect(w, newURL)
88+
return true
89+
}
90+
if strings.HasPrefix(path, "/vmui/") {
91+
r.URL.Path = path
92+
vmuiFileServer.ServeHTTP(w, r)
93+
return true
94+
}
95+
96+
// Limit the number of concurrent queries, which can consume big amounts of CPU.
7897
startTime := time.Now()
7998
stopCh := r.Context().Done()
8099
select {
@@ -115,24 +134,11 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
115134
}
116135

117136
switch {
118-
case path == "/vmui":
119-
// VMUI access via incomplete url without `/` in the end. Redirect to complete url.
120-
// Use relative redirect, since, since the hostname and path prefix may be incorrect if VictoriaMetrics
121-
// is hidden behind vmauth or similar proxy.
122-
_ = r.ParseForm()
123-
path = strings.TrimPrefix(path, "/")
124-
newURL := path + "/?" + r.Form.Encode()
125-
httpserver.Redirect(w, newURL)
126-
return true
127137
case path == "/logsql/query":
128138
logsqlQueryRequests.Inc()
129139
httpserver.EnableCORS(w, r)
130140
logsql.ProcessQueryRequest(w, r, stopCh)
131141
return true
132-
case strings.HasPrefix(path, "/vmui/"):
133-
r.URL.Path = path
134-
vmuiFileServer.ServeHTTP(w, r)
135-
return true
136142
default:
137143
return false
138144
}

app/vmselect/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
175175
switch {
176176
case path == "/vmui" || path == "/graph":
177177
// VMUI access via incomplete url without `/` in the end. Redirect to complete url.
178-
// Use relative redirect, since, since the hostname and path prefix may be incorrect if VictoriaMetrics
178+
// Use relative redirect, since the hostname and path prefix may be incorrect if VictoriaMetrics
179179
// is hidden behind vmauth or similar proxy.
180180
_ = r.ParseForm()
181181
path = strings.TrimPrefix(path, "/")

docs/VictoriaLogs/querying/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ with `vl_http_requests_total{path="/select/logsql/query"}` metric.
6060
## Web UI
6161

6262
VictoriaLogs provides a simple Web UI for logs [querying](https://docs.victoriametrics.com/VictoriaLogs/LogsQL.html) and exploration
63-
at `http://localhost:9428/vmui`. The UI allows exploring query results:
63+
at `http://localhost:9428/select/vmui`. The UI allows exploring query results:
6464

6565
<img src="vmui.png" width="800" />
6666

0 commit comments

Comments
 (0)