diff --git a/Makefile b/Makefile index cddd06ced..551c587c7 100644 --- a/Makefile +++ b/Makefile @@ -418,27 +418,37 @@ check-licenses: install-wwhrd wwhrd check -f .wwhrd.yml copy-docs: - echo '' > ${DST} + echo "---" > ${DST} @if [ ${ORDER} -ne 0 ]; then \ - echo "---\nsort: ${ORDER}\n---\n" > ${DST}; \ + echo "sort: ${ORDER}" >> ${DST}; \ + echo "weight: ${ORDER}" >> ${DST}; \ + echo "menu:\n docs:\n parent: 'victoriametrics'\n weight: ${ORDER}" >> ${DST}; \ fi + + echo "title: ${TITLE}" >> ${DST} + @if [ ${OLD_URL} ]; then \ + echo "aliases:\n - ${OLD_URL}" >> ${DST}; \ + fi + echo "---" >> ${DST} cat ${SRC} >> ${DST} sed -i='.tmp' 's/ 0 { + ns.extraHeaders = make([]keyValue, len(s.extraHeaders)) + copy(ns.extraHeaders, s.extraHeaders) + } + for k, v := range s.extraParams { + ns.extraParams[k] = v + } + + return ns } // ApplyParams - changes given querier params. func (s *VMStorage) ApplyParams(params QuerierParams) *VMStorage { s.dataSourceType = toDatasourceType(params.DataSourceType) s.evaluationInterval = params.EvaluationInterval - s.extraParams = params.QueryParams - s.debug = params.Debug + if params.QueryParams != nil { + if s.extraParams == nil { + s.extraParams = url.Values{} + } + for k, vl := range params.QueryParams { + for _, v := range vl { // custom query params are prior to default ones + s.extraParams.Set(k, v) + } + } + } if params.Headers != nil { for key, value := range params.Headers { kv := keyValue{key: key, value: value} s.extraHeaders = append(s.extraHeaders, kv) } } + s.debug = params.Debug return s } @@ -95,6 +121,7 @@ func NewVMStorage(baseURL string, authCfg *promauth.Config, lookBack time.Durati lookBack: lookBack, queryStep: queryStep, dataSourceType: datasourcePrometheus, + extraParams: url.Values{}, } } diff --git a/app/vmalert/datasource/vm_test.go b/app/vmalert/datasource/vm_test.go index 3ae1bf173..3df8805c2 100644 --- a/app/vmalert/datasource/vm_test.go +++ b/app/vmalert/datasource/vm_test.go @@ -378,6 +378,9 @@ func TestRequestParams(t *testing.T) { } query := "up" timestamp := time.Date(2001, 2, 3, 4, 5, 6, 0, time.UTC) + storage := VMStorage{ + extraParams: url.Values{"round_digits": {"10"}}, + } testCases := []struct { name string queryRange bool @@ -574,6 +577,17 @@ func TestRequestParams(t *testing.T) { checkEqualString(t, exp, r.URL.RawQuery) }, }, + { + "custom params overrides the original params", + false, + storage.Clone().ApplyParams(QuerierParams{ + QueryParams: url.Values{"round_digits": {"2"}}, + }), + func(t *testing.T, r *http.Request) { + exp := fmt.Sprintf("query=%s&round_digits=2&time=%d", query, timestamp.Unix()) + checkEqualString(t, exp, r.URL.RawQuery) + }, + }, { "graphite extra params", false, diff --git a/app/vmalert/main.go b/app/vmalert/main.go index 9758e9aca..0762cc634 100644 --- a/app/vmalert/main.go +++ b/app/vmalert/main.go @@ -74,7 +74,7 @@ absolute path to all .tpl files in root. ruleUpdateEntriesLimit = flag.Int("rule.updateEntriesLimit", 20, "Defines the max number of rule's state updates stored in-memory. "+ "Rule's updates are available on rule's Details page and are used for debugging purposes. The number of stored updates can be overridden per rule via update_entries_limit param.") - externalURL = flag.String("external.url", "", "External URL is used as alert's source for sent alerts to the notifier") + externalURL = flag.String("external.url", "", "External URL is used as alert's source for sent alerts to the notifier. By default, hostname is used as address.") externalAlertSource = flag.String("external.alert.source", "", `External Alert Source allows to override the Source link for alerts sent to AlertManager `+ `for cases where you want to build a custom link to Grafana, Prometheus or any other service. `+ `Supports templating - see https://docs.victoriametrics.com/vmalert.html#templating . `+ diff --git a/app/vmalert/manager.go b/app/vmalert/manager.go index fa04f778a..25fdfbe92 100644 --- a/app/vmalert/manager.go +++ b/app/vmalert/manager.go @@ -188,6 +188,7 @@ func (g *Group) toAPI() APIGroup { Labels: g.Labels, } + ag.Rules = make([]APIRule, 0) for _, r := range g.Rules { ag.Rules = append(ag.Rules, r.ToAPI()) } diff --git a/app/vmalert/tpl/header.qtpl b/app/vmalert/tpl/header.qtpl index 42390fa1f..d08ae138c 100644 --- a/app/vmalert/tpl/header.qtpl +++ b/app/vmalert/tpl/header.qtpl @@ -1,5 +1,4 @@ {% import ( - "strings" "net/http" "path" "net/url" @@ -85,10 +84,7 @@ type NavItem struct { {% func printNavItems(r *http.Request, current string, items []NavItem) %} {%code - prefix := "/vmalert/" - if strings.HasPrefix(r.URL.Path, prefix) { - prefix = "" - } + prefix := utils.Prefix(r.URL.Path) %} diff --git a/app/vmalert/tpl/header.qtpl.go b/app/vmalert/tpl/header.qtpl.go index 56c9002a1..0d0b46a49 100644 --- a/app/vmalert/tpl/header.qtpl.go +++ b/app/vmalert/tpl/header.qtpl.go @@ -9,52 +9,51 @@ import ( "net/http" "net/url" "path" - "strings" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils" ) -//line app/vmalert/tpl/header.qtpl:10 +//line app/vmalert/tpl/header.qtpl:9 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line app/vmalert/tpl/header.qtpl:10 +//line app/vmalert/tpl/header.qtpl:9 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line app/vmalert/tpl/header.qtpl:10 +//line app/vmalert/tpl/header.qtpl:9 func StreamHeader(qw422016 *qt422016.Writer, r *http.Request, navItems []NavItem, title string) { -//line app/vmalert/tpl/header.qtpl:10 +//line app/vmalert/tpl/header.qtpl:9 qw422016.N().S(` `) -//line app/vmalert/tpl/header.qtpl:11 +//line app/vmalert/tpl/header.qtpl:10 prefix := utils.Prefix(r.URL.Path) -//line app/vmalert/tpl/header.qtpl:11 +//line app/vmalert/tpl/header.qtpl:10 qw422016.N().S(` vmalert`) -//line app/vmalert/tpl/header.qtpl:15 +//line app/vmalert/tpl/header.qtpl:14 if title != "" { -//line app/vmalert/tpl/header.qtpl:15 +//line app/vmalert/tpl/header.qtpl:14 qw422016.N().S(` - `) -//line app/vmalert/tpl/header.qtpl:15 +//line app/vmalert/tpl/header.qtpl:14 qw422016.E().S(title) -//line app/vmalert/tpl/header.qtpl:15 +//line app/vmalert/tpl/header.qtpl:14 } -//line app/vmalert/tpl/header.qtpl:15 +//line app/vmalert/tpl/header.qtpl:14 qw422016.N().S(`