Skip to content

Commit

Permalink
Pull request #100: Use Go1.23, upgrade dependencies
Browse files Browse the repository at this point in the history
Merge in PRODUCT/squirreldb from upgrade-deps-2024-09-24 to main

* commit '749a462b7bfada74b90d0586b384b720577d0ec7':
  Use alpine:3.20 as base for Docker image
  Update goreleaser
  Update & please linters
  Use Go1.23, upgrade dependencies
  • Loading branch information
Thomas Delbende authored and cavanierc committed Sep 30, 2024
2 parents c3beb36 + 749a462 commit a080b95
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
go: "1.22"
go: "1.23"
timeout: 5m

linters:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM alpine:3.16 AS build
FROM --platform=$BUILDPLATFORM alpine:3.20 AS build

ARG TARGETARCH

Expand All @@ -8,7 +8,7 @@ COPY dist/squirreldb_linux_arm_6/squirreldb /squirreldb.arm

RUN cp -p /squirreldb.$TARGETARCH /squirreldb

FROM alpine:3.16
FROM alpine:3.20

LABEL maintainer="Bleemeo Docker Maintainers <[email protected]>"

Expand Down
4 changes: 2 additions & 2 deletions api/fake_remote_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func patchRemoteWriteHandler(api *v1.API, backdateOffset time.Duration) {
futurePointsBackdateOffset: backdateOffset,
// Unsafely casting the original write handler in our own type that mimics the original one,
// to be able to access its private fields and methods.
originalWriteHandler: (*writeHandler)(unsafe.Pointer(writeHandlerField.Elem().Pointer())), //nolint: gosec
originalWriteHandler: (*writeHandler)(unsafe.Pointer(writeHandlerField.Elem().Pointer())),
}

writableWriteHandler := reflect.NewAt(writeHandlerField.Type(), unsafe.Pointer(writeHandlerField.UnsafeAddr())).Elem() //nolint: gosec,lll
writableWriteHandler := reflect.NewAt(writeHandlerField.Type(), unsafe.Pointer(writeHandlerField.UnsafeAddr())).Elem()
// Setting our own write-handler in the API's remoteWriteHandler field
writableWriteHandler.Set(reflect.ValueOf(ourWriteHandler))
}
Expand Down
2 changes: 1 addition & 1 deletion api/promql/queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s Store) makePerRequestData(r *http.Request) (perRequest, error) {
return perRequest{}, err
}

maxEvaluatedSeries = uint32(tmp) //nolint:gosec
maxEvaluatedSeries = uint32(tmp)
}

limitIndex := &limitingIndex{
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
USER_UID=$(id -u)

# Should be the same as run-tests.sh
GORELEASER_VERSION="v2.2.0"
GORELEASER_VERSION="v2.3.2"

case "$1" in
"")
Expand Down
8 changes: 4 additions & 4 deletions cassandra/index/bulk_deleted.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newBulkDeleter(c *CassandraIndex) *deleter {
// sortedLabels may be nil if labels are unknown (so only ID is deleted from all postings).
// Skipping labels2id is used by index fix. It shouldn't be used in normal condition.
func (d *deleter) PrepareDelete(id types.MetricID, sortedLabels labels.Labels, skipLabels2Id bool) {
d.deleteIDs = append(d.deleteIDs, uint64(id))
d.deleteIDs = append(d.deleteIDs, uint64(id)) //nolint:gosec

if sortedLabels != nil && !skipLabels2Id {
sortedLabelsString := sortedLabels.String()
Expand Down Expand Up @@ -67,7 +67,7 @@ func (d *deleter) PrepareDelete(id types.MetricID, sortedLabels labels.Labels, s
d.labelToPostingUpdates[label] = idx
}

d.unshardedPostingUpdates[idx].RemoveIDs = append(d.unshardedPostingUpdates[idx].RemoveIDs, uint64(id))
d.unshardedPostingUpdates[idx].RemoveIDs = append(d.unshardedPostingUpdates[idx].RemoveIDs, uint64(id)) //nolint:gosec
}
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func (d *deleter) Delete(ctx context.Context) error {
// This usually occur if a Cassandra error happen after deleting from maybePresence and before
// deleting it from existingShardsLabel.
// Cleanup entry in existingShardsLabel
shardDeleter.ShardsListUpdate.RemoveIDs = append(shardDeleter.ShardsListUpdate.RemoveIDs, uint64(shard))
shardDeleter.ShardsListUpdate.RemoveIDs = append(shardDeleter.ShardsListUpdate.RemoveIDs, uint64(shard)) //nolint:gosec,lll

continue
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func (d *postingsInShardDeleter) Delete(ctx context.Context) error {
// it is nil iff it's empty (or an error occure)
if it == nil || errors.Is(err, errBitmapEmpty) {
d.l.Lock()
d.ShardsListUpdate.RemoveIDs = append(d.ShardsListUpdate.RemoveIDs, uint64(req.Shard))
d.ShardsListUpdate.RemoveIDs = append(d.ShardsListUpdate.RemoveIDs, uint64(req.Shard)) //nolint:gosec
d.l.Unlock()
}

Expand Down
50 changes: 25 additions & 25 deletions cassandra/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ func (c *CassandraIndex) InfoByID(ctx context.Context, w io.Writer, id types.Met
var lbls labels.Labels

if len(labelsMap) == 0 {
fmt.Fprintf(w, "Metric ID %d not found in id2labels and isInGlobal=%v\n", id, allPosting.Contains(uint64(id)))
fmt.Fprintf(w, "Metric ID %d not found in id2labels and isInGlobal=%v\n", id, allPosting.Contains(uint64(id))) //nolint:gosec,lll
} else {
lbls = labelsMap[id]

Expand All @@ -926,7 +926,7 @@ func (c *CassandraIndex) InfoByID(ctx context.Context, w io.Writer, id types.Met
id,
lbls,
expiration[id],
allPosting.Contains(uint64(id)),
allPosting.Contains(uint64(id)), //nolint:gosec
)

sortedLabels := sortLabels(lbls)
Expand Down Expand Up @@ -971,8 +971,8 @@ func (c *CassandraIndex) InfoByID(ctx context.Context, w io.Writer, id types.Met
return err
}

inPosting := postingShard.Contains(uint64(id))
inMaybe := maybepostingShard.Contains(uint64(id))
inPosting := postingShard.Contains(uint64(id)) //nolint:gosec
inMaybe := maybepostingShard.Contains(uint64(id)) //nolint:gosec

fmt.Fprintf(
w,
Expand All @@ -992,7 +992,7 @@ func (c *CassandraIndex) InfoByID(ctx context.Context, w io.Writer, id types.Met
return err
}

if !posting.Contains(uint64(id)) {
if !posting.Contains(uint64(id)) { //nolint:gosec
missingPostings = append(missingPostings, fmt.Sprintf("%s=%s", l.Name, l.Value))
}
}
Expand Down Expand Up @@ -1315,12 +1315,12 @@ func mergeSorted(left, right []string) (result []string) {
i++
}

for j := range len(left) {
for j := range left {
result[i] = left[j]
i++
}

for j := range len(right) {
for j := range right {
result[i] = right[j]
i++
}
Expand Down Expand Up @@ -1549,7 +1549,7 @@ func (c *CassandraIndex) lookupIDsFromCache(
return nil, nil, err
}

possibleInvalidIDs = append(possibleInvalidIDs, uint64(data.id))
possibleInvalidIDs = append(possibleInvalidIDs, uint64(data.id)) //nolint:gosec
found = false
}

Expand Down Expand Up @@ -1765,12 +1765,12 @@ func (c *CassandraIndex) refreshExpiration(

req := c.expirationUpdateRequests[previousDay.Unix()]

req.RemoveIDs = append(req.RemoveIDs, uint64(id))
req.RemoveIDs = append(req.RemoveIDs, uint64(id)) //nolint:gosec
c.expirationUpdateRequests[previousDay.Unix()] = req

req = c.expirationUpdateRequests[newDay.Unix()]

req.AddIDs = append(req.AddIDs, uint64(id))
req.AddIDs = append(req.AddIDs, uint64(id)) //nolint:gosec
c.expirationUpdateRequests[newDay.Unix()] = req

return nil
Expand Down Expand Up @@ -1917,13 +1917,13 @@ func (c *CassandraIndex) createMetrics( //nolint:maintidx

c.metrics.LookupIDConcurrentNew.Inc()

if !allPosting.Contains(uint64(id)) {
if !allPosting.Contains(uint64(id)) { //nolint:gosec
c.logger.Error().Int64("id", int64(id)).Msg("already registered ID is not present in allPosting!")

// Add the bad ID to next expiration, so it could be cleanup if possible
today := c.options.InternalNowFunction().Truncate(24 * time.Hour)
expReq := expirationUpdateRequests[today.Unix()]
expReq.AddIDs = append(expReq.AddIDs, uint64(id))
expReq.AddIDs = append(expReq.AddIDs, uint64(id)) //nolint:gosec
expirationUpdateRequests[today.Unix()] = expReq

// Do not use this ID. A new ID will be allocated.
Expand Down Expand Up @@ -1951,7 +1951,7 @@ func (c *CassandraIndex) createMetrics( //nolint:maintidx
// Add the bad ID to next expiration, so it could be cleanup if possible
today := c.options.InternalNowFunction().Truncate(24 * time.Hour)
expReq := expirationUpdateRequests[today.Unix()]
expReq.AddIDs = append(expReq.AddIDs, uint64(id))
expReq.AddIDs = append(expReq.AddIDs, uint64(id)) //nolint:gosec
expirationUpdateRequests[today.Unix()] = expReq

// Do not use this ID. A new ID will be allocated.
Expand Down Expand Up @@ -1984,7 +1984,7 @@ func (c *CassandraIndex) createMetrics( //nolint:maintidx
return nil, errors.New("too many metrics registered, unable to find a free ID")
}

_, err = allPosting.AddN(uint64(newID))
_, err = allPosting.AddN(uint64(newID)) //nolint:gosec
if err != nil {
return nil, fmt.Errorf("update bitmap: %w", err)
}
Expand All @@ -2005,7 +2005,7 @@ func (c *CassandraIndex) createMetrics( //nolint:maintidx
day := cassandraExpiration.Truncate(24 * time.Hour)
expReq := expirationUpdateRequests[day.Unix()]

expReq.AddIDs = append(expReq.AddIDs, uint64(newID))
expReq.AddIDs = append(expReq.AddIDs, uint64(newID)) //nolint:gosec

expirationUpdateRequests[day.Unix()] = expReq
}
Expand Down Expand Up @@ -2170,7 +2170,7 @@ func (c *CassandraIndex) updatePostingShards(
c.idInShardLastAccess[shard] = now

it := c.idInShard[shard]
if it != nil && it.Contains(uint64(entry.id)) {
if it != nil && it.Contains(uint64(entry.id)) { //nolint:gosec
continue
}

Expand All @@ -2183,7 +2183,7 @@ func (c *CassandraIndex) updatePostingShards(
}
}

req.AddIDs = append(req.AddIDs, uint64(entry.id))
req.AddIDs = append(req.AddIDs, uint64(entry.id)) //nolint:gosec
maybePresent[shard] = req

labelsList := make(labels.Labels, 0, len(entry.unsortedLabels)*2)
Expand Down Expand Up @@ -2219,7 +2219,7 @@ func (c *CassandraIndex) updatePostingShards(
m[lbl] = idx
}

updates[idx].AddIDs = append(updates[idx].AddIDs, uint64(entry.id))
updates[idx].AddIDs = append(updates[idx].AddIDs, uint64(entry.id)) //nolint:gosec
}

req, ok = precense[shard]
Expand All @@ -2231,7 +2231,7 @@ func (c *CassandraIndex) updatePostingShards(
}
}

req.AddIDs = append(req.AddIDs, uint64(entry.id))
req.AddIDs = append(req.AddIDs, uint64(entry.id)) //nolint:gosec
precense[shard] = req
}
}
Expand Down Expand Up @@ -2329,7 +2329,7 @@ func (c *CassandraIndex) applyUpdatePostingShards(
newShard := make([]uint64, 0, len(maybePresent))

for shard := range maybePresent {
newShard = append(newShard, uint64(shard))
newShard = append(newShard, uint64(shard)) //nolint:gosec
}

_, err := c.postingUpdate(ctx, postingUpdateRequest{
Expand Down Expand Up @@ -3078,7 +3078,7 @@ func (c *CassandraIndex) cassandraCheckExpire(ctx context.Context, ids []uint64,
dayToExpireUpdates[expireDay.Unix()] = idx
}

expireUpdates[idx].AddIDs = append(expireUpdates[idx].AddIDs, uint64(id))
expireUpdates[idx].AddIDs = append(expireUpdates[idx].AddIDs, uint64(id)) //nolint:gosec

continue
}
Expand Down Expand Up @@ -3187,7 +3187,7 @@ func (c *CassandraIndex) deleteShard(ctx context.Context, shard int32) error {
Name: existingShardsLabel,
Value: existingShardsLabel,
},
RemoveIDs: []uint64{uint64(shard)},
RemoveIDs: []uint64{uint64(shard)}, //nolint:gosec
}

_, err = c.postingUpdate(ctx, updateRequest)
Expand Down Expand Up @@ -3499,7 +3499,7 @@ func (c *CassandraIndex) postingsForMatchers( //nolint:gocognit
// With postings filtering, we do one Cassandra query per matchers.
// With explicit matching on labels, we do one Cassandra query per IDs BUT this query will be done anyway if the
// series would be kept.
if results != nil && results.Count() <= uint64(directCheckThreshold) {
if results != nil && results.Count() <= uint64(directCheckThreshold) { //nolint:gosec
needCheckMatches = true

break
Expand Down Expand Up @@ -3548,7 +3548,7 @@ func (c *CassandraIndex) postingsForMatchers( //nolint:gocognit
return nil, false, ctx.Err()
}

if results != nil && results.Count() <= uint64(directCheckThreshold) {
if results != nil && results.Count() <= uint64(directCheckThreshold) { //nolint:gosec
needCheckMatches = true

break
Expand Down Expand Up @@ -3856,7 +3856,7 @@ func (c *CassandraIndex) getTimeShards(ctx context.Context, start, end time.Time
current := startShard

for current <= endShard {
if returnAll || existingShards.Contains(uint64(current)) {
if returnAll || existingShards.Contains(uint64(current)) { //nolint:gosec
results = append(results, current)
}

Expand Down
2 changes: 1 addition & 1 deletion cassandra/index/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5911,7 +5911,7 @@ func Test_expiration(t *testing.T) { //nolint:maintidx
}

// Check in store that correct write happened
for n := range len(metrics) {
for n := range metrics {
labels := labelsMapToList(metrics[n], true)
id := metricsID[n]

Expand Down
20 changes: 10 additions & 10 deletions cassandra/index/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (ve *verifierExecution) verifyMissingShard(
return 0, shards, err
}

if it != nil && it.Any() && !shards.Contains(uint64(queryShard[0])) {
if it != nil && it.Any() && !shards.Contains(uint64(queryShard[0])) { //nolint:gosec
errorCount++

fmt.Fprintf(
Expand All @@ -301,7 +301,7 @@ func (ve *verifierExecution) verifyMissingShard(
)

if ve.doFix {
_, err = shards.AddN(uint64(queryShard[0]))
_, err = shards.AddN(uint64(queryShard[0])) //nolint:gosec
if err != nil {
return 0, shards, fmt.Errorf("update bitmap: %w", err)
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func (ve *verifierExecution) verifyMissingShard(
)

if ve.doFix {
_, err = shards.RemoveN(uint64(shard))
_, err = shards.RemoveN(uint64(shard)) //nolint:gosec
if err != nil {
return 0, shards, fmt.Errorf("update bitmap: %w", err)
}
Expand Down Expand Up @@ -385,7 +385,7 @@ func (ve *verifierExecution) verifyBulk( //nolint:maintidx
}

if !ok {
if _, err := ve.expectedUnknowDate.AddN(uint64(id)); err != nil {
if _, err := ve.expectedUnknowDate.AddN(uint64(id)); err != nil { //nolint:gosec
return false, err
}

Expand All @@ -407,7 +407,7 @@ func (ve *verifierExecution) verifyBulk( //nolint:maintidx
}

if !ok {
if _, err := ve.expectedUnknowDate.AddN(uint64(id)); err != nil {
if _, err := ve.expectedUnknowDate.AddN(uint64(id)); err != nil { //nolint:gosec
return false, err
}

Expand Down Expand Up @@ -446,7 +446,7 @@ func (ve *verifierExecution) verifyBulk( //nolint:maintidx
it = roaring.NewBTreeBitmap()
}

if _, err := it.AddN(uint64(id)); err != nil {
if _, err := it.AddN(uint64(id)); err != nil { //nolint:gosec
return false, err
}

Expand Down Expand Up @@ -506,7 +506,7 @@ func (ve *verifierExecution) verifyBulk( //nolint:maintidx
ve.bulkDeleter.PrepareDelete(id2, lbls, false)
ve.bulkDeleter.PrepareDelete(id, lbls, false)
}
case !ve.allPosting.Contains(uint64(id2)):
case !ve.allPosting.Contains(uint64(id2)): //nolint:gosec
fmt.Fprintf(
ve.output,
"ID %10d (%v) conflict with ID %d (which isn't listed in all posting! THIS SHOULD NOT HAPPEN.)\n",
Expand Down Expand Up @@ -557,7 +557,7 @@ func (ve *verifierExecution) verifyBulk( //nolint:maintidx
continue
}

_, err = ve.allGoodIDs.AddN(uint64(id))
_, err = ve.allGoodIDs.AddN(uint64(id)) //nolint:gosec
if err != nil {
return hadIssue, fmt.Errorf("update bitmap: %w", err)
}
Expand Down Expand Up @@ -719,7 +719,7 @@ func (ve *verifierExecution) verifyShard( //nolint:maintidx
bitset = roaring.NewBTreeBitmap()
}

_, err = bitset.AddN(uint64(id))
_, err = bitset.AddN(uint64(id)) //nolint:gosec
if err != nil {
return true, fmt.Errorf("update bitmap: %w", err)
}
Expand All @@ -736,7 +736,7 @@ func (ve *verifierExecution) verifyShard( //nolint:maintidx
bitset = roaring.NewBTreeBitmap()
}

_, err = bitset.AddN(uint64(id))
_, err = bitset.AddN(uint64(id)) //nolint:gosec
if err != nil {
return true, fmt.Errorf("update bitmap: %w", err)
}
Expand Down
Loading

0 comments on commit a080b95

Please sign in to comment.