From db39f045e1e9008bdeda2c23a06234d2efa54f5e Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Wed, 2 Jul 2025 22:42:02 +0300 Subject: [PATCH] ci: golangci-lint 1.6.x -> 2.2.1 --- .golangci.yml | 49 ++++++++------ Makefile | 4 +- app/vmagent/remotewrite/client.go | 11 +++- app/vmagent/remotewrite/client_test.go | 2 +- app/vmalert-tool/unittest/unittest.go | 3 +- app/vmalert/notifier/config_watcher.go | 2 +- app/vmalert/web.go | 2 +- app/vmctl/stepper/split.go | 2 +- app/vmselect/prometheus/prometheus.go | 5 +- apptest/tests/dedup_test.go | 5 +- apptest/tests/metric_names_stats_test.go | 65 +++++++++---------- apptest/tests/replication_test.go | 7 +- apptest/tests/vmagent_remotewrite_test.go | 23 ++++--- lib/decimal/decimal.go | 21 +++--- .../discovery/kubernetes/api_watcher.go | 2 +- lib/promscrape/discovery/ovhcloud/common.go | 7 +- lib/promscrape/scrapework_test.go | 2 +- 17 files changed, 113 insertions(+), 99 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a5cb830575..035b90a2bd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,22 +1,29 @@ -run: - timeout: 2m - +version: "2" linters: - enable: - - revive - -issues: - exclude-rules: - - linters: - - staticcheck - text: "SA(4003|1019|5011):" - include: - - EXC0012 - - EXC0014 - -linters-settings: - errcheck: - exclude-functions: - - "fmt.Fprintf" - - "fmt.Fprint" - - "(net/http.ResponseWriter).Write" + settings: + errcheck: + exclude-functions: + - fmt.Fprintf + - fmt.Fprint + - (net/http.ResponseWriter).Write + exclusions: + generated: lax + presets: + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - staticcheck + text: 'SA(4003|1019|5011):' + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 40c58ec0d3..40fef0f053 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,8 @@ EXTRA_DOCKER_TAG_SUFFIX ?= EXTRA_DOCKER_TAG_SUFFIX GO_BUILDINFO = -X '$(PKG_PREFIX)/lib/buildinfo.Version=$(APP_NAME)-$(DATEINFO_TAG)-$(BUILDINFO_TAG)' TAR_OWNERSHIP ?= --owner=1000 --group=1000 +GOLANGCI_LINT_VERSION := 2.2.1 + .PHONY: $(MAKECMDGOALS) include app/*/Makefile @@ -612,7 +614,7 @@ golangci-lint: install-golangci-lint GOEXPERIMENT=synctest golangci-lint run install-golangci-lint: - which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.64.7 + which golangci-lint && (golangci-lint --version | grep -q $(GOLANGCI_LINT_VERSION)) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v$(GOLANGCI_LINT_VERSION) remove-golangci-lint: rm -rf `which golangci-lint` diff --git a/app/vmagent/remotewrite/client.go b/app/vmagent/remotewrite/client.go index b205f805ec..907f622b99 100644 --- a/app/vmagent/remotewrite/client.go +++ b/app/vmagent/remotewrite/client.go @@ -448,7 +448,8 @@ again: } metrics.GetOrCreateCounter(fmt.Sprintf(`vmagent_remotewrite_requests_total{url=%q, status_code="%d"}`, c.sanitizedURL, statusCode)).Inc() - if statusCode == 409 { + switch statusCode { + case 409: logBlockRejected(block, c.sanitizedURL, resp) // Just drop block on 409 status code like Prometheus does. @@ -461,7 +462,13 @@ again: // - Remote Write v2 specification explicitly specifies a `415 Unsupported Media Type` for unsupported encodings. // - Real-world implementations of v1 use both 400 and 415 status codes. // See more in research: https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8462#issuecomment-2786918054 - } else if statusCode == 415 || statusCode == 400 { + case 415, 400: + if c.canDowngradeVMProto.Swap(false) { + logger.Infof("received unsupported media type or bad request from remote storage at %q. Downgrading protocol from VictoriaMetrics to Prometheus remote write for all future requests. "+ + "See https://docs.victoriametrics.com/victoriametrics/vmagent/#victoriametrics-remote-write-protocol", c.sanitizedURL) + c.useVMProto.Store(false) + } + if encoding.IsZstd(block) { logger.Infof("received unsupported media type or bad request from remote storage at %q. Re-packing the block to Prometheus remote write and retrying."+ "See https://docs.victoriametrics.com/victoriametrics/vmagent/#victoriametrics-remote-write-protocol", c.sanitizedURL) diff --git a/app/vmagent/remotewrite/client_test.go b/app/vmagent/remotewrite/client_test.go index 26b20b31b4..7e2316c06b 100644 --- a/app/vmagent/remotewrite/client_test.go +++ b/app/vmagent/remotewrite/client_test.go @@ -25,7 +25,7 @@ func TestCalculateRetryDuration(t *testing.T) { expectMaxDuration := helper(expectMinDuration) expectMinDuration = expectMinDuration - (1000 * time.Millisecond) // Avoid edge case when calculating time.Until(now) - if !(retryDuration >= expectMinDuration && retryDuration <= expectMaxDuration) { + if retryDuration < expectMinDuration || retryDuration > expectMaxDuration { t.Fatalf( "incorrect retry duration, want (ms): [%d, %d], got (ms): %d", expectMinDuration.Milliseconds(), expectMaxDuration.Milliseconds(), diff --git a/app/vmalert-tool/unittest/unittest.go b/app/vmalert-tool/unittest/unittest.go index f88fd10c4c..767c1713d4 100644 --- a/app/vmalert-tool/unittest/unittest.go +++ b/app/vmalert-tool/unittest/unittest.go @@ -19,7 +19,6 @@ import ( "gopkg.in/yaml.v2" - "github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/config" vmalertconfig "github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/config" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource" "github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/notifier" @@ -112,7 +111,7 @@ func UnitTest(files []string, disableGroupLabel bool, externalLabels []string, e defer vmselect.Stop() disableAlertgroupLabel = disableGroupLabel - testfiles, err := config.ReadFromFS(files) + testfiles, err := vmalertconfig.ReadFromFS(files) if err != nil { logger.Fatalf("failed to load test files %q: %v", files, err) } diff --git a/app/vmalert/notifier/config_watcher.go b/app/vmalert/notifier/config_watcher.go index c59ce3d57f..4f2d9241f9 100644 --- a/app/vmalert/notifier/config_watcher.go +++ b/app/vmalert/notifier/config_watcher.go @@ -248,7 +248,7 @@ func (cw *configWatcher) updateTargets(key TargetType, targetMetadata map[string for _, ot := range oldTargets { if _, ok := targetMetadata[ot.Addr()]; !ok { // if target not exists in currentTargets, close it - ot.Notifier.Close() + ot.Close() } else { updatedTargets = append(updatedTargets, ot) delete(targetMetadata, ot.Addr()) diff --git a/app/vmalert/web.go b/app/vmalert/web.go index f89b6b076d..fe6b7fb206 100644 --- a/app/vmalert/web.go +++ b/app/vmalert/web.go @@ -459,7 +459,7 @@ func (rh *requestHandler) listNotifiers() ([]byte, error) { } for _, target := range protoTargets { notifier.Targets = append(notifier.Targets, &apiTarget{ - Address: target.Notifier.Addr(), + Address: target.Addr(), Labels: target.Labels.ToMap(), }) } diff --git a/app/vmctl/stepper/split.go b/app/vmctl/stepper/split.go index 6e54014cdc..5bf19bb03c 100644 --- a/app/vmctl/stepper/split.go +++ b/app/vmctl/stepper/split.go @@ -33,7 +33,7 @@ func SplitDateRange(start, end time.Time, step string, timeReverse bool) ([][]ti case StepMonth: nextStep = func(t time.Time) (time.Time, time.Time) { endOfMonth := time.Date(t.Year(), t.Month()+1, 1, 0, 0, 0, 0, t.Location()).Add(-1 * time.Nanosecond) - if t == endOfMonth { + if t.Equal(endOfMonth) { endOfMonth = time.Date(t.Year(), t.Month()+2, 1, 0, 0, 0, 0, t.Location()).Add(-1 * time.Nanosecond) t = time.Date(t.Year(), t.Month()+1, 1, 0, 0, 0, 0, t.Location()) } diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 89744a63df..c919e523bc 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -331,14 +331,15 @@ func exportHandler(qt *querytracer.Tracer, w http.ResponseWriter, cp *commonPara return sw.maybeFlushBuffer(bb) } contentType := "application/stream+json; charset=utf-8" - if format == "prometheus" { + switch format { + case "prometheus": contentType = "text/plain; charset=utf-8" writeLineFunc = func(xb *exportBlock, workerID uint) error { bb := sw.getBuffer(workerID) WriteExportPrometheusLine(bb, xb) return sw.maybeFlushBuffer(bb) } - } else if format == "promapi" { + case "promapi": WriteExportPromAPIHeader(bw) var firstLineOnce atomic.Bool var firstLineSent atomic.Bool diff --git a/apptest/tests/dedup_test.go b/apptest/tests/dedup_test.go index 94801e22b3..ab688f2b00 100644 --- a/apptest/tests/dedup_test.go +++ b/apptest/tests/dedup_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/VictoriaMetrics/VictoriaMetrics/apptest" at "github.com/VictoriaMetrics/VictoriaMetrics/apptest" "github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal" pb "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal" @@ -134,7 +133,7 @@ func testDeduplication(tc *at.TestCase, sut at.PrometheusWriteQuerier, deduplica }, } - sut.PrometheusAPIV1Write(t, data, apptest.QueryOpts{}) + sut.PrometheusAPIV1Write(t, data, at.QueryOpts{}) sut.ForceFlush(t) sut.ForceMerge(t) @@ -207,7 +206,7 @@ func testDeduplication(tc *at.TestCase, sut at.PrometheusWriteQuerier, deduplica tc.Assert(&at.AssertOptions{ Msg: "unexpected response", Got: func() any { - got := sut.PrometheusAPIV1Export(t, `{__name__=~"metric.*"}`, apptest.QueryOpts{ + got := sut.PrometheusAPIV1Export(t, `{__name__=~"metric.*"}`, at.QueryOpts{ ReduceMemUsage: "1", Start: fmt.Sprintf("%d", start.UnixMilli()), End: fmt.Sprintf("%d", end.UnixMilli()), diff --git a/apptest/tests/metric_names_stats_test.go b/apptest/tests/metric_names_stats_test.go index e70391e153..e7f0a8c0a9 100644 --- a/apptest/tests/metric_names_stats_test.go +++ b/apptest/tests/metric_names_stats_test.go @@ -9,7 +9,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/VictoriaMetrics/VictoriaMetrics/apptest" at "github.com/VictoriaMetrics/VictoriaMetrics/apptest" ) @@ -35,13 +34,13 @@ func TestSingleMetricNamesStats(t *testing.T) { for idx := range dataSet { dataSet[idx] += ingestTimestamp } - tsdbMetricNameEntryCmpOpts := cmpopts.IgnoreFields(apptest.TSDBStatusResponseMetricNameEntry{}, "LastRequestTimestamp") + tsdbMetricNameEntryCmpOpts := cmpopts.IgnoreFields(at.TSDBStatusResponseMetricNameEntry{}, "LastRequestTimestamp") sut.PrometheusAPIV1ImportPrometheus(t, dataSet, at.QueryOpts{}) sut.ForceFlush(t) // verify ingest request correctly registered - expected := apptest.MetricNamesStatsResponse{ + expected := at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{ {MetricName: largeMetricName}, {MetricName: "metric_name_1"}, @@ -56,7 +55,7 @@ func TestSingleMetricNamesStats(t *testing.T) { // verify query request correctly registered sut.PrometheusAPIV1Query(t, `{__name__!=""}`, at.QueryOpts{Time: ingestDateTime}) - expected = apptest.MetricNamesStatsResponse{ + expected = at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{ {MetricName: largeMetricName, QueryRequestsCount: 1}, {MetricName: "metric_name_1", QueryRequestsCount: 3}, @@ -69,36 +68,36 @@ func TestSingleMetricNamesStats(t *testing.T) { t.Errorf("unexpected response (-want, +got):\n%s", diff) } - expectedStatsResponse := apptest.TSDBStatusResponse{ + expectedStatsResponse := at.TSDBStatusResponse{ Data: at.TSDBStatusResponseData{ TotalSeries: 6, TotalLabelValuePairs: 12, - SeriesCountByMetricName: []apptest.TSDBStatusResponseMetricNameEntry{ + SeriesCountByMetricName: []at.TSDBStatusResponseMetricNameEntry{ {Name: "metric_name_1", RequestsCount: 3}, {Name: largeMetricName, RequestsCount: 1}, {Name: "metric_name_2", RequestsCount: 1}, {Name: "metric_name_3", RequestsCount: 1}, }, - SeriesCountByLabelName: []apptest.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, - SeriesCountByFocusLabelValue: []apptest.TSDBStatusResponseEntry{}, - SeriesCountByLabelValuePair: []apptest.TSDBStatusResponseEntry{ + SeriesCountByLabelName: []at.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, + SeriesCountByFocusLabelValue: []at.TSDBStatusResponseEntry{}, + SeriesCountByLabelValuePair: []at.TSDBStatusResponseEntry{ {Name: "__name__=" + largeMetricName}, {Name: "__name__=metric_name_1"}, {Name: "label=baz"}, {Name: "__name__=metric_name_2"}, {Name: "__name__=metric_name_3"}, {Name: "label=bar"}, {Name: "label=foo"}, }, - LabelValueCountByLabelName: []apptest.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, + LabelValueCountByLabelName: []at.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, }, } expectedStatsResponse.Sort() - gotStatus := sut.APIV1StatusTSDB(t, "", date, "", apptest.QueryOpts{}) + gotStatus := sut.APIV1StatusTSDB(t, "", date, "", at.QueryOpts{}) if diff := cmp.Diff(expectedStatsResponse, gotStatus, tsdbMetricNameEntryCmpOpts); diff != "" { t.Errorf("unexpected APIV1StatusTSDB response (-want, +got):\n%s", diff) } // perform query request for single metric and check counter increase sut.PrometheusAPIV1Query(t, `metric_name_2`, at.QueryOpts{Time: ingestDateTime}) - expected = apptest.MetricNamesStatsResponse{ + expected = at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{ {MetricName: largeMetricName, QueryRequestsCount: 1}, {MetricName: "metric_name_1", QueryRequestsCount: 3}, @@ -112,7 +111,7 @@ func TestSingleMetricNamesStats(t *testing.T) { } // verify le filter - expected = apptest.MetricNamesStatsResponse{ + expected = at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{ {MetricName: largeMetricName, QueryRequestsCount: 1}, {MetricName: "metric_name_2", QueryRequestsCount: 2}, @@ -126,7 +125,7 @@ func TestSingleMetricNamesStats(t *testing.T) { // reset state and check empty request response sut.APIV1AdminStatusMetricNamesStatsReset(t, at.QueryOpts{}) - expected = apptest.MetricNamesStatsResponse{ + expected = at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{}, } got = sut.APIV1StatusMetricNamesStats(t, "", "", "", at.QueryOpts{}) @@ -140,7 +139,7 @@ func TestClusterMetricNamesStats(t *testing.T) { os.RemoveAll(t.Name()) - tc := apptest.NewTestCase(t) + tc := at.NewTestCase(t) defer tc.Stop() vmstorage1 := tc.MustStartVmstorage("vmstorage-1", []string{ "-storageDataPath=" + tc.Dir() + "/vmstorage-1", @@ -160,7 +159,7 @@ func TestClusterMetricNamesStats(t *testing.T) { fmt.Sprintf("-storageNode=%s,%s", vmstorage1.VmselectAddr(), vmstorage2.VmselectAddr()), }) // verify empty stats - resp := vmselect.MetricNamesStats(t, "", "", "", apptest.QueryOpts{Tenant: "0:0"}) + resp := vmselect.MetricNamesStats(t, "", "", "", at.QueryOpts{Tenant: "0:0"}) if len(resp.Records) != 0 { t.Fatalf("unexpected resp Records: %d, want: %d", len(resp.Records), 0) } @@ -182,17 +181,17 @@ func TestClusterMetricNamesStats(t *testing.T) { dataSet[idx] += ingestTimestamp } - tsdbMetricNameEntryCmpOpts := cmpopts.IgnoreFields(apptest.TSDBStatusResponseMetricNameEntry{}, "LastRequestTimestamp") + tsdbMetricNameEntryCmpOpts := cmpopts.IgnoreFields(at.TSDBStatusResponseMetricNameEntry{}, "LastRequestTimestamp") // ingest per tenant data and verify it with search tenantIDs := []string{"1:1", "1:15", "15:15"} for _, tenantID := range tenantIDs { - vminsert.PrometheusAPIV1ImportPrometheus(t, dataSet, apptest.QueryOpts{Tenant: tenantID}) + vminsert.PrometheusAPIV1ImportPrometheus(t, dataSet, at.QueryOpts{Tenant: tenantID}) vmstorage1.ForceFlush(t) vmstorage2.ForceFlush(t) // verify ingest request correctly registered - expected := apptest.MetricNamesStatsResponse{ + expected := at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{ {MetricName: largeMetricName}, {MetricName: "metric_name_1"}, @@ -200,17 +199,17 @@ func TestClusterMetricNamesStats(t *testing.T) { {MetricName: "metric_name_3"}, }, } - gotStats := vmselect.MetricNamesStats(t, "", "", "", apptest.QueryOpts{Tenant: tenantID}) + gotStats := vmselect.MetricNamesStats(t, "", "", "", at.QueryOpts{Tenant: tenantID}) if diff := cmp.Diff(expected, gotStats); diff != "" { t.Errorf("unexpected response (-want, +got):\n%s", diff) } // verify query request registered correctly - vmselect.PrometheusAPIV1Query(t, `{__name__!=""}`, apptest.QueryOpts{ + vmselect.PrometheusAPIV1Query(t, `{__name__!=""}`, at.QueryOpts{ Tenant: tenantID, Time: ingestDateTime, }) - expected = apptest.MetricNamesStatsResponse{ + expected = at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{ {MetricName: largeMetricName, QueryRequestsCount: 1}, {MetricName: "metric_name_2", QueryRequestsCount: 1}, @@ -218,41 +217,41 @@ func TestClusterMetricNamesStats(t *testing.T) { {MetricName: "metric_name_1", QueryRequestsCount: 3}, }, } - gotStats = vmselect.MetricNamesStats(t, "", "", "", apptest.QueryOpts{Tenant: tenantID}) + gotStats = vmselect.MetricNamesStats(t, "", "", "", at.QueryOpts{Tenant: tenantID}) if diff := cmp.Diff(expected, gotStats); diff != "" { t.Errorf("unexpected response tenant: %s (-want, +got):\n%s", tenantID, diff) } - expectedStatsResponse := apptest.TSDBStatusResponse{ + expectedStatsResponse := at.TSDBStatusResponse{ Data: at.TSDBStatusResponseData{ TotalSeries: 6, TotalLabelValuePairs: 12, - SeriesCountByMetricName: []apptest.TSDBStatusResponseMetricNameEntry{ + SeriesCountByMetricName: []at.TSDBStatusResponseMetricNameEntry{ {Name: "metric_name_1", RequestsCount: 3}, {Name: largeMetricName, RequestsCount: 1}, {Name: "metric_name_2", RequestsCount: 1}, {Name: "metric_name_3", RequestsCount: 1}, }, - SeriesCountByLabelName: []apptest.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, - SeriesCountByFocusLabelValue: []apptest.TSDBStatusResponseEntry{}, - SeriesCountByLabelValuePair: []apptest.TSDBStatusResponseEntry{ + SeriesCountByLabelName: []at.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, + SeriesCountByFocusLabelValue: []at.TSDBStatusResponseEntry{}, + SeriesCountByLabelValuePair: []at.TSDBStatusResponseEntry{ {Name: "__name__=" + largeMetricName}, {Name: "__name__=metric_name_1"}, {Name: "label=baz"}, {Name: "__name__=metric_name_2"}, {Name: "__name__=metric_name_3"}, {Name: "label=bar"}, {Name: "label=foo"}, }, - LabelValueCountByLabelName: []apptest.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, + LabelValueCountByLabelName: []at.TSDBStatusResponseEntry{{Name: "__name__"}, {Name: "label"}}, }, } expectedStatsResponse.Sort() - gotStatus := vmselect.APIV1StatusTSDB(t, "", date, "", apptest.QueryOpts{Tenant: tenantID}) + gotStatus := vmselect.APIV1StatusTSDB(t, "", date, "", at.QueryOpts{Tenant: tenantID}) if diff := cmp.Diff(expectedStatsResponse, gotStatus, tsdbMetricNameEntryCmpOpts); diff != "" { t.Errorf("unexpected APIV1StatusTSDB response tenant: %s (-want, +got):\n%s", tenantID, diff) } } // verify multitenant stats - expected := apptest.MetricNamesStatsResponse{ + expected := at.MetricNamesStatsResponse{ Records: []at.MetricNamesStatsRecord{ {MetricName: largeMetricName, QueryRequestsCount: 3}, {MetricName: "metric_name_2", QueryRequestsCount: 3}, @@ -260,14 +259,14 @@ func TestClusterMetricNamesStats(t *testing.T) { {MetricName: "metric_name_1", QueryRequestsCount: 9}, }, } - gotStats := vmselect.MetricNamesStats(t, "", "", "", apptest.QueryOpts{Tenant: "multitenant"}) + gotStats := vmselect.MetricNamesStats(t, "", "", "", at.QueryOpts{Tenant: "multitenant"}) if diff := cmp.Diff(expected, gotStats); diff != "" { t.Errorf("unexpected response (-want, +got):\n%s", diff) } // reset cache and check empty state vmselect.MetricNamesStatsReset(t, at.QueryOpts{}) - resp = vmselect.MetricNamesStats(t, "", "", "", apptest.QueryOpts{Tenant: "multitenant"}) + resp = vmselect.MetricNamesStats(t, "", "", "", at.QueryOpts{Tenant: "multitenant"}) if len(resp.Records) != 0 { t.Fatalf("want 0 records, got: %d", len(resp.Records)) } diff --git a/apptest/tests/replication_test.go b/apptest/tests/replication_test.go index 19253042c7..969a87e4a5 100644 --- a/apptest/tests/replication_test.go +++ b/apptest/tests/replication_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - "github.com/VictoriaMetrics/VictoriaMetrics/apptest" at "github.com/VictoriaMetrics/VictoriaMetrics/apptest" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -377,7 +376,7 @@ func TestClusterReplication_PartialResponse(t *testing.T) { IsPartial: wantPartial, }, CmpOpts: []cmp.Option{ - cmpopts.IgnoreFields(apptest.PrometheusAPIV1SeriesResponse{}, "Data"), + cmpopts.IgnoreFields(at.PrometheusAPIV1SeriesResponse{}, "Data"), }, }) } @@ -1030,7 +1029,7 @@ func testGroupPartialResponse(tc *at.TestCase, opts *testGroupReplicationOpts) { IsPartial: wantPartial, }, CmpOpts: []cmp.Option{ - cmpopts.IgnoreFields(apptest.PrometheusAPIV1SeriesResponse{}, "Data"), + cmpopts.IgnoreFields(at.PrometheusAPIV1SeriesResponse{}, "Data"), }, }) } @@ -1151,7 +1150,7 @@ func TestClusterReplication_PartialResponseMultitenant(t *testing.T) { IsPartial: wantPartial, }, CmpOpts: []cmp.Option{ - cmpopts.IgnoreFields(apptest.PrometheusAPIV1QueryResponse{}, "Data"), + cmpopts.IgnoreFields(at.PrometheusAPIV1QueryResponse{}, "Data"), }, }) } diff --git a/apptest/tests/vmagent_remotewrite_test.go b/apptest/tests/vmagent_remotewrite_test.go index 757f4bb307..93f071d294 100644 --- a/apptest/tests/vmagent_remotewrite_test.go +++ b/apptest/tests/vmagent_remotewrite_test.go @@ -8,13 +8,12 @@ import ( "sync" "testing" - "github.com/VictoriaMetrics/VictoriaMetrics/apptest" at "github.com/VictoriaMetrics/VictoriaMetrics/apptest" ) // TestSingleVMAgentReloadConfigs verifies that vmagent reload new configurations on SIGHUP signal func TestSingleVMAgentReloadConfigs(t *testing.T) { - tc := apptest.NewTestCase(t) + tc := at.NewTestCase(t) defer tc.Stop() vmsingle := tc.MustStartDefaultVmsingle() @@ -38,7 +37,7 @@ func TestSingleVMAgentReloadConfigs(t *testing.T) { vmagent.APIV1ImportPrometheus(t, []string{ "foo_bar 1 1652169600000", // 2022-05-10T08:00:00Z - }, apptest.QueryOpts{}) + }, at.QueryOpts{}) vmsingle.ForceFlush(t) @@ -69,7 +68,7 @@ func TestSingleVMAgentReloadConfigs(t *testing.T) { vmagent.APIV1ImportPrometheus(t, []string{ "bar_foo 1 1652169600001", // 2022-05-10T08:00:00Z - }, apptest.QueryOpts{}) + }, at.QueryOpts{}) vmsingle.ForceFlush(t) @@ -101,7 +100,7 @@ func TestSingleVMAgentSnappyRemoteWrite(t *testing.T) { } func testSingleVMAgentRemoteWrite(t *testing.T, forcePromProto bool) { - tc := apptest.NewTestCase(t) + tc := at.NewTestCase(t) defer tc.Stop() vmsingle := tc.MustStartDefaultVmsingle() @@ -115,7 +114,7 @@ func testSingleVMAgentRemoteWrite(t *testing.T, forcePromProto bool) { vmagent.APIV1ImportPrometheus(t, []string{ "foo_bar 1 1652169600000", // 2022-05-10T08:00:00Z - }, apptest.QueryOpts{}) + }, at.QueryOpts{}) vmsingle.ForceFlush(t) @@ -138,7 +137,7 @@ func testSingleVMAgentRemoteWrite(t *testing.T, forcePromProto bool) { // - Starts with Prometheus remote write protocol using `snappy`. // - Does not retry `snappy`-encoded requests if they fail; instead, they are dropped. func TestSingleVMAgentUnsupportedMediaTypeDropIfSnappy(t *testing.T) { - tc := apptest.NewTestCase(t) + tc := at.NewTestCase(t) defer tc.Stop() var remoteWriteContentEncodingsMux sync.Mutex @@ -164,11 +163,11 @@ func TestSingleVMAgentUnsupportedMediaTypeDropIfSnappy(t *testing.T) { vmagent.APIV1ImportPrometheusNoWaitFlush(t, []string{ "foo_bar 1 1652169600000", // 2022-05-10T08:00:00Z - }, apptest.QueryOpts{}) + }, at.QueryOpts{}) vmagent.APIV1ImportPrometheusNoWaitFlush(t, []string{ "foo_bar 1 1652169600000", // 2022-05-10T08:00:00Z - }, apptest.QueryOpts{}) + }, at.QueryOpts{}) tc.Assert(&at.AssertOptions{ Msg: `unexpected content encoding headers sent to remote write server; expected zstd`, @@ -197,7 +196,7 @@ func TestSingleVMAgentUnsupportedMediaTypeDropIfSnappy(t *testing.T) { // - Re-packs and retries failed requests. // - Sends all subsequent requests using `snappy`. func TestSingleVMAgentDowngradeRemoteWriteProtocol(t *testing.T) { - tc := apptest.NewTestCase(t) + tc := at.NewTestCase(t) defer tc.Stop() var remoteWriteContentEncodings []string @@ -228,12 +227,12 @@ func TestSingleVMAgentDowngradeRemoteWriteProtocol(t *testing.T) { // Send request encoded with `zstd`; it fails, gets repacked as `snappy`, and retries successfully. vmagent.APIV1ImportPrometheus(t, []string{ "foo_bar 1 1652169600000", // 2022-05-10T08:00:00Z - }, apptest.QueryOpts{}) + }, at.QueryOpts{}) // Send request encoded with `snappy` immediately; it succeeds without retries. vmagent.APIV1ImportPrometheus(t, []string{ "foo_bar 1 1652169600000", // 2022-05-10T08:00:00Z - }, apptest.QueryOpts{}) + }, at.QueryOpts{}) tc.Assert(&at.AssertOptions{ Msg: `unexpected content encoding headers sent to remote write server`, diff --git a/lib/decimal/decimal.go b/lib/decimal/decimal.go index ab05068941..b258a9a4b0 100644 --- a/lib/decimal/decimal.go +++ b/lib/decimal/decimal.go @@ -115,11 +115,12 @@ func AppendDecimalToFloat(dst []float64, va []int64, e int16) []float64 { if !isSpecialValue(v) { continue } - if v == vInfPos { + switch v { + case vInfPos: a[i] = infPos - } else if v == vInfNeg { + case vInfNeg: a[i] = infNeg - } else { + default: a[i] = StaleNaN } } @@ -135,11 +136,12 @@ func AppendDecimalToFloat(dst []float64, va []int64, e int16) []float64 { if !isSpecialValue(v) { continue } - if v == vInfPos { + switch v { + case vInfPos: a[i] = infPos - } else if v == vInfNeg { + case vInfNeg: a[i] = infNeg - } else { + default: a[i] = StaleNaN } } @@ -152,11 +154,12 @@ func AppendDecimalToFloat(dst []float64, va []int64, e int16) []float64 { if !isSpecialValue(v) { continue } - if v == vInfPos { + switch v { + case vInfPos: a[i] = infPos - } else if v == vInfNeg { + case vInfNeg: a[i] = infNeg - } else { + default: a[i] = StaleNaN } } diff --git a/lib/promscrape/discovery/kubernetes/api_watcher.go b/lib/promscrape/discovery/kubernetes/api_watcher.go index acab878884..530b446dd9 100644 --- a/lib/promscrape/discovery/kubernetes/api_watcher.go +++ b/lib/promscrape/discovery/kubernetes/api_watcher.go @@ -943,7 +943,7 @@ func (uw *urlWatcher) removeObjectLocked(key string) { func (uw *urlWatcher) maybeUpdateDependedScrapeWorksLocked() { role := uw.role attachNodeMetadata := uw.gw.attachNodeMetadata - if !(role == "pod" || role == "service" || (attachNodeMetadata && role == "node")) { + if role != "pod" && role != "service" && (!attachNodeMetadata || role != "node") { // Nothing to update return } diff --git a/lib/promscrape/discovery/ovhcloud/common.go b/lib/promscrape/discovery/ovhcloud/common.go index e46500cc32..8ed4d58c1b 100644 --- a/lib/promscrape/discovery/ovhcloud/common.go +++ b/lib/promscrape/discovery/ovhcloud/common.go @@ -19,14 +19,13 @@ func getAuthHeaders(cfg *apiConfig, headers http.Header, endpoint, path string) headers.Add("X-Ovh-Consumer", cfg.consumerKey) h := sha1.New() - h.Write([]byte(fmt.Sprintf("%s+%s+%s+%s+%s+%d", + fmt.Fprintf(h, "%s+%s+%s+%s+%s+%d", cfg.applicationSecret, cfg.consumerKey, "GET", endpoint+path, - "", // no body contained in any service discovery request, so it's set to empty by default - timestamp, - ))) + "", + timestamp) headers.Set("X-Ovh-Signature", fmt.Sprintf("$1$%x", h.Sum(nil))) return headers, nil } diff --git a/lib/promscrape/scrapework_test.go b/lib/promscrape/scrapework_test.go index 1c6fa23a37..9ba63b3b13 100644 --- a/lib/promscrape/scrapework_test.go +++ b/lib/promscrape/scrapework_test.go @@ -599,7 +599,7 @@ func TestScrapeWorkScrapeInternalStreamConcurrency(t *testing.T) { // see https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8515#issuecomment-2741063155 lowerExpectedDelta := pushedTimeseries.Load() - timeseriesExpectedDelta upperExpectedDelta := pushedTimeseries.Load() + timeseriesExpectedDelta + 1 - if !(timeseriesExpected >= lowerExpectedDelta && timeseriesExpected < upperExpectedDelta) { + if timeseriesExpected < lowerExpectedDelta || timeseriesExpected >= upperExpectedDelta { t.Fatalf("unexpected number of pushed timeseries; got %d; want within range [%d, %d)", pushedTimeseries.Load(), lowerExpectedDelta,