Skip to content

Commit

Permalink
[chore]: enable gofumpt linter in connector, consumer, exporter, exte…
Browse files Browse the repository at this point in the history
…nsion and featuregate (open-telemetry#11854)

#### Description

[gofumpt](https://golangci-lint.run/usage/linters/#gofumpt) is a
stricter format than gofmt, while being backwards compatible.

Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored Dec 12, 2024
1 parent 824c9f7 commit 0b97830
Show file tree
Hide file tree
Showing 39 changed files with 139 additions and 86 deletions.
6 changes: 6 additions & 0 deletions connector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,35 @@ type nopConnector struct {
func createTracesToTraces(context.Context, Settings, component.Config, consumer.Traces) (Traces, error) {
return nopInstance, nil
}

func createTracesToMetrics(context.Context, Settings, component.Config, consumer.Metrics) (Traces, error) {
return nopInstance, nil
}

func createTracesToLogs(context.Context, Settings, component.Config, consumer.Logs) (Traces, error) {
return nopInstance, nil
}

func createMetricsToTraces(context.Context, Settings, component.Config, consumer.Traces) (Metrics, error) {
return nopInstance, nil
}

func createMetricsToMetrics(context.Context, Settings, component.Config, consumer.Metrics) (Metrics, error) {
return nopInstance, nil
}

func createMetricsToLogs(context.Context, Settings, component.Config, consumer.Logs) (Metrics, error) {
return nopInstance, nil
}

func createLogsToTraces(context.Context, Settings, component.Config, consumer.Traces) (Logs, error) {
return nopInstance, nil
}

func createLogsToMetrics(context.Context, Settings, component.Config, consumer.Metrics) (Logs, error) {
return nopInstance, nil
}

func createLogsToLogs(context.Context, Settings, component.Config, consumer.Logs) (Logs, error) {
return nopInstance, nil
}
2 changes: 2 additions & 0 deletions connector/connectorprofiles/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ func createProfilesToProfiles(context.Context, connector.Settings, component.Con
func createProfilesToTraces(context.Context, connector.Settings, component.Config, consumer.Traces) (Profiles, error) {
return nopInstance, nil
}

func createProfilesToMetrics(context.Context, connector.Settings, component.Config, consumer.Metrics) (Profiles, error) {
return nopInstance, nil
}

func createProfilesToLogs(context.Context, connector.Settings, component.Config, consumer.Logs) (Profiles, error) {
return nopInstance, nil
}
2 changes: 1 addition & 1 deletion connector/connectorprofiles/profiles_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (mts *mutatingProfilesSink) Capabilities() consumer.Capabilities {
}

func TestProfilesRouterMultiplexing(t *testing.T) {
var num = 20
num := 20
for numIDs := 1; numIDs < num; numIDs++ {
for numCons := 1; numCons < num; numCons++ {
for numProfiles := 1; numProfiles < num; numProfiles++ {
Expand Down
3 changes: 3 additions & 0 deletions connector/connectortest/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func createMetricsToMetricsConnector(context.Context, connector.Settings, compon
func createMetricsToLogsConnector(context.Context, connector.Settings, component.Config, consumer.Logs) (connector.Metrics, error) {
return &nopConnector{Consumer: consumertest.NewNop()}, nil
}

func createMetricsToProfilesConnector(context.Context, connector.Settings, component.Config, consumerprofiles.Profiles) (connector.Metrics, error) {
return &nopConnector{Consumer: consumertest.NewNop()}, nil
}
Expand All @@ -98,6 +99,7 @@ func createLogsToMetricsConnector(context.Context, connector.Settings, component
func createLogsToLogsConnector(context.Context, connector.Settings, component.Config, consumer.Logs) (connector.Logs, error) {
return &nopConnector{Consumer: consumertest.NewNop()}, nil
}

func createLogsToProfilesConnector(context.Context, connector.Settings, component.Config, consumerprofiles.Profiles) (connector.Logs, error) {
return &nopConnector{Consumer: consumertest.NewNop()}, nil
}
Expand All @@ -113,6 +115,7 @@ func createProfilesToMetricsConnector(context.Context, connector.Settings, compo
func createProfilesToLogsConnector(context.Context, connector.Settings, component.Config, consumer.Logs) (connectorprofiles.Profiles, error) {
return &nopConnector{Consumer: consumertest.NewNop()}, nil
}

func createProfilesToProfilesConnector(context.Context, connector.Settings, component.Config, consumerprofiles.Profiles) (connectorprofiles.Profiles, error) {
return &nopConnector{Consumer: consumertest.NewNop()}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion connector/logs_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (mts *mutatingLogsSink) Capabilities() consumer.Capabilities {
}

func TestLogsRouterMultiplexing(t *testing.T) {
var num = 20
num := 20
for numIDs := 1; numIDs < num; numIDs++ {
for numCons := 1; numCons < num; numCons++ {
for numLogs := 1; numLogs < num; numLogs++ {
Expand Down
2 changes: 1 addition & 1 deletion connector/metrics_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (mts *mutatingMetricsSink) Capabilities() consumer.Capabilities {
}

func TestMetricsRouterMultiplexing(t *testing.T) {
var num = 20
num := 20
for numIDs := 1; numIDs < num; numIDs++ {
for numCons := 1; numCons < num; numCons++ {
for numMetrics := 1; numMetrics < num; numMetrics++ {
Expand Down
2 changes: 1 addition & 1 deletion connector/traces_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (mts *mutatingTracesSink) Capabilities() consumer.Capabilities {
}

func TestTracesRouterMultiplexing(t *testing.T) {
var num = 20
num := 20
for numIDs := 1; numIDs < num; numIDs++ {
for numCons := 1; numCons < num; numCons++ {
for numTraces := 1; numTraces < num; numTraces++ {
Expand Down
10 changes: 6 additions & 4 deletions consumer/consumertest/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ type Consumer interface {
unexported()
}

var _ consumer.Logs = (Consumer)(nil)
var _ consumer.Metrics = (Consumer)(nil)
var _ consumer.Traces = (Consumer)(nil)
var _ consumerprofiles.Profiles = (Consumer)(nil)
var (
_ consumer.Logs = (Consumer)(nil)
_ consumer.Metrics = (Consumer)(nil)
_ consumer.Traces = (Consumer)(nil)
_ consumerprofiles.Profiles = (Consumer)(nil)
)

type nonMutatingConsumer struct{}

Expand Down
16 changes: 7 additions & 9 deletions exporter/debugexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import (
"go.opentelemetry.io/collector/config/configtelemetry"
)

var (
// supportedLevels in this exporter's configuration.
// configtelemetry.LevelNone and other future values are not supported.
supportedLevels map[configtelemetry.Level]struct{} = map[configtelemetry.Level]struct{}{
configtelemetry.LevelBasic: {},
configtelemetry.LevelNormal: {},
configtelemetry.LevelDetailed: {},
}
)
// supportedLevels in this exporter's configuration.
// configtelemetry.LevelNone and other future values are not supported.
var supportedLevels map[configtelemetry.Level]struct{} = map[configtelemetry.Level]struct{}{
configtelemetry.LevelBasic: {},
configtelemetry.LevelNormal: {},
configtelemetry.LevelDetailed: {},
}

// Config defines configuration for debug exporter.
type Config struct {
Expand Down
4 changes: 2 additions & 2 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func TestNewFactory(t *testing.T) {
var testType = component.MustNewType("test")
testType := component.MustNewType("test")
defaultCfg := struct{}{}
f := NewFactory(
testType,
Expand All @@ -32,7 +32,7 @@ func TestNewFactory(t *testing.T) {
}

func TestNewFactoryWithOptions(t *testing.T) {
var testType = component.MustNewType("test")
testType := component.MustNewType("test")
defaultCfg := struct{}{}
f := NewFactory(
testType,
Expand Down
6 changes: 4 additions & 2 deletions exporter/exporterhelper/exporterhelperprofiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"go.opentelemetry.io/collector/pipeline/pipelineprofiles"
)

var profilesMarshaler = &pprofile.ProtoMarshaler{}
var profilesUnmarshaler = &pprofile.ProtoUnmarshaler{}
var (
profilesMarshaler = &pprofile.ProtoMarshaler{}
profilesUnmarshaler = &pprofile.ProtoUnmarshaler{}
)

type profilesRequest struct {
pd pprofile.Profiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ func TestExtractProfiles(t *testing.T) {
}

// dummyRequest implements Request. It is for checking that merging two request types would fail
type dummyRequest struct {
}
type dummyRequest struct{}

func (req *dummyRequest) Export(_ context.Context) error {
return nil
Expand All @@ -160,6 +159,7 @@ func (req *dummyRequest) Merge(_ context.Context, _ exporterhelper.Request) (exp
}

func (req *dummyRequest) MergeSplit(_ context.Context, _ exporterbatcher.MaxSizeConfig, _ exporterhelper.Request) (
[]exporterhelper.Request, error) {
[]exporterhelper.Request, error,
) {
return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ const (
fakeProfilesParentSpanName = "fake_profiles_parent_span_name"
)

var (
fakeProfilesExporterConfig = struct{}{}
)
var fakeProfilesExporterConfig = struct{}{}

func TestProfilesRequest(t *testing.T) {
lr := newProfilesRequest(testdata.GenerateProfiles(1), nil)
Expand Down Expand Up @@ -301,8 +299,10 @@ func generateProfilesTraffic(t *testing.T, tracer trace.Tracer, le exporterprofi
}
}

// nolint: unparam
func checkWrapSpanForProfilesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporterprofiles.Profiles,
wantError error, numSampleRecords int64) { // nolint: unparam
wantError error, numSampleRecords int64,
) {
const numRequests = 5
generateProfilesTraffic(t, tracer, le, numRequests, wantError)

Expand Down
18 changes: 12 additions & 6 deletions exporter/exporterhelper/internal/batch_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func TestBatchSender_Merge(t *testing.T) {
runTest := func(testName string, enableQueueBatcher bool, tt struct {
name string
batcherOption Option
}) {
},
) {
t.Run(testName, func(t *testing.T) {
resetFeatureGate := setFeatureGateForTest(t, usePullingBasedExporterQueueBatcher, enableQueueBatcher)
be := queueBatchExporter(t, tt.batcherOption)
Expand Down Expand Up @@ -78,8 +79,10 @@ func TestBatchSender_Merge(t *testing.T) {
time.Sleep(50 * time.Millisecond)

// should be ignored because of the merge error.
require.NoError(t, be.Send(context.Background(), &fakeRequest{items: 3, sink: sink,
mergeErr: errors.New("merge error")}))
require.NoError(t, be.Send(context.Background(), &fakeRequest{
items: 3, sink: sink,
mergeErr: errors.New("merge error"),
}))

assert.Equal(t, int64(1), sink.requestsCount.Load())
assert.Eventually(t, func() bool {
Expand Down Expand Up @@ -130,7 +133,8 @@ func TestBatchSender_BatchExportError(t *testing.T) {
batcherOption Option
expectedRequests int64
expectedItems int64
}) {
},
) {
t.Run(testName, func(t *testing.T) {
resetFeatureGate := setFeatureGateForTest(t, usePullingBasedExporterQueueBatcher, enableQueueBatcher)
be := queueBatchExporter(t, tt.batcherOption)
Expand Down Expand Up @@ -200,8 +204,10 @@ func TestBatchSender_MergeOrSplit(t *testing.T) {
}, 50*time.Millisecond, 10*time.Millisecond)

// request that cannot be split should be dropped.
require.NoError(t, be.Send(context.Background(), &fakeRequest{items: 11, sink: sink,
mergeErr: errors.New("split error")}))
require.NoError(t, be.Send(context.Background(), &fakeRequest{
items: 11, sink: sink,
mergeErr: errors.New("split error"),
}))

// big request should be broken down into two requests, both are sent right away.
require.NoError(t, be.Send(context.Background(), &fakeRequest{items: 13, sink: sink}))
Expand Down
3 changes: 2 additions & 1 deletion exporter/exporterhelper/internal/queue_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func NewQueueSender(
numConsumers int,
exportFailureMessage string,
obsrep *ObsReport,
batcherCfg exporterbatcher.Config) *QueueSender {
batcherCfg exporterbatcher.Config,
) *QueueSender {
qs := &QueueSender{
queue: q,
numConsumers: numConsumers,
Expand Down
12 changes: 7 additions & 5 deletions exporter/exporterhelper/internal/queue_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func TestQueuedRetryHappyPath(t *testing.T) {
runTest := func(testName string, enableQueueBatcher bool, tt struct {
name string
queueOptions []Option
}) {
},
) {
t.Run(testName, func(t *testing.T) {
resetFeatureGate := setFeatureGateForTest(t, usePullingBasedExporterQueueBatcher, enableQueueBatcher)
tel, err := componenttest.SetupTelemetry(defaultID)
Expand Down Expand Up @@ -361,7 +362,8 @@ func TestQueueRetryWithDisabledQueue(t *testing.T) {
runTest := func(testName string, enableQueueBatcher bool, tt struct {
name string
queueOptions []Option
}) {
},
) {
t.Run(testName, func(t *testing.T) {
defer setFeatureGateForTest(t, usePullingBasedExporterQueueBatcher, enableQueueBatcher)
set := exportertest.NewNopSettings()
Expand Down Expand Up @@ -432,7 +434,7 @@ func TestQueuedRetryPersistenceEnabled(t *testing.T) {
WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)

var extensions = map[component.ID]component.Component{
extensions := map[component.ID]component.Component{
storageID: queue.NewMockStorageExtension(nil),
}
host := &MockHost{Ext: extensions}
Expand Down Expand Up @@ -465,7 +467,7 @@ func TestQueuedRetryPersistenceEnabledStorageError(t *testing.T) {
WithUnmarshaler(mockRequestUnmarshaler(&mockRequest{})), WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)

var extensions = map[component.ID]component.Component{
extensions := map[component.ID]component.Component{
storageID: queue.NewMockStorageExtension(storageError),
}
host := &MockHost{Ext: extensions}
Expand Down Expand Up @@ -497,7 +499,7 @@ func TestQueuedRetryPersistentEnabled_NoDataLossOnShutdown(t *testing.T) {
WithUnmarshaler(mockRequestUnmarshaler(mockReq)), WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)

var extensions = map[component.ID]component.Component{
extensions := map[component.ID]component.Component{
storageID: queue.NewMockStorageExtension(nil),
}
host := &MockHost{Ext: extensions}
Expand Down
6 changes: 4 additions & 2 deletions exporter/exporterhelper/internal/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func (r *fakeRequest) ItemsCount() int {
}

func (r *fakeRequest) Merge(_ context.Context,
r2 internal.Request) (internal.Request, error) {
r2 internal.Request,
) (internal.Request, error) {
if r == nil {
return r2, nil
}
Expand All @@ -74,7 +75,8 @@ func (r *fakeRequest) Merge(_ context.Context,
}

func (r *fakeRequest) MergeSplit(ctx context.Context, cfg exporterbatcher.MaxSizeConfig,
r2 internal.Request) ([]internal.Request, error) {
r2 internal.Request,
) ([]internal.Request, error) {
if r.mergeErr != nil {
return nil, r.mergeErr
}
Expand Down
6 changes: 4 additions & 2 deletions exporter/exporterhelper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"go.opentelemetry.io/collector/pipeline"
)

var logsMarshaler = &plog.ProtoMarshaler{}
var logsUnmarshaler = &plog.ProtoUnmarshaler{}
var (
logsMarshaler = &plog.ProtoMarshaler{}
logsUnmarshaler = &plog.ProtoUnmarshaler{}
)

type logsRequest struct {
ld plog.Logs
Expand Down
4 changes: 3 additions & 1 deletion exporter/exporterhelper/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,10 @@ func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le exporter.Logs, nu
}
}

// nolint: unparam
func checkWrapSpanForLogs(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporter.Logs,
wantError error, numLogRecords int64) { // nolint: unparam
wantError error, numLogRecords int64,
) {
const numRequests = 5
generateLogsTraffic(t, tracer, le, numRequests, wantError)

Expand Down
6 changes: 4 additions & 2 deletions exporter/exporterhelper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"go.opentelemetry.io/collector/pipeline"
)

var metricsMarshaler = &pmetric.ProtoMarshaler{}
var metricsUnmarshaler = &pmetric.ProtoUnmarshaler{}
var (
metricsMarshaler = &pmetric.ProtoMarshaler{}
metricsUnmarshaler = &pmetric.ProtoUnmarshaler{}
)

type metricsRequest struct {
md pmetric.Metrics
Expand Down
Loading

0 comments on commit 0b97830

Please sign in to comment.