Skip to content

Commit

Permalink
fix(deps): update module github.com/golangci/golangci-lint to v1.60.2 (
Browse files Browse the repository at this point in the history
…#6008)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint)
| `v1.60.1` -> `v1.60.2` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fgolangci%2fgolangci-lint/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fgolangci%2fgolangci-lint/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fgolangci%2fgolangci-lint/v1.60.1/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fgolangci%2fgolangci-lint/v1.60.1/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>golangci/golangci-lint
(github.com/golangci/golangci-lint)</summary>

###
[`v1.60.2`](https://github.com/golangci/golangci-lint/compare/v1.60.1...v1.60.2)

[Compare
Source](https://github.com/golangci/golangci-lint/compare/v1.60.1...v1.60.2)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-go-contrib).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNi4xIiwidXBkYXRlZEluVmVyIjoiMzguMjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiU2tpcCBDaGFuZ2Vsb2ciLCJkZXBlbmRlbmNpZXMiXX0=-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
  • Loading branch information
4 people committed Aug 23, 2024
1 parent 21e0a4d commit fd28620
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 92 deletions.
7 changes: 6 additions & 1 deletion bridges/otelslog/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,12 @@ func convertValue(v slog.Value) log.Value {
case slog.KindTime:
return log.Int64Value(v.Time().UnixNano())
case slog.KindUint64:
return log.Int64Value(int64(v.Uint64()))
const maxInt64 = ^uint64(0) >> 1
u := v.Uint64()
if u > maxInt64 {
return log.Float64Value(float64(u))
}
return log.Int64Value(int64(u)) // nolint:gosec // Overflow checked above.
case slog.KindGroup:
g := v.Group()
buf := newKVBuffer(len(g))
Expand Down
8 changes: 5 additions & 3 deletions bridges/otelzap/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (m *objectEncoder) AddUint16(k string, v uint16) {
}

func (m *objectEncoder) AddUint8(k string, v uint8) {
m.AddInt64(k, int64(v))
m.AddInt64(k, int64(v)) // nolint: gosec // https://github.com/securego/gosec/issues/1185
}

func (m *objectEncoder) AddUintptr(k string, v uintptr) {
Expand All @@ -187,7 +187,7 @@ func assignUintValue(v uint64) log.Value {
if v > maxInt64 {
return log.Float64Value(float64(v))
}
return log.Int64Value(int64(v))
return log.Int64Value(int64(v)) // nolint:gosec // Overflow checked above.
}

// arrayEncoder implements [zapcore.ArrayEncoder].
Expand Down Expand Up @@ -272,8 +272,10 @@ func (a *arrayEncoder) AppendTime(v time.Time) { a.AppendInt64(v.UnixNan
func (a *arrayEncoder) AppendUint(v uint) { a.AppendUint64(uint64(v)) }
func (a *arrayEncoder) AppendUint32(v uint32) { a.AppendInt64(int64(v)) }
func (a *arrayEncoder) AppendUint16(v uint16) { a.AppendInt64(int64(v)) }
func (a *arrayEncoder) AppendUint8(v uint8) { a.AppendInt64(int64(v)) }
func (a *arrayEncoder) AppendUintptr(v uintptr) { a.AppendUint64(uint64(v)) }
func (a *arrayEncoder) AppendUint8(v uint8) {
a.AppendInt64(int64(v)) // nolint: gosec // https://github.com/securego/gosec/issues/1185
}

func convertValue(v interface{}) log.Value {
switch v := v.(type) {
Expand Down
4 changes: 2 additions & 2 deletions bridges/prometheus/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ func convertExponentialBuckets(bucketSpans []*dto.BucketSpan, deltas []int64) me
initialOffset := bucketSpans[0].GetOffset() - 1
// We will have one bucket count for each delta, and zeros for the offsets
// after the initial offset.
lenCounts := int32(len(deltas))
lenCounts := len(deltas)
for i, bs := range bucketSpans {
if i != 0 {
lenCounts += bs.GetOffset()
lenCounts += int(bs.GetOffset())
}
}
counts := make([]uint64, lenCounts)
Expand Down
16 changes: 12 additions & 4 deletions config/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -358,8 +359,8 @@ func aggregation(aggr *ViewStreamAggregation) sdkmetric.Aggregation {

if aggr.Base2ExponentialBucketHistogram != nil {
return sdkmetric.AggregationBase2ExponentialHistogram{
MaxSize: int32(intOrZero(aggr.Base2ExponentialBucketHistogram.MaxSize)),
MaxScale: int32(intOrZero(aggr.Base2ExponentialBucketHistogram.MaxScale)),
MaxSize: int32OrZero(aggr.Base2ExponentialBucketHistogram.MaxSize),
MaxScale: int32OrZero(aggr.Base2ExponentialBucketHistogram.MaxScale),
// Need to negate because config has the positive action RecordMinMax.
NoMinMax: !boolOrFalse(aggr.Base2ExponentialBucketHistogram.RecordMinMax),
}
Expand Down Expand Up @@ -426,11 +427,18 @@ func boolOrFalse(pBool *bool) bool {
return *pBool
}

func intOrZero(pInt *int) int {
func int32OrZero(pInt *int) int32 {
if pInt == nil {
return 0
}
return *pInt
i := *pInt
if i > math.MaxInt32 {
return math.MaxInt32
}
if i < math.MinInt32 {
return math.MinInt32
}
return int32(i) // nolint: gosec // Overflow and underflow checked above.
}

func strOrEmpty(pStr *string) string {
Expand Down
2 changes: 1 addition & 1 deletion config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func keyVal(k string, v any) attribute.KeyValue {
case int8:
return attribute.Int64(k, int64(val))
case uint8:
return attribute.Int64(k, int64(val))
return attribute.Int64(k, int64(val)) // nolint: gosec // https://github.com/securego/gosec/issues/1185
case int16:
return attribute.Int64(k, int64(val))
case uint16:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Bitsize checked to be 16 above.
}

func netProtocol(proto string) (name string, version string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Bitsize checked to be 16 above.
}

func netProtocol(proto string) (name string, version string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Bitsize checked to be 16 above.
}

func netProtocol(proto string) (name string, version string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Bitsize checked to be 16 above.
}

func netProtocol(proto string) (name string, version string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ import (
)

var (
reqSizes = []int{27182, 8, 1828, 45904}
respSizes = []int{31415, 9, 2653, 58979}
largeReqSize = 271828
largeRespSize = 314159
initialMetadataKey = "x-grpc-test-echo-initial"
trailingMetadataKey = "x-grpc-test-echo-trailing-bin"
reqSizes = []int32{27182, 8, 1828, 45904}
respSizes = []int32{31415, 9, 2653, 58979}
largeReqSize = 271828
largeRespSize int32 = 314159
initialMetadataKey = "x-grpc-test-echo-initial"
trailingMetadataKey = "x-grpc-test-echo-trailing-bin"

logger = grpclog.Component("interop")
)
Expand Down Expand Up @@ -87,7 +87,7 @@ func DoLargeUnaryCall(ctx context.Context, tc testpb.TestServiceClient, args ...
pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE,
ResponseSize: int32(largeRespSize),
ResponseSize: largeRespSize,
Payload: pl,
}
reply, err := tc.UnaryCall(ctx, req, args...)
Expand All @@ -96,7 +96,7 @@ func DoLargeUnaryCall(ctx context.Context, tc testpb.TestServiceClient, args ...
}
t := reply.GetPayload().GetType()
s := len(reply.GetPayload().GetBody())
if t != testpb.PayloadType_COMPRESSABLE || s != largeRespSize {
if t != testpb.PayloadType_COMPRESSABLE || s != int(largeRespSize) {
logger.Fatalf("Got the reply with type %d len %d; want %d, %d", t, s, testpb.PayloadType_COMPRESSABLE, largeRespSize)
}
}
Expand All @@ -107,9 +107,9 @@ func DoClientStreaming(ctx context.Context, tc testpb.TestServiceClient, args ..
if err != nil {
logger.Fatalf("%v.StreamingInputCall(_) = _, %v", tc, err)
}
var sum int
var sum int32
for _, s := range reqSizes {
pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, s)
pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, int(s))
req := &testpb.StreamingInputCallRequest{
Payload: pl,
}
Expand All @@ -122,7 +122,7 @@ func DoClientStreaming(ctx context.Context, tc testpb.TestServiceClient, args ..
if err != nil {
logger.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, nil)
}
if reply.GetAggregatedPayloadSize() != int32(sum) {
if reply.GetAggregatedPayloadSize() != sum {
logger.Fatalf("%v.CloseAndRecv().GetAggregatePayloadSize() = %v; want %v", stream, reply.GetAggregatedPayloadSize(), sum)
}
}
Expand All @@ -132,7 +132,7 @@ func DoServerStreaming(ctx context.Context, tc testpb.TestServiceClient, args ..
respParam := make([]*testpb.ResponseParameters, len(respSizes))
for i, s := range respSizes {
respParam[i] = &testpb.ResponseParameters{
Size: int32(s),
Size: s,
}
}
req := &testpb.StreamingOutputCallRequest{
Expand All @@ -157,7 +157,7 @@ func DoServerStreaming(ctx context.Context, tc testpb.TestServiceClient, args ..
logger.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
}
size := len(reply.GetPayload().GetBody())
if size != respSizes[index] {
if size != int(respSizes[index]) {
logger.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
}
index++
Expand All @@ -181,10 +181,10 @@ func DoPingPong(ctx context.Context, tc testpb.TestServiceClient, args ...grpc.C
for index < len(reqSizes) {
respParam := []*testpb.ResponseParameters{
{
Size: int32(respSizes[index]),
Size: respSizes[index],
},
}
pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, reqSizes[index])
pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, int(reqSizes[index]))
req := &testpb.StreamingOutputCallRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE,
ResponseParameters: respParam,
Expand All @@ -202,7 +202,7 @@ func DoPingPong(ctx context.Context, tc testpb.TestServiceClient, args ...grpc.C
logger.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
}
size := len(reply.GetPayload().GetBody())
if size != respSizes[index] {
if size != int(respSizes[index]) {
logger.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
}
index++
Expand Down Expand Up @@ -304,19 +304,21 @@ func (s *testServer) StreamingOutputCall(args *testpb.StreamingOutputCallRequest
}

func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInputCallServer) error {
var sum int
var sum int32
for {
in, err := stream.Recv()
if errors.Is(err, io.EOF) {
return stream.SendAndClose(&testpb.StreamingInputCallResponse{
AggregatedPayloadSize: int32(sum),
AggregatedPayloadSize: sum,
})
}
if err != nil {
return err
}
p := in.GetPayload().GetBody()
sum += len(p)
n := len(in.GetPayload().GetBody())
// This could overflow, but given this is a test and the negative value
// should be detectable this should be good enough.
sum += int32(n) // nolint: gosec
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Bitsize checked to be 16 above.
}

func netProtocol(proto string) (name string, version string) {
Expand Down
22 changes: 17 additions & 5 deletions instrumentation/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package host // import "go.opentelemetry.io/contrib/instrumentation/host"
import (
"context"
"fmt"
"math"
"os"
"sync"

Expand Down Expand Up @@ -118,7 +119,11 @@ func (h *host) register() error {
lock sync.Mutex
)

proc, err := process.NewProcess(int32(os.Getpid()))
pid := os.Getpid()
if pid > math.MaxInt32 || pid < math.MinInt32 {
return fmt.Errorf("invalid process ID: %d", pid)
}
proc, err := process.NewProcess(int32(pid)) // nolint: gosec // Overflow checked above.
if err != nil {
return fmt.Errorf("could not find this process: %w", err)
}
Expand Down Expand Up @@ -246,9 +251,9 @@ func (h *host) register() error {

// Host memory usage
opt = metric.WithAttributeSet(AttributeMemoryUsed)
o.ObserveInt64(hostMemoryUsage, int64(vmStats.Used), opt)
o.ObserveInt64(hostMemoryUsage, clampInt64(vmStats.Used), opt)
opt = metric.WithAttributeSet(AttributeMemoryAvailable)
o.ObserveInt64(hostMemoryUsage, int64(vmStats.Available), opt)
o.ObserveInt64(hostMemoryUsage, clampInt64(vmStats.Available), opt)

// Host memory utilization
opt = metric.WithAttributeSet(AttributeMemoryUsed)
Expand All @@ -262,9 +267,9 @@ func (h *host) register() error {
// interface, with similar questions to those posed
// about per-CPU measurements above.
opt = metric.WithAttributeSet(AttributeNetworkTransmit)
o.ObserveInt64(networkIOUsage, int64(ioStats[0].BytesSent), opt)
o.ObserveInt64(networkIOUsage, clampInt64(ioStats[0].BytesSent), opt)
opt = metric.WithAttributeSet(AttributeNetworkReceive)
o.ObserveInt64(networkIOUsage, int64(ioStats[0].BytesRecv), opt)
o.ObserveInt64(networkIOUsage, clampInt64(ioStats[0].BytesRecv), opt)

return nil
},
Expand All @@ -280,3 +285,10 @@ func (h *host) register() error {

return nil
}

func clampInt64(v uint64) int64 {
if v > math.MaxInt64 {
return math.MaxInt64
}
return int64(v) // nolint: gosec // Overflow checked.
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Bitsize checked to be 16 above.
}

func netProtocol(proto string) (name string, version string) {
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/net/http/otelhttp/internal/semconv/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Byte size checked 16 above.
}

func requiredHTTPPort(https bool, port int) int { // nolint:revive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func splitHostPort(hostport string) (host string, port int) {
if err != nil {
return
}
return host, int(p)
return host, int(p) // nolint: gosec // Bitsize checked to be 16 above.
}

func netProtocol(proto string) (name string, version string) {
Expand Down
Loading

0 comments on commit fd28620

Please sign in to comment.