all: fix golangci-lint(revive) warnings after 0c0ed61ce7

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6001
This commit is contained in:
Aliaksandr Valialkin 2024-04-02 23:16:24 +03:00
parent c3a72b6cdb
commit 918cccaddf
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
47 changed files with 976 additions and 970 deletions

View file

@ -369,7 +369,7 @@ func readIn(readFor string, t *testing.T, insertTime time.Time) []test {
t.Helper() t.Helper()
s := newSuite(t) s := newSuite(t)
var tt []test var tt []test
s.noError(filepath.Walk(filepath.Join(testFixturesDir, readFor), func(path string, info os.FileInfo, err error) error { s.noError(filepath.Walk(filepath.Join(testFixturesDir, readFor), func(path string, _ os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }

View file

@ -33,7 +33,7 @@ func benchmarkReadBulkRequest(b *testing.B, isGzip bool) {
timeField := "@timestamp" timeField := "@timestamp"
msgField := "message" msgField := "message"
processLogMessage := func(timestmap int64, fields []logstorage.Field) {} processLogMessage := func(_ int64, _ []logstorage.Field) {}
b.ReportAllocs() b.ReportAllocs()
b.SetBytes(int64(len(data))) b.SetBytes(int64(len(data)))

View file

@ -11,7 +11,7 @@ import (
func TestParseJSONRequestFailure(t *testing.T) { func TestParseJSONRequestFailure(t *testing.T) {
f := func(s string) { f := func(s string) {
t.Helper() t.Helper()
n, err := parseJSONRequest([]byte(s), func(timestamp int64, fields []logstorage.Field) { n, err := parseJSONRequest([]byte(s), func(_ int64, _ []logstorage.Field) {
t.Fatalf("unexpected call to parseJSONRequest callback!") t.Fatalf("unexpected call to parseJSONRequest callback!")
}) })
if err == nil { if err == nil {

View file

@ -27,7 +27,7 @@ func benchmarkParseJSONRequest(b *testing.B, streams, rows, labels int) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
data := getJSONBody(streams, rows, labels) data := getJSONBody(streams, rows, labels)
for pb.Next() { for pb.Next() {
_, err := parseJSONRequest(data, func(timestamp int64, fields []logstorage.Field) {}) _, err := parseJSONRequest(data, func(_ int64, _ []logstorage.Field) {})
if err != nil { if err != nil {
panic(fmt.Errorf("unexpected error: %w", err)) panic(fmt.Errorf("unexpected error: %w", err))
} }

View file

@ -29,7 +29,7 @@ func benchmarkParseProtobufRequest(b *testing.B, streams, rows, labels int) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
body := getProtobufBody(streams, rows, labels) body := getProtobufBody(streams, rows, labels)
for pb.Next() { for pb.Next() {
_, err := parseProtobufRequest(body, func(timestamp int64, fields []logstorage.Field) {}) _, err := parseProtobufRequest(body, func(_ int64, _ []logstorage.Field) {})
if err != nil { if err != nil {
panic(fmt.Errorf("unexpected error: %w", err)) panic(fmt.Errorf("unexpected error: %w", err))
} }

View file

@ -1004,7 +1004,7 @@ func getRowsCount(tss []prompbmarshal.TimeSeries) int {
// CheckStreamAggrConfigs checks configs pointed by -remoteWrite.streamAggr.config // CheckStreamAggrConfigs checks configs pointed by -remoteWrite.streamAggr.config
func CheckStreamAggrConfigs() error { func CheckStreamAggrConfigs() error {
pushNoop := func(tss []prompbmarshal.TimeSeries) {} pushNoop := func(_ []prompbmarshal.TimeSeries) {}
for idx, sasFile := range *streamAggrConfig { for idx, sasFile := range *streamAggrConfig {
if sasFile == "" { if sasFile == "" {
continue continue

View file

@ -71,7 +71,7 @@ func TestVMInstantQuery(t *testing.T) {
w.Write([]byte(`{"status":"success","data":{"resultType":"scalar","result":[1583786142, "1"]},"stats":{"seriesFetched": "42"}}`)) w.Write([]byte(`{"status":"success","data":{"resultType":"scalar","result":[1583786142, "1"]},"stats":{"seriesFetched": "42"}}`))
} }
}) })
mux.HandleFunc("/render", func(w http.ResponseWriter, request *http.Request) { mux.HandleFunc("/render", func(w http.ResponseWriter, _ *http.Request) {
c++ c++
switch c { switch c {
case 8: case 8:

View file

@ -304,7 +304,7 @@ func getAlertURLGenerator(externalURL *url.URL, externalAlertSource string, vali
"tpl": externalAlertSource, "tpl": externalAlertSource,
} }
return func(alert notifier.Alert) string { return func(alert notifier.Alert) string {
qFn := func(query string) ([]datasource.Metric, error) { qFn := func(_ string) ([]datasource.Metric, error) {
return nil, fmt.Errorf("`query` template isn't supported for alert source template") return nil, fmt.Errorf("`query` template isn't supported for alert source template")
} }
templated, err := alert.ExecTemplate(qFn, alert.Labels, m) templated, err := alert.ExecTemplate(qFn, alert.Labels, m)

View file

@ -178,7 +178,7 @@ func TestAlert_ExecTemplate(t *testing.T) {
}, },
} }
qFn := func(q string) ([]datasource.Metric, error) { qFn := func(_ string) ([]datasource.Metric, error) {
return []datasource.Metric{ return []datasource.Metric{
{ {
Labels: []datasource.Label{ Labels: []datasource.Label{

View file

@ -310,7 +310,7 @@ func (ar *AlertingRule) execRange(ctx context.Context, start, end time.Time) ([]
} }
var result []prompbmarshal.TimeSeries var result []prompbmarshal.TimeSeries
holdAlertState := make(map[uint64]*notifier.Alert) holdAlertState := make(map[uint64]*notifier.Alert)
qFn := func(query string) ([]datasource.Metric, error) { qFn := func(_ string) ([]datasource.Metric, error) {
return nil, fmt.Errorf("`query` template isn't supported in replay mode") return nil, fmt.Errorf("`query` template isn't supported in replay mode")
} }
for _, s := range res.Data { for _, s := range res.Data {

View file

@ -476,7 +476,7 @@ func templateFuncs() textTpl.FuncMap {
// For example, {{ query "foo" | first | value }} will // For example, {{ query "foo" | first | value }} will
// execute "/api/v1/query?query=foo" request and will return // execute "/api/v1/query?query=foo" request and will return
// the first value in response. // the first value in response.
"query": func(q string) ([]metric, error) { "query": func(_ string) ([]metric, error) {
// query function supposed to be substituted at FuncsWithQuery(). // query function supposed to be substituted at FuncsWithQuery().
// it is present here only for validation purposes, when there is no // it is present here only for validation purposes, when there is no
// provided datasource. // provided datasource.

View file

@ -36,7 +36,7 @@ func TestHandler(t *testing.T) {
}} }}
rh := &requestHandler{m: m} rh := &requestHandler{m: m}
getResp := func(url string, to interface{}, code int) { getResp := func(t *testing.T, url string, to interface{}, code int) {
t.Helper() t.Helper()
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
@ -60,43 +60,43 @@ func TestHandler(t *testing.T) {
defer ts.Close() defer ts.Close()
t.Run("/", func(t *testing.T) { t.Run("/", func(t *testing.T) {
getResp(ts.URL, nil, 200) getResp(t, ts.URL, nil, 200)
getResp(ts.URL+"/vmalert", nil, 200) getResp(t, ts.URL+"/vmalert", nil, 200)
getResp(ts.URL+"/vmalert/alerts", nil, 200) getResp(t, ts.URL+"/vmalert/alerts", nil, 200)
getResp(ts.URL+"/vmalert/groups", nil, 200) getResp(t, ts.URL+"/vmalert/groups", nil, 200)
getResp(ts.URL+"/vmalert/notifiers", nil, 200) getResp(t, ts.URL+"/vmalert/notifiers", nil, 200)
getResp(ts.URL+"/rules", nil, 200) getResp(t, ts.URL+"/rules", nil, 200)
}) })
t.Run("/vmalert/rule", func(t *testing.T) { t.Run("/vmalert/rule", func(t *testing.T) {
a := ruleToAPI(ar) a := ruleToAPI(ar)
getResp(ts.URL+"/vmalert/"+a.WebLink(), nil, 200) getResp(t, ts.URL+"/vmalert/"+a.WebLink(), nil, 200)
r := ruleToAPI(rr) r := ruleToAPI(rr)
getResp(ts.URL+"/vmalert/"+r.WebLink(), nil, 200) getResp(t, ts.URL+"/vmalert/"+r.WebLink(), nil, 200)
}) })
t.Run("/vmalert/alert", func(t *testing.T) { t.Run("/vmalert/alert", func(t *testing.T) {
alerts := ruleToAPIAlert(ar) alerts := ruleToAPIAlert(ar)
for _, a := range alerts { for _, a := range alerts {
getResp(ts.URL+"/vmalert/"+a.WebLink(), nil, 200) getResp(t, ts.URL+"/vmalert/"+a.WebLink(), nil, 200)
} }
}) })
t.Run("/vmalert/rule?badParam", func(t *testing.T) { t.Run("/vmalert/rule?badParam", func(t *testing.T) {
params := fmt.Sprintf("?%s=0&%s=1", paramGroupID, paramRuleID) params := fmt.Sprintf("?%s=0&%s=1", paramGroupID, paramRuleID)
getResp(ts.URL+"/vmalert/rule"+params, nil, 404) getResp(t, ts.URL+"/vmalert/rule"+params, nil, 404)
params = fmt.Sprintf("?%s=1&%s=0", paramGroupID, paramRuleID) params = fmt.Sprintf("?%s=1&%s=0", paramGroupID, paramRuleID)
getResp(ts.URL+"/vmalert/rule"+params, nil, 404) getResp(t, ts.URL+"/vmalert/rule"+params, nil, 404)
}) })
t.Run("/api/v1/alerts", func(t *testing.T) { t.Run("/api/v1/alerts", func(t *testing.T) {
lr := listAlertsResponse{} lr := listAlertsResponse{}
getResp(ts.URL+"/api/v1/alerts", &lr, 200) getResp(t, ts.URL+"/api/v1/alerts", &lr, 200)
if length := len(lr.Data.Alerts); length != 1 { if length := len(lr.Data.Alerts); length != 1 {
t.Errorf("expected 1 alert got %d", length) t.Errorf("expected 1 alert got %d", length)
} }
lr = listAlertsResponse{} lr = listAlertsResponse{}
getResp(ts.URL+"/vmalert/api/v1/alerts", &lr, 200) getResp(t, ts.URL+"/vmalert/api/v1/alerts", &lr, 200)
if length := len(lr.Data.Alerts); length != 1 { if length := len(lr.Data.Alerts); length != 1 {
t.Errorf("expected 1 alert got %d", length) t.Errorf("expected 1 alert got %d", length)
} }
@ -104,13 +104,13 @@ func TestHandler(t *testing.T) {
t.Run("/api/v1/alert?alertID&groupID", func(t *testing.T) { t.Run("/api/v1/alert?alertID&groupID", func(t *testing.T) {
expAlert := newAlertAPI(ar, ar.GetAlerts()[0]) expAlert := newAlertAPI(ar, ar.GetAlerts()[0])
alert := &apiAlert{} alert := &apiAlert{}
getResp(ts.URL+"/"+expAlert.APILink(), alert, 200) getResp(t, ts.URL+"/"+expAlert.APILink(), alert, 200)
if !reflect.DeepEqual(alert, expAlert) { if !reflect.DeepEqual(alert, expAlert) {
t.Errorf("expected %v is equal to %v", alert, expAlert) t.Errorf("expected %v is equal to %v", alert, expAlert)
} }
alert = &apiAlert{} alert = &apiAlert{}
getResp(ts.URL+"/vmalert/"+expAlert.APILink(), alert, 200) getResp(t, ts.URL+"/vmalert/"+expAlert.APILink(), alert, 200)
if !reflect.DeepEqual(alert, expAlert) { if !reflect.DeepEqual(alert, expAlert) {
t.Errorf("expected %v is equal to %v", alert, expAlert) t.Errorf("expected %v is equal to %v", alert, expAlert)
} }
@ -118,28 +118,28 @@ func TestHandler(t *testing.T) {
t.Run("/api/v1/alert?badParams", func(t *testing.T) { t.Run("/api/v1/alert?badParams", func(t *testing.T) {
params := fmt.Sprintf("?%s=0&%s=1", paramGroupID, paramAlertID) params := fmt.Sprintf("?%s=0&%s=1", paramGroupID, paramAlertID)
getResp(ts.URL+"/api/v1/alert"+params, nil, 404) getResp(t, ts.URL+"/api/v1/alert"+params, nil, 404)
getResp(ts.URL+"/vmalert/api/v1/alert"+params, nil, 404) getResp(t, ts.URL+"/vmalert/api/v1/alert"+params, nil, 404)
params = fmt.Sprintf("?%s=1&%s=0", paramGroupID, paramAlertID) params = fmt.Sprintf("?%s=1&%s=0", paramGroupID, paramAlertID)
getResp(ts.URL+"/api/v1/alert"+params, nil, 404) getResp(t, ts.URL+"/api/v1/alert"+params, nil, 404)
getResp(ts.URL+"/vmalert/api/v1/alert"+params, nil, 404) getResp(t, ts.URL+"/vmalert/api/v1/alert"+params, nil, 404)
// bad request, alertID is missing // bad request, alertID is missing
params = fmt.Sprintf("?%s=1", paramGroupID) params = fmt.Sprintf("?%s=1", paramGroupID)
getResp(ts.URL+"/api/v1/alert"+params, nil, 400) getResp(t, ts.URL+"/api/v1/alert"+params, nil, 400)
getResp(ts.URL+"/vmalert/api/v1/alert"+params, nil, 400) getResp(t, ts.URL+"/vmalert/api/v1/alert"+params, nil, 400)
}) })
t.Run("/api/v1/rules", func(t *testing.T) { t.Run("/api/v1/rules", func(t *testing.T) {
lr := listGroupsResponse{} lr := listGroupsResponse{}
getResp(ts.URL+"/api/v1/rules", &lr, 200) getResp(t, ts.URL+"/api/v1/rules", &lr, 200)
if length := len(lr.Data.Groups); length != 1 { if length := len(lr.Data.Groups); length != 1 {
t.Errorf("expected 1 group got %d", length) t.Errorf("expected 1 group got %d", length)
} }
lr = listGroupsResponse{} lr = listGroupsResponse{}
getResp(ts.URL+"/vmalert/api/v1/rules", &lr, 200) getResp(t, ts.URL+"/vmalert/api/v1/rules", &lr, 200)
if length := len(lr.Data.Groups); length != 1 { if length := len(lr.Data.Groups); length != 1 {
t.Errorf("expected 1 group got %d", length) t.Errorf("expected 1 group got %d", length)
} }
@ -147,21 +147,21 @@ func TestHandler(t *testing.T) {
t.Run("/api/v1/rule?ruleID&groupID", func(t *testing.T) { t.Run("/api/v1/rule?ruleID&groupID", func(t *testing.T) {
expRule := ruleToAPI(ar) expRule := ruleToAPI(ar)
gotRule := apiRule{} gotRule := apiRule{}
getResp(ts.URL+"/"+expRule.APILink(), &gotRule, 200) getResp(t, ts.URL+"/"+expRule.APILink(), &gotRule, 200)
if expRule.ID != gotRule.ID { if expRule.ID != gotRule.ID {
t.Errorf("expected to get Rule %q; got %q instead", expRule.ID, gotRule.ID) t.Errorf("expected to get Rule %q; got %q instead", expRule.ID, gotRule.ID)
} }
gotRule = apiRule{} gotRule = apiRule{}
getResp(ts.URL+"/vmalert/"+expRule.APILink(), &gotRule, 200) getResp(t, ts.URL+"/vmalert/"+expRule.APILink(), &gotRule, 200)
if expRule.ID != gotRule.ID { if expRule.ID != gotRule.ID {
t.Errorf("expected to get Rule %q; got %q instead", expRule.ID, gotRule.ID) t.Errorf("expected to get Rule %q; got %q instead", expRule.ID, gotRule.ID)
} }
gotRuleWithUpdates := apiRuleWithUpdates{} gotRuleWithUpdates := apiRuleWithUpdates{}
getResp(ts.URL+"/"+expRule.APILink(), &gotRuleWithUpdates, 200) getResp(t, ts.URL+"/"+expRule.APILink(), &gotRuleWithUpdates, 200)
if gotRuleWithUpdates.StateUpdates == nil || len(gotRuleWithUpdates.StateUpdates) < 1 { if gotRuleWithUpdates.StateUpdates == nil || len(gotRuleWithUpdates.StateUpdates) < 1 {
t.Fatalf("expected %+v to have state updates field not empty", gotRuleWithUpdates.StateUpdates) t.Fatalf("expected %+v to have state updates field not empty", gotRuleWithUpdates.StateUpdates)
} }
@ -171,7 +171,7 @@ func TestHandler(t *testing.T) {
check := func(url string, expGroups, expRules int) { check := func(url string, expGroups, expRules int) {
t.Helper() t.Helper()
lr := listGroupsResponse{} lr := listGroupsResponse{}
getResp(ts.URL+url, &lr, 200) getResp(t, ts.URL+url, &lr, 200)
if length := len(lr.Data.Groups); length != expGroups { if length := len(lr.Data.Groups); length != expGroups {
t.Errorf("expected %d groups got %d", expGroups, length) t.Errorf("expected %d groups got %d", expGroups, length)
} }
@ -210,7 +210,7 @@ func TestHandler(t *testing.T) {
t.Run("/api/v1/rules&exclude_alerts=true", func(t *testing.T) { t.Run("/api/v1/rules&exclude_alerts=true", func(t *testing.T) {
// check if response returns active alerts by default // check if response returns active alerts by default
lr := listGroupsResponse{} lr := listGroupsResponse{}
getResp(ts.URL+"/api/v1/rules?rule_group[]=group&file[]=rules.yaml", &lr, 200) getResp(t, ts.URL+"/api/v1/rules?rule_group[]=group&file[]=rules.yaml", &lr, 200)
activeAlerts := 0 activeAlerts := 0
for _, gr := range lr.Data.Groups { for _, gr := range lr.Data.Groups {
for _, r := range gr.Rules { for _, r := range gr.Rules {
@ -223,7 +223,7 @@ func TestHandler(t *testing.T) {
// disable returning alerts via param // disable returning alerts via param
lr = listGroupsResponse{} lr = listGroupsResponse{}
getResp(ts.URL+"/api/v1/rules?rule_group[]=group&file[]=rules.yaml&exclude_alerts=true", &lr, 200) getResp(t, ts.URL+"/api/v1/rules?rule_group[]=group&file[]=rules.yaml&exclude_alerts=true", &lr, 200)
activeAlerts = 0 activeAlerts = 0
for _, gr := range lr.Data.Groups { for _, gr := range lr.Data.Groups {
for _, r := range gr.Rules { for _, r := range gr.Rules {
@ -241,7 +241,7 @@ func TestEmptyResponse(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { rhWithNoGroups.handler(w, r) })) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { rhWithNoGroups.handler(w, r) }))
defer ts.Close() defer ts.Close()
getResp := func(url string, to interface{}, code int) { getResp := func(t *testing.T, url string, to interface{}, code int) {
t.Helper() t.Helper()
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
@ -264,13 +264,13 @@ func TestEmptyResponse(t *testing.T) {
t.Run("no groups /api/v1/alerts", func(t *testing.T) { t.Run("no groups /api/v1/alerts", func(t *testing.T) {
lr := listAlertsResponse{} lr := listAlertsResponse{}
getResp(ts.URL+"/api/v1/alerts", &lr, 200) getResp(t, ts.URL+"/api/v1/alerts", &lr, 200)
if lr.Data.Alerts == nil { if lr.Data.Alerts == nil {
t.Errorf("expected /api/v1/alerts response to have non-nil data") t.Errorf("expected /api/v1/alerts response to have non-nil data")
} }
lr = listAlertsResponse{} lr = listAlertsResponse{}
getResp(ts.URL+"/vmalert/api/v1/alerts", &lr, 200) getResp(t, ts.URL+"/vmalert/api/v1/alerts", &lr, 200)
if lr.Data.Alerts == nil { if lr.Data.Alerts == nil {
t.Errorf("expected /api/v1/alerts response to have non-nil data") t.Errorf("expected /api/v1/alerts response to have non-nil data")
} }
@ -278,13 +278,13 @@ func TestEmptyResponse(t *testing.T) {
t.Run("no groups /api/v1/rules", func(t *testing.T) { t.Run("no groups /api/v1/rules", func(t *testing.T) {
lr := listGroupsResponse{} lr := listGroupsResponse{}
getResp(ts.URL+"/api/v1/rules", &lr, 200) getResp(t, ts.URL+"/api/v1/rules", &lr, 200)
if lr.Data.Groups == nil { if lr.Data.Groups == nil {
t.Errorf("expected /api/v1/rules response to have non-nil data") t.Errorf("expected /api/v1/rules response to have non-nil data")
} }
lr = listGroupsResponse{} lr = listGroupsResponse{}
getResp(ts.URL+"/vmalert/api/v1/rules", &lr, 200) getResp(t, ts.URL+"/vmalert/api/v1/rules", &lr, 200)
if lr.Data.Groups == nil { if lr.Data.Groups == nil {
t.Errorf("expected /api/v1/rules response to have non-nil data") t.Errorf("expected /api/v1/rules response to have non-nil data")
} }
@ -295,13 +295,13 @@ func TestEmptyResponse(t *testing.T) {
t.Run("empty group /api/v1/rules", func(t *testing.T) { t.Run("empty group /api/v1/rules", func(t *testing.T) {
lr := listGroupsResponse{} lr := listGroupsResponse{}
getResp(ts.URL+"/api/v1/rules", &lr, 200) getResp(t, ts.URL+"/api/v1/rules", &lr, 200)
if lr.Data.Groups == nil { if lr.Data.Groups == nil {
t.Fatalf("expected /api/v1/rules response to have non-nil data") t.Fatalf("expected /api/v1/rules response to have non-nil data")
} }
lr = listGroupsResponse{} lr = listGroupsResponse{}
getResp(ts.URL+"/vmalert/api/v1/rules", &lr, 200) getResp(t, ts.URL+"/vmalert/api/v1/rules", &lr, 200)
if lr.Data.Groups == nil { if lr.Data.Groups == nil {
t.Fatalf("expected /api/v1/rules response to have non-nil data") t.Fatalf("expected /api/v1/rules response to have non-nil data")
} }

View file

@ -373,7 +373,7 @@ func main() {
return cli.Exit(fmt.Errorf("cannot open exported block at path=%q err=%w", blockPath, err), 1) return cli.Exit(fmt.Errorf("cannot open exported block at path=%q err=%w", blockPath, err), 1)
} }
var blocksCount atomic.Uint64 var blocksCount atomic.Uint64
if err := stream.Parse(f, isBlockGzipped, func(block *stream.Block) error { if err := stream.Parse(f, isBlockGzipped, func(_ *stream.Block) error {
blocksCount.Add(1) blocksCount.Add(1)
return nil return nil
}); err != nil { }); err != nil {

View file

@ -54,7 +54,7 @@ func CheckStreamAggrConfig() error {
if *streamAggrConfig == "" { if *streamAggrConfig == "" {
return nil return nil
} }
pushNoop := func(tss []prompbmarshal.TimeSeries) {} pushNoop := func(_ []prompbmarshal.TimeSeries) {}
opts := &streamaggr.Options{ opts := &streamaggr.Options{
DedupInterval: *streamAggrDedupInterval, DedupInterval: *streamAggrDedupInterval,
DropInputLabels: *streamAggrDropInputLabels, DropInputLabels: *streamAggrDropInputLabels,

View file

@ -101,7 +101,7 @@ func Init() {
if len(*opentsdbHTTPListenAddr) > 0 { if len(*opentsdbHTTPListenAddr) > 0 {
opentsdbhttpServer = opentsdbhttpserver.MustStart(*opentsdbHTTPListenAddr, *opentsdbHTTPUseProxyProtocol, opentsdbhttp.InsertHandler) opentsdbhttpServer = opentsdbhttpserver.MustStart(*opentsdbHTTPListenAddr, *opentsdbHTTPUseProxyProtocol, opentsdbhttp.InsertHandler)
} }
promscrape.Init(func(at *auth.Token, wr *prompbmarshal.WriteRequest) { promscrape.Init(func(_ *auth.Token, wr *prompbmarshal.WriteRequest) {
prompush.Push(wr) prompush.Push(wr)
}) })
} }

View file

@ -160,7 +160,7 @@ func newNextSeriesForSearchQuery(ec *evalConfig, sq *storage.SearchQuery, expr g
seriesCh := make(chan *series, cgroup.AvailableCPUs()) seriesCh := make(chan *series, cgroup.AvailableCPUs())
errCh := make(chan error, 1) errCh := make(chan error, 1)
go func() { go func() {
err := rss.RunParallel(nil, func(rs *netstorage.Result, workerID uint) error { err := rss.RunParallel(nil, func(rs *netstorage.Result, _ uint) error {
nameWithTags := getCanonicalPath(&rs.MetricName) nameWithTags := getCanonicalPath(&rs.MetricName)
tags := unmarshalTags(nameWithTags) tags := unmarshalTags(nameWithTags)
s := &series{ s := &series{

View file

@ -405,7 +405,7 @@ func aggregateSeriesWithWildcards(ec *evalConfig, expr graphiteql.Expr, nextSeri
for _, pos := range positions { for _, pos := range positions {
positionsMap[pos] = struct{}{} positionsMap[pos] = struct{}{}
} }
keyFunc := func(name string, tags map[string]string) string { keyFunc := func(name string, _ map[string]string) string {
parts := strings.Split(getPathFromName(name), ".") parts := strings.Split(getPathFromName(name), ".")
dstParts := parts[:0] dstParts := parts[:0]
for i, part := range parts { for i, part := range parts {
@ -1881,7 +1881,7 @@ func transformGroupByTags(ec *evalConfig, fe *graphiteql.FuncExpr) (nextSeriesFu
if err != nil { if err != nil {
return nil, err return nil, err
} }
keyFunc := func(name string, tags map[string]string) string { keyFunc := func(_ string, tags map[string]string) string {
return formatKeyFromTags(tags, tagKeys, callback) return formatKeyFromTags(tags, tagKeys, callback)
} }
return groupByKeyFunc(ec, fe, nextSeries, callback, keyFunc) return groupByKeyFunc(ec, fe, nextSeries, callback, keyFunc)

View file

@ -251,7 +251,7 @@ func ExportNativeHandler(startTime time.Time, w http.ResponseWriter, r *http.Req
_, _ = bw.Write(trBuf) _, _ = bw.Write(trBuf)
// Marshal native blocks. // Marshal native blocks.
err = netstorage.ExportBlocks(nil, sq, cp.deadline, func(mn *storage.MetricName, b *storage.Block, tr storage.TimeRange, workerID uint) error { err = netstorage.ExportBlocks(nil, sq, cp.deadline, func(mn *storage.MetricName, b *storage.Block, _ storage.TimeRange, workerID uint) error {
if err := bw.Error(); err != nil { if err := bw.Error(); err != nil {
return err return err
} }
@ -1238,7 +1238,7 @@ func (sw *scalableWriter) maybeFlushBuffer(bb *bytesutil.ByteBuffer) error {
} }
func (sw *scalableWriter) flush() error { func (sw *scalableWriter) flush() error {
sw.m.Range(func(k, v interface{}) bool { sw.m.Range(func(_, v interface{}) bool {
bb := v.(*bytesutil.ByteBuffer) bb := v.(*bytesutil.ByteBuffer)
_, err := sw.bw.Write(bb.B) _, err := sw.bw.Write(bb.B)
return err == nil return err == nil

View file

@ -76,7 +76,7 @@ func newAggrFunc(afe func(tss []*timeseries) []*timeseries) aggrFunc {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return aggrFuncExt(func(tss []*timeseries, modififer *metricsql.ModifierExpr) []*timeseries { return aggrFuncExt(func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
return afe(tss) return afe(tss)
}, tss, &afa.ae.Modifier, afa.ae.Limit, false) }, tss, &afa.ae.Modifier, afa.ae.Limit, false)
} }
@ -158,7 +158,7 @@ func aggrFuncAny(afa *aggrFuncArg) ([]*timeseries, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
return tss[:1] return tss[:1]
} }
limit := afa.ae.Limit limit := afa.ae.Limit
@ -467,7 +467,7 @@ func aggrFuncShare(afa *aggrFuncArg) ([]*timeseries, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
for i := range tss[0].Values { for i := range tss[0].Values {
// Calculate sum for non-negative points at position i. // Calculate sum for non-negative points at position i.
var sum float64 var sum float64
@ -498,7 +498,7 @@ func aggrFuncZScore(afa *aggrFuncArg) ([]*timeseries, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
for i := range tss[0].Values { for i := range tss[0].Values {
// Calculate avg and stddev for tss points at position i. // Calculate avg and stddev for tss points at position i.
// See `Rapid calculation methods` at https://en.wikipedia.org/wiki/Standard_deviation // See `Rapid calculation methods` at https://en.wikipedia.org/wiki/Standard_deviation
@ -594,7 +594,7 @@ func aggrFuncCountValues(afa *aggrFuncArg) ([]*timeseries, error) {
// Do nothing // Do nothing
} }
afe := func(tss []*timeseries, modififer *metricsql.ModifierExpr) ([]*timeseries, error) { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) ([]*timeseries, error) {
m := make(map[float64]*timeseries) m := make(map[float64]*timeseries)
for _, ts := range tss { for _, ts := range tss {
for i, v := range ts.Values { for i, v := range ts.Values {
@ -656,7 +656,7 @@ func newAggrFuncTopK(isReverse bool) aggrFunc {
if err != nil { if err != nil {
return nil, err return nil, err
} }
afe := func(tss []*timeseries, modififer *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
for n := range tss[0].Values { for n := range tss[0].Values {
lessFunc := lessWithNaNs lessFunc := lessWithNaNs
if isReverse { if isReverse {
@ -960,7 +960,7 @@ func aggrFuncOutliersIQR(afa *aggrFuncArg) ([]*timeseries, error) {
if err := expectTransformArgsNum(args, 1); err != nil { if err := expectTransformArgsNum(args, 1); err != nil {
return nil, err return nil, err
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
// Calculate lower and upper bounds for interquartile range per each point across tss // Calculate lower and upper bounds for interquartile range per each point across tss
// according to Outliers section at https://en.wikipedia.org/wiki/Interquartile_range // according to Outliers section at https://en.wikipedia.org/wiki/Interquartile_range
lower, upper := getPerPointIQRBounds(tss) lower, upper := getPerPointIQRBounds(tss)
@ -1016,7 +1016,7 @@ func aggrFuncOutliersMAD(afa *aggrFuncArg) ([]*timeseries, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
// Calculate medians for each point across tss. // Calculate medians for each point across tss.
medians := getPerPointMedians(tss) medians := getPerPointMedians(tss)
// Calculate MAD values multiplied by tolerance for each point across tss. // Calculate MAD values multiplied by tolerance for each point across tss.
@ -1052,7 +1052,7 @@ func aggrFuncOutliersK(afa *aggrFuncArg) ([]*timeseries, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
// Calculate medians for each point across tss. // Calculate medians for each point across tss.
medians := getPerPointMedians(tss) medians := getPerPointMedians(tss)
// Return topK time series with the highest variance from median. // Return topK time series with the highest variance from median.
@ -1123,7 +1123,7 @@ func aggrFuncLimitK(afa *aggrFuncArg) ([]*timeseries, error) {
if limit < 0 { if limit < 0 {
limit = 0 limit = 0
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
// Sort series by metricName hash in order to get consistent set of output series // Sort series by metricName hash in order to get consistent set of output series
// across multiple calls to limitk() function. // across multiple calls to limitk() function.
// Sort series by hash in order to guarantee uniform selection across series. // Sort series by hash in order to guarantee uniform selection across series.
@ -1187,7 +1187,7 @@ func aggrFuncQuantiles(afa *aggrFuncArg) ([]*timeseries, error) {
phis[i] = phisLocal[0] phis[i] = phisLocal[0]
} }
argOrig := args[len(args)-1] argOrig := args[len(args)-1]
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
tssDst := make([]*timeseries, len(phiArgs)) tssDst := make([]*timeseries, len(phiArgs))
for j := range tssDst { for j := range tssDst {
ts := &timeseries{} ts := &timeseries{}
@ -1244,7 +1244,7 @@ func aggrFuncMedian(afa *aggrFuncArg) ([]*timeseries, error) {
} }
func newAggrQuantileFunc(phis []float64) func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { func newAggrQuantileFunc(phis []float64) func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries {
return func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { return func(tss []*timeseries, _ *metricsql.ModifierExpr) []*timeseries {
dst := tss[0] dst := tss[0]
a := getFloat64s() a := getFloat64s()
values := a.A values := a.A

View file

@ -74,7 +74,7 @@ func newBinaryOpCmpFunc(cf func(left, right float64) bool) binaryOpFunc {
} }
func newBinaryOpArithFunc(af func(left, right float64) float64) binaryOpFunc { func newBinaryOpArithFunc(af func(left, right float64) float64) binaryOpFunc {
afe := func(left, right float64, isBool bool) float64 { afe := func(left, right float64, _ bool) float64 {
return af(left, right) return af(left, right)
} }
return newBinaryOpFunc(afe) return newBinaryOpFunc(afe)

View file

@ -210,11 +210,13 @@ func TestExecSuccess(t *testing.T) {
f(q, resultExpected) f(q, resultExpected)
}) })
t.Run("scalar-string-nonnum", func(t *testing.T) { t.Run("scalar-string-nonnum", func(t *testing.T) {
t.Parallel()
q := `scalar("fooobar")` q := `scalar("fooobar")`
resultExpected := []netstorage.Result{} resultExpected := []netstorage.Result{}
f(q, resultExpected) f(q, resultExpected)
}) })
t.Run("scalar-string-num", func(t *testing.T) { t.Run("scalar-string-num", func(t *testing.T) {
t.Parallel()
q := `scalar("-12.34")` q := `scalar("-12.34")`
r := netstorage.Result{ r := netstorage.Result{
MetricName: metricNameExpected, MetricName: metricNameExpected,

View file

@ -371,10 +371,10 @@ func getRollupTag(expr metricsql.Expr) (string, error) {
func getRollupConfigs(funcName string, rf rollupFunc, expr metricsql.Expr, start, end, step int64, maxPointsPerSeries int, func getRollupConfigs(funcName string, rf rollupFunc, expr metricsql.Expr, start, end, step int64, maxPointsPerSeries int,
window, lookbackDelta int64, sharedTimestamps []int64) ( window, lookbackDelta int64, sharedTimestamps []int64) (
func(values []float64, timestamps []int64), []*rollupConfig, error) { func(values []float64, timestamps []int64), []*rollupConfig, error) {
preFunc := func(values []float64, timestamps []int64) {} preFunc := func(_ []float64, _ []int64) {}
funcName = strings.ToLower(funcName) funcName = strings.ToLower(funcName)
if rollupFuncsRemoveCounterResets[funcName] { if rollupFuncsRemoveCounterResets[funcName] {
preFunc = func(values []float64, timestamps []int64) { preFunc = func(values []float64, _ []int64) {
removeCounterResets(values) removeCounterResets(values)
} }
} }
@ -486,7 +486,7 @@ func getRollupConfigs(funcName string, rf rollupFunc, expr metricsql.Expr, start
for _, aggrFuncName := range aggrFuncNames { for _, aggrFuncName := range aggrFuncNames {
if rollupFuncsRemoveCounterResets[aggrFuncName] { if rollupFuncsRemoveCounterResets[aggrFuncName] {
// There is no need to save the previous preFunc, since it is either empty or the same. // There is no need to save the previous preFunc, since it is either empty or the same.
preFunc = func(values []float64, timestamps []int64) { preFunc = func(values []float64, _ []int64) {
removeCounterResets(values) removeCounterResets(values)
} }
} }

View file

@ -10,13 +10,13 @@ import (
) )
func TestRollupResultCacheInitStop(t *testing.T) { func TestRollupResultCacheInitStop(t *testing.T) {
t.Run("inmemory", func(t *testing.T) { t.Run("inmemory", func(_ *testing.T) {
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
InitRollupResultCache("") InitRollupResultCache("")
StopRollupResultCache() StopRollupResultCache()
} }
}) })
t.Run("file-based", func(t *testing.T) { t.Run("file-based", func(_ *testing.T) {
cacheFilePath := "test-rollup-result-cache" cacheFilePath := "test-rollup-result-cache"
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
InitRollupResultCache(cacheFilePath) InitRollupResultCache(cacheFilePath)

View file

@ -918,7 +918,7 @@ func transformHistogramQuantile(tfa *transformFuncArg) ([]*timeseries, error) {
m := groupLeTimeseries(tss) m := groupLeTimeseries(tss)
// Calculate quantile for each group in m // Calculate quantile for each group in m
lastNonInf := func(i int, xss []leTimeseries) float64 { lastNonInf := func(_ int, xss []leTimeseries) float64 {
for len(xss) > 0 { for len(xss) > 0 {
xsLast := xss[len(xss)-1] xsLast := xss[len(xss)-1]
if !math.IsInf(xsLast.le, 0) { if !math.IsInf(xsLast.le, 0) {

View file

@ -90,7 +90,7 @@ type RequestHandler func(w http.ResponseWriter, r *http.Request) bool
// See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt // See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
func Serve(addrs []string, useProxyProtocol *flagutil.ArrayBool, rh RequestHandler) { func Serve(addrs []string, useProxyProtocol *flagutil.ArrayBool, rh RequestHandler) {
if rh == nil { if rh == nil {
rh = func(w http.ResponseWriter, r *http.Request) bool { rh = func(_ http.ResponseWriter, _ *http.Request) bool {
return false return false
} }
} }
@ -152,7 +152,7 @@ func serveWithListener(addr string, ln net.Listener, rh RequestHandler) {
ErrorLog: logger.StdErrorLogger(), ErrorLog: logger.StdErrorLogger(),
} }
if *connTimeout > 0 { if *connTimeout > 0 {
s.s.ConnContext = func(ctx context.Context, c net.Conn) context.Context { s.s.ConnContext = func(ctx context.Context, _ net.Conn) context.Context {
timeoutSec := connTimeout.Seconds() timeoutSec := connTimeout.Seconds()
// Add a jitter for connection timeout in order to prevent Thundering herd problem // Add a jitter for connection timeout in order to prevent Thundering herd problem
// when all the connections are established at the same time. // when all the connections are established at the same time.

View file

@ -211,11 +211,11 @@ func TestFilterBitmap(t *testing.T) {
}) })
// Clear all the bits // Clear all the bits
bm.forEachSetBit(func(idx int) bool { bm.forEachSetBit(func(_ int) bool {
return false return false
}) })
bitsCount := 0 bitsCount := 0
bm.forEachSetBit(func(idx int) bool { bm.forEachSetBit(func(_ int) bool {
bitsCount++ bitsCount++
return true return true
}) })
@ -9226,7 +9226,7 @@ func testFilterMatchForStorage(t *testing.T, s *Storage, tenantID TenantID, f fi
resultColumnNames: []string{resultColumnName}, resultColumnNames: []string{resultColumnName},
} }
workersCount := 3 workersCount := 3
s.search(workersCount, so, nil, func(workerID uint, br *blockResult) { s.search(workersCount, so, nil, func(_ uint, br *blockResult) {
// Verify tenantID // Verify tenantID
if !br.streamID.tenantID.equal(&tenantID) { if !br.streamID.tenantID.equal(&tenantID) {
t.Fatalf("unexpected tenantID in blockResult; got %s; want %s", &br.streamID.tenantID, &tenantID) t.Fatalf("unexpected tenantID in blockResult; got %s; want %s", &br.streamID.tenantID, &tenantID)

View file

@ -76,58 +76,58 @@ func TestStorageSearchStreamIDs(t *testing.T) {
} }
} }
}) })
t.Run("missing-job", func(t *testing.T) {
f(`{job="non-existing-job",instance="instance-0"}`, nil)
})
t.Run("missing-job-re", func(t *testing.T) {
f(`{job=~"non-existing-job|",instance="instance-0"}`, nil)
})
t.Run("missing-job-negative-re", func(t *testing.T) {
f(`{job!~"job.+",instance="instance-0"}`, nil)
})
t.Run("empty-job", func(t *testing.T) {
f(`{job="",instance="instance-0"}`, nil)
})
t.Run("missing-instance", func(t *testing.T) {
f(`{job="job-0",instance="non-existing-instance"}`, nil)
})
t.Run("missing-instance-re", func(t *testing.T) {
f(`{job="job-0",instance=~"non-existing-instance|"}`, nil)
})
t.Run("missing-instance-negative-re", func(t *testing.T) {
f(`{job="job-0",instance!~"instance.+"}`, nil)
})
t.Run("empty-instance", func(t *testing.T) {
f(`{job="job-0",instance=""}`, nil)
})
t.Run("non-existing-tag", func(t *testing.T) {
f(`{job="job-0",instance="instance-0",non_existing_tag="foobar"}`, nil)
})
t.Run("non-existing-non-empty-tag", func(t *testing.T) {
f(`{job="job-0",instance="instance-0",non_existing_tag!=""}`, nil)
})
t.Run("non-existing-tag-re", func(t *testing.T) {
f(`{job="job-0",instance="instance-0",non_existing_tag=~"foo.+"}`, nil)
})
t.Run("non-existing-non-empty-tag-re", func(t *testing.T) {
f(`{job="job-0",instance="instance-0",non_existing_tag!~""}`, nil)
})
t.Run("match-job-instance", func(t *testing.T) { // missing-job
f(`{job="non-existing-job",instance="instance-0"}`, nil)
// missing-job-re
f(`{job=~"non-existing-job|",instance="instance-0"}`, nil)
// missing-job-negative-re
f(`{job!~"job.+",instance="instance-0"}`, nil)
// empty-job
f(`{job="",instance="instance-0"}`, nil)
// missing-instance
f(`{job="job-0",instance="non-existing-instance"}`, nil)
// missing-instance-re
f(`{job="job-0",instance=~"non-existing-instance|"}`, nil)
// missing-instance-negative-re
f(`{job="job-0",instance!~"instance.+"}`, nil)
// empty-instance
f(`{job="job-0",instance=""}`, nil)
// non-existing-tag
f(`{job="job-0",instance="instance-0",non_existing_tag="foobar"}`, nil)
// non-existing-non-empty-tag
f(`{job="job-0",instance="instance-0",non_existing_tag!=""}`, nil)
// non-existing-tag-re
f(`{job="job-0",instance="instance-0",non_existing_tag=~"foo.+"}`, nil)
//non-existing-non-empty-tag-re
f(`{job="job-0",instance="instance-0",non_existing_tag!~""}`, nil)
// match-job-instance
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
"instance": "instance-0", "instance": "instance-0",
"job": "job-0", "job": "job-0",
}) })
f(`{job="job-0",instance="instance-0"}`, []streamID{sid}) f(`{job="job-0",instance="instance-0"}`, []streamID{sid})
})
t.Run("match-non-existing-tag", func(t *testing.T) { // match-non-existing-tag
sid, _ := getStreamIDForTags(map[string]string{ sid, _ = getStreamIDForTags(map[string]string{
"instance": "instance-0", "instance": "instance-0",
"job": "job-0", "job": "job-0",
}) })
f(`{job="job-0",instance="instance-0",non_existing_tag=~"foo|"}`, []streamID{sid}) f(`{job="job-0",instance="instance-0",non_existing_tag=~"foo|"}`, []streamID{sid})
})
t.Run("match-job", func(t *testing.T) { // match-job
var streamIDs []streamID var streamIDs []streamID
for i := 0; i < instancesCount; i++ { for i := 0; i < instancesCount; i++ {
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
@ -137,9 +137,9 @@ func TestStorageSearchStreamIDs(t *testing.T) {
streamIDs = append(streamIDs, sid) streamIDs = append(streamIDs, sid)
} }
f(`{job="job-0"}`, streamIDs) f(`{job="job-0"}`, streamIDs)
})
t.Run("match-instance", func(t *testing.T) { // match-instance
var streamIDs []streamID streamIDs = nil
for i := 0; i < jobsCount; i++ { for i := 0; i < jobsCount; i++ {
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
"instance": "instance-1", "instance": "instance-1",
@ -148,9 +148,9 @@ func TestStorageSearchStreamIDs(t *testing.T) {
streamIDs = append(streamIDs, sid) streamIDs = append(streamIDs, sid)
} }
f(`{instance="instance-1"}`, streamIDs) f(`{instance="instance-1"}`, streamIDs)
})
t.Run("match-re", func(t *testing.T) { // match-re
var streamIDs []streamID streamIDs = nil
for _, instanceID := range []int{3, 1} { for _, instanceID := range []int{3, 1} {
for _, jobID := range []int{0, 2} { for _, jobID := range []int{0, 2} {
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
@ -161,9 +161,9 @@ func TestStorageSearchStreamIDs(t *testing.T) {
} }
} }
f(`{job=~"job-(0|2)",instance=~"instance-[13]"}`, streamIDs) f(`{job=~"job-(0|2)",instance=~"instance-[13]"}`, streamIDs)
})
t.Run("match-re-empty-match", func(t *testing.T) { // match-re-empty-match
var streamIDs []streamID streamIDs = nil
for _, instanceID := range []int{3, 1} { for _, instanceID := range []int{3, 1} {
for _, jobID := range []int{0, 2} { for _, jobID := range []int{0, 2} {
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
@ -174,8 +174,8 @@ func TestStorageSearchStreamIDs(t *testing.T) {
} }
} }
f(`{job=~"job-(0|2)|",instance=~"instance-[13]"}`, streamIDs) f(`{job=~"job-(0|2)|",instance=~"instance-[13]"}`, streamIDs)
})
t.Run("match-negative-re", func(t *testing.T) { // match-negative-re
var instanceIDs []int var instanceIDs []int
for i := 0; i < instancesCount; i++ { for i := 0; i < instancesCount; i++ {
if i != 0 && i != 1 { if i != 0 && i != 1 {
@ -188,7 +188,7 @@ func TestStorageSearchStreamIDs(t *testing.T) {
jobIDs = append(jobIDs, i) jobIDs = append(jobIDs, i)
} }
} }
var streamIDs []streamID streamIDs = nil
for _, instanceID := range instanceIDs { for _, instanceID := range instanceIDs {
for _, jobID := range jobIDs { for _, jobID := range jobIDs {
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
@ -199,21 +199,21 @@ func TestStorageSearchStreamIDs(t *testing.T) {
} }
} }
f(`{job!~"job-[0-2]",instance!~"instance-(0|1)"}`, streamIDs) f(`{job!~"job-[0-2]",instance!~"instance-(0|1)"}`, streamIDs)
})
t.Run("match-negative-re-empty-match", func(t *testing.T) { // match-negative-re-empty-match
var instanceIDs []int instanceIDs = nil
for i := 0; i < instancesCount; i++ { for i := 0; i < instancesCount; i++ {
if i != 0 && i != 1 { if i != 0 && i != 1 {
instanceIDs = append(instanceIDs, i) instanceIDs = append(instanceIDs, i)
} }
} }
var jobIDs []int jobIDs = nil
for i := 0; i < jobsCount; i++ { for i := 0; i < jobsCount; i++ {
if i > 2 { if i > 2 {
jobIDs = append(jobIDs, i) jobIDs = append(jobIDs, i)
} }
} }
var streamIDs []streamID streamIDs = nil
for _, instanceID := range instanceIDs { for _, instanceID := range instanceIDs {
for _, jobID := range jobIDs { for _, jobID := range jobIDs {
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
@ -224,16 +224,16 @@ func TestStorageSearchStreamIDs(t *testing.T) {
} }
} }
f(`{job!~"job-[0-2]",instance!~"instance-(0|1)|"}`, streamIDs) f(`{job!~"job-[0-2]",instance!~"instance-(0|1)|"}`, streamIDs)
})
t.Run("match-negative-job", func(t *testing.T) { // match-negative-job
instanceIDs := []int{2} instanceIDs = []int{2}
var jobIDs []int jobIDs = nil
for i := 0; i < jobsCount; i++ { for i := 0; i < jobsCount; i++ {
if i != 1 { if i != 1 {
jobIDs = append(jobIDs, i) jobIDs = append(jobIDs, i)
} }
} }
var streamIDs []streamID streamIDs = nil
for _, instanceID := range instanceIDs { for _, instanceID := range instanceIDs {
for _, jobID := range jobIDs { for _, jobID := range jobIDs {
sid, _ := getStreamIDForTags(map[string]string{ sid, _ := getStreamIDForTags(map[string]string{
@ -244,7 +244,6 @@ func TestStorageSearchStreamIDs(t *testing.T) {
} }
} }
f(`{instance="instance-2",job!="job-1"}`, streamIDs) f(`{instance="instance-2",job!="job-1"}`, streamIDs)
})
mustCloseIndexdb(idb) mustCloseIndexdb(idb)
fs.MustRemoveAll(path) fs.MustRemoveAll(path)

View file

@ -51,7 +51,7 @@ func (s *Storage) RunQuery(tenantIDs []TenantID, q *Query, stopCh <-chan struct{
resultColumnNames: resultColumnNames, resultColumnNames: resultColumnNames,
} }
workersCount := cgroup.AvailableCPUs() workersCount := cgroup.AvailableCPUs()
s.search(workersCount, so, stopCh, func(workerID uint, br *blockResult) { s.search(workersCount, so, stopCh, func(_ uint, br *blockResult) {
brs := getBlockRows() brs := getBlockRows()
cs := brs.cs cs := brs.cs

View file

@ -78,25 +78,25 @@ func TestStorageRunQuery(t *testing.T) {
s.debugFlush() s.debugFlush()
// run tests on the storage data // run tests on the storage data
t.Run("missing-tenant", func(t *testing.T) { t.Run("missing-tenant", func(_ *testing.T) {
q := mustParseQuery(`"log message"`) q := mustParseQuery(`"log message"`)
tenantID := TenantID{ tenantID := TenantID{
AccountID: 0, AccountID: 0,
ProjectID: 0, ProjectID: 0,
} }
processBlock := func(columns []BlockColumn) { processBlock := func(_ []BlockColumn) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(tenantIDs, q, nil, processBlock) s.RunQuery(tenantIDs, q, nil, processBlock)
}) })
t.Run("missing-message-text", func(t *testing.T) { t.Run("missing-message-text", func(_ *testing.T) {
q := mustParseQuery(`foobar`) q := mustParseQuery(`foobar`)
tenantID := TenantID{ tenantID := TenantID{
AccountID: 1, AccountID: 1,
ProjectID: 11, ProjectID: 11,
} }
processBlock := func(columns []BlockColumn) { processBlock := func(_ []BlockColumn) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
@ -168,9 +168,9 @@ func TestStorageRunQuery(t *testing.T) {
t.Fatalf("unexpected number of matching rows; got %d; want %d", n, expectedRowsCount) t.Fatalf("unexpected number of matching rows; got %d; want %d", n, expectedRowsCount)
} }
}) })
t.Run("stream-filter-mismatch", func(t *testing.T) { t.Run("stream-filter-mismatch", func(_ *testing.T) {
q := mustParseQuery(`_stream:{job="foobar",instance=~"host-.+:2345"} log`) q := mustParseQuery(`_stream:{job="foobar",instance=~"host-.+:2345"} log`)
processBlock := func(columns []BlockColumn) { processBlock := func(_ []BlockColumn) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
s.RunQuery(allTenantIDs, q, nil, processBlock) s.RunQuery(allTenantIDs, q, nil, processBlock)
@ -273,7 +273,7 @@ func TestStorageRunQuery(t *testing.T) {
t.Fatalf("unexpected number of rows; got %d; want %d", n, expectedRowsCount) t.Fatalf("unexpected number of rows; got %d; want %d", n, expectedRowsCount)
} }
}) })
t.Run("matching-stream-id-missing-time-range", func(t *testing.T) { t.Run("matching-stream-id-missing-time-range", func(_ *testing.T) {
minTimestamp := baseTimestamp + (rowsPerBlock+1)*1e9 minTimestamp := baseTimestamp + (rowsPerBlock+1)*1e9
maxTimestamp := baseTimestamp + (rowsPerBlock+2)*1e9 maxTimestamp := baseTimestamp + (rowsPerBlock+2)*1e9
q := mustParseQuery(fmt.Sprintf(`_stream:{job="foobar",instance="host-1:234"} _time:[%d, %d)`, minTimestamp/1e9, maxTimestamp/1e9)) q := mustParseQuery(fmt.Sprintf(`_stream:{job="foobar",instance="host-1:234"} _time:[%d, %d)`, minTimestamp/1e9, maxTimestamp/1e9))
@ -281,13 +281,13 @@ func TestStorageRunQuery(t *testing.T) {
AccountID: 1, AccountID: 1,
ProjectID: 11, ProjectID: 11,
} }
processBlock := func(columns []BlockColumn) { processBlock := func(_ []BlockColumn) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
s.RunQuery(tenantIDs, q, nil, processBlock) s.RunQuery(tenantIDs, q, nil, processBlock)
}) })
t.Run("missing-time-range", func(t *testing.T) { t.Run("missing-time-range", func(_ *testing.T) {
minTimestamp := baseTimestamp + (rowsPerBlock+1)*1e9 minTimestamp := baseTimestamp + (rowsPerBlock+1)*1e9
maxTimestamp := baseTimestamp + (rowsPerBlock+2)*1e9 maxTimestamp := baseTimestamp + (rowsPerBlock+2)*1e9
q := mustParseQuery(fmt.Sprintf(`_time:[%d, %d)`, minTimestamp/1e9, maxTimestamp/1e9)) q := mustParseQuery(fmt.Sprintf(`_time:[%d, %d)`, minTimestamp/1e9, maxTimestamp/1e9))
@ -295,7 +295,7 @@ func TestStorageRunQuery(t *testing.T) {
AccountID: 1, AccountID: 1,
ProjectID: 11, ProjectID: 11,
} }
processBlock := func(columns []BlockColumn) { processBlock := func(_ []BlockColumn) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
tenantIDs := []TenantID{tenantID} tenantIDs := []TenantID{tenantID}
@ -392,7 +392,7 @@ func TestStorageSearch(t *testing.T) {
} }
} }
t.Run("missing-tenant-smaller-than-existing", func(t *testing.T) { t.Run("missing-tenant-smaller-than-existing", func(_ *testing.T) {
tenantID := TenantID{ tenantID := TenantID{
AccountID: 0, AccountID: 0,
ProjectID: 0, ProjectID: 0,
@ -405,12 +405,12 @@ func TestStorageSearch(t *testing.T) {
filter: f, filter: f,
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, _ *blockResult) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
s.search(workersCount, so, nil, processBlock) s.search(workersCount, so, nil, processBlock)
}) })
t.Run("missing-tenant-bigger-than-existing", func(t *testing.T) { t.Run("missing-tenant-bigger-than-existing", func(_ *testing.T) {
tenantID := TenantID{ tenantID := TenantID{
AccountID: tenantsCount + 1, AccountID: tenantsCount + 1,
ProjectID: 0, ProjectID: 0,
@ -423,12 +423,12 @@ func TestStorageSearch(t *testing.T) {
filter: f, filter: f,
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, _ *blockResult) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
s.search(workersCount, so, nil, processBlock) s.search(workersCount, so, nil, processBlock)
}) })
t.Run("missing-tenant-middle", func(t *testing.T) { t.Run("missing-tenant-middle", func(_ *testing.T) {
tenantID := TenantID{ tenantID := TenantID{
AccountID: 1, AccountID: 1,
ProjectID: 0, ProjectID: 0,
@ -441,7 +441,7 @@ func TestStorageSearch(t *testing.T) {
filter: f, filter: f,
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, _ *blockResult) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
s.search(workersCount, so, nil, processBlock) s.search(workersCount, so, nil, processBlock)
@ -461,7 +461,7 @@ func TestStorageSearch(t *testing.T) {
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
var rowsCount atomic.Uint32 var rowsCount atomic.Uint32
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, br *blockResult) {
if !br.streamID.tenantID.equal(&tenantID) { if !br.streamID.tenantID.equal(&tenantID) {
panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID)) panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID))
} }
@ -485,7 +485,7 @@ func TestStorageSearch(t *testing.T) {
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
var rowsCount atomic.Uint32 var rowsCount atomic.Uint32
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, br *blockResult) {
rowsCount.Add(uint32(br.RowsCount())) rowsCount.Add(uint32(br.RowsCount()))
} }
s.search(workersCount, so, nil, processBlock) s.search(workersCount, so, nil, processBlock)
@ -495,7 +495,7 @@ func TestStorageSearch(t *testing.T) {
t.Fatalf("unexpected number of matching rows; got %d; want %d", n, expectedRowsCount) t.Fatalf("unexpected number of matching rows; got %d; want %d", n, expectedRowsCount)
} }
}) })
t.Run("stream-filter-mismatch", func(t *testing.T) { t.Run("stream-filter-mismatch", func(_ *testing.T) {
sf := mustNewStreamFilter(`{job="foobar",instance=~"host-.+:2345"}`) sf := mustNewStreamFilter(`{job="foobar",instance=~"host-.+:2345"}`)
minTimestamp := baseTimestamp minTimestamp := baseTimestamp
maxTimestamp := baseTimestamp + rowsPerBlock*1e9 + blocksPerStream maxTimestamp := baseTimestamp + rowsPerBlock*1e9 + blocksPerStream
@ -505,7 +505,7 @@ func TestStorageSearch(t *testing.T) {
filter: f, filter: f,
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, _ *blockResult) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
s.search(workersCount, so, nil, processBlock) s.search(workersCount, so, nil, processBlock)
@ -526,7 +526,7 @@ func TestStorageSearch(t *testing.T) {
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
var rowsCount atomic.Uint32 var rowsCount atomic.Uint32
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, br *blockResult) {
if !br.streamID.tenantID.equal(&tenantID) { if !br.streamID.tenantID.equal(&tenantID) {
panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID)) panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID))
} }
@ -555,7 +555,7 @@ func TestStorageSearch(t *testing.T) {
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
var rowsCount atomic.Uint32 var rowsCount atomic.Uint32
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, br *blockResult) {
if !br.streamID.tenantID.equal(&tenantID) { if !br.streamID.tenantID.equal(&tenantID) {
panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID)) panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID))
} }
@ -592,7 +592,7 @@ func TestStorageSearch(t *testing.T) {
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
var rowsCount atomic.Uint32 var rowsCount atomic.Uint32
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, br *blockResult) {
if !br.streamID.tenantID.equal(&tenantID) { if !br.streamID.tenantID.equal(&tenantID) {
panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID)) panic(fmt.Errorf("unexpected tenantID; got %s; want %s", &br.streamID.tenantID, &tenantID))
} }
@ -620,7 +620,7 @@ func TestStorageSearch(t *testing.T) {
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
var rowsCount atomic.Uint32 var rowsCount atomic.Uint32
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, br *blockResult) {
rowsCount.Add(uint32(br.RowsCount())) rowsCount.Add(uint32(br.RowsCount()))
} }
s.search(workersCount, so, nil, processBlock) s.search(workersCount, so, nil, processBlock)
@ -630,7 +630,7 @@ func TestStorageSearch(t *testing.T) {
t.Fatalf("unexpected number of rows; got %d; want %d", n, expectedRowsCount) t.Fatalf("unexpected number of rows; got %d; want %d", n, expectedRowsCount)
} }
}) })
t.Run("matching-stream-id-missing-time-range", func(t *testing.T) { t.Run("matching-stream-id-missing-time-range", func(_ *testing.T) {
sf := mustNewStreamFilter(`{job="foobar",instance="host-1:234"}`) sf := mustNewStreamFilter(`{job="foobar",instance="host-1:234"}`)
tenantID := TenantID{ tenantID := TenantID{
AccountID: 1, AccountID: 1,
@ -644,7 +644,7 @@ func TestStorageSearch(t *testing.T) {
filter: f, filter: f,
resultColumnNames: []string{"_msg"}, resultColumnNames: []string{"_msg"},
} }
processBlock := func(workerID uint, br *blockResult) { processBlock := func(_ uint, _ *blockResult) {
panic(fmt.Errorf("unexpected match")) panic(fmt.Errorf("unexpected match"))
} }
s.search(workersCount, so, nil, processBlock) s.search(workersCount, so, nil, processBlock)

View file

@ -32,7 +32,7 @@ func GetServerTLSConfig(tlsCertFile, tlsKeyFile, tlsMinVersion string, tlsCipher
MinVersion: minVersion, MinVersion: minVersion,
// Do not set MaxVersion, since this has no sense from security PoV. // Do not set MaxVersion, since this has no sense from security PoV.
// This can only result in lower security level if improperly set. // This can only result in lower security level if improperly set.
GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) { GetCertificate: func(_ *tls.ClientHelloInfo) (*tls.Certificate, error) {
certLock.Lock() certLock.Lock()
defer certLock.Unlock() defer certLock.Unlock()
if fasttime.UnixTimestamp() > certDeadline { if fasttime.UnixTimestamp() > certDeadline {

View file

@ -22,7 +22,7 @@ func TestQueueOpenClose(t *testing.T) {
} }
func TestQueueOpen(t *testing.T) { func TestQueueOpen(t *testing.T) {
t.Run("invalid-metainfo", func(t *testing.T) { t.Run("invalid-metainfo", func(_ *testing.T) {
path := "queue-open-invalid-metainfo" path := "queue-open-invalid-metainfo"
mustCreateDir(path) mustCreateDir(path)
mustCreateFile(filepath.Join(path, metainfoFilename), "foobarbaz") mustCreateFile(filepath.Join(path, metainfoFilename), "foobarbaz")
@ -30,7 +30,7 @@ func TestQueueOpen(t *testing.T) {
q.MustClose() q.MustClose()
mustDeleteDir(path) mustDeleteDir(path)
}) })
t.Run("junk-files-and-dirs", func(t *testing.T) { t.Run("junk-files-and-dirs", func(_ *testing.T) {
path := "queue-open-junk-files-and-dir" path := "queue-open-junk-files-and-dir"
mustCreateDir(path) mustCreateDir(path)
mustCreateEmptyMetainfo(path, "foobar") mustCreateEmptyMetainfo(path, "foobar")
@ -40,7 +40,7 @@ func TestQueueOpen(t *testing.T) {
q.MustClose() q.MustClose()
mustDeleteDir(path) mustDeleteDir(path)
}) })
t.Run("invalid-chunk-offset", func(t *testing.T) { t.Run("invalid-chunk-offset", func(_ *testing.T) {
path := "queue-open-invalid-chunk-offset" path := "queue-open-invalid-chunk-offset"
mustCreateDir(path) mustCreateDir(path)
mustCreateEmptyMetainfo(path, "foobar") mustCreateEmptyMetainfo(path, "foobar")
@ -49,7 +49,7 @@ func TestQueueOpen(t *testing.T) {
q.MustClose() q.MustClose()
mustDeleteDir(path) mustDeleteDir(path)
}) })
t.Run("too-new-chunk", func(t *testing.T) { t.Run("too-new-chunk", func(_ *testing.T) {
path := "queue-open-too-new-chunk" path := "queue-open-too-new-chunk"
mustCreateDir(path) mustCreateDir(path)
mustCreateEmptyMetainfo(path, "foobar") mustCreateEmptyMetainfo(path, "foobar")
@ -88,7 +88,7 @@ func TestQueueOpen(t *testing.T) {
q.MustClose() q.MustClose()
mustDeleteDir(path) mustDeleteDir(path)
}) })
t.Run("metainfo-dir", func(t *testing.T) { t.Run("metainfo-dir", func(_ *testing.T) {
path := "queue-open-metainfo-dir" path := "queue-open-metainfo-dir"
mustCreateDir(path) mustCreateDir(path)
mustCreateDir(filepath.Join(path, metainfoFilename)) mustCreateDir(filepath.Join(path, metainfoFilename))
@ -112,7 +112,7 @@ func TestQueueOpen(t *testing.T) {
q.MustClose() q.MustClose()
mustDeleteDir(path) mustDeleteDir(path)
}) })
t.Run("invalid-writer-file-size", func(t *testing.T) { t.Run("invalid-writer-file-size", func(_ *testing.T) {
path := "too-small-reader-file" path := "too-small-reader-file"
mustCreateDir(path) mustCreateDir(path)
mustCreateEmptyMetainfo(path, "foobar") mustCreateEmptyMetainfo(path, "foobar")

View file

@ -101,12 +101,12 @@ func TestLoadRelabelConfigsFailure(t *testing.T) {
t.Fatalf("unexpected non-empty rcs: %#v", rcs) t.Fatalf("unexpected non-empty rcs: %#v", rcs)
} }
} }
t.Run("non-existing-file", func(t *testing.T) {
// non-existing-file
f("testdata/non-exsiting-file") f("testdata/non-exsiting-file")
})
t.Run("invalid-file", func(t *testing.T) { // invalid-file
f("testdata/invalid_config.yml") f("testdata/invalid_config.yml")
})
} }
func TestParsedConfigsString(t *testing.T) { func TestParsedConfigsString(t *testing.T) {
@ -209,7 +209,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
t.Fatalf("unexpected non-empty pcs: %#v", pcs) t.Fatalf("unexpected non-empty pcs: %#v", pcs)
} }
} }
t.Run("invalid-regex", func(t *testing.T) {
// invalid regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
SourceLabels: []string{"aaa"}, SourceLabels: []string{"aaa"},
@ -219,55 +220,55 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("replace-missing-target-label", func(t *testing.T) { // replace-missing-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "replace", Action: "replace",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("replace_all-missing-source-labels", func(t *testing.T) { // replace_all-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "replace_all", Action: "replace_all",
TargetLabel: "xxx", TargetLabel: "xxx",
}, },
}) })
})
t.Run("replace_all-missing-target-label", func(t *testing.T) { // replace_all-missing-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "replace_all", Action: "replace_all",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("keep-missing-source-labels", func(t *testing.T) { // keep-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep", Action: "keep",
}, },
}) })
})
t.Run("keep_if_contains-missing-target-label", func(t *testing.T) { // keep_if_contains-missing-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_if_contains", Action: "keep_if_contains",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("keep_if_contains-missing-source-labels", func(t *testing.T) { // keep_if_contains-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_if_contains", Action: "keep_if_contains",
TargetLabel: "foo", TargetLabel: "foo",
}, },
}) })
})
t.Run("keep_if_contains-unused-regex", func(t *testing.T) { // keep_if_contains-unused-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_if_contains", Action: "keep_if_contains",
@ -278,24 +279,24 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("drop_if_contains-missing-target-label", func(t *testing.T) { // drop_if_contains-missing-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_if_contains", Action: "drop_if_contains",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("drop_if_contains-missing-source-labels", func(t *testing.T) { // drop_if_contains-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_if_contains", Action: "drop_if_contains",
TargetLabel: "foo", TargetLabel: "foo",
}, },
}) })
})
t.Run("drop_if_contains-unused-regex", func(t *testing.T) { // drop_if_contains-unused-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_if_contains", Action: "drop_if_contains",
@ -306,23 +307,23 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("keep_if_equal-missing-source-labels", func(t *testing.T) { // keep_if_equal-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_if_equal", Action: "keep_if_equal",
}, },
}) })
})
t.Run("keep_if_equal-single-source-label", func(t *testing.T) { // keep_if_equal-single-source-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_if_equal", Action: "keep_if_equal",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("keep_if_equal-unused-target-label", func(t *testing.T) { // keep_if_equal-unused-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_if_equal", Action: "keep_if_equal",
@ -330,8 +331,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
TargetLabel: "foo", TargetLabel: "foo",
}, },
}) })
})
t.Run("keep_if_equal-unused-regex", func(t *testing.T) { // keep_if_equal-unused-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_if_equal", Action: "keep_if_equal",
@ -341,23 +342,23 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("drop_if_equal-missing-source-labels", func(t *testing.T) { // drop_if_equal-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_if_equal", Action: "drop_if_equal",
}, },
}) })
})
t.Run("drop_if_equal-single-source-label", func(t *testing.T) { // drop_if_equal-single-source-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_if_equal", Action: "drop_if_equal",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("drop_if_equal-unused-target-label", func(t *testing.T) { // drop_if_equal-unused-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_if_equal", Action: "drop_if_equal",
@ -365,8 +366,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
TargetLabel: "foo", TargetLabel: "foo",
}, },
}) })
})
t.Run("drop_if_equal-unused-regex", func(t *testing.T) { // drop_if_equal-unused-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_if_equal", Action: "drop_if_equal",
@ -376,23 +377,23 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("keepequal-missing-source-labels", func(t *testing.T) { // keepequal-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keepequal", Action: "keepequal",
}, },
}) })
})
t.Run("keepequal-missing-target-label", func(t *testing.T) { // keepequal-missing-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keepequal", Action: "keepequal",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("keepequal-unused-regex", func(t *testing.T) { // keepequal-unused-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keepequal", Action: "keepequal",
@ -403,23 +404,23 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("dropequal-missing-source-labels", func(t *testing.T) { // dropequal-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "dropequal", Action: "dropequal",
}, },
}) })
})
t.Run("dropequal-missing-target-label", func(t *testing.T) { // dropequal-missing-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "dropequal", Action: "dropequal",
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("dropequal-unused-regex", func(t *testing.T) { // dropequal-unused-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "dropequal", Action: "dropequal",
@ -430,15 +431,15 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("drop-missing-source-labels", func(t *testing.T) { // drop-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop", Action: "drop",
}, },
}) })
})
t.Run("hashmod-missing-source-labels", func(t *testing.T) { // hashmod-missing-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "hashmod", Action: "hashmod",
@ -446,8 +447,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
Modulus: 123, Modulus: 123,
}, },
}) })
})
t.Run("hashmod-missing-target-label", func(t *testing.T) { // hashmod-missing-target-label
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "hashmod", Action: "hashmod",
@ -455,8 +456,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
Modulus: 123, Modulus: 123,
}, },
}) })
})
t.Run("hashmod-missing-modulus", func(t *testing.T) { // hashmod-missing-modulus
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "hashmod", Action: "hashmod",
@ -464,22 +465,22 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
TargetLabel: "xxx", TargetLabel: "xxx",
}, },
}) })
})
t.Run("invalid-action", func(t *testing.T) { // invalid-action
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "invalid-action", Action: "invalid-action",
}, },
}) })
})
t.Run("drop_metrics-missing-regex", func(t *testing.T) { // drop_metrics-missing-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_metrics", Action: "drop_metrics",
}, },
}) })
})
t.Run("drop_metrics-non-empty-source-labels", func(t *testing.T) { // drop_metrics-non-empty-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "drop_metrics", Action: "drop_metrics",
@ -489,15 +490,15 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("keep_metrics-missing-regex", func(t *testing.T) { // keep_metrics-missing-regex
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_metrics", Action: "keep_metrics",
}, },
}) })
})
t.Run("keep_metrics-non-empty-source-labels", func(t *testing.T) { // keep_metrics-non-empty-source-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "keep_metrics", Action: "keep_metrics",
@ -507,24 +508,24 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("uppercase-missing-sourceLabels", func(t *testing.T) { // uppercase-missing-sourceLabels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "uppercase", Action: "uppercase",
TargetLabel: "foobar", TargetLabel: "foobar",
}, },
}) })
})
t.Run("lowercase-missing-targetLabel", func(t *testing.T) { // lowercase-missing-targetLabel
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "lowercase", Action: "lowercase",
SourceLabels: []string{"foobar"}, SourceLabels: []string{"foobar"},
}, },
}) })
})
t.Run("graphite-missing-match", func(t *testing.T) { // graphite-missing-match
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "graphite", Action: "graphite",
@ -533,16 +534,16 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
t.Run("graphite-missing-labels", func(t *testing.T) { // graphite-missing-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "graphite", Action: "graphite",
Match: "foo.*.bar", Match: "foo.*.bar",
}, },
}) })
})
t.Run("graphite-superflouous-sourceLabels", func(t *testing.T) { // graphite-superflouous-sourceLabels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "graphite", Action: "graphite",
@ -553,8 +554,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
SourceLabels: []string{"foo"}, SourceLabels: []string{"foo"},
}, },
}) })
})
t.Run("graphite-superflouous-targetLabel", func(t *testing.T) { // graphite-superflouous-targetLabel
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "graphite", Action: "graphite",
@ -565,9 +566,9 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
TargetLabel: "foo", TargetLabel: "foo",
}, },
}) })
})
// graphite-superflouous-replacement
replacement := "foo" replacement := "foo"
t.Run("graphite-superflouous-replacement", func(t *testing.T) {
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "graphite", Action: "graphite",
@ -578,9 +579,9 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
Replacement: &replacement, Replacement: &replacement,
}, },
}) })
})
// graphite-superflouous-regex
var re MultiLineRegex var re MultiLineRegex
t.Run("graphite-superflouous-regex", func(t *testing.T) {
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "graphite", Action: "graphite",
@ -591,8 +592,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
Regex: &re, Regex: &re,
}, },
}) })
})
t.Run("non-graphite-superflouos-match", func(t *testing.T) { // non-graphite-superflouos-match
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "uppercase", Action: "uppercase",
@ -601,8 +602,8 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
Match: "aaa", Match: "aaa",
}, },
}) })
})
t.Run("non-graphite-superflouos-labels", func(t *testing.T) { // non-graphite-superflouos-labels
f([]RelabelConfig{ f([]RelabelConfig{
{ {
Action: "uppercase", Action: "uppercase",
@ -613,7 +614,6 @@ func TestParseRelabelConfigsFailure(t *testing.T) {
}, },
}, },
}) })
})
} }
func TestIsDefaultRegex(t *testing.T) { func TestIsDefaultRegex(t *testing.T) {

View file

@ -181,14 +181,15 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
t.Fatalf("unexpected result; got\n%s\nwant\n%s", result, resultExpected) t.Fatalf("unexpected result; got\n%s\nwant\n%s", result, resultExpected)
} }
} }
t.Run("empty_relabel_configs", func(t *testing.T) {
// empty_relabel_configs
f("", `{}`, false, `{}`) f("", `{}`, false, `{}`)
f("", `{}`, true, `{}`) f("", `{}`, true, `{}`)
f("", `{foo="bar"}`, false, `{foo="bar"}`) f("", `{foo="bar"}`, false, `{foo="bar"}`)
f("", `xxx{foo="bar",__aaa="yyy"}`, false, `xxx{__aaa="yyy",foo="bar"}`) f("", `xxx{foo="bar",__aaa="yyy"}`, false, `xxx{__aaa="yyy",foo="bar"}`)
f("", `xxx{foo="bar",__aaa="yyy"}`, true, `xxx{foo="bar"}`) f("", `xxx{foo="bar",__aaa="yyy"}`, true, `xxx{foo="bar"}`)
})
t.Run("replace-miss", func(t *testing.T) { // replace-miss"
f(` f(`
- action: replace - action: replace
target_label: bar target_label: bar
@ -215,8 +216,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: "xxx" target_label: "xxx"
regex: ".+" regex: ".+"
`, `{xxx="yyy"}`, false, `{xxx="yyy"}`) `, `{xxx="yyy"}`, false, `{xxx="yyy"}`)
})
t.Run("replace-if-miss", func(t *testing.T) { // replace-if-miss
f(` f(`
- action: replace - action: replace
if: '{foo="bar"}' if: '{foo="bar"}'
@ -224,8 +225,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: "bar" target_label: "bar"
replacement: "a-$1-b" replacement: "a-$1-b"
`, `{xxx="yyy"}`, false, `{xxx="yyy"}`) `, `{xxx="yyy"}`, false, `{xxx="yyy"}`)
})
t.Run("replace-hit", func(t *testing.T) { // replace-hit
f(` f(`
- action: replace - action: replace
source_labels: ["xxx", "foo"] source_labels: ["xxx", "foo"]
@ -242,8 +243,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
source_labels: ["foo"] source_labels: ["foo"]
target_label: "xxx" target_label: "xxx"
`, `{xxx="yyy"}`, false, `{}`) `, `{xxx="yyy"}`, false, `{}`)
})
t.Run("replace-if-hit", func(t *testing.T) { // replace-if-hit
f(` f(`
- action: replace - action: replace
if: '{xxx=~".y."}' if: '{xxx=~".y."}'
@ -251,8 +252,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: "bar" target_label: "bar"
replacement: "a-$1-b" replacement: "a-$1-b"
`, `{xxx="yyy"}`, false, `{bar="a-yyy;-b",xxx="yyy"}`) `, `{xxx="yyy"}`, false, `{bar="a-yyy;-b",xxx="yyy"}`)
})
t.Run("replace-remove-label-value-hit", func(t *testing.T) { // replace-remove-label-value-hit
f(` f(`
- action: replace - action: replace
source_labels: ["foo"] source_labels: ["foo"]
@ -260,8 +261,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
regex: "xxx" regex: "xxx"
replacement: "" replacement: ""
`, `{foo="xxx",bar="baz"}`, false, `{bar="baz"}`) `, `{foo="xxx",bar="baz"}`, false, `{bar="baz"}`)
})
t.Run("replace-remove-label-value-miss", func(t *testing.T) { // replace-remove-label-value-miss
f(` f(`
- action: replace - action: replace
source_labels: ["foo"] source_labels: ["foo"]
@ -269,8 +270,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
regex: "xxx" regex: "xxx"
replacement: "" replacement: ""
`, `{foo="yyy",bar="baz"}`, false, `{bar="baz",foo="yyy"}`) `, `{foo="yyy",bar="baz"}`, false, `{bar="baz",foo="yyy"}`)
})
t.Run("replace-hit-remove-label", func(t *testing.T) { // replace-hit-remove-label
f(` f(`
- action: replace - action: replace
source_labels: ["xxx", "foo"] source_labels: ["xxx", "foo"]
@ -278,8 +279,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: "foo" target_label: "foo"
replacement: "" replacement: ""
`, `{xxx="yyy",foo="bar"}`, false, `{xxx="yyy"}`) `, `{xxx="yyy",foo="bar"}`, false, `{xxx="yyy"}`)
})
t.Run("replace-miss-remove-label", func(t *testing.T) { // replace-miss-remove-label
f(` f(`
- action: replace - action: replace
source_labels: ["xxx", "foo"] source_labels: ["xxx", "foo"]
@ -287,16 +288,16 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: "foo" target_label: "foo"
replacement: "" replacement: ""
`, `{xxx="yyyz",foo="bar"}`, false, `{foo="bar",xxx="yyyz"}`) `, `{xxx="yyyz",foo="bar"}`, false, `{foo="bar",xxx="yyyz"}`)
})
t.Run("replace-hit-target-label-with-capture-group", func(t *testing.T) { // replace-hit-target-label-with-capture-group
f(` f(`
- action: replace - action: replace
source_labels: ["xxx", "foo"] source_labels: ["xxx", "foo"]
target_label: "bar-$1" target_label: "bar-$1"
replacement: "a-$1-b" replacement: "a-$1-b"
`, `{xxx="yyy"}`, false, `{bar-yyy;="a-yyy;-b",xxx="yyy"}`) `, `{xxx="yyy"}`, false, `{bar-yyy;="a-yyy;-b",xxx="yyy"}`)
})
t.Run("replace_all-miss", func(t *testing.T) { // replace_all-miss
f(` f(`
- action: replace_all - action: replace_all
source_labels: [foo] source_labels: [foo]
@ -318,8 +319,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: "bar" target_label: "bar"
regex: ".+" regex: ".+"
`, `{xxx="yyy"}`, false, `{xxx="yyy"}`) `, `{xxx="yyy"}`, false, `{xxx="yyy"}`)
})
t.Run("replace_all-if-miss", func(t *testing.T) { // replace_all-if-miss
f(` f(`
- action: replace_all - action: replace_all
if: 'foo' if: 'foo'
@ -328,8 +329,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
regex: "-" regex: "-"
replacement: "." replacement: "."
`, `{xxx="a-b-c"}`, false, `{xxx="a-b-c"}`) `, `{xxx="a-b-c"}`, false, `{xxx="a-b-c"}`)
})
t.Run("replace_all-hit", func(t *testing.T) { // replace_all-hit
f(` f(`
- action: replace_all - action: replace_all
source_labels: ["xxx"] source_labels: ["xxx"]
@ -337,8 +338,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
regex: "-" regex: "-"
replacement: "." replacement: "."
`, `{xxx="a-b-c"}`, false, `{xxx="a.b.c"}`) `, `{xxx="a-b-c"}`, false, `{xxx="a.b.c"}`)
})
t.Run("replace_all-if-hit", func(t *testing.T) { // replace_all-if-hit
f(` f(`
- action: replace_all - action: replace_all
if: '{non_existing_label=~".*"}' if: '{non_existing_label=~".*"}'
@ -347,8 +348,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
regex: "-" regex: "-"
replacement: "." replacement: "."
`, `{xxx="a-b-c"}`, false, `{xxx="a.b.c"}`) `, `{xxx="a-b-c"}`, false, `{xxx="a.b.c"}`)
})
t.Run("replace_all-regex-hit", func(t *testing.T) { // replace_all-regex-hit
f(` f(`
- action: replace_all - action: replace_all
source_labels: ["xxx", "foo"] source_labels: ["xxx", "foo"]
@ -356,8 +357,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
regex: "(;)" regex: "(;)"
replacement: "-$1-" replacement: "-$1-"
`, `{xxx="y;y"}`, false, `{xxx="y-;-y-;-"}`) `, `{xxx="y;y"}`, false, `{xxx="y-;-y-;-"}`)
})
t.Run("replace-add-multi-labels", func(t *testing.T) { // replace-add-multi-labels
f(` f(`
- action: replace - action: replace
source_labels: ["xxx"] source_labels: ["xxx"]
@ -368,121 +369,121 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: "zar" target_label: "zar"
replacement: "b-$1" replacement: "b-$1"
`, `{xxx="yyy",instance="a.bc"}`, true, `{bar="a-yyy",instance="a.bc",xxx="yyy",zar="b-a-yyy"}`) `, `{xxx="yyy",instance="a.bc"}`, true, `{bar="a-yyy",instance="a.bc",xxx="yyy",zar="b-a-yyy"}`)
})
t.Run("replace-self", func(t *testing.T) { // replace-self
f(` f(`
- action: replace - action: replace
source_labels: ["foo"] source_labels: ["foo"]
target_label: "foo" target_label: "foo"
replacement: "a-$1" replacement: "a-$1"
`, `{foo="aaxx"}`, true, `{foo="a-aaxx"}`) `, `{foo="aaxx"}`, true, `{foo="a-aaxx"}`)
})
t.Run("replace-missing-source", func(t *testing.T) { // replace-missing-source
f(` f(`
- action: replace - action: replace
target_label: foo target_label: foo
replacement: "foobar" replacement: "foobar"
`, `{}`, true, `{foo="foobar"}`) `, `{}`, true, `{foo="foobar"}`)
})
t.Run("keep_if_contains-non-existing-target-and-source", func(t *testing.T) { // keep_if_contains-non-existing-target-and-source
f(` f(`
- action: keep_if_contains - action: keep_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{x="y"}`, true, `{x="y"}`) `, `{x="y"}`, true, `{x="y"}`)
})
t.Run("keep_if_contains-non-existing-target", func(t *testing.T) { // keep_if_contains-non-existing-target
f(` f(`
- action: keep_if_contains - action: keep_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{bar="aaa"}`, true, `{}`) `, `{bar="aaa"}`, true, `{}`)
})
t.Run("keep_if_contains-non-existing-source", func(t *testing.T) { // keep_if_contains-non-existing-source
f(` f(`
- action: keep_if_contains - action: keep_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{foo="aaa"}`, true, `{foo="aaa"}`) `, `{foo="aaa"}`, true, `{foo="aaa"}`)
})
t.Run("keep_if_contains-matching-source-target", func(t *testing.T) { // keep_if_contains-matching-source-target
f(` f(`
- action: keep_if_contains - action: keep_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{bar="aaa",foo="aaa"}`, true, `{bar="aaa",foo="aaa"}`) `, `{bar="aaa",foo="aaa"}`, true, `{bar="aaa",foo="aaa"}`)
})
t.Run("keep_if_contains-matching-sources-target", func(t *testing.T) { // keep_if_contains-matching-sources-target
f(` f(`
- action: keep_if_contains - action: keep_if_contains
target_label: foo target_label: foo
source_labels: [bar, baz] source_labels: [bar, baz]
`, `{bar="aaa",foo="aaa",baz="aaa"}`, true, `{bar="aaa",baz="aaa",foo="aaa"}`) `, `{bar="aaa",foo="aaa",baz="aaa"}`, true, `{bar="aaa",baz="aaa",foo="aaa"}`)
})
t.Run("keep_if_contains-mismatching-source-target", func(t *testing.T) { // keep_if_contains-mismatching-source-target
f(` f(`
- action: keep_if_contains - action: keep_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{bar="aaa",foo="bbb"}`, true, `{}`) `, `{bar="aaa",foo="bbb"}`, true, `{}`)
})
t.Run("keep_if_contains-mismatching-sources-target", func(t *testing.T) { // keep_if_contains-mismatching-sources-target
f(` f(`
- action: keep_if_contains - action: keep_if_contains
target_label: foo target_label: foo
source_labels: [bar, baz] source_labels: [bar, baz]
`, `{bar="aaa",foo="aaa",baz="bbb"}`, true, `{}`) `, `{bar="aaa",foo="aaa",baz="bbb"}`, true, `{}`)
})
t.Run("drop_if_contains-non-existing-target-and-source", func(t *testing.T) { // drop_if_contains-non-existing-target-and-source
f(` f(`
- action: drop_if_contains - action: drop_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{x="y"}`, true, `{}`) `, `{x="y"}`, true, `{}`)
})
t.Run("drop_if_contains-non-existing-target", func(t *testing.T) { // drop_if_contains-non-existing-target
f(` f(`
- action: drop_if_contains - action: drop_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{bar="aaa"}`, true, `{bar="aaa"}`) `, `{bar="aaa"}`, true, `{bar="aaa"}`)
})
t.Run("drop_if_contains-non-existing-source", func(t *testing.T) { // drop_if_contains-non-existing-source
f(` f(`
- action: drop_if_contains - action: drop_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{foo="aaa"}`, true, `{}`) `, `{foo="aaa"}`, true, `{}`)
})
t.Run("drop_if_contains-matching-source-target", func(t *testing.T) { // drop_if_contains-matching-source-target
f(` f(`
- action: drop_if_contains - action: drop_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{bar="aaa",foo="aaa"}`, true, `{}`) `, `{bar="aaa",foo="aaa"}`, true, `{}`)
})
t.Run("drop_if_contains-matching-sources-target", func(t *testing.T) { // drop_if_contains-matching-sources-target
f(` f(`
- action: drop_if_contains - action: drop_if_contains
target_label: foo target_label: foo
source_labels: [bar, baz] source_labels: [bar, baz]
`, `{bar="aaa",foo="aaa",baz="aaa"}`, true, `{}`) `, `{bar="aaa",foo="aaa",baz="aaa"}`, true, `{}`)
})
t.Run("drop_if_contains-mismatching-source-target", func(t *testing.T) { // drop_if_contains-mismatching-source-target
f(` f(`
- action: drop_if_contains - action: drop_if_contains
target_label: foo target_label: foo
source_labels: [bar] source_labels: [bar]
`, `{bar="aaa",foo="bbb"}`, true, `{bar="aaa",foo="bbb"}`) `, `{bar="aaa",foo="bbb"}`, true, `{bar="aaa",foo="bbb"}`)
})
t.Run("drop_if_contains-mismatching-sources-target", func(t *testing.T) { // drop_if_contains-mismatching-sources-target
f(` f(`
- action: drop_if_contains - action: drop_if_contains
target_label: foo target_label: foo
source_labels: [bar, baz] source_labels: [bar, baz]
`, `{bar="aaa",foo="aaa",baz="bbb"}`, true, `{bar="aaa",baz="bbb",foo="aaa"}`) `, `{bar="aaa",foo="aaa",baz="bbb"}`, true, `{bar="aaa",baz="bbb",foo="aaa"}`)
})
t.Run("keep_if_equal-miss", func(t *testing.T) { // keep_if_equal-miss
f(` f(`
- action: keep_if_equal - action: keep_if_equal
source_labels: ["foo", "bar"] source_labels: ["foo", "bar"]
@ -491,14 +492,14 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
- action: keep_if_equal - action: keep_if_equal
source_labels: ["xxx", "bar"] source_labels: ["xxx", "bar"]
`, `{xxx="yyy"}`, true, `{}`) `, `{xxx="yyy"}`, true, `{}`)
})
t.Run("keep_if_equal-hit", func(t *testing.T) { // keep_if_equal-hit
f(` f(`
- action: keep_if_equal - action: keep_if_equal
source_labels: ["xxx", "bar"] source_labels: ["xxx", "bar"]
`, `{xxx="yyy",bar="yyy"}`, true, `{bar="yyy",xxx="yyy"}`) `, `{xxx="yyy",bar="yyy"}`, true, `{bar="yyy",xxx="yyy"}`)
})
t.Run("drop_if_equal-miss", func(t *testing.T) { // drop_if_equal-miss
f(` f(`
- action: drop_if_equal - action: drop_if_equal
source_labels: ["foo", "bar"] source_labels: ["foo", "bar"]
@ -507,42 +508,42 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
- action: drop_if_equal - action: drop_if_equal
source_labels: ["xxx", "bar"] source_labels: ["xxx", "bar"]
`, `{xxx="yyy"}`, true, `{xxx="yyy"}`) `, `{xxx="yyy"}`, true, `{xxx="yyy"}`)
})
t.Run("drop_if_equal-hit", func(t *testing.T) { // drop_if_equal-hit
f(` f(`
- action: drop_if_equal - action: drop_if_equal
source_labels: [xxx, bar] source_labels: [xxx, bar]
`, `{xxx="yyy",bar="yyy"}`, true, `{}`) `, `{xxx="yyy",bar="yyy"}`, true, `{}`)
})
t.Run("keepequal-hit", func(t *testing.T) { // keepequal-hit
f(` f(`
- action: keepequal - action: keepequal
source_labels: [foo] source_labels: [foo]
target_label: bar target_label: bar
`, `{foo="a",bar="a"}`, true, `{bar="a",foo="a"}`) `, `{foo="a",bar="a"}`, true, `{bar="a",foo="a"}`)
})
t.Run("keepequal-miss", func(t *testing.T) { // keepequal-miss
f(` f(`
- action: keepequal - action: keepequal
source_labels: [foo] source_labels: [foo]
target_label: bar target_label: bar
`, `{foo="a",bar="x"}`, true, `{}`) `, `{foo="a",bar="x"}`, true, `{}`)
})
t.Run("dropequal-hit", func(t *testing.T) { // dropequal-hit
f(` f(`
- action: dropequal - action: dropequal
source_labels: [foo] source_labels: [foo]
target_label: bar target_label: bar
`, `{foo="a",bar="a"}`, true, `{}`) `, `{foo="a",bar="a"}`, true, `{}`)
})
t.Run("dropequal-miss", func(t *testing.T) { // dropequal-miss
f(` f(`
- action: dropequal - action: dropequal
source_labels: [foo] source_labels: [foo]
target_label: bar target_label: bar
`, `{foo="a",bar="x"}`, true, `{bar="x",foo="a"}`) `, `{foo="a",bar="x"}`, true, `{bar="x",foo="a"}`)
})
t.Run("keep-miss", func(t *testing.T) { // keep-miss
f(` f(`
- action: keep - action: keep
source_labels: [foo] source_labels: [foo]
@ -553,62 +554,62 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
source_labels: [foo] source_labels: [foo]
regex: ".+" regex: ".+"
`, `{xxx="yyy"}`, true, `{}`) `, `{xxx="yyy"}`, true, `{}`)
})
t.Run("keep-if-miss", func(t *testing.T) { // keep-if-miss
f(` f(`
- action: keep - action: keep
if: '{foo="bar"}' if: '{foo="bar"}'
`, `{foo="yyy"}`, false, `{}`) `, `{foo="yyy"}`, false, `{}`)
})
t.Run("keep-if-hit", func(t *testing.T) { // keep-if-hit
f(` f(`
- action: keep - action: keep
if: ['foobar', '{foo="yyy"}', '{a="b"}'] if: ['foobar', '{foo="yyy"}', '{a="b"}']
`, `{foo="yyy"}`, false, `{foo="yyy"}`) `, `{foo="yyy"}`, false, `{foo="yyy"}`)
})
t.Run("keep-hit", func(t *testing.T) { // keep-hit
f(` f(`
- action: keep - action: keep
source_labels: [foo] source_labels: [foo]
regex: "yyy" regex: "yyy"
`, `{foo="yyy"}`, false, `{foo="yyy"}`) `, `{foo="yyy"}`, false, `{foo="yyy"}`)
})
t.Run("keep-hit-regexp", func(t *testing.T) { // keep-hit-regexp
f(` f(`
- action: keep - action: keep
source_labels: ["foo"] source_labels: ["foo"]
regex: ".+" regex: ".+"
`, `{foo="yyy"}`, false, `{foo="yyy"}`) `, `{foo="yyy"}`, false, `{foo="yyy"}`)
})
t.Run("keep_metrics-miss", func(t *testing.T) { // keep_metrics-miss
f(` f(`
- action: keep_metrics - action: keep_metrics
regex: regex:
- foo - foo
- bar - bar
`, `xxx`, true, `{}`) `, `xxx`, true, `{}`)
})
t.Run("keep_metrics-if-miss", func(t *testing.T) { // keep_metrics-if-miss
f(` f(`
- action: keep_metrics - action: keep_metrics
if: 'bar' if: 'bar'
`, `foo`, true, `{}`) `, `foo`, true, `{}`)
})
t.Run("keep_metrics-if-hit", func(t *testing.T) { // keep_metrics-if-hit
f(` f(`
- action: keep_metrics - action: keep_metrics
if: 'foo' if: 'foo'
`, `foo`, true, `foo`) `, `foo`, true, `foo`)
})
t.Run("keep_metrics-hit", func(t *testing.T) { // keep_metrics-hit
f(` f(`
- action: keep_metrics - action: keep_metrics
regex: regex:
- foo - foo
- bar - bar
`, `foo`, true, `foo`) `, `foo`, true, `foo`)
})
t.Run("drop-miss", func(t *testing.T) { // drop-miss
f(` f(`
- action: drop - action: drop
source_labels: [foo] source_labels: [foo]
@ -619,70 +620,70 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
source_labels: [foo] source_labels: [foo]
regex: ".+" regex: ".+"
`, `{xxx="yyy"}`, true, `{xxx="yyy"}`) `, `{xxx="yyy"}`, true, `{xxx="yyy"}`)
})
t.Run("drop-if-miss", func(t *testing.T) { // drop-if-miss
f(` f(`
- action: drop - action: drop
if: '{foo="bar"}' if: '{foo="bar"}'
`, `{foo="yyy"}`, true, `{foo="yyy"}`) `, `{foo="yyy"}`, true, `{foo="yyy"}`)
})
t.Run("drop-if-hit", func(t *testing.T) { // drop-if-hit
f(` f(`
- action: drop - action: drop
if: '{foo="yyy"}' if: '{foo="yyy"}'
`, `{foo="yyy"}`, true, `{}`) `, `{foo="yyy"}`, true, `{}`)
})
t.Run("drop-hit", func(t *testing.T) { // drop-hit
f(` f(`
- action: drop - action: drop
source_labels: [foo] source_labels: [foo]
regex: yyy regex: yyy
`, `{foo="yyy"}`, true, `{}`) `, `{foo="yyy"}`, true, `{}`)
})
t.Run("drop-hit-regexp", func(t *testing.T) { // drop-hit-regexp
f(` f(`
- action: drop - action: drop
source_labels: [foo] source_labels: [foo]
regex: ".+" regex: ".+"
`, `{foo="yyy"}`, true, `{}`) `, `{foo="yyy"}`, true, `{}`)
})
t.Run("drop_metrics-miss", func(t *testing.T) { // drop_metrics-miss
f(` f(`
- action: drop_metrics - action: drop_metrics
regex: regex:
- foo - foo
- bar - bar
`, `xxx`, true, `xxx`) `, `xxx`, true, `xxx`)
})
t.Run("drop_metrics-if-miss", func(t *testing.T) { // drop_metrics-if-miss
f(` f(`
- action: drop_metrics - action: drop_metrics
if: bar if: bar
`, `foo`, true, `foo`) `, `foo`, true, `foo`)
})
t.Run("drop_metrics-if-hit", func(t *testing.T) { // drop_metrics-if-hit
f(` f(`
- action: drop_metrics - action: drop_metrics
if: foo if: foo
`, `foo`, true, `{}`) `, `foo`, true, `{}`)
})
t.Run("drop_metrics-hit", func(t *testing.T) { // drop_metrics-hit
f(` f(`
- action: drop_metrics - action: drop_metrics
regex: regex:
- foo - foo
- bar - bar
`, `foo`, true, `{}`) `, `foo`, true, `{}`)
})
t.Run("hashmod-miss", func(t *testing.T) { // hashmod-miss
f(` f(`
- action: hashmod - action: hashmod
source_labels: [foo] source_labels: [foo]
target_label: aaa target_label: aaa
modulus: 123 modulus: 123
`, `{xxx="yyy"}`, false, `{aaa="81",xxx="yyy"}`) `, `{xxx="yyy"}`, false, `{aaa="81",xxx="yyy"}`)
})
t.Run("hashmod-if-miss", func(t *testing.T) { // hashmod-if-miss
f(` f(`
- action: hashmod - action: hashmod
if: '{foo="bar"}' if: '{foo="bar"}'
@ -690,8 +691,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: aaa target_label: aaa
modulus: 123 modulus: 123
`, `{foo="yyy"}`, true, `{foo="yyy"}`) `, `{foo="yyy"}`, true, `{foo="yyy"}`)
})
t.Run("hashmod-if-hit", func(t *testing.T) { // hashmod-if-hit
f(` f(`
- action: hashmod - action: hashmod
if: '{foo="yyy"}' if: '{foo="yyy"}'
@ -699,98 +700,100 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
target_label: aaa target_label: aaa
modulus: 123 modulus: 123
`, `{foo="yyy"}`, true, `{aaa="73",foo="yyy"}`) `, `{foo="yyy"}`, true, `{aaa="73",foo="yyy"}`)
})
t.Run("hashmod-hit", func(t *testing.T) { // hashmod-hit
f(` f(`
- action: hashmod - action: hashmod
source_labels: [foo] source_labels: [foo]
target_label: aaa target_label: aaa
modulus: 123 modulus: 123
`, `{foo="yyy"}`, true, `{aaa="73",foo="yyy"}`) `, `{foo="yyy"}`, true, `{aaa="73",foo="yyy"}`)
})
t.Run("labelmap-copy-label-if-miss", func(t *testing.T) { // labelmap-copy-label-if-miss
f(` f(`
- action: labelmap - action: labelmap
if: '{foo="yyy",foobar="aab"}' if: '{foo="yyy",foobar="aab"}'
regex: "foo" regex: "foo"
replacement: "bar" replacement: "bar"
`, `{foo="yyy",foobar="aaa"}`, true, `{foo="yyy",foobar="aaa"}`) `, `{foo="yyy",foobar="aaa"}`, true, `{foo="yyy",foobar="aaa"}`)
})
t.Run("labelmap-copy-label-if-hit", func(t *testing.T) { // labelmap-copy-label-if-hit
f(` f(`
- action: labelmap - action: labelmap
if: '{foo="yyy",foobar="aaa"}' if: '{foo="yyy",foobar="aaa"}'
regex: "foo" regex: "foo"
replacement: "bar" replacement: "bar"
`, `{foo="yyy",foobar="aaa"}`, true, `{bar="yyy",foo="yyy",foobar="aaa"}`) `, `{foo="yyy",foobar="aaa"}`, true, `{bar="yyy",foo="yyy",foobar="aaa"}`)
})
t.Run("labelmap-copy-label", func(t *testing.T) { // labelmap-copy-label
f(` f(`
- action: labelmap - action: labelmap
regex: "foo" regex: "foo"
replacement: "bar" replacement: "bar"
`, `{foo="yyy",foobar="aaa"}`, true, `{bar="yyy",foo="yyy",foobar="aaa"}`) `, `{foo="yyy",foobar="aaa"}`, true, `{bar="yyy",foo="yyy",foobar="aaa"}`)
})
t.Run("labelmap-remove-prefix-dot-star", func(t *testing.T) { // labelmap-remove-prefix-dot-star
f(` f(`
- action: labelmap - action: labelmap
regex: "foo(.*)" regex: "foo(.*)"
`, `{xoo="yyy",foobar="aaa"}`, true, `{bar="aaa",foobar="aaa",xoo="yyy"}`) `, `{xoo="yyy",foobar="aaa"}`, true, `{bar="aaa",foobar="aaa",xoo="yyy"}`)
})
t.Run("labelmap-remove-prefix-dot-plus", func(t *testing.T) { // labelmap-remove-prefix-dot-plus
f(` f(`
- action: labelmap - action: labelmap
regex: "foo(.+)" regex: "foo(.+)"
`, `{foo="yyy",foobar="aaa"}`, true, `{bar="aaa",foo="yyy",foobar="aaa"}`) `, `{foo="yyy",foobar="aaa"}`, true, `{bar="aaa",foo="yyy",foobar="aaa"}`)
})
t.Run("labelmap-regex", func(t *testing.T) { // labelmap-regex
f(` f(`
- action: labelmap - action: labelmap
regex: "foo(.+)" regex: "foo(.+)"
replacement: "$1-x" replacement: "$1-x"
`, `{foo="yyy",foobar="aaa"}`, true, `{bar-x="aaa",foo="yyy",foobar="aaa"}`) `, `{foo="yyy",foobar="aaa"}`, true, `{bar-x="aaa",foo="yyy",foobar="aaa"}`)
})
t.Run("labelmap_all-if-miss", func(t *testing.T) { // labelmap_all-if-miss
f(` f(`
- action: labelmap_all - action: labelmap_all
if: foobar if: foobar
regex: "\\." regex: "\\."
replacement: "-" replacement: "-"
`, `{foo.bar.baz="yyy",foobar="aaa"}`, true, `{foo.bar.baz="yyy",foobar="aaa"}`) `, `{foo.bar.baz="yyy",foobar="aaa"}`, true, `{foo.bar.baz="yyy",foobar="aaa"}`)
})
t.Run("labelmap_all-if-hit", func(t *testing.T) { // labelmap_all-if-hit
f(` f(`
- action: labelmap_all - action: labelmap_all
if: '{foo.bar.baz="yyy"}' if: '{foo.bar.baz="yyy"}'
regex: "\\." regex: "\\."
replacement: "-" replacement: "-"
`, `{foo.bar.baz="yyy",foobar="aaa"}`, true, `{foo-bar-baz="yyy",foobar="aaa"}`) `, `{foo.bar.baz="yyy",foobar="aaa"}`, true, `{foo-bar-baz="yyy",foobar="aaa"}`)
})
t.Run("labelmap_all", func(t *testing.T) { // labelmap_all
f(` f(`
- action: labelmap_all - action: labelmap_all
regex: "\\." regex: "\\."
replacement: "-" replacement: "-"
`, `{foo.bar.baz="yyy",foobar="aaa"}`, true, `{foo-bar-baz="yyy",foobar="aaa"}`) `, `{foo.bar.baz="yyy",foobar="aaa"}`, true, `{foo-bar-baz="yyy",foobar="aaa"}`)
})
t.Run("labelmap_all-regexp", func(t *testing.T) { // labelmap_all-regexp
f(` f(`
- action: labelmap_all - action: labelmap_all
regex: "ba(.)" regex: "ba(.)"
replacement: "${1}ss" replacement: "${1}ss"
`, `{foo.bar.baz="yyy",foozar="aaa"}`, true, `{foo.rss.zss="yyy",foozar="aaa"}`) `, `{foo.bar.baz="yyy",foozar="aaa"}`, true, `{foo.rss.zss="yyy",foozar="aaa"}`)
})
t.Run("labeldrop", func(t *testing.T) { // labeldrop
f(` f(`
- action: labeldrop - action: labeldrop
regex: dropme regex: dropme
`, `{aaa="bbb"}`, true, `{aaa="bbb"}`) `, `{aaa="bbb"}`, true, `{aaa="bbb"}`)
// if-miss // if-miss
f(` f(`
- action: labeldrop - action: labeldrop
if: foo if: foo
regex: dropme regex: dropme
`, `{xxx="yyy",dropme="aaa",foo="bar"}`, false, `{dropme="aaa",foo="bar",xxx="yyy"}`) `, `{xxx="yyy",dropme="aaa",foo="bar"}`, false, `{dropme="aaa",foo="bar",xxx="yyy"}`)
// if-hit // if-hit
f(` f(`
- action: labeldrop - action: labeldrop
@ -801,18 +804,20 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
- action: labeldrop - action: labeldrop
regex: dropme regex: dropme
`, `{xxx="yyy",dropme="aaa",foo="bar"}`, false, `{foo="bar",xxx="yyy"}`) `, `{xxx="yyy",dropme="aaa",foo="bar"}`, false, `{foo="bar",xxx="yyy"}`)
// regex in single quotes // regex in single quotes
f(` f(`
- action: labeldrop - action: labeldrop
regex: 'dropme' regex: 'dropme'
`, `{xxx="yyy",dropme="aaa"}`, false, `{xxx="yyy"}`) `, `{xxx="yyy",dropme="aaa"}`, false, `{xxx="yyy"}`)
// regex in double quotes // regex in double quotes
f(` f(`
- action: labeldrop - action: labeldrop
regex: "dropme" regex: "dropme"
`, `{xxx="yyy",dropme="aaa"}`, false, `{xxx="yyy"}`) `, `{xxx="yyy",dropme="aaa"}`, false, `{xxx="yyy"}`)
})
t.Run("labeldrop-prefix", func(t *testing.T) { // labeldrop-prefix
f(` f(`
- action: labeldrop - action: labeldrop
regex: "dropme.*" regex: "dropme.*"
@ -821,8 +826,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
- action: labeldrop - action: labeldrop
regex: "dropme(.+)" regex: "dropme(.+)"
`, `{xxx="yyy",dropme-please="aaa",foo="bar"}`, false, `{foo="bar",xxx="yyy"}`) `, `{xxx="yyy",dropme-please="aaa",foo="bar"}`, false, `{foo="bar",xxx="yyy"}`)
})
t.Run("labeldrop-regexp", func(t *testing.T) { // labeldrop-regexp
f(` f(`
- action: labeldrop - action: labeldrop
regex: ".*dropme.*" regex: ".*dropme.*"
@ -831,18 +836,20 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
- action: labeldrop - action: labeldrop
regex: ".*dropme.*" regex: ".*dropme.*"
`, `{xxx="yyy",dropme-please="aaa",foo="bar"}`, false, `{foo="bar",xxx="yyy"}`) `, `{xxx="yyy",dropme-please="aaa",foo="bar"}`, false, `{foo="bar",xxx="yyy"}`)
})
t.Run("labelkeep", func(t *testing.T) { // labelkeep
f(` f(`
- action: labelkeep - action: labelkeep
regex: "keepme" regex: "keepme"
`, `{keepme="aaa"}`, true, `{keepme="aaa"}`) `, `{keepme="aaa"}`, true, `{keepme="aaa"}`)
// if-miss // if-miss
f(` f(`
- action: labelkeep - action: labelkeep
if: '{aaaa="awefx"}' if: '{aaaa="awefx"}'
regex: keepme regex: keepme
`, `{keepme="aaa",aaaa="awef",keepme-aaa="234"}`, false, `{aaaa="awef",keepme="aaa",keepme-aaa="234"}`) `, `{keepme="aaa",aaaa="awef",keepme-aaa="234"}`, false, `{aaaa="awef",keepme="aaa",keepme-aaa="234"}`)
// if-hit // if-hit
f(` f(`
- action: labelkeep - action: labelkeep
@ -853,8 +860,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
- action: labelkeep - action: labelkeep
regex: keepme regex: keepme
`, `{keepme="aaa",aaaa="awef",keepme-aaa="234"}`, false, `{keepme="aaa"}`) `, `{keepme="aaa",aaaa="awef",keepme-aaa="234"}`, false, `{keepme="aaa"}`)
})
t.Run("labelkeep-regexp", func(t *testing.T) { // labelkeep-regexp
f(` f(`
- action: labelkeep - action: labelkeep
regex: "keepme.*" regex: "keepme.*"
@ -863,8 +870,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
- action: labelkeep - action: labelkeep
regex: "keepme.*" regex: "keepme.*"
`, `{keepme="aaa",aaaa="awef",keepme-aaa="234"}`, false, `{keepme="aaa",keepme-aaa="234"}`) `, `{keepme="aaa",aaaa="awef",keepme-aaa="234"}`, false, `{keepme="aaa",keepme-aaa="234"}`)
})
t.Run("upper-lower-case", func(t *testing.T) { // upper-lower-case
f(` f(`
- action: uppercase - action: uppercase
source_labels: ["foo"] source_labels: ["foo"]
@ -885,8 +892,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
source_labels: ["bar"] source_labels: ["bar"]
target_label: baz target_label: baz
`, `{qux="quux"}`, true, `{qux="quux"}`) `, `{qux="quux"}`, true, `{qux="quux"}`)
})
t.Run("graphite-match", func(t *testing.T) { // graphite-match
f(` f(`
- action: graphite - action: graphite
match: foo.*.baz match: foo.*.baz
@ -894,8 +901,8 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
__name__: aaa __name__: aaa
job: ${1}-zz job: ${1}-zz
`, `foo.bar.baz`, true, `aaa{job="bar-zz"}`) `, `foo.bar.baz`, true, `aaa{job="bar-zz"}`)
})
t.Run("graphite-mismatch", func(t *testing.T) { // graphite-mismatch
f(` f(`
- action: graphite - action: graphite
match: foo.*.baz match: foo.*.baz
@ -903,13 +910,14 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
__name__: aaa __name__: aaa
job: ${1}-zz job: ${1}-zz
`, `foo.bar.bazz`, true, `foo.bar.bazz`) `, `foo.bar.bazz`, true, `foo.bar.bazz`)
})
t.Run("replacement-with-label-refs", func(t *testing.T) { // replacement-with-label-refs
// no regex // no regex
f(` f(`
- target_label: abc - target_label: abc
replacement: "{{__name__}}.{{foo}}" replacement: "{{__name__}}.{{foo}}"
`, `qwe{foo="bar",baz="aaa"}`, true, `qwe{abc="qwe.bar",baz="aaa",foo="bar"}`) `, `qwe{foo="bar",baz="aaa"}`, true, `qwe{abc="qwe.bar",baz="aaa",foo="bar"}`)
// with regex // with regex
f(` f(`
- target_label: abc - target_label: abc
@ -917,17 +925,16 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
source_labels: [baz] source_labels: [baz]
regex: "a(.+)" regex: "a(.+)"
`, `qwe{foo="bar",baz="aaa"}`, true, `qwe{abc="qwe.bar.aa",baz="aaa",foo="bar"}`) `, `qwe{foo="bar",baz="aaa"}`, true, `qwe{abc="qwe.bar.aa",baz="aaa",foo="bar"}`)
})
// Check $ at the end of regex - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3131 // Check $ at the end of regex - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3131
t.Run("replacement-with-$-at-the-end-of-regex", func(t *testing.T) {
f(` f(`
- target_label: xyz - target_label: xyz
regex: "foo\\$$" regex: "foo\\$$"
replacement: bar replacement: bar
source_labels: [xyz] source_labels: [xyz]
`, `metric{xyz="foo$",a="b"}`, true, `metric{a="b",xyz="bar"}`) `, `metric{xyz="foo$",a="b"}`, true, `metric{a="b",xyz="bar"}`)
})
t.Run("issue-3251", func(t *testing.T) { // issue-3251
f(` f(`
- source_labels: [instance, container_label_com_docker_swarm_task_name] - source_labels: [instance, container_label_com_docker_swarm_task_name]
separator: ';' separator: ';'
@ -938,7 +945,6 @@ func TestParsedRelabelConfigsApply(t *testing.T) {
action: replace action: replace
`, `{instance="subdomain.domain.com",container_label_com_docker_swarm_task_name="myservice.h408nlaxmv8oqkn1pjjtd71to.nv987lz99rb27lkjjnfiay0g4"}`, true, `, `{instance="subdomain.domain.com",container_label_com_docker_swarm_task_name="myservice.h408nlaxmv8oqkn1pjjtd71to.nv987lz99rb27lkjjnfiay0g4"}`, true,
`{container_label_com_docker_swarm_task_name="myservice:subdomain",instance="subdomain.domain.com"}`) `{container_label_com_docker_swarm_task_name="myservice:subdomain",instance="subdomain.domain.com"}`)
})
} }
func TestFinalizeLabels(t *testing.T) { func TestFinalizeLabels(t *testing.T) {
@ -1064,7 +1070,7 @@ func TestParsedRelabelConfigsApplyForMultipleSeries(t *testing.T) {
} }
} }
t.Run("drops one of series", func(t *testing.T) { // drops one of series
f(` f(`
- action: drop - action: drop
if: '{__name__!~"smth"}' if: '{__name__!~"smth"}'
@ -1073,5 +1079,4 @@ func TestParsedRelabelConfigsApplyForMultipleSeries(t *testing.T) {
- action: drop - action: drop
if: '{__name__!~"smth"}' if: '{__name__!~"smth"}'
`, []string{`notthis`, `smth`}, []string{`smth`}) `, []string{`notthis`, `smth`}, []string{`smth`})
})
} }

View file

@ -54,7 +54,7 @@ func newClient(ctx context.Context, sw *ScrapeWork) (*client, error) {
setHeaders := func(req *http.Request) error { setHeaders := func(req *http.Request) error {
return sw.AuthConfig.SetHeaders(req, true) return sw.AuthConfig.SetHeaders(req, true)
} }
setProxyHeaders := func(req *http.Request) error { setProxyHeaders := func(_ *http.Request) error {
return nil return nil
} }
proxyURL := sw.ProxyURL proxyURL := sw.ProxyURL
@ -90,7 +90,7 @@ func newClient(ctx context.Context, sw *ScrapeWork) (*client, error) {
Timeout: sw.ScrapeTimeout, Timeout: sw.ScrapeTimeout,
} }
if sw.DenyRedirects { if sw.DenyRedirects {
hc.CheckRedirect = func(req *http.Request, via []*http.Request) error { hc.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
} }
} }

View file

@ -144,20 +144,20 @@ func NewClient(apiServer string, ac *promauth.Config, proxyURL *proxy.URL, proxy
}, },
} }
setHTTPHeaders := func(req *http.Request) error { return nil } setHTTPHeaders := func(_ *http.Request) error { return nil }
if ac != nil { if ac != nil {
setHTTPHeaders = func(req *http.Request) error { setHTTPHeaders = func(req *http.Request) error {
return ac.SetHeaders(req, true) return ac.SetHeaders(req, true)
} }
} }
if httpCfg.FollowRedirects != nil && !*httpCfg.FollowRedirects { if httpCfg.FollowRedirects != nil && !*httpCfg.FollowRedirects {
checkRedirect := func(req *http.Request, via []*http.Request) error { checkRedirect := func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
} }
client.CheckRedirect = checkRedirect client.CheckRedirect = checkRedirect
blockingClient.CheckRedirect = checkRedirect blockingClient.CheckRedirect = checkRedirect
} }
setHTTPProxyHeaders := func(req *http.Request) error { return nil } setHTTPProxyHeaders := func(_ *http.Request) error { return nil }
if proxyAC != nil { if proxyAC != nil {
setHTTPProxyHeaders = func(req *http.Request) error { setHTTPProxyHeaders = func(req *http.Request) error {
return proxyURL.SetHeaders(proxyAC, req) return proxyURL.SetHeaders(proxyAC, req)

View file

@ -141,7 +141,7 @@ func runScraper(configFile string, pushData func(at *auth.Token, wr *prompbmarsh
scs.add("nomad_sd_configs", *nomad.SDCheckInterval, func(cfg *Config, swsPrev []*ScrapeWork) []*ScrapeWork { return cfg.getNomadSDScrapeWork(swsPrev) }) scs.add("nomad_sd_configs", *nomad.SDCheckInterval, func(cfg *Config, swsPrev []*ScrapeWork) []*ScrapeWork { return cfg.getNomadSDScrapeWork(swsPrev) })
scs.add("openstack_sd_configs", *openstack.SDCheckInterval, func(cfg *Config, swsPrev []*ScrapeWork) []*ScrapeWork { return cfg.getOpenStackSDScrapeWork(swsPrev) }) scs.add("openstack_sd_configs", *openstack.SDCheckInterval, func(cfg *Config, swsPrev []*ScrapeWork) []*ScrapeWork { return cfg.getOpenStackSDScrapeWork(swsPrev) })
scs.add("yandexcloud_sd_configs", *yandexcloud.SDCheckInterval, func(cfg *Config, swsPrev []*ScrapeWork) []*ScrapeWork { return cfg.getYandexCloudSDScrapeWork(swsPrev) }) scs.add("yandexcloud_sd_configs", *yandexcloud.SDCheckInterval, func(cfg *Config, swsPrev []*ScrapeWork) []*ScrapeWork { return cfg.getYandexCloudSDScrapeWork(swsPrev) })
scs.add("static_configs", 0, func(cfg *Config, swsPrev []*ScrapeWork) []*ScrapeWork { return cfg.getStaticScrapeWork() }) scs.add("static_configs", 0, func(cfg *Config, _ []*ScrapeWork) []*ScrapeWork { return cfg.getStaticScrapeWork() })
var tickerCh <-chan time.Time var tickerCh <-chan time.Time
if *configCheckInterval > 0 { if *configCheckInterval > 0 {

View file

@ -90,14 +90,14 @@ func TestScrapeWorkScrapeInternalFailure(t *testing.T) {
} }
readDataCalls := 0 readDataCalls := 0
sw.ReadData = func(dst *bytesutil.ByteBuffer) error { sw.ReadData = func(_ *bytesutil.ByteBuffer) error {
readDataCalls++ readDataCalls++
return fmt.Errorf("error when reading data") return fmt.Errorf("error when reading data")
} }
pushDataCalls := 0 pushDataCalls := 0
var pushDataErr error var pushDataErr error
sw.PushData = func(at *auth.Token, wr *prompbmarshal.WriteRequest) { sw.PushData = func(_ *auth.Token, wr *prompbmarshal.WriteRequest) {
if err := expectEqualTimeseries(wr.Timeseries, timeseriesExpected); err != nil { if err := expectEqualTimeseries(wr.Timeseries, timeseriesExpected); err != nil {
pushDataErr = fmt.Errorf("unexpected data pushed: %w\ngot\n%#v\nwant\n%#v", err, wr.Timeseries, timeseriesExpected) pushDataErr = fmt.Errorf("unexpected data pushed: %w\ngot\n%#v\nwant\n%#v", err, wr.Timeseries, timeseriesExpected)
} }
@ -139,7 +139,7 @@ func TestScrapeWorkScrapeInternalSuccess(t *testing.T) {
pushDataCalls := 0 pushDataCalls := 0
var pushDataErr error var pushDataErr error
sw.PushData = func(at *auth.Token, wr *prompbmarshal.WriteRequest) { sw.PushData = func(_ *auth.Token, wr *prompbmarshal.WriteRequest) {
pushDataCalls++ pushDataCalls++
if len(wr.Timeseries) > len(timeseriesExpected) { if len(wr.Timeseries) > len(timeseriesExpected) {
pushDataErr = fmt.Errorf("too many time series obtained; got %d; want %d\ngot\n%+v\nwant\n%+v", pushDataErr = fmt.Errorf("too many time series obtained; got %d; want %d\ngot\n%+v\nwant\n%+v",
@ -721,7 +721,7 @@ func TestSendStaleSeries(t *testing.T) {
defer common.StopUnmarshalWorkers() defer common.StopUnmarshalWorkers()
var staleMarks int var staleMarks int
sw.PushData = func(at *auth.Token, wr *prompbmarshal.WriteRequest) { sw.PushData = func(_ *auth.Token, wr *prompbmarshal.WriteRequest) {
staleMarks += len(wr.Timeseries) staleMarks += len(wr.Timeseries)
} }
sw.sendStaleSeries(lastScrape, currScrape, 0, false) sw.sendStaleSeries(lastScrape, currScrape, 0, false)

View file

@ -84,7 +84,7 @@ vm_tcplistener_write_calls_total{name="https", addr=":443"} 132356
var sw scrapeWork var sw scrapeWork
sw.Config = &ScrapeWork{} sw.Config = &ScrapeWork{}
sw.ReadData = readDataFunc sw.ReadData = readDataFunc
sw.PushData = func(at *auth.Token, wr *prompbmarshal.WriteRequest) {} sw.PushData = func(_ *auth.Token, _ *prompbmarshal.WriteRequest) {}
tsmGlobal.Register(&sw) tsmGlobal.Register(&sw)
timestamp := int64(0) timestamp := int64(0)
for pb.Next() { for pb.Next() {

View file

@ -14,7 +14,7 @@ func TestParseFailure(t *testing.T) {
f := func(req string) { f := func(req string) {
t.Helper() t.Helper()
callback := func(rows []newrelic.Row) error { callback := func(_ []newrelic.Row) error {
panic(fmt.Errorf("unexpected call into callback")) panic(fmt.Errorf("unexpected call into callback"))
} }
r := bytes.NewReader([]byte(req)) r := bytes.NewReader([]byte(req))

View file

@ -24,7 +24,7 @@ func BenchmarkParseStream(b *testing.B) {
data := pbRequest.MarshalProtobuf(nil) data := pbRequest.MarshalProtobuf(nil)
for p.Next() { for p.Next() {
err := ParseStream(bytes.NewBuffer(data), false, nil, func(tss []prompbmarshal.TimeSeries) error { err := ParseStream(bytes.NewBuffer(data), false, nil, func(_ []prompbmarshal.TimeSeries) error {
return nil return nil
}) })
if err != nil { if err != nil {

View file

@ -644,7 +644,7 @@ const (
func getOptimizedReMatchFuncExt(reMatch func(b []byte) bool, sre *syntax.Regexp) (func(b []byte) bool, string, uint64) { func getOptimizedReMatchFuncExt(reMatch func(b []byte) bool, sre *syntax.Regexp) (func(b []byte) bool, string, uint64) {
if isDotStar(sre) { if isDotStar(sre) {
// '.*' // '.*'
return func(b []byte) bool { return func(_ []byte) bool {
return true return true
}, "", fullMatchCost }, "", fullMatchCost
} }

View file

@ -784,7 +784,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
} }
} }
t.Run("plain-value", func(t *testing.T) { t.Run("plain-value", func(_ *testing.T) {
value := "xx" value := "xx"
isNegative := false isNegative := false
isRegexp := false isRegexp := false
@ -796,7 +796,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("foo") mismatch("foo")
mismatch("xx") mismatch("xx")
}) })
t.Run("negative-plain-value", func(t *testing.T) { t.Run("negative-plain-value", func(_ *testing.T) {
value := "xx" value := "xx"
isNegative := true isNegative := true
isRegexp := false isRegexp := false
@ -811,7 +811,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
match("xxx") match("xxx")
match("xxfoo") match("xxfoo")
}) })
t.Run("regexp-convert-to-plain-value", func(t *testing.T) { t.Run("regexp-convert-to-plain-value", func(_ *testing.T) {
value := "http" value := "http"
isNegative := false isNegative := false
isRegexp := true isRegexp := true
@ -824,7 +824,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("http") mismatch("http")
mismatch("foobar") mismatch("foobar")
}) })
t.Run("negative-regexp-convert-to-plain-value", func(t *testing.T) { t.Run("negative-regexp-convert-to-plain-value", func(_ *testing.T) {
value := "http" value := "http"
isNegative := true isNegative := true
isRegexp := true isRegexp := true
@ -839,7 +839,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
match("httpx") match("httpx")
match("foobar") match("foobar")
}) })
t.Run("regexp-prefix-any-suffix", func(t *testing.T) { t.Run("regexp-prefix-any-suffix", func(_ *testing.T) {
value := "http.*" value := "http.*"
isNegative := false isNegative := false
isRegexp := true isRegexp := true
@ -852,7 +852,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
match("http") match("http")
match("foobar") match("foobar")
}) })
t.Run("negative-regexp-prefix-any-suffix", func(t *testing.T) { t.Run("negative-regexp-prefix-any-suffix", func(_ *testing.T) {
value := "http.*" value := "http.*"
isNegative := true isNegative := true
isRegexp := true isRegexp := true
@ -867,7 +867,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("httpsdf") mismatch("httpsdf")
mismatch("foobar") mismatch("foobar")
}) })
t.Run("regexp-prefix-contains-suffix", func(t *testing.T) { t.Run("regexp-prefix-contains-suffix", func(_ *testing.T) {
value := "http.*foo.*" value := "http.*foo.*"
isNegative := false isNegative := false
isRegexp := true isRegexp := true
@ -883,7 +883,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
match("xfoobar") match("xfoobar")
match("xfoo") match("xfoo")
}) })
t.Run("negative-regexp-prefix-contains-suffix", func(t *testing.T) { t.Run("negative-regexp-prefix-contains-suffix", func(_ *testing.T) {
value := "http.*foo.*" value := "http.*foo.*"
isNegative := true isNegative := true
isRegexp := true isRegexp := true
@ -903,7 +903,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("httpxfoobar") mismatch("httpxfoobar")
mismatch("httpxfoo") mismatch("httpxfoo")
}) })
t.Run("negative-regexp-noprefix-contains-suffix", func(t *testing.T) { t.Run("negative-regexp-noprefix-contains-suffix", func(_ *testing.T) {
value := ".*foo.*" value := ".*foo.*"
isNegative := true isNegative := true
isRegexp := true isRegexp := true
@ -919,7 +919,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("xfoobar") mismatch("xfoobar")
mismatch("xfoo") mismatch("xfoo")
}) })
t.Run("regexp-prefix-special-suffix", func(t *testing.T) { t.Run("regexp-prefix-special-suffix", func(_ *testing.T) {
value := "http.*bar" value := "http.*bar"
isNegative := false isNegative := false
isRegexp := true isRegexp := true
@ -934,7 +934,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
match("foobar") match("foobar")
mismatch("foobarx") mismatch("foobarx")
}) })
t.Run("negative-regexp-prefix-special-suffix", func(t *testing.T) { t.Run("negative-regexp-prefix-special-suffix", func(_ *testing.T) {
value := "http.*bar" value := "http.*bar"
isNegative := true isNegative := true
isRegexp := true isRegexp := true
@ -951,7 +951,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
match("httpxybarx") match("httpxybarx")
mismatch("ahttpxybar") mismatch("ahttpxybar")
}) })
t.Run("negative-regexp-noprefix-special-suffix", func(t *testing.T) { t.Run("negative-regexp-noprefix-special-suffix", func(_ *testing.T) {
value := ".*bar" value := ".*bar"
isNegative := true isNegative := true
isRegexp := true isRegexp := true
@ -1002,7 +1002,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("bar") mismatch("bar")
match("xhttpbar") match("xhttpbar")
}) })
t.Run("regexp-iflag-no-suffix", func(t *testing.T) { t.Run("regexp-iflag-no-suffix", func(_ *testing.T) {
value := "(?i)http" value := "(?i)http"
isNegative := false isNegative := false
isRegexp := true isRegexp := true
@ -1020,7 +1020,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("xhttp://") mismatch("xhttp://")
mismatch("hTTp://foobar.com") mismatch("hTTp://foobar.com")
}) })
t.Run("negative-regexp-iflag-no-suffix", func(t *testing.T) { t.Run("negative-regexp-iflag-no-suffix", func(_ *testing.T) {
value := "(?i)http" value := "(?i)http"
isNegative := true isNegative := true
isRegexp := true isRegexp := true
@ -1038,7 +1038,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
match("xhttp://") match("xhttp://")
match("hTTp://foobar.com") match("hTTp://foobar.com")
}) })
t.Run("regexp-iflag-any-suffix", func(t *testing.T) { t.Run("regexp-iflag-any-suffix", func(_ *testing.T) {
value := "(?i)http.*" value := "(?i)http.*"
isNegative := false isNegative := false
isRegexp := true isRegexp := true
@ -1055,7 +1055,7 @@ func TestTagFilterMatchSuffix(t *testing.T) {
mismatch("xhttp") mismatch("xhttp")
mismatch("xhttp://") mismatch("xhttp://")
}) })
t.Run("negative-regexp-iflag-any-suffix", func(t *testing.T) { t.Run("negative-regexp-iflag-any-suffix", func(_ *testing.T) {
value := "(?i)http.*" value := "(?i)http.*"
isNegative := true isNegative := true
isRegexp := true isRegexp := true

View file

@ -411,7 +411,7 @@ func BenchmarkOptimizedReMatchCost(b *testing.B) {
}) })
}) })
b.Run(".*", func(b *testing.B) { b.Run(".*", func(b *testing.B) {
reMatch := func(b []byte) bool { reMatch := func(_ []byte) bool {
return true return true
} }
suffix := []byte("foo1.bar.baz.sss.ddd") suffix := []byte("foo1.bar.baz.sss.ddd")

View file

@ -8,7 +8,7 @@ import (
) )
func BenchmarkDeduplicatorPush(b *testing.B) { func BenchmarkDeduplicatorPush(b *testing.B) {
pushFunc := func(tss []prompbmarshal.TimeSeries) {} pushFunc := func(_ []prompbmarshal.TimeSeries) {}
d := NewDeduplicator(pushFunc, time.Hour, nil) d := NewDeduplicator(pushFunc, time.Hour, nil)
b.ReportAllocs() b.ReportAllocs()

View file

@ -17,7 +17,7 @@ import (
func TestAggregatorsFailure(t *testing.T) { func TestAggregatorsFailure(t *testing.T) {
f := func(config string) { f := func(config string) {
t.Helper() t.Helper()
pushFunc := func(tss []prompbmarshal.TimeSeries) { pushFunc := func(_ []prompbmarshal.TimeSeries) {
panic(fmt.Errorf("pushFunc shouldn't be called")) panic(fmt.Errorf("pushFunc shouldn't be called"))
} }
a, err := newAggregatorsFromData([]byte(config), pushFunc, nil) a, err := newAggregatorsFromData([]byte(config), pushFunc, nil)
@ -157,7 +157,7 @@ func TestAggregatorsEqual(t *testing.T) {
f := func(a, b string, expectedResult bool) { f := func(a, b string, expectedResult bool) {
t.Helper() t.Helper()
pushFunc := func(tss []prompbmarshal.TimeSeries) {} pushFunc := func(_ []prompbmarshal.TimeSeries) {}
aa, err := newAggregatorsFromData([]byte(a), pushFunc, nil) aa, err := newAggregatorsFromData([]byte(a), pushFunc, nil)
if err != nil { if err != nil {
t.Fatalf("cannot initialize aggregators: %s", err) t.Fatalf("cannot initialize aggregators: %s", err)

View file

@ -43,7 +43,7 @@ func BenchmarkAggregatorsFlushSerial(b *testing.B) {
"max", "avg", "increase", "count_series", "max", "avg", "increase", "count_series",
"last", "stddev", "stdvar", "total_prometheus", "increase_prometheus", "last", "stddev", "stdvar", "total_prometheus", "increase_prometheus",
} }
pushFunc := func(tss []prompbmarshal.TimeSeries) {} pushFunc := func(_ []prompbmarshal.TimeSeries) {}
a := newBenchAggregators(outputs, pushFunc) a := newBenchAggregators(outputs, pushFunc)
defer a.MustStop() defer a.MustStop()
_ = a.Push(benchSeries, nil) _ = a.Push(benchSeries, nil)
@ -59,7 +59,7 @@ func BenchmarkAggregatorsFlushSerial(b *testing.B) {
} }
func benchmarkAggregatorsPush(b *testing.B, output string) { func benchmarkAggregatorsPush(b *testing.B, output string) {
pushFunc := func(tss []prompbmarshal.TimeSeries) {} pushFunc := func(_ []prompbmarshal.TimeSeries) {}
a := newBenchAggregators([]string{output}, pushFunc) a := newBenchAggregators([]string{output}, pushFunc)
defer a.MustStop() defer a.MustStop()

View file

@ -403,7 +403,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) {
// Verify fast stop // Verify fast stop
calls := 0 calls := 0
s.ForEach(func(part []uint64) bool { s.ForEach(func(_ []uint64) bool {
calls++ calls++
return false return false
}) })
@ -413,7 +413,7 @@ func testSetBasicOps(t *testing.T, itemsCount int) {
// Verify ForEach on nil set. // Verify ForEach on nil set.
var s1 *Set var s1 *Set
s1.ForEach(func(part []uint64) bool { s1.ForEach(func(_ []uint64) bool {
t.Fatalf("callback shouldn't be called on empty set") t.Fatalf("callback shouldn't be called on empty set")
return true return true
}) })