Skip to content

Commit ac32268

Browse files
committed
Revert "app/vlselect: introduce -vmalert.proxyURL flag to proxy /select/vmalert requests to VMAlert (#5)"
This reverts commit 2d4b343. Reason for revert: this commit mixes two unrelated features: - Proxying vmalert requests ( #90 ) - Introducing vmui config handler at /select/vmui/config.json ( there should be a separate feature request with the explanation why this handler is needed ) - Returning AccountID and ProjectID response headers ( #656 ) It is better from the maintenance and git history investigation PoV to split the implementation of these features into separate pull requests. This commit also has a few issues in the code, which must be addressed in the follow-up pull requests: - The description of the `-vmalert.proxyURL` command-line flag misses a whitespace between the `vmalert.` and `See`. - The description of the `-vmalert.proxyURL` command-line flag contains non-canonical link to docs - https://docs.victoriametrics.com/victorialogs#vmalert . It must be https://docs.victoriametrics.com/victorialogs/#vmalert - The `r.URL.Path = strings.TrimPrefix(path, "/select")` line isn't needed in the code block, which returns vmui config to the client. Updates #5
1 parent 0463c2a commit ac32268

File tree

4 files changed

+0
-115
lines changed

4 files changed

+0
-115
lines changed

app/vlselect/main.go

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ package vlselect
33
import (
44
"context"
55
"embed"
6-
"encoding/json"
76
"flag"
87
"fmt"
98
"net/http"
10-
nethttputil "net/http/httputil"
11-
"net/url"
129
"strings"
1310
"time"
1411

15-
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
1612
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
1713
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
1814
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httputil"
@@ -33,9 +29,6 @@ var (
3329

3430
disableSelect = flag.Bool("select.disable", false, "Whether to disable /select/* HTTP endpoints")
3531
disableInternal = flag.Bool("internalselect.disable", false, "Whether to disable /internal/select/* HTTP endpoints")
36-
37-
vmalertProxyURL = flag.String("vmalert.proxyURL", "", "Optional URL for proxying requests to vmalert."+
38-
"See https://docs.victoriametrics.com/victorialogs#vmalert.")
3932
)
4033

4134
func getDefaultMaxConcurrentRequests() int {
@@ -55,8 +48,6 @@ func getDefaultMaxConcurrentRequests() int {
5548
// Init initializes vlselect
5649
func Init() {
5750
concurrencyLimitCh = make(chan struct{}, *maxConcurrentRequests)
58-
initVMUIConfig()
59-
initVMAlertProxy()
6051

6152
internalselect.Init()
6253
}
@@ -125,22 +116,6 @@ func selectHandler(w http.ResponseWriter, r *http.Request, path string) bool {
125116
return true
126117
}
127118
if strings.HasPrefix(path, "/select/vmui/") {
128-
if path == "/select/vmui/config.json" {
129-
w.Header().Set("Content-Type", "application/json")
130-
r.URL.Path = strings.TrimPrefix(path, "/select")
131-
if disableTenantControls := r.Header.Get("VL-Disable-Tenant-Controls"); disableTenantControls == "true" {
132-
w.Header().Set("VL-Disable-Tenant-Controls", "true")
133-
} else {
134-
if accountID := r.Header.Get("AccountID"); len(accountID) > 0 {
135-
w.Header().Set("AccountID", accountID)
136-
}
137-
if projectID := r.Header.Get("ProjectID"); len(projectID) > 0 {
138-
w.Header().Set("ProjectID", projectID)
139-
}
140-
}
141-
fmt.Fprint(w, vmuiConfig)
142-
return true
143-
}
144119
if strings.HasPrefix(path, "/select/vmui/static/") {
145120
// Allow clients caching static contents for long period of time, since it shouldn't change over time.
146121
// Path to static contents (such as js and css) must be changed whenever its contents is changed.
@@ -242,17 +217,6 @@ func decRequestConcurrency() {
242217
func processSelectRequest(ctx context.Context, w http.ResponseWriter, r *http.Request, path string) bool {
243218
httpserver.EnableCORS(w, r)
244219
startTime := time.Now()
245-
if strings.HasPrefix(path, "/select/vmalert/") {
246-
vmalertRequests.Inc()
247-
if len(*vmalertProxyURL) == 0 {
248-
w.Header().Set("Content-Type", "application/json")
249-
w.WriteHeader(http.StatusBadRequest)
250-
fmt.Fprintf(w, "%s", `{"status":"error","msg":"for accessing vmalert flag '-vmalert.proxyURL' must be configured"}`)
251-
return true
252-
}
253-
proxyVMAlertRequests(w, r)
254-
return true
255-
}
256220
switch path {
257221
case "/select/logsql/facets":
258222
logsqlFacetsRequests.Inc()
@@ -327,72 +291,6 @@ func getMaxQueryDuration(r *http.Request) time.Duration {
327291
return d
328292
}
329293

330-
func proxyVMAlertRequests(w http.ResponseWriter, r *http.Request) {
331-
defer func() {
332-
err := recover()
333-
if err == nil || err == http.ErrAbortHandler {
334-
// Suppress http.ErrAbortHandler panic.
335-
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1353
336-
return
337-
}
338-
// Forward other panics to the caller.
339-
panic(err)
340-
}()
341-
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/select")
342-
r.Host = vmalertProxyHost
343-
vmalertProxy.ServeHTTP(w, r)
344-
}
345-
346-
func initVMUIConfig() {
347-
var cfg struct {
348-
Version string `json:"version"`
349-
License struct {
350-
Type string `json:"type"`
351-
} `json:"license"`
352-
VMAlert struct {
353-
Enabled bool `json:"enabled"`
354-
} `json:"vmalert"`
355-
}
356-
cfg.Version = buildinfo.ShortVersion()
357-
if cfg.Version == "" {
358-
// buildinfo.ShortVersion() may return empty result for builds without tags
359-
cfg.Version = buildinfo.Version
360-
}
361-
data, err := vmuiFiles.ReadFile("vmui/config.json")
362-
if err != nil {
363-
logger.Fatalf("cannot read vmui default config: %s", err)
364-
}
365-
err = json.Unmarshal(data, &cfg)
366-
if err != nil {
367-
logger.Fatalf("cannot parse vmui default config: %s", err)
368-
}
369-
cfg.VMAlert.Enabled = len(*vmalertProxyURL) != 0
370-
data, err = json.Marshal(&cfg)
371-
if err != nil {
372-
logger.Fatalf("cannot create vmui config: %s", err)
373-
}
374-
vmuiConfig = string(data)
375-
}
376-
377-
// initVMAlertProxy must be called after flag.Parse(), since it uses command-line flags.
378-
func initVMAlertProxy() {
379-
if len(*vmalertProxyURL) == 0 {
380-
return
381-
}
382-
proxyURL, err := url.Parse(*vmalertProxyURL)
383-
if err != nil {
384-
logger.Fatalf("cannot parse -vmalert.proxyURL=%q: %s", *vmalertProxyURL, err)
385-
}
386-
vmalertProxyHost = proxyURL.Host
387-
vmalertProxy = nethttputil.NewSingleHostReverseProxy(proxyURL)
388-
}
389-
390-
var (
391-
vmalertProxyHost string
392-
vmalertProxy *nethttputil.ReverseProxy
393-
vmuiConfig string
394-
)
395-
396294
var (
397295
logsqlFacetsRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/logsql/facets"}`)
398296
logsqlFacetsDuration = metrics.NewSummary(`vl_http_request_duration_seconds{path="/select/logsql/facets"}`)
@@ -429,6 +327,4 @@ var (
429327

430328
// no need to track duration for tail requests, as they usually take long time
431329
logsqlTailRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/logsql/tail"}`)
432-
433-
vmalertRequests = metrics.NewCounter(`vl_http_requests_total{path="/select/vmalert"}`)
434330
)

docs/victorialogs/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta
1919
## tip
2020

2121
* FEATURE: [querying](https://docs.victoriametrics.com/victorialogs/querying/): add an ability to return partial responses in [VictoriaLogs cluster setup](https://docs.victoriametrics.com/victorialogs/cluster/) when some of `vlstorage` nodes are unavailable. See [these docs](https://docs.victoriametrics.com/victorialogs/querying/#partial-responses) for details. See [#72](https://github.com/VictoriaMetrics/VictoriaLogs/issues/72).
22-
* FEATURE: proxy VMAlert requests at `/select/vmalert` path, when `-vmalert.proxyURL` flag is set. See [#90](https://github.com/VictoriaMetrics/VictoriaLogs/issues/90).
2322
* FEATURE: [vlselect](https://docs.victoriametrics.com/victorialogs/cluster/): add `-storageNode.usernameFile` command-line flag for dynamically reloading basic auth username for the corresponding `-storageNode` from the given file. See [#459](https://github.com/VictoriaMetrics/VictoriaLogs/issues/459).
2423

2524
* BUGFIX: [LogsQL](https://docs.victoriametrics.com/victorialogs/logsql/): disallow incorrectly written filters such as `foo = bar`, `foo != bar`, `foo > bar`, etc. They must be written as `foo:=bar`, `foo:!=bar`, `foo:>bar`. See [#590](https://github.com/VictoriaMetrics/VictoriaLogs/issues/590).

docs/victorialogs/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,6 @@ The following steps must be performed for restoring the partition data from back
339339

340340
It is also possible to use **the disk snapshot** feature provided by the operating system or cloud provider in order to perform a backup.
341341

342-
## vmalert
343-
344-
VictoriaLogs is capable of proxying requests to [VMAlert](https://docs.victoriametrics.com/victorialogs/vmalert/)
345-
when `-vmalert.proxyURL` flag is set. Use this feature for accessing VMAlert API through VictoriaLogs Web interface.
346-
347-
For accessing VMAlert API through VictoriaLogs configure `-vmalert.proxyURL` flag. All VMAlert endpoints become available at `http://<victorialogs-addr>:9428/select/vmalert`.
348-
349342
## Multitenancy
350343

351344
VictoriaLogs supports multitenancy. A tenant is identified by `(AccountID, ProjectID)` pair, where `AccountID` and `ProjectID` are arbitrary 32-bit unsigned integers.

docs/victorialogs/vmalert.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ and [`/select/logsql/stats_query_range`](https://docs.victoriametrics.com/victor
1818
These endpoints return the log stats in a format compatible with [Prometheus querying API](https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries).
1919
It allows using VictoriaLogs as the datasource in vmalert, creating alerting and recording rules via [LogsQL](https://docs.victoriametrics.com/victorialogs/logsql/).
2020

21-
Configure `-vmalert.proxyURL` on [VictoriaLogs](https://docs.victoriametrics.com/victorialogs/#vmalert){{% available_from "#" %}} to proxy requests to `vmalert`.
22-
Proxying is needed to access `vmalert`'s UI through [vmui](https://docs.victoriametrics.com/#vmui).
23-
2421
> This page provides only integration instructions for vmalert and VictoriaLogs. See the full textbook for vmalert [here](https://docs.victoriametrics.com/victoriametrics/vmalert/).
2522
2623
## Quick Start

0 commit comments

Comments
 (0)