From 9f2753791dacea451db440b6895e34bb3e7ff1df Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Mon, 17 Jun 2024 08:34:30 +0200 Subject: [PATCH] mimir-build-image: Upgrade golangci-lint to v1.59.1 Signed-off-by: Arve Knudsen --- mimir-build-image/Dockerfile | 2 +- pkg/alertmanager/alertmanager.go | 4 +- pkg/alertmanager/sender_test.go | 2 +- pkg/distributor/otel_test.go | 2 +- pkg/distributor/push_test.go | 2 +- pkg/frontend/querymiddleware/remote_read.go | 2 +- .../querymiddleware/remote_read_test.go | 2 +- pkg/ingester/ingester_test.go | 2 +- pkg/mimirpb/compat_test.go | 4 ++ pkg/mimirpb/timeseries_test.go | 40 +++++++++++++++++++ pkg/querier/api/consistency_test.go | 2 +- pkg/storegateway/indexcache/cache.go | 4 ++ pkg/storegateway/indexcache/inmemory.go | 4 ++ pkg/streamingpromql/functions/common.go | 2 +- .../function_over_instant_vector_test.go | 4 +- 15 files changed, 65 insertions(+), 13 deletions(-) diff --git a/mimir-build-image/Dockerfile b/mimir-build-image/Dockerfile index 9680f7df53..e661322477 100644 --- a/mimir-build-image/Dockerfile +++ b/mimir-build-image/Dockerfile @@ -35,7 +35,7 @@ RUN GOARCH=$(go env GOARCH) && \ curl -fSL -o "/usr/bin/tk" "https://github.com/grafana/tanka/releases/download/v${TANKA_VERSION}/tk-linux-${GOARCH}" && \ chmod a+x /usr/bin/tk -RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b /usr/bin v1.54.1 +RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b /usr/bin v1.59.1 ENV SKOPEO_VERSION=v1.15.1 RUN git clone --depth 1 --branch ${SKOPEO_VERSION} https://github.com/containers/skopeo /go/src/github.com/containers/skopeo && \ diff --git a/pkg/alertmanager/alertmanager.go b/pkg/alertmanager/alertmanager.go index 83e1253103..6edbe6f6fe 100644 --- a/pkg/alertmanager/alertmanager.go +++ b/pkg/alertmanager/alertmanager.go @@ -531,10 +531,10 @@ func buildIntegrationsMap(nc []*definition.PostableApiReceiver, tmpl *template.T func buildGrafanaReceiverIntegrations(rcv *definition.PostableApiReceiver, tmpl *template.Template, logger log.Logger) ([]*nfstatus.Integration, error) { loggerFactory := newLoggerFactory(logger) - whFn := func(n alertingReceivers.Metadata) (alertingReceivers.WebhookSender, error) { + whFn := func(alertingReceivers.Metadata) (alertingReceivers.WebhookSender, error) { return NewSender(logger), nil } - emailFn := func(n alertingReceivers.Metadata) (alertingReceivers.EmailSender, error) { + emailFn := func(alertingReceivers.Metadata) (alertingReceivers.EmailSender, error) { return NewSender(logger), nil } diff --git a/pkg/alertmanager/sender_test.go b/pkg/alertmanager/sender_test.go index 7bdf720f6a..d259aba5ae 100644 --- a/pkg/alertmanager/sender_test.go +++ b/pkg/alertmanager/sender_test.go @@ -81,7 +81,7 @@ func TestSendWebhook(t *testing.T) { testErr := errors.New("test") cmd = alertingReceivers.SendWebhookSettings{ URL: server.URL, - Validation: func(body []byte, statusCode int) error { return testErr }, + Validation: func([]byte, int) error { return testErr }, } require.ErrorIs(t, s.SendWebhook(context.Background(), &cmd), testErr) diff --git a/pkg/distributor/otel_test.go b/pkg/distributor/otel_test.go index 9f58e7b114..cb59bc19b3 100644 --- a/pkg/distributor/otel_test.go +++ b/pkg/distributor/otel_test.go @@ -318,7 +318,7 @@ func TestHandlerOTLPPush(t *testing.T) { maxMsgSize: 100000, series: sampleSeries, metadata: sampleMetadata, - verifyFunc: func(_ *testing.T, pushReq *Request) error { + verifyFunc: func(*testing.T, *Request) error { return httpgrpc.Errorf(http.StatusTooManyRequests, "go slower") }, responseCode: http.StatusTooManyRequests, diff --git a/pkg/distributor/push_test.go b/pkg/distributor/push_test.go index 42470c5441..896ea0f4b1 100644 --- a/pkg/distributor/push_test.go +++ b/pkg/distributor/push_test.go @@ -902,7 +902,7 @@ func TestOTLPPushHandlerErrorsAreReportedCorrectlyViaHttpgrpc(t *testing.T) { srv, err := dskit_server.New(cfg) require.NoError(t, err) - push := func(ctx context.Context, req *Request) error { + push := func(_ context.Context, req *Request) error { // Trigger conversion of incoming request to WriteRequest. wr, err := req.WriteRequest() if err != nil { diff --git a/pkg/frontend/querymiddleware/remote_read.go b/pkg/frontend/querymiddleware/remote_read.go index 8d85fdb9a5..0552175ec3 100644 --- a/pkg/frontend/querymiddleware/remote_read.go +++ b/pkg/frontend/querymiddleware/remote_read.go @@ -58,7 +58,7 @@ func (r *remoteReadRoundTripper) RoundTrip(req *http.Request) (*http.Response, e if err != nil { return nil, err } - handler := r.middleware.Wrap(HandlerFunc(func(ctx context.Context, req MetricsQueryRequest) (Response, error) { + handler := r.middleware.Wrap(HandlerFunc(func(context.Context, MetricsQueryRequest) (Response, error) { // We do not need to do anything here as this middleware is used for // validation only and previous middlewares would have already returned errors. return nil, nil diff --git a/pkg/frontend/querymiddleware/remote_read_test.go b/pkg/frontend/querymiddleware/remote_read_test.go index fae2d4c534..aadbbe02f4 100644 --- a/pkg/frontend/querymiddleware/remote_read_test.go +++ b/pkg/frontend/querymiddleware/remote_read_test.go @@ -121,7 +121,7 @@ func TestRemoteReadRoundTripperCallsDownstreamOnAll(t *testing.T) { t.Run(name, func(t *testing.T) { roundTripper := &mockRoundTripper{} countMiddleWareCalls := 0 - middleware := MetricsQueryMiddlewareFunc(func(next MetricsQueryHandler) MetricsQueryHandler { + middleware := MetricsQueryMiddlewareFunc(func(MetricsQueryHandler) MetricsQueryHandler { countMiddleWareCalls++ return tc.handler }) diff --git a/pkg/ingester/ingester_test.go b/pkg/ingester/ingester_test.go index a43331a5e5..0e351539ea 100644 --- a/pkg/ingester/ingester_test.go +++ b/pkg/ingester/ingester_test.go @@ -242,7 +242,7 @@ func TestIngester_StartReadRequest(t *testing.T) { utilizationLimiter = &fakeUtilizationBasedLimiter{limitingReason: "cpu"} ) - setupIngester := func(tc testCase) *failingIngester { + setupIngester := func(testCase) *failingIngester { cfg := defaultIngesterTestConfig(t) cfg.ReadCircuitBreaker = CircuitBreakerConfig{ Enabled: true, diff --git a/pkg/mimirpb/compat_test.go b/pkg/mimirpb/compat_test.go index 97fa9cced7..0c28b445e8 100644 --- a/pkg/mimirpb/compat_test.go +++ b/pkg/mimirpb/compat_test.go @@ -197,7 +197,11 @@ func TestFromLabelAdaptersToLabelsWithCopy(t *testing.T) { // All strings must be copied. actualValue := actual.Get("hello") + // Ignore deprecation warning for now + //nolint:staticcheck hInputValue := (*reflect.StringHeader)(unsafe.Pointer(&input[0].Value)) + // Ignore deprecation warning for now + //nolint:staticcheck hActualValue := (*reflect.StringHeader)(unsafe.Pointer(&actualValue)) assert.NotEqual(t, hInputValue.Data, hActualValue.Data) } diff --git a/pkg/mimirpb/timeseries_test.go b/pkg/mimirpb/timeseries_test.go index baa9a0ae5b..d079f1fd59 100644 --- a/pkg/mimirpb/timeseries_test.go +++ b/pkg/mimirpb/timeseries_test.go @@ -79,6 +79,8 @@ func TestTimeseriesFromPool(t *testing.T) { func TestCopyToYoloString(t *testing.T) { stringByteArray := func(val string) uintptr { + // Ignore deprecation warning for now + //nolint:staticcheck return (*reflect.SliceHeader)(unsafe.Pointer(&val)).Data } @@ -102,6 +104,8 @@ func TestCopyToYoloString(t *testing.T) { assert.Len(t, remainingBuf, 0) // Verify that the remainingBuf is using the same underlying byte array as safeCopy but advanced by the length. + // Ignore deprecation warning for now + //nolint:staticcheck remainingBufArray := (*reflect.SliceHeader)(unsafe.Pointer(&remainingBuf)).Data assert.Equal(t, int(safeCopyByteArray)+len(newBuf), int(remainingBufArray)) } @@ -153,43 +157,79 @@ func TestDeepCopyTimeseries(t *testing.T) { // Check all the slices in the struct to ensure that // none of them refer to the same underlying array. assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Labels)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Labels)).Data, ) assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Samples)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Samples)).Data, ) assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Histograms)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Histograms)).Data, ) assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Exemplars)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Exemplars)).Data, ) for histogramIdx := range src.Histograms { assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Histograms[histogramIdx].NegativeSpans)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Histograms[histogramIdx].NegativeSpans)).Data, ) assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Histograms[histogramIdx].NegativeDeltas)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Histograms[histogramIdx].NegativeDeltas)).Data, ) assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Histograms[histogramIdx].PositiveSpans)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Histograms[histogramIdx].PositiveSpans)).Data, ) assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Histograms[histogramIdx].PositiveDeltas)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Histograms[histogramIdx].PositiveDeltas)).Data, ) } for exemplarIdx := range src.Exemplars { assert.NotEqual(t, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&src.Exemplars[exemplarIdx].Labels)).Data, + // Ignore deprecation warning for now + //nolint:staticcheck (*reflect.SliceHeader)(unsafe.Pointer(&dst.Exemplars[exemplarIdx].Labels)).Data, ) } diff --git a/pkg/querier/api/consistency_test.go b/pkg/querier/api/consistency_test.go index a4f6d39b02..25c5cc0ab7 100644 --- a/pkg/querier/api/consistency_test.go +++ b/pkg/querier/api/consistency_test.go @@ -34,7 +34,7 @@ func BenchmarkReadConsistencyServerUnaryInterceptor(b *testing.B) { ctx := metadata.NewIncomingContext(context.Background(), md) for n := 0; n < b.N; n++ { - _, _ = ReadConsistencyServerUnaryInterceptor(ctx, nil, nil, func(ctx context.Context, req any) (any, error) { + _, _ = ReadConsistencyServerUnaryInterceptor(ctx, nil, nil, func(context.Context, any) (any, error) { return nil, nil }) } diff --git a/pkg/storegateway/indexcache/cache.go b/pkg/storegateway/indexcache/cache.go index 29822e184f..b52a9339ab 100644 --- a/pkg/storegateway/indexcache/cache.go +++ b/pkg/storegateway/indexcache/cache.go @@ -158,7 +158,11 @@ const bytesPerPosting = int(unsafe.Sizeof(storage.SeriesRef(0))) // It casts the memory region of the underlying array to a slice of bytes. The resulting byte slice is only valid as long as the postings slice exists and is unmodified. func unsafeCastPostingsToBytes(postings []storage.SeriesRef) []byte { byteSlice := make([]byte, 0) + // Ignore deprecation warning for now + //nolint:staticcheck slicePtr := (*reflect.SliceHeader)(unsafe.Pointer(&byteSlice)) + // Ignore deprecation warning for now + //nolint:staticcheck slicePtr.Data = (*reflect.SliceHeader)(unsafe.Pointer(&postings)).Data slicePtr.Len = len(postings) * bytesPerPosting slicePtr.Cap = slicePtr.Len diff --git a/pkg/storegateway/indexcache/inmemory.go b/pkg/storegateway/indexcache/inmemory.go index de626385f9..ee900293c4 100644 --- a/pkg/storegateway/indexcache/inmemory.go +++ b/pkg/storegateway/indexcache/inmemory.go @@ -277,7 +277,11 @@ func (c *InMemoryIndexCache) reset() { func copyString(s string) string { var b []byte + // Ignore deprecation warning for now + //nolint:staticcheck h := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + // Ignore deprecation warning for now + //nolint:staticcheck h.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data h.Len = len(s) h.Cap = len(s) diff --git a/pkg/streamingpromql/functions/common.go b/pkg/streamingpromql/functions/common.go index 3087eec8fa..45136fab59 100644 --- a/pkg/streamingpromql/functions/common.go +++ b/pkg/streamingpromql/functions/common.go @@ -21,7 +21,7 @@ type InstantVectorFunction func(seriesData types.InstantVectorSeriesData, pool * // floatTransformationFunc is not needed elsewhere, so it is not exported yet func floatTransformationFunc(transform func(f float64) float64) InstantVectorFunction { - return func(seriesData types.InstantVectorSeriesData, pool *pooling.LimitingPool) (types.InstantVectorSeriesData, error) { + return func(seriesData types.InstantVectorSeriesData, _ *pooling.LimitingPool) (types.InstantVectorSeriesData, error) { for i := range seriesData.Floats { seriesData.Floats[i].F = transform(seriesData.Floats[i].F) } diff --git a/pkg/streamingpromql/operators/function_over_instant_vector_test.go b/pkg/streamingpromql/operators/function_over_instant_vector_test.go index eb8653c3ea..2ea06629e5 100644 --- a/pkg/streamingpromql/operators/function_over_instant_vector_test.go +++ b/pkg/streamingpromql/operators/function_over_instant_vector_test.go @@ -30,14 +30,14 @@ func TestFunctionOverInstantVector(t *testing.T) { } metadataFuncCalled := false - mustBeCalledMetadata := func(seriesMetadata []types.SeriesMetadata, pool *pooling.LimitingPool) ([]types.SeriesMetadata, error) { + mustBeCalledMetadata := func(seriesMetadata []types.SeriesMetadata, _ *pooling.LimitingPool) ([]types.SeriesMetadata, error) { require.Equal(t, len(inner.series), len(seriesMetadata)) metadataFuncCalled = true return nil, nil } seriesDataFuncCalledTimes := 0 - mustBeCalledSeriesData := func(seriesData types.InstantVectorSeriesData, pool *pooling.LimitingPool) (types.InstantVectorSeriesData, error) { + mustBeCalledSeriesData := func(types.InstantVectorSeriesData, *pooling.LimitingPool) (types.InstantVectorSeriesData, error) { seriesDataFuncCalledTimes++ return types.InstantVectorSeriesData{}, nil }