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

Fix lint issues for golangci-lint 1.62.0 #5967

Merged
merged 2 commits into from
Nov 13, 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 attribute/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestJSONValue(t *testing.T) {

data, err := json.Marshal(kvs)
require.NoError(t, err)
require.Equal(t,
require.JSONEq(t,
`[{"Key":"A","Value":{"Type":"STRING","Value":"B"}},{"Key":"C","Value":{"Type":"INT64","Value":1}}]`,
string(data))
}
Expand Down
4 changes: 2 additions & 2 deletions baggage/baggage.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,15 @@ func parseMember(member string) (Member, error) {
}

// replaceInvalidUTF8Sequences replaces invalid UTF-8 sequences with '�'.
func replaceInvalidUTF8Sequences(cap int, unescapeVal string) string {
func replaceInvalidUTF8Sequences(c int, unescapeVal string) string {
if utf8.ValidString(unescapeVal) {
return unescapeVal
}
// W3C baggage spec:
// https://github.com/w3c/baggage/blob/8c215efbeebd3fa4b1aceb937a747e56444f22f3/baggage/HTTP_HEADER_FORMAT.md?plain=1#L69

var b strings.Builder
b.Grow(cap)
b.Grow(c)
for i := 0; i < len(unescapeVal); {
r, size := utf8.DecodeRuneInString(unescapeVal[i:])
if r == utf8.RuneError && size == 1 {
Expand Down
2 changes: 1 addition & 1 deletion baggage/baggage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func TestBaggageParseValue(t *testing.T) {
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
b, err := Parse(tc.in)
assert.Empty(t, err)
assert.NoError(t, err)

val := b.Members()[0].Value()

Expand Down
7 changes: 0 additions & 7 deletions bridge/opentracing/mix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,6 @@ func simpleSpanIDs(count int) []trace.SpanID {
return base[:count]
}

func min(a, b int) int {
if a > b {
return b
}
return a
}

func runOtelOTOtel(t *testing.T, ctx context.Context, name string, callback func(*testing.T, context.Context) context.Context) {
tr := otel.Tracer("")
ctx, span := tr.Start(ctx, fmt.Sprintf("%s_Otel_OTOtel", name), trace.WithSpanKind(trace.SpanKindClient))
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/otlplog/otlploghttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ func newWeakCertificate() (tls.Certificate, error) {
}
notBefore := time.Now()
notAfter := notBefore.Add(time.Hour)
max := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, max)
m := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, m)
if err != nil {
return tls.Certificate{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var (
Value: &cpb.AnyValue_StringValue{StringValue: "v0.1.0"},
}}

min, max, sum = 2.0, 4.0, 90.0
hdp = []*mpb.HistogramDataPoint{
mi, ma, sum = 2.0, 4.0, 90.0
hdp = []*mpb.HistogramDataPoint{
{
Attributes: []*cpb.KeyValue{kvAlice},
StartTimeUnixNano: uint64(start.UnixNano()),
Expand All @@ -53,8 +53,8 @@ var (
Sum: &sum,
ExplicitBounds: []float64{1, 5},
BucketCounts: []uint64{0, 30, 0},
Min: &min,
Max: &max,
Min: &mi,
Max: &ma,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ func weakCertificate() (tls.Certificate, error) {
}
notBefore := time.Now()
notAfter := notBefore.Add(time.Hour)
max := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, max)
m := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, m)
if err != nil {
return tls.Certificate{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var (
Value: &cpb.AnyValue_StringValue{StringValue: "v0.1.0"},
}}

min, max, sum = 2.0, 4.0, 90.0
hdp = []*mpb.HistogramDataPoint{
mi, ma, sum = 2.0, 4.0, 90.0
hdp = []*mpb.HistogramDataPoint{
{
Attributes: []*cpb.KeyValue{kvAlice},
StartTimeUnixNano: uint64(start.UnixNano()),
Expand All @@ -53,8 +53,8 @@ var (
Sum: &sum,
ExplicitBounds: []float64{1, 5},
BucketCounts: []uint64{0, 30, 0},
Min: &min,
Max: &max,
Min: &mi,
Max: &ma,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ func weakCertificate() (tls.Certificate, error) {
}
notBefore := time.Now()
notAfter := notBefore.Add(time.Hour)
max := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, max)
m := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, m)
if err != nil {
return tls.Certificate{}, err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/shared/otlp/otlpmetric/otest/client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var (
Value: &cpb.AnyValue_StringValue{StringValue: "v0.1.0"},
}}

min, max, sum = 2.0, 4.0, 90.0
hdp = []*mpb.HistogramDataPoint{
mi, ma, sum = 2.0, 4.0, 90.0
hdp = []*mpb.HistogramDataPoint{
{
Attributes: []*cpb.KeyValue{kvAlice},
StartTimeUnixNano: uint64(start.UnixNano()),
Expand All @@ -53,8 +53,8 @@ var (
Sum: &sum,
ExplicitBounds: []float64{1, 5},
BucketCounts: []uint64{0, 30, 0},
Min: &min,
Max: &max,
Min: &mi,
Max: &ma,
},
}

Expand Down
4 changes: 2 additions & 2 deletions internal/shared/otlp/otlpmetric/otest/collector.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ func weakCertificate() (tls.Certificate, error) {
}
notBefore := time.Now()
notAfter := notBefore.Add(time.Hour)
max := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, max)
m := new(big.Int).Lsh(big.NewInt(1), 128)
sn, err := rand.Int(rand.Reader, m)
if err != nil {
return tls.Certificate{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func ExampleMeter_observableUpDownCounter() {
// The function registers asynchronous metrics for the provided db.
// Make sure to unregister metric.Registration before closing the provided db.
_ = func(db *sql.DB, meter metric.Meter, poolName string) (metric.Registration, error) {
max, err := meter.Int64ObservableUpDownCounter(
m, err := meter.Int64ObservableUpDownCounter(
"db.client.connections.max",
metric.WithDescription("The maximum number of open connections allowed."),
metric.WithUnit("{connection}"),
Expand All @@ -253,11 +253,11 @@ func ExampleMeter_observableUpDownCounter() {
reg, err := meter.RegisterCallback(
func(_ context.Context, o metric.Observer) error {
stats := db.Stats()
o.ObserveInt64(max, int64(stats.MaxOpenConnections))
o.ObserveInt64(m, int64(stats.MaxOpenConnections))
o.ObserveInt64(waitTime, int64(stats.WaitDuration))
return nil
},
max,
m,
waitTime,
)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions sdk/metric/internal/aggregate/exponential_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ type expoHistogramDataPoint[N int64 | float64] struct {

func newExpoHistogramDataPoint[N int64 | float64](attrs attribute.Set, maxSize int, maxScale int32, noMinMax, noSum bool) *expoHistogramDataPoint[N] {
f := math.MaxFloat64
max := N(f) // if N is int64, max will overflow to -9223372036854775808
min := N(-f)
ma := N(f) // if N is int64, max will overflow to -9223372036854775808
mi := N(-f)
if N(maxInt64) > N(f) {
max = N(maxInt64)
min = N(minInt64)
ma = N(maxInt64)
mi = N(minInt64)
}
return &expoHistogramDataPoint[N]{
attrs: attrs,
min: max,
max: min,
min: ma,
max: mi,
maxSize: maxSize,
noMinMax: noMinMax,
noSum: noSum,
Expand Down
6 changes: 3 additions & 3 deletions sdk/metric/internal/aggregate/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ func TestBucketsBin(t *testing.T) {
func testBucketsBin[N int64 | float64]() func(t *testing.T) {
return func(t *testing.T) {
b := newBuckets[N](alice, 3)
assertB := func(counts []uint64, count uint64, min, max N) {
assertB := func(counts []uint64, count uint64, mi, ma N) {
t.Helper()
assert.Equal(t, counts, b.counts)
assert.Equal(t, count, b.count)
assert.Equal(t, min, b.min)
assert.Equal(t, max, b.max)
assert.Equal(t, mi, b.min)
assert.Equal(t, ma, b.max)
}

assertB([]uint64{0, 0, 0}, 0, 0, 0)
Expand Down
2 changes: 1 addition & 1 deletion sdk/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestMarshalJSON(t *testing.T) {
r := resource.NewSchemaless(attribute.Int64("A", 1), attribute.String("C", "D"))
data, err := json.Marshal(r)
require.NoError(t, err)
require.Equal(t,
require.JSONEq(t,
`[{"Key":"A","Value":{"Type":"INT64","Value":1}},{"Key":"C","Value":{"Type":"STRING","Value":"D"}}]`,
string(data))
}
Expand Down
Loading