Skip to content

Commit cb5c3f4

Browse files
authored
[chore]: fix staticcheck exclusions (#12792)
#### Description Fixes staticcheck rules which where disabled with golangci-lint v2 upgrade Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 5b8d569 commit cb5c3f4

File tree

38 files changed

+88
-121
lines changed

38 files changed

+88
-121
lines changed

.golangci.yml

+3-25
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ formatters:
33
- gofumpt
44
- goimports
55

6-
exclusions:
7-
# which dirs to skip: issues from them won't be reported;
8-
# can use regexp here: generated.*, regexp is applied on full path;
9-
# default value is empty list, but default dirs are skipped independently
10-
# from this option's value (see exclude-dirs-use-default).
11-
paths:
12-
- third_party
13-
146
settings:
157
gofmt:
168
# simplify code: gofmt with `-s` option, true by default
@@ -52,13 +44,6 @@ linters:
5244
- whitespace
5345

5446
exclusions:
55-
# which dirs to skip: issues from them won't be reported;
56-
# can use regexp here: generated.*, regexp is applied on full path;
57-
# default value is empty list, but default dirs are skipped independently
58-
# from this option's value (see exclude-dirs-use-default).
59-
paths:
60-
- third_party
61-
6247
presets:
6348
- std-error-handling
6449

@@ -195,16 +180,9 @@ linters:
195180
staticcheck:
196181
checks:
197182
- all
198-
- -QF1001 # FIXME
199-
- -QF1003 # FIXME
200-
- -QF1006 # FIXME
201-
- -QF1008 # FIXME
202-
- -ST1000 # FIXME
203-
- -ST1016 # FIXME
204-
- -ST1017 # FIXME
205-
- -ST1020 # FIXME
206-
- -ST1021 # FIXME
207-
- -ST1022 # FIXME
183+
- -ST1000
184+
- -ST1021
185+
- -ST1022
208186

209187
testifylint:
210188
disable:

cmd/mdatagen/internal/metric.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (mit MetricInputType) HasMetricInputType() bool {
172172
return mit.InputType != ""
173173
}
174174

175-
// Type returns name of the datapoint type.
175+
// String returns name of the datapoint type.
176176
func (mit MetricInputType) String() string {
177177
return mit.InputType
178178
}
@@ -210,7 +210,7 @@ func (mvt *MetricValueType) UnmarshalText(text []byte) error {
210210
return nil
211211
}
212212

213-
// Type returns name of the datapoint type.
213+
// String returns name of the datapoint type.
214214
func (mvt MetricValueType) String() string {
215215
return mvt.ValueType.String()
216216
}
@@ -258,7 +258,7 @@ func (d *Gauge) HasAggregated() bool {
258258
}
259259

260260
func (d *Gauge) Instrument() string {
261-
instrumentName := cases.Title(language.English).String(d.MetricValueType.BasicType())
261+
instrumentName := cases.Title(language.English).String(d.BasicType())
262262

263263
if d.Async {
264264
instrumentName += "Observable"
@@ -314,7 +314,7 @@ func (d *Sum) HasAggregated() bool {
314314
}
315315

316316
func (d *Sum) Instrument() string {
317-
instrumentName := cases.Title(language.English).String(d.MetricValueType.BasicType())
317+
instrumentName := cases.Title(language.English).String(d.BasicType())
318318

319319
if d.Async {
320320
instrumentName += "Observable"
@@ -354,7 +354,7 @@ func (d *Histogram) HasAggregated() bool {
354354
}
355355

356356
func (d *Histogram) Instrument() string {
357-
instrumentName := cases.Title(language.English).String(d.MetricValueType.BasicType())
357+
instrumentName := cases.Title(language.English).String(d.BasicType())
358358
return instrumentName + d.Type()
359359
}
360360

config/configgrpc/configgrpc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (gcs *ClientConfig) ToClientConn(
257257
if err != nil {
258258
return nil, err
259259
}
260-
//nolint:staticcheck //SA1019 see https://github.com/open-telemetry/opentelemetry-collector/pull/11575
260+
//nolint:staticcheck // SA1019 see https://github.com/open-telemetry/opentelemetry-collector/pull/11575
261261
return grpc.DialContext(ctx, gcs.sanitizedEndpoint(), grpcOpts...)
262262
}
263263

config/confighttp/internal/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
1111
)
1212

13-
// toServerOptions has options that change the behavior of the HTTP server
13+
// ToServerOptions has options that change the behavior of the HTTP server
1414
// returned by ServerConfig.ToServer().
1515
type ToServerOptions struct {
1616
ErrHandler func(w http.ResponseWriter, r *http.Request, errorMsg string, statusCode int)

confmap/confmap_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ func TestUnmarshaler(t *testing.T) {
500500
require.NoError(t, cfgMap.Unmarshal(tc))
501501
assert.Equal(t, "make sure this is only called directly", tc.Another)
502502
assert.Equal(t, "make sure this is called", tc.Next.String)
503-
assert.Equal(t, "make sure this is also called", tc.EmbeddedConfig.Some)
504-
assert.Equal(t, "this better be also called2", tc.EmbeddedConfig2.Some2)
503+
assert.Equal(t, "make sure this is also called", tc.Some)
504+
assert.Equal(t, "this better be also called2", tc.Some2)
505505
}
506506

507507
func TestEmbeddedUnmarshaler(t *testing.T) {
@@ -518,8 +518,8 @@ func TestEmbeddedUnmarshaler(t *testing.T) {
518518
require.NoError(t, cfgMap.Unmarshal(tc))
519519
assert.Equal(t, "make sure this", tc.Another)
520520
assert.Equal(t, "make sure this is called", tc.Next.String)
521-
assert.Equal(t, "make sure this is also called", tc.EmbeddedConfig.Some)
522-
assert.Equal(t, "this better be also called2", tc.EmbeddedConfig2.Some2)
521+
assert.Equal(t, "make sure this is also called", tc.Some)
522+
assert.Equal(t, "this better be also called2", tc.Some2)
523523
}
524524

525525
func TestEmbeddedUnmarshalerError(t *testing.T) {
@@ -808,8 +808,8 @@ func TestUnmarshalThroughEmbeddedStruct(t *testing.T) {
808808
cfg := &topLevel{}
809809
err := c.Unmarshal(cfg)
810810
require.NoError(t, err)
811-
require.Equal(t, "success", cfg.Cfg.embeddedStructWithUnmarshal.success)
812-
require.Equal(t, "bar", cfg.Cfg.embeddedStructWithUnmarshal.Foo)
811+
require.Equal(t, "success", cfg.Cfg.success)
812+
require.Equal(t, "bar", cfg.Cfg.Foo)
813813
}
814814

815815
type configWithOwnUnmarshalAndEmbeddedSquashedStruct struct {
@@ -830,8 +830,8 @@ func TestUnmarshalOwnThroughEmbeddedSquashedStruct(t *testing.T) {
830830
cfg := &topLevelSquashedEmbedded{}
831831
err := c.Unmarshal(cfg)
832832
require.NoError(t, err)
833-
require.Equal(t, "success", cfg.Cfg.embeddedStructWithUnmarshal.success)
834-
require.Equal(t, "bar", cfg.Cfg.embeddedStructWithUnmarshal.Foo)
833+
require.Equal(t, "success", cfg.Cfg.success)
834+
require.Equal(t, "bar", cfg.Cfg.Foo)
835835
}
836836

837837
type recursive struct {

consumer/consumertest/sink.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (ste *ProfilesSink) AllProfiles() []pprofile.Profiles {
191191
return copyProfiles
192192
}
193193

194-
// ProfileRecordCount returns the number of profiles stored by this sink since last Reset.
194+
// SampleCount returns the number of profiles stored by this sink since last Reset.
195195
func (ste *ProfilesSink) SampleCount() int {
196196
ste.mu.Lock()
197197
defer ste.mu.Unlock()

exporter/debugexporter/factory.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func createDefaultConfig() component.Config {
5252

5353
func createTraces(ctx context.Context, set exporter.Settings, config component.Config) (exporter.Traces, error) {
5454
cfg := config.(*Config)
55-
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
55+
exporterLogger := createLogger(cfg, set.Logger)
5656
debug := newDebugExporter(exporterLogger, cfg.Verbosity)
5757
return exporterhelper.NewTraces(ctx, set, config,
5858
debug.pushTraces,
@@ -64,7 +64,7 @@ func createTraces(ctx context.Context, set exporter.Settings, config component.C
6464

6565
func createMetrics(ctx context.Context, set exporter.Settings, config component.Config) (exporter.Metrics, error) {
6666
cfg := config.(*Config)
67-
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
67+
exporterLogger := createLogger(cfg, set.Logger)
6868
debug := newDebugExporter(exporterLogger, cfg.Verbosity)
6969
return exporterhelper.NewMetrics(ctx, set, config,
7070
debug.pushMetrics,
@@ -76,7 +76,7 @@ func createMetrics(ctx context.Context, set exporter.Settings, config component.
7676

7777
func createLogs(ctx context.Context, set exporter.Settings, config component.Config) (exporter.Logs, error) {
7878
cfg := config.(*Config)
79-
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
79+
exporterLogger := createLogger(cfg, set.Logger)
8080
debug := newDebugExporter(exporterLogger, cfg.Verbosity)
8181
return exporterhelper.NewLogs(ctx, set, config,
8282
debug.pushLogs,
@@ -88,7 +88,7 @@ func createLogs(ctx context.Context, set exporter.Settings, config component.Con
8888

8989
func createProfiles(ctx context.Context, set exporter.Settings, config component.Config) (xexporter.Profiles, error) {
9090
cfg := config.(*Config)
91-
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
91+
exporterLogger := createLogger(cfg, set.Logger)
9292
debug := newDebugExporter(exporterLogger, cfg.Verbosity)
9393
return xexporterhelper.NewProfilesExporter(ctx, set, config,
9494
debug.pushProfiles,

exporter/exporterhelper/internal/queuebatch/async_queue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (qc *asyncQueue[T]) Start(ctx context.Context, host component.Host) error {
4040
startWG.Done()
4141
defer qc.stopWG.Done()
4242
for {
43-
ctx, req, done, ok := qc.readableQueue.Read(context.Background())
43+
ctx, req, done, ok := qc.Read(context.Background())
4444
if !ok {
4545
return
4646
}

exporter/exporterhelper/internal/queuebatch/default_batcher_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func TestDefaultBatcher_MergeError(t *testing.T) {
396396
sink.SetExportErr(errors.New("transient error"))
397397
ba.Consume(context.Background(), &requesttest.FakeRequest{Items: 4, Bytes: 4}, done)
398398
assert.Eventually(t, func() bool {
399-
return 2 == done.errors.Load()
399+
return done.errors.Load() == 2
400400
}, 1*time.Second, 10*time.Millisecond)
401401

402402
// Check that done callback is called for the right amount of times.

exporter/exporterhelper/internal/queuebatch/persistent_queue_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func TestPersistentBlockingQueue(t *testing.T) {
444444
wg.Wait()
445445
// Because the persistent queue is not draining after Shutdown, need to wait here for the drain.
446446
assert.Eventually(t, func() bool {
447-
return 1_000_000 == int(consumed.Load())
447+
return int(consumed.Load()) == 1_000_000
448448
}, 5*time.Second, 10*time.Millisecond)
449449
require.NoError(t, ac.Shutdown(context.Background()))
450450
})

exporter/exportertest/contract_checker_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (mef *mockFactory) createMockTraces(
4646
cfg component.Config,
4747
) (exporter.Traces, error) {
4848
return exporterhelper.NewTraces(ctx, set, cfg,
49-
mef.mr.Traces.ConsumeTraces,
49+
mef.mr.ConsumeTraces,
5050
exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
5151
exporterhelper.WithRetry(retryConfig),
5252
)
@@ -58,7 +58,7 @@ func (mef *mockFactory) createMockMetrics(
5858
cfg component.Config,
5959
) (exporter.Metrics, error) {
6060
return exporterhelper.NewMetrics(ctx, set, cfg,
61-
mef.mr.Metrics.ConsumeMetrics,
61+
mef.mr.ConsumeMetrics,
6262
exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
6363
exporterhelper.WithRetry(retryConfig),
6464
)
@@ -70,7 +70,7 @@ func (mef *mockFactory) createMockLogs(
7070
cfg component.Config,
7171
) (exporter.Logs, error) {
7272
return exporterhelper.NewLogs(ctx, set, cfg,
73-
mef.mr.Logs.ConsumeLogs,
73+
mef.mr.ConsumeLogs,
7474
exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
7575
exporterhelper.WithRetry(retryConfig),
7676
)

exporter/otlpexporter/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ type Config struct {
2929
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved
3030
//
3131
// Deprecated: [v0.123.0] batch configuration moving to queue configuration.
32-
BatcherConfig exporterhelper.BatcherConfig `mapstructure:"batcher"` //nolint:staticcheck
32+
BatcherConfig exporterhelper.BatcherConfig `mapstructure:"batcher"` //nolint:staticcheck // SA1019
3333

3434
// remove at the same time as BatcherConfig
3535
hasBatcher bool
3636
}
3737

3838
func (c *Config) Unmarshal(conf *confmap.Conf) error {
3939
if conf.IsSet("batcher") {
40-
c.BatcherConfig = exporterhelper.NewDefaultBatcherConfig() //nolint:staticcheck
40+
c.BatcherConfig = exporterhelper.NewDefaultBatcherConfig() //nolint:staticcheck // SA1019
4141
c.BatcherConfig.Enabled = false
4242
c.hasBatcher = true
4343
}

exporter/otlpexporter/factory.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func createTraces(
6161
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
6262
exporterhelper.WithRetry(oCfg.RetryConfig),
6363
exporterhelper.WithQueue(oCfg.QueueConfig),
64-
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
64+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck // SA1019
6565
exporterhelper.WithStart(oce.start),
6666
exporterhelper.WithShutdown(oce.shutdown),
6767
)
@@ -80,7 +80,7 @@ func createMetrics(
8080
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
8181
exporterhelper.WithRetry(oCfg.RetryConfig),
8282
exporterhelper.WithQueue(oCfg.QueueConfig),
83-
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
83+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck // SA1019
8484
exporterhelper.WithStart(oce.start),
8585
exporterhelper.WithShutdown(oce.shutdown),
8686
)
@@ -99,7 +99,7 @@ func createLogs(
9999
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
100100
exporterhelper.WithRetry(oCfg.RetryConfig),
101101
exporterhelper.WithQueue(oCfg.QueueConfig),
102-
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
102+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck // SA1019
103103
exporterhelper.WithStart(oce.start),
104104
exporterhelper.WithShutdown(oce.shutdown),
105105
)
@@ -118,7 +118,7 @@ func createProfilesExporter(
118118
exporterhelper.WithTimeout(oCfg.TimeoutConfig),
119119
exporterhelper.WithRetry(oCfg.RetryConfig),
120120
exporterhelper.WithQueue(oCfg.QueueConfig),
121-
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck
121+
exporterhelper.WithBatcher(oCfg.BatcherConfig), //nolint:staticcheck // SA1019
122122
exporterhelper.WithStart(oce.start),
123123
exporterhelper.WithShutdown(oce.shutdown),
124124
)

exporter/otlpexporter/otlp.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func newExporter(cfg component.Config, set exporter.Settings) *baseExporter {
5454
oCfg := cfg.(*Config)
5555

5656
if oCfg.hasBatcher {
57-
set.TelemetrySettings.Logger.Warn("using deprecated field: batcher")
57+
set.Logger.Warn("using deprecated field: batcher")
5858
}
5959

6060
userAgent := fmt.Sprintf("%s/%s (%s/%s)",
@@ -100,7 +100,7 @@ func (e *baseExporter) pushTraces(ctx context.Context, td ptrace.Traces) error {
100100
return err
101101
}
102102
partialSuccess := resp.PartialSuccess()
103-
if !(partialSuccess.ErrorMessage() == "" && partialSuccess.RejectedSpans() == 0) {
103+
if partialSuccess.ErrorMessage() != "" || partialSuccess.RejectedSpans() != 0 {
104104
e.settings.Logger.Warn("Partial success response",
105105
zap.String("message", resp.PartialSuccess().ErrorMessage()),
106106
zap.Int64("dropped_spans", resp.PartialSuccess().RejectedSpans()),
@@ -116,7 +116,7 @@ func (e *baseExporter) pushMetrics(ctx context.Context, md pmetric.Metrics) erro
116116
return err
117117
}
118118
partialSuccess := resp.PartialSuccess()
119-
if !(partialSuccess.ErrorMessage() == "" && partialSuccess.RejectedDataPoints() == 0) {
119+
if partialSuccess.ErrorMessage() != "" || partialSuccess.RejectedDataPoints() != 0 {
120120
e.settings.Logger.Warn("Partial success response",
121121
zap.String("message", resp.PartialSuccess().ErrorMessage()),
122122
zap.Int64("dropped_data_points", resp.PartialSuccess().RejectedDataPoints()),
@@ -132,7 +132,7 @@ func (e *baseExporter) pushLogs(ctx context.Context, ld plog.Logs) error {
132132
return err
133133
}
134134
partialSuccess := resp.PartialSuccess()
135-
if !(partialSuccess.ErrorMessage() == "" && partialSuccess.RejectedLogRecords() == 0) {
135+
if partialSuccess.ErrorMessage() != "" || partialSuccess.RejectedLogRecords() != 0 {
136136
e.settings.Logger.Warn("Partial success response",
137137
zap.String("message", resp.PartialSuccess().ErrorMessage()),
138138
zap.Int64("dropped_log_records", resp.PartialSuccess().RejectedLogRecords()),
@@ -148,7 +148,7 @@ func (e *baseExporter) pushProfiles(ctx context.Context, td pprofile.Profiles) e
148148
return err
149149
}
150150
partialSuccess := resp.PartialSuccess()
151-
if !(partialSuccess.ErrorMessage() == "" && partialSuccess.RejectedProfiles() == 0) {
151+
if partialSuccess.ErrorMessage() != "" || partialSuccess.RejectedProfiles() != 0 {
152152
e.settings.Logger.Warn("Partial success response",
153153
zap.String("message", resp.PartialSuccess().ErrorMessage()),
154154
zap.Int64("dropped_profiles", resp.PartialSuccess().RejectedProfiles()),

exporter/otlpexporter/otlp_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func TestSendTraces(t *testing.T) {
319319

320320
// For testing the "Partial success" warning.
321321
logger, observed := observer.New(zap.DebugLevel)
322-
set.TelemetrySettings.Logger = zap.New(logger)
322+
set.Logger = zap.New(logger)
323323

324324
exp, err := factory.CreateTraces(context.Background(), set, cfg)
325325
require.NoError(t, err)
@@ -491,7 +491,7 @@ func TestSendMetrics(t *testing.T) {
491491

492492
// For testing the "Partial success" warning.
493493
logger, observed := observer.New(zap.DebugLevel)
494-
set.TelemetrySettings.Logger = zap.New(logger)
494+
set.Logger = zap.New(logger)
495495

496496
exp, err := factory.CreateMetrics(context.Background(), set, cfg)
497497
require.NoError(t, err)
@@ -785,7 +785,7 @@ func TestSendLogData(t *testing.T) {
785785

786786
// For testing the "Partial success" warning.
787787
logger, observed := observer.New(zap.DebugLevel)
788-
set.TelemetrySettings.Logger = zap.New(logger)
788+
set.Logger = zap.New(logger)
789789

790790
exp, err := factory.CreateLogs(context.Background(), set, cfg)
791791
require.NoError(t, err)
@@ -892,7 +892,7 @@ func TestSendProfiles(t *testing.T) {
892892

893893
// For testing the "Partial success" warning.
894894
logger, observed := observer.New(zap.DebugLevel)
895-
set.TelemetrySettings.Logger = zap.New(logger)
895+
set.Logger = zap.New(logger)
896896

897897
exp, err := factory.(xexporter.Factory).CreateProfiles(context.Background(), set, cfg)
898898
require.NoError(t, err)

0 commit comments

Comments
 (0)