Skip to content

Commit 3b1598e

Browse files
updated docs
1 parent 01ddff7 commit 3b1598e

File tree

3 files changed

+50
-40
lines changed

3 files changed

+50
-40
lines changed

app/vlselect/main.go

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package vlselect
33
import (
44
"context"
55
"embed"
6+
"encoding/json"
67
"flag"
78
"fmt"
89
"net/http"
@@ -52,6 +53,7 @@ func getDefaultMaxConcurrentRequests() int {
5253
// Init initializes vlselect
5354
func Init() {
5455
concurrencyLimitCh = make(chan struct{}, *maxConcurrentRequests)
56+
initVMUIConfig()
5557
initVMAlertProxy()
5658
}
5759

@@ -116,6 +118,11 @@ func selectHandler(w http.ResponseWriter, r *http.Request, path string) bool {
116118
return true
117119
}
118120
if strings.HasPrefix(path, "/select/vmui/") {
121+
if path == "/select/vmui/config.json" {
122+
w.Header().Set("Content-Type", "application/json")
123+
fmt.Fprint(w, vmuiConfig)
124+
return true
125+
}
119126
if strings.HasPrefix(path, "/select/vmui/static/") {
120127
// Allow clients caching static contents for long period of time, since it shouldn't change over time.
121128
// Path to static contents (such as js and css) must be changed whenever its contents is changed.
@@ -217,6 +224,17 @@ func decRequestConcurrency() {
217224
func processSelectRequest(ctx context.Context, w http.ResponseWriter, r *http.Request, path string) bool {
218225
httpserver.EnableCORS(w, r)
219226
startTime := time.Now()
227+
if strings.HasPrefix(path, "/select/vmalert/") {
228+
vmalertRequests.Inc()
229+
if len(*vmalertProxyURL) == 0 {
230+
w.WriteHeader(http.StatusBadRequest)
231+
w.Header().Set("Content-Type", "application/json")
232+
fmt.Fprintf(w, "%s", `{"status":"error","msg":"for accessing vmalert flag '-vmalert.proxyURL' must be configured"}`)
233+
return true
234+
}
235+
proxyVMAlertRequests(w, r)
236+
return true
237+
}
220238
switch path {
221239
case "/select/logsql/facets":
222240
logsqlFacetsRequests.Inc()
@@ -273,36 +291,6 @@ func processSelectRequest(ctx context.Context, w http.ResponseWriter, r *http.Re
273291
logsql.ProcessStreamsRequest(ctx, w, r)
274292
logsqlStreamsDuration.UpdateDuration(startTime)
275293
return true
276-
case "/select/api/v1/notifiers":
277-
notifiersRequests.Inc()
278-
if len(*vmalertProxyURL) > 0 {
279-
r.URL.Path = path[len("/select"):]
280-
proxyVMAlertRequests(w, r)
281-
return true
282-
}
283-
w.Header().Set("Content-Type", "application/json")
284-
fmt.Fprint(w, `{"status":"success","data":{"notifiers":[]}}`)
285-
return true
286-
case "/select/api/v1/alerts":
287-
alertsRequests.Inc()
288-
if len(*vmalertProxyURL) > 0 {
289-
r.URL.Path = path[len("/select"):]
290-
proxyVMAlertRequests(w, r)
291-
return true
292-
}
293-
w.Header().Set("Content-Type", "application/json")
294-
fmt.Fprint(w, `{"status":"success","data":{"alerts":[]}}`)
295-
return true
296-
case "/select/api/v1/rules":
297-
rulesRequests.Inc()
298-
if len(*vmalertProxyURL) > 0 {
299-
r.URL.Path = path[len("/select"):]
300-
proxyVMAlertRequests(w, r)
301-
return true
302-
}
303-
w.Header().Set("Content-Type", "application/json")
304-
fmt.Fprint(w, `{"status":"success","data":{"rules":[]}}`)
305-
return true
306294
default:
307295
return false
308296
}
@@ -332,10 +320,36 @@ func proxyVMAlertRequests(w http.ResponseWriter, r *http.Request) {
332320
// Forward other panics to the caller.
333321
panic(err)
334322
}()
323+
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/select")
335324
r.Host = vmalertProxyHost
336325
vmalertProxy.ServeHTTP(w, r)
337326
}
338327

328+
func initVMUIConfig() {
329+
var cfg struct {
330+
License struct {
331+
Type string `json:"type"`
332+
} `json:"license"`
333+
VMAlert struct {
334+
Enabled bool `json:"enabled"`
335+
} `json:"vmalert"`
336+
}
337+
data, err := vmuiFiles.ReadFile("vmui/config.json")
338+
if err != nil {
339+
logger.Fatalf("cannot read vmui default config: %s", err)
340+
}
341+
err = json.Unmarshal(data, &cfg)
342+
if err != nil {
343+
logger.Fatalf("cannot parse vmui default config: %s", err)
344+
}
345+
cfg.VMAlert.Enabled = len(*vmalertProxyURL) != 0
346+
data, err = json.Marshal(&cfg)
347+
if err != nil {
348+
logger.Fatalf("cannot create vmui config: %s", err)
349+
}
350+
vmuiConfig = string(data)
351+
}
352+
339353
// initVMAlertProxy must be called after flag.Parse(), since it uses command-line flags.
340354
func initVMAlertProxy() {
341355
if len(*vmalertProxyURL) == 0 {
@@ -352,6 +366,7 @@ func initVMAlertProxy() {
352366
var (
353367
vmalertProxyHost string
354368
vmalertProxy *nethttputil.ReverseProxy
369+
vmuiConfig string
355370
)
356371

357372
var (
@@ -391,7 +406,5 @@ var (
391406
// no need to track duration for tail requests, as they usually take long time
392407
logsqlTailRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/logsql/tail"}`)
393408

394-
rulesRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/api/v1/rules"}`)
395-
alertsRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/api/v1/alerts"}`)
396-
notifiersRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/api/v1/notifiers"}`)
409+
vmalertRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/vmalert"}`)
397410
)

docs/victorialogs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta
1818

1919
## tip
2020

21-
* FEATURE: proxy requests to `/api/v1/notifiers`, `/api/v1/alerts` and `/api/v1/rules` to VMAlert, when `-vmalert.proxyURL` flag is set. See [#8272](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8272).
21+
* FEATURE: proxy VMAlert requests at `/select/vmalert` path, when `-vmalert.proxyURL` flag is set. See [#8272](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8272).
2222

2323
## [v1.25.0](https://github.com/VictoriaMetrics/VictoriaLogs/releases/tag/v1.25.0)
2424

docs/victorialogs/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,10 @@ cloud provider, or third-party tools. Note that the snapshot must be **consisten
263263

264264
## vmalert
265265

266-
VictoriaLogs is capable of proxying requests to [vmalert](https://docs.victoriametrics.com/victoriametrics/vmalert/)
267-
when `-vmalert.proxyURL` flag is set. Use this feature for the following cases:
268-
* for proxying requests from [Grafana Alerting UI](https://grafana.com/docs/grafana/latest/alerting/);
269-
* for accessing vmalerts UI through VictoriaLogs Web interface.
266+
VictoriaLogs is capable of proxying requests to [VMAlert](https://docs.victoriametrics.com/victoriametrics/vmalert/)
267+
when `-vmalert.proxyURL` flag is set. Use this feature for accessing VMAlert API through VictoriaLogs Web interface.
270268

271-
For accessing vmalerts UI through VictoriaLogs configure `-vmalert.proxyURL` flag and visit
272-
`http://<victorialogs-addr>:9428/vmalert/` link.
269+
For accessing VMAlert API through VictoriaLogs configure `-vmalert.proxyURL` flag. All VMAlert endpoints become available at `http://<victorialogs-addr>:9428/select/vmalert`.
273270

274271
## Multitenancy
275272

0 commit comments

Comments
 (0)