Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimir-build-image: Upgrade golangci-lint #8385

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ mimir-build-image/$(UPTODATE): mimir-build-image/*
# All the boiler plate for building golang follows:
SUDO := $(shell docker info >/dev/null 2>&1 || echo "sudo -E")
BUILD_IN_CONTAINER ?= true
LATEST_BUILD_IMAGE_TAG ?= pr8347-55c99be7fb
LATEST_BUILD_IMAGE_TAG ?= pr8385-000f1b4a10

# TTY is parameterized to allow Google Cloud Builder to run builds,
# as it currently disallows TTY devices. This value needs to be overridden
Expand Down
2 changes: 1 addition & 1 deletion mimir-build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
4 changes: 2 additions & 2 deletions pkg/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/alertmanager/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/distributor/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/distributor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/querymiddleware/remote_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/querymiddleware/remote_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions pkg/mimirpb/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package mimirpb
import (
stdlibjson "encoding/json"
"math"
"reflect"
"strconv"
"testing"
"unsafe"
Expand Down Expand Up @@ -197,9 +196,7 @@ func TestFromLabelAdaptersToLabelsWithCopy(t *testing.T) {

// All strings must be copied.
actualValue := actual.Get("hello")
hInputValue := (*reflect.StringHeader)(unsafe.Pointer(&input[0].Value))
hActualValue := (*reflect.StringHeader)(unsafe.Pointer(&actualValue))
assert.NotEqual(t, hInputValue.Data, hActualValue.Data)
assert.NotSame(t, unsafe.StringData(input[0].Value), unsafe.StringData(actualValue))
}

func BenchmarkFromLabelAdaptersToLabelsWithCopy(b *testing.B) {
Expand Down
40 changes: 40 additions & 0 deletions pkg/mimirpb/timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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))
}
Expand Down Expand Up @@ -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,
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/api/consistency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/storegateway/indexcache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/storegateway/indexcache/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/streamingpromql/functions/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading