Skip to content

Commit

Permalink
Merge pull request #349 from SOF3/update-lint
Browse files Browse the repository at this point in the history
chore: update .golangci.yaml
  • Loading branch information
SOF3 authored Sep 3, 2024
2 parents b66f00b + 68f98fb commit 0917028
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ linters:
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupl
Expand All @@ -17,9 +18,7 @@ linters:
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- gci
- gocheckcompilerdirectives
Expand Down
1 change: 1 addition & 0 deletions pkg/aggregator/spancache/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func EncodeInt64(i int64) [8]byte {
}

func DecodeInt64(b [8]byte) int64 {
// #nosec G115 -- Wrapping is intentional and acceptable
return int64(binary.LittleEndian.Uint64(b[:]))
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/audit/mq/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"hash/fnv"
"math"
"math/rand"
"sync/atomic"
"time"
Expand Down Expand Up @@ -93,6 +94,11 @@ func (q *LocalQueue) Start(ctx context.Context) error {
}
numPartitions = len(consumers)
}

if numPartitions > math.MaxInt32 {
return fmt.Errorf("too many partitions")
}
// #nosec G115 -- checked
q.numPartitions = int32(numPartitions)

for _, consumers := range q.consumers {
Expand Down Expand Up @@ -135,6 +141,7 @@ func (producer *localProducer) Send(partitionKey []byte, value []byte) error {
keyHasher := fnv.New32()
_, _ = keyHasher.Write(partitionKey) // fnv.Write is infallible
hash := keyHasher.Sum32()
// #nosec G115 -- hash % numPartitions < numPartitions <= MaxInt32
partition = int32(hash % uint32(producer.queue.numPartitions))
} else {
partition = rand.Int31n(producer.queue.numPartitions)
Expand Down
1 change: 1 addition & 0 deletions pkg/frontend/reader/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (fl *followLinkPool[M]) scheduleFrom(obj *object[M], followLimit *atomic.In
if subSelector != nil {
admittedLinks = append(admittedLinks, link)
fl.knownKeys.Insert(link.Key)
// #nosec G115 -- Trace period cannot practically exceed int32.
fl.schedule(link.Key, subSelector, followLimit, int32(fl.endTime.Sub(fl.startTime)/(time.Minute*30)))
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/frontend/reader/merge/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func do(
return out, nil
},
len(traces),
// #nosec G115 -- test cases have reasonably small sizes.
int32(len(traces)),
false,
))
Expand Down
1 change: 1 addition & 0 deletions pkg/frontend/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func generateCacheId(mode tfconfig.Id) model.TraceID {

func extractDisplayMode(cacheId model.TraceID) tfconfig.Id {
displayMode := cacheId.High >> CacheIdHighBitShift
// #nosec G115 -- intentional truncation.
return tfconfig.Id(uint32(displayMode))
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/frontend/tf/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (id *Id) UnmarshalText(text []byte) error {
if err != nil {
return err
}

// #nosec G115 -- ParseUint bitSize is 32
*id = Id(uint32(i))
return nil
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/frontend/tf/config/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ func (p *FileProvider) loadJsonBytes(jsonBytes []byte) error {
modifiers := make([]knownModifier, 0, len(file.Modifiers))

for bitmask, modifierConfig := range file.Modifiers {
bitmask := bitmask
modifierConfig := modifierConfig

displayName := modifierConfig.DisplayName

factory, hasFactory := p.RegisteredModifiers.Indexed[modifierConfig.ModifierName]
Expand Down
8 changes: 0 additions & 8 deletions pkg/frontend/tf/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ func (x *FetchExtensionsAndStoreCache) ProcessExtensions(
}

for _, span := range spans {
span := span

tags := model.KeyValues(span.Tags)
if tag, isPseudo := tags.FindByKey(zconstants.PseudoType); isPseudo && tag.VStr == string(zconstants.PseudoTypeObject) {
for extId, ext := range extensions {
ext := ext

objectRef, ok := objectRefFromTags(tags)
if !ok {
return nil, fmt.Errorf("expected object tags in nestingLevel=object spans")
Expand All @@ -116,8 +112,6 @@ func (x *FetchExtensionsAndStoreCache) ProcessExtensions(
}
} else if tag, exists := tags.FindByKey(zconstants.TraceSource); exists && tag.VStr == zconstants.TraceSourceAudit {
for extId, ext := range extensions {
ext := ext

objectRef, ok := objectRefFromTags(tags)
if !ok {
return nil, fmt.Errorf("expected object tags in traceSource=audit spans")
Expand All @@ -142,8 +136,6 @@ func (x *FetchExtensionsAndStoreCache) ProcessExtensions(

fullSem := semaphore.NewUnbounded()
for extId := range extensionSemaphores {
extId := extId

fullSem.Schedule(func(ctx context.Context) (semaphore.Publish, error) {
semRunCtx, cancelFunc := context.WithTimeout(ctx, extensions[extId].TotalTimeout())
defer cancelFunc()
Expand Down
1 change: 1 addition & 0 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ type logrusSink struct{ delegate logrus.FieldLogger }

func (s logrusSink) Init(info logr.RuntimeInfo) {}

// #nosec G115 -- log levels are all small values.
func (s logrusSink) Enabled(level int) bool { return klog.V(klog.Level(level)).Enabled() }

func kvToLogr(keysAndValues []any) logrus.Fields {
Expand Down
2 changes: 0 additions & 2 deletions pkg/k8s/multileader/elector.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ func configureCallbacks(configs []*leaderelection.LeaderElectionConfig) <-chan e
ch := make(chan event, 1)

for i := range configs {
i := i

configs[i].Callbacks.OnStartedLeading = func(ctx context.Context) {
// only the first event needs to get sent
// other goroutines should exit immediately to avoid leak
Expand Down
2 changes: 0 additions & 2 deletions pkg/manager/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ func Ptr[CompTy any](obj CompTy) ComponentFactory {
var populate func(structTy reflect.Type, structValue reflect.Value)
populate = func(structTy reflect.Type, structValue reflect.Value) {
for i := 0; i < structTy.NumField(); i++ {
i := i

field := structTy.Field(i)
if field.IsExported() && !field.Anonymous && structValue.Field(i).IsZero() {
if _, recurse := field.Tag.Lookup("managerRecurse"); recurse {
Expand Down

0 comments on commit 0917028

Please sign in to comment.