Skip to content

Commit 822d699

Browse files
authored
Update code to fix almost all pre-existing lint errors (#2008)
* Cleanup linting errors around deadcode To be specific ineffassign, deadcode and unused errors Signed-off-by: Nathan Zender <[email protected]> * Replaced by keysFn and if the config defines it then it will distribute keys using hashing Signed-off-by: Nathan Zender <[email protected]> * Hold over from when readBatch as also the iterator Now that we have an iterator there is no need to also have a consumed bool on the underlying object. Signed-off-by: Nathan Zender <[email protected]> * Necessary to fix the false sharing problem Will never actually be used. Only necessary to pad out CPU cache lines. Signed-off-by: Nathan Zender <[email protected]> * Removing unused code Signed-off-by: Nathan Zender <[email protected]> * Cleanup all gosimple suggestions Signed-off-by: Nathan Zender <[email protected]> * Fixing all errcheck Attempted not to change any existing logic so if an error was ignored we will now either explicitly ignore it or in the case of a goroutine being called with a func that is ignoring the error we will just put a //noling:errcheck on that line. If it was in a test case we went ahead and did the extra assertion checks b/c its always good to know where something might have errored in your test cases. Signed-off-by: Nathan Zender <[email protected]> * Fix most staticcheck lint issues Signed-off-by: Nathan Zender <[email protected]> * Cleanup deprecated call to snappy.NewWriter Signed-off-by: Nathan Zender <[email protected]> * Remove rev from Makefile Signed-off-by: Nathan Zender <[email protected]> * Reorder imports Signed-off-by: Nathan Zender <[email protected]> * Ignoring this for now We have opened up issue #2015 to address the deprecation of this type. Signed-off-by: Nathan Zender <[email protected]> * Explicitly ignoring this error The test is currently failing due to a data race. I believe it is due to this bug in golang. golang/go#30597 As far as this test cares it does not really matter that this happens so removing the need to check for NoError "fixes" it. Signed-off-by: Nathan Zender <[email protected]> * Require noerror since this is a test Signed-off-by: Nathan Zender <[email protected]> * Switch over to use require.NoError Signed-off-by: Nathan Zender <[email protected]> * Move func to test class since that is only place it was used Signed-off-by: Nathan Zender <[email protected]> * Log warning if save to cache errors Signed-off-by: Nathan Zender <[email protected]> * Condense a little Signed-off-by: Nathan Zender <[email protected]> * Use returned error instead of capturing it Signed-off-by: Nathan Zender <[email protected]> * Bringing back ctx and adding comment Signed-off-by: Nathan Zender <[email protected]> * Log error if changing ring state fails when Leaving Signed-off-by: Nathan Zender <[email protected]> * If context deadline exceeded return the error Signed-off-by: Nathan Zender <[email protected]> * Can't defer this otherwise we will have no data Signed-off-by: Nathan Zender <[email protected]> * Comment to make it clear why this nolint was added Signed-off-by: Nathan Zender <[email protected]> * Refactor method out Since Fixture is already in testutils and it is being used in both places pulled it out into a common helper method in the testutils package. Signed-off-by: Nathan Zender <[email protected]> * io.Copy added to global errcheck exclude Signed-off-by: Nathan Zender <[email protected]> * If error dont do anything else Signed-off-by: Nathan Zender <[email protected]> * Cleanup unused function Signed-off-by: Nathan Zender <[email protected]> * Adding tracer to global excludes Signed-off-by: Nathan Zender <[email protected]> * Cleanup post rebase Formatting and import issues that got missed when merging. Signed-off-by: Nathan Zender <[email protected]> * Ratelimiter returns resource exhausted error This is necessary so that when it is used with the backoff retry it will allow for the backoff to continue to work as expected. Signed-off-by: Nathan Zender <[email protected]>
1 parent fa7b676 commit 822d699

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+223
-235
lines changed

.errcheck-exclude

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
io/ioutil.WriteFile
22
io/ioutil.ReadFile
33
(github.com/go-kit/kit/log.Logger).Log
4+
io.Copy
5+
(github.com/opentracing/opentracing-go.Tracer).Inject

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protos: $(PROTO_GOS)
122122

123123
lint:
124124
misspell -error docs
125-
golangci-lint run --new-from-rev ed7c302fd968 --build-tags netgo --timeout=5m --enable golint --enable misspell --enable gofmt
125+
golangci-lint run --build-tags netgo --timeout=5m --enable golint --enable misspell --enable gofmt
126126

127127
# Validate Kubernetes spec files. Requires:
128128
# https://kubeval.instrumenta.dev

cmd/cortex/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ func captureOutput(t *testing.T) *capturedOutput {
161161
co.wg.Add(1)
162162
go func() {
163163
defer co.wg.Done()
164-
_, _ = io.Copy(&co.stdoutBuf, stdoutR)
164+
io.Copy(&co.stdoutBuf, stdoutR)
165165
}()
166166

167167
co.wg.Add(1)
168168
go func() {
169169
defer co.wg.Done()
170-
_, _ = io.Copy(&co.stderrBuf, stderrR)
170+
io.Copy(&co.stderrBuf, stderrR)
171171
}()
172172

173173
return co

cmd/test-exporter/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ func main() {
5252
}))
5353

5454
prometheus.MustRegister(runner)
55-
server.Run()
55+
err = server.Run()
56+
util.CheckFatal("running server", err)
5657
}

pkg/alertmanager/alertmanager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func init() {
7878
// from disk, we just ignore web-based reload signals. Config updates are
7979
// only applied externally via ApplyConfig().
8080
case <-webReload:
81+
default:
82+
continue
8183
}
8284
}
8385
}()
@@ -176,7 +178,7 @@ func clusterWait(p *cluster.Peer, timeout time.Duration) func() time.Duration {
176178

177179
// ApplyConfig applies a new configuration to an Alertmanager.
178180
func (am *Alertmanager) ApplyConfig(userID string, conf *config.Config) error {
179-
templateFiles := make([]string, len(conf.Templates), len(conf.Templates))
181+
templateFiles := make([]string, len(conf.Templates))
180182
if len(conf.Templates) > 0 {
181183
for i, t := range conf.Templates {
182184
templateFiles[i] = filepath.Join(am.cfg.DataDir, "templates", userID, t)

pkg/chunk/aws/dynamodb_storage_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (a dynamoDBStorageClient) BatchWrite(ctx context.Context, input chunk.Write
245245
if awsErr, ok := err.(awserr.Error); ok && ((awsErr.Code() == dynamodb.ErrCodeProvisionedThroughputExceededException) || request.Retryable()) {
246246
logWriteRetry(ctx, requests)
247247
unprocessed.TakeReqs(requests, -1)
248-
a.writeThrottle.WaitN(ctx, len(requests))
248+
_ = a.writeThrottle.WaitN(ctx, len(requests))
249249
backoff.Wait()
250250
continue
251251
} else if ok && awsErr.Code() == validationException {
@@ -269,7 +269,7 @@ func (a dynamoDBStorageClient) BatchWrite(ctx context.Context, input chunk.Write
269269
unprocessedItems := dynamoDBWriteBatch(resp.UnprocessedItems)
270270
if len(unprocessedItems) > 0 {
271271
logWriteRetry(ctx, unprocessedItems)
272-
a.writeThrottle.WaitN(ctx, unprocessedItems.Len())
272+
_ = a.writeThrottle.WaitN(ctx, unprocessedItems.Len())
273273
unprocessed.TakeReqs(unprocessedItems, -1)
274274
}
275275

pkg/chunk/aws/dynamodb_storage_client_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const (
1717

1818
func TestChunksPartialError(t *testing.T) {
1919
fixture := dynamoDBFixture(0, 10, 20)
20-
defer fixture.Teardown()
20+
defer testutils.TeardownFixture(t, fixture)
21+
2122
_, client, err := testutils.Setup(fixture, tableName)
2223
require.NoError(t, err)
2324

pkg/chunk/aws/dynamodb_table_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (d dynamoTableClient) backoffAndRetry(ctx context.Context, fn func(context.
8080

8181
func (d callManager) backoffAndRetry(ctx context.Context, fn func(context.Context) error) error {
8282
if d.limiter != nil { // Tests will have a nil limiter.
83-
d.limiter.Wait(ctx)
83+
_ = d.limiter.Wait(ctx)
8484
}
8585

8686
backoff := util.NewBackoff(ctx, d.backoffConfig)

pkg/chunk/aws/mock.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (a dynamoDBStorageClient) setErrorParameters(provisionedErr, errAfter int)
5656
}
5757
}
5858

59+
//nolint:unused //Leaving this around in the case we need to create a table via mock this is useful.
5960
func (m *mockDynamoDBClient) createTable(name string) {
6061
m.mtx.Lock()
6162
defer m.mtx.Unlock()

pkg/chunk/cache/fifo_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (c *FifoCache) Get(ctx context.Context, key string) (interface{}, bool) {
228228
index, ok := c.index[key]
229229
if ok {
230230
updated := c.entries[index].updated
231-
if c.validity == 0 || time.Now().Sub(updated) < c.validity {
231+
if c.validity == 0 || time.Since(updated) < c.validity {
232232
return c.entries[index].value, true
233233
}
234234

0 commit comments

Comments
 (0)