Skip to content

Commit 8d67668

Browse files
committed
[chore] Upgrade golangci and fix lint issues
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 23306ea commit 8d67668

File tree

29 files changed

+148
-189
lines changed

29 files changed

+148
-189
lines changed

exporter/alibabacloudlogserviceexporter/metricsdata_to_logservice.go

-7
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,6 @@ func newMetricLogFromRaw(
139139
}
140140
}
141141

142-
func min(l, r int) int {
143-
if l < r {
144-
return l
145-
}
146-
return r
147-
}
148-
149142
func resourceToMetricLabels(labels *KeyValues, resource pcommon.Resource) {
150143
attrs := resource.Attributes()
151144
attrs.Range(func(k string, v pcommon.Value) bool {

exporter/awsemfexporter/metric_translator_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,6 @@ func stringSlicesEqual(expected, actual []string) bool {
120120
return true
121121
}
122122

123-
func min(i, j int) int {
124-
if i < j {
125-
return i
126-
}
127-
return j
128-
}
129-
130123
type dimensionality [][]string
131124

132125
func (d dimensionality) Len() int {

exporter/googlecloudpubsubexporter/watermark.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ type collector struct {
3535
func (c *collector) earliest(timestamp pcommon.Timestamp) bool {
3636
t := timestamp.AsTime()
3737
if t.Before(c.calculatedTime) {
38-
min := c.processingTime.Add(-c.allowedDrift)
39-
if t.Before(min) {
40-
c.calculatedTime = min
38+
minTime := c.processingTime.Add(-c.allowedDrift)
39+
if t.Before(minTime) {
40+
c.calculatedTime = minTime
4141
return true
4242
}
4343
c.calculatedTime = t

exporter/mezmoexporter/utils.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
package mezmoexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/mezmoexporter"
55

66
// truncateString Truncates the given string to a maximum length provided by max.
7-
func truncateString(s string, max int) string {
8-
if len(s) < max {
7+
func truncateString(s string, maxLen int) string {
8+
if len(s) < maxLen {
99
return s
1010
}
1111

12-
return s[:max]
12+
return s[:maxLen]
1313
}

exporter/signalfxexporter/internal/apm/correlations/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ func (cc *Client) Correlate(cor *Correlation, cb CorrelateCB) {
191191
cor.Logger(cc.log).WithFields(log.Fields{"method": http.MethodPut}).Info("Updated dimension")
192192
}
193193
case http.StatusTeapot:
194-
max := &ErrMaxEntries{}
195-
err = json.Unmarshal(body, max)
194+
maxEntry := &ErrMaxEntries{}
195+
err = json.Unmarshal(body, maxEntry)
196196
if err == nil {
197-
err = max
197+
err = maxEntry
198198
}
199199
}
200200
if err != nil {

exporter/signalfxexporter/internal/apm/tracetracker/cache.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ func (t *TimeoutCache) IsFull() bool {
5252
return false
5353
}
5454

55-
func (t *TimeoutCache) SetMaxSize(max int64, now time.Time) {
55+
func (t *TimeoutCache) SetMaxSize(maxSize int64, now time.Time) {
5656
t.Lock()
5757
defer t.Unlock()
58-
t.maxSize = max
58+
t.maxSize = maxSize
5959
t.maxSizeExpiryTS = now.Add(time.Hour * 1)
6060
}
6161

exporter/signalfxexporter/internal/apm/tracetracker/tracker.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func (a *ActiveServiceTracker) processEnvironment(res pcommon.Resource, now time
167167
a.hostEnvironmentCache.UpdateOrCreate(&CacheKey{value: environment}, now)
168168
}
169169
// nolint:errorlint
170-
if max, ok := err.(*correlations.ErrMaxEntries); ok && max.MaxEntries > 0 {
171-
a.hostEnvironmentCache.SetMaxSize(max.MaxEntries, now)
170+
if maxEntry, ok := err.(*correlations.ErrMaxEntries); ok && maxEntry.MaxEntries > 0 {
171+
a.hostEnvironmentCache.SetMaxSize(maxEntry.MaxEntries, now)
172172
}
173173
})
174174
}
@@ -226,8 +226,8 @@ func (a *ActiveServiceTracker) processService(res pcommon.Resource, now time.Tim
226226
a.hostServiceCache.UpdateOrCreate(&CacheKey{value: service}, now)
227227
}
228228
// nolint:errorlint
229-
if max, ok := err.(*correlations.ErrMaxEntries); ok && max.MaxEntries > 0 {
230-
a.hostServiceCache.SetMaxSize(max.MaxEntries, now)
229+
if maxEntry, ok := err.(*correlations.ErrMaxEntries); ok && maxEntry.MaxEntries > 0 {
230+
a.hostServiceCache.SetMaxSize(maxEntry.MaxEntries, now)
231231
}
232232
})
233233
}

extension/observer/ecsobserver/fetcher.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (f *taskFetcher) attachContainerInstance(ctx context.Context, tasks []*task
260260

261261
// DescribeContainerInstance size limit is 100, do it in batch.
262262
for i := 0; i < len(instanceList); i += describeContainerInstanceLimit {
263-
end := minInt(i+describeContainerInstanceLimit, len(instanceList))
263+
end := min(i+describeContainerInstanceLimit, len(instanceList))
264264
if err := f.describeContainerInstances(ctx, instanceList[i:end], ciToEC2); err != nil {
265265
return fmt.Errorf("describe container instanced failed offset=%d: %w", i, err)
266266
}
@@ -365,7 +365,7 @@ func (f *taskFetcher) getAllServices(ctx context.Context) ([]*ecs.Service, error
365365
// DescribeServices size limit is 10 so we need to do paging on client side.
366366
var services []*ecs.Service
367367
for i := 0; i < len(servicesToDescribe); i += describeServiceLimit {
368-
end := minInt(i+describeServiceLimit, len(servicesToDescribe))
368+
end := min(i+describeServiceLimit, len(servicesToDescribe))
369369
desc := &ecs.DescribeServicesInput{
370370
Cluster: cluster,
371371
Services: servicesToDescribe[i:end],
@@ -424,12 +424,3 @@ func sortStringPointers(ps []*string) {
424424
ps[i] = aws.String(ss[i])
425425
}
426426
}
427-
428-
func minInt(a, b int) int {
429-
if a < b {
430-
return a
431-
}
432-
return b
433-
}
434-
435-
// Util End

extension/observer/ecsobserver/internal/ecsmock/service.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func getPage(p pageInput) (*pageOutput, error) {
437437
return nil, fmt.Errorf("invalid next token %q: %w", token, err)
438438
}
439439
}
440-
end := minInt(p.size, start+p.limit)
440+
end := min(p.size, start+p.limit)
441441
var newNextToken *string
442442
if end < p.size {
443443
newNextToken = aws.String(strconv.Itoa(end))
@@ -462,12 +462,3 @@ func getArns(items any, arnGetter func(i int) *string) []*string {
462462
}
463463
return arns
464464
}
465-
466-
// 'generic' End
467-
468-
func minInt(a, b int) int {
469-
if a < b {
470-
return a
471-
}
472-
return b
473-
}

extension/solarwindsapmsettingsextension/config_test.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package solarwindsapmsettingsextension
55

66
import (
7-
"os"
87
"path/filepath"
98
"testing"
109
"time"
@@ -275,21 +274,26 @@ func TestLoadConfig(t *testing.T) {
275274
}
276275
}
277276

278-
func TestResolveServiceNameBestEffort(t *testing.T) {
277+
func TestResolveServiceNameBestEffortNoEnv(t *testing.T) {
279278
// Without any environment variables
280279
require.Empty(t, resolveServiceNameBestEffort())
281-
// With OTEL_SERVICE_NAME only
282-
require.NoError(t, os.Setenv("OTEL_SERVICE_NAME", "otel_ser1"))
280+
}
281+
282+
// With OTEL_SERVICE_NAME only
283+
func TestResolveServiceNameBestEffortOnlyOtelService(t *testing.T) {
284+
t.Setenv("OTEL_SERVICE_NAME", "otel_ser1")
283285
require.Equal(t, "otel_ser1", resolveServiceNameBestEffort())
284-
require.NoError(t, os.Unsetenv("OTEL_SERVICE_NAME"))
285-
// With AWS_LAMBDA_FUNCTION_NAME only
286-
require.NoError(t, os.Setenv("AWS_LAMBDA_FUNCTION_NAME", "lambda"))
286+
}
287+
288+
// With AWS_LAMBDA_FUNCTION_NAME only
289+
func TestResolveServiceNameBestEffortOnlyAwsLambda(t *testing.T) {
290+
t.Setenv("AWS_LAMBDA_FUNCTION_NAME", "lambda")
287291
require.Equal(t, "lambda", resolveServiceNameBestEffort())
288-
require.NoError(t, os.Unsetenv("AWS_LAMBDA_FUNCTION_NAME"))
289-
// With both
290-
require.NoError(t, os.Setenv("OTEL_SERVICE_NAME", "otel_ser1"))
291-
require.NoError(t, os.Setenv("AWS_LAMBDA_FUNCTION_NAME", "lambda"))
292+
}
293+
294+
// With both
295+
func TestResolveServiceNameBestEffortBoth(t *testing.T) {
296+
t.Setenv("OTEL_SERVICE_NAME", "otel_ser1")
297+
t.Setenv("AWS_LAMBDA_FUNCTION_NAME", "lambda")
292298
require.Equal(t, "otel_ser1", resolveServiceNameBestEffort())
293-
require.NoError(t, os.Unsetenv("AWS_LAMBDA_FUNCTION_NAME"))
294-
require.NoError(t, os.Unsetenv("OTEL_SERVICE_NAME"))
295299
}

internal/aws/cwlogs/pusher_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,29 @@ func TestValidateLogEventFailed(t *testing.T) {
5454

5555
// eventBatch Tests
5656
func TestLogEventBatch_timestampWithin24Hours(t *testing.T) {
57-
min := time.Date(2017, time.June, 20, 23, 38, 0, 0, time.Local)
58-
max := min.Add(23 * time.Hour)
57+
minDate := time.Date(2017, time.June, 20, 23, 38, 0, 0, time.Local)
58+
maxDate := minDate.Add(23 * time.Hour)
5959
logEventBatch := &eventBatch{
60-
maxTimestampMs: max.UnixNano() / 1e6,
61-
minTimestampMs: min.UnixNano() / 1e6,
60+
maxTimestampMs: maxDate.UnixNano() / 1e6,
61+
minTimestampMs: minDate.UnixNano() / 1e6,
6262
}
6363

6464
// less than the min
65-
target := min.Add(-1 * time.Hour)
65+
target := minDate.Add(-1 * time.Hour)
6666
assert.True(t, logEventBatch.isActive(aws.Int64(target.UnixNano()/1e6)))
6767

6868
target = target.Add(-1 * time.Millisecond)
6969
assert.False(t, logEventBatch.isActive(aws.Int64(target.UnixNano()/1e6)))
7070

7171
// more than the max
72-
target = max.Add(1 * time.Hour)
72+
target = maxDate.Add(1 * time.Hour)
7373
assert.True(t, logEventBatch.isActive(aws.Int64(target.UnixNano()/1e6)))
7474

7575
target = target.Add(1 * time.Millisecond)
7676
assert.False(t, logEventBatch.isActive(aws.Int64(target.UnixNano()/1e6)))
7777

7878
// in between min and max
79-
target = min.Add(2 * time.Hour)
79+
target = minDate.Add(2 * time.Hour)
8080
assert.True(t, logEventBatch.isActive(aws.Int64(target.UnixNano()/1e6)))
8181
}
8282

internal/exp/metrics/staleness/staleness.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type Staleness[T any] struct {
3131
pq PriorityQueue
3232
}
3333

34-
func NewStaleness[T any](max time.Duration, items streams.Map[T]) *Staleness[T] {
34+
func NewStaleness[T any](maxDuration time.Duration, items streams.Map[T]) *Staleness[T] {
3535
return &Staleness[T]{
36-
Max: max,
36+
Max: maxDuration,
3737

3838
items: items,
3939
pq: NewPriorityQueue(),
@@ -117,13 +117,13 @@ func (stale Tracker) Refresh(ts time.Time, ids ...identity.Stream) {
117117
}
118118
}
119119

120-
func (stale Tracker) Collect(max time.Duration) []identity.Stream {
120+
func (stale Tracker) Collect(maxDuration time.Duration) []identity.Stream {
121121
now := NowFunc()
122122

123123
var ids []identity.Stream
124124
for stale.pq.Len() > 0 {
125125
_, ts := stale.pq.Peek()
126-
if now.Sub(ts) < max {
126+
if now.Sub(ts) < maxDuration {
127127
break
128128
}
129129
id, _ := stale.pq.Pop()

internal/exp/metrics/staleness/staleness_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import (
1414
)
1515

1616
func TestStaleness(t *testing.T) {
17-
max := 1 * time.Second
1817
stalenessMap := NewStaleness[int](
19-
max,
18+
1*time.Second,
2019
make(streams.HashMap[int]),
2120
)
2221

0 commit comments

Comments
 (0)