[chore]: enable gofumpt linter in internal, otelcol, pdata, pipeline and processor (#11855)

#### Description

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

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
This commit is contained in:
Matthieu MOREL 2024-12-12 20:21:54 +01:00 committed by GitHub
parent 96e860b9cb
commit 824c9f7a43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 94 additions and 76 deletions

View File

@ -131,7 +131,6 @@ func NewMountPointFromLine(line string) (*MountPoint, error) {
// the host file system path in the mount namespace the *MountPoint belongs to.
func (mp *MountPoint) Translate(absPath string) (string, error) {
relPath, err := filepath.Rel(mp.Root, absPath)
if err != nil {
return "", err
}

View File

@ -102,8 +102,10 @@ func (c *Component[V]) Start(ctx context.Context, host component.Host) error {
return nil
}
var _ component.Host = (*hostWrapper)(nil)
var _ componentstatus.Reporter = (*hostWrapper)(nil)
var (
_ component.Host = (*hostWrapper)(nil)
_ componentstatus.Reporter = (*hostWrapper)(nil)
)
type hostWrapper struct {
host component.Host

View File

@ -82,7 +82,8 @@ func TestSharedComponent(t *testing.T) {
ShutdownFunc: func(context.Context) error {
calledStop++
return wantErr
}}
},
}
comps := NewMap[component.ID, *baseComponent]()
got, err := comps.LoadOrStore(
@ -198,8 +199,10 @@ func TestReportStatusOnStartShutdown(t *testing.T) {
}
}
var _ component.Host = (*testHost)(nil)
var _ componentstatus.Reporter = (*testHost)(nil)
var (
_ component.Host = (*testHost)(nil)
_ componentstatus.Reporter = (*testHost)(nil)
)
type testHost struct {
component.Host

View File

@ -37,7 +37,7 @@ func (c *errConfig) Validate() error {
}
func TestConfigValidate(t *testing.T) {
var testCases = []struct {
testCases := []struct {
name string // test case name (also file name containing config yaml)
cfgFn func() *Config
expected error

View File

@ -17,9 +17,8 @@ import (
)
func newConfig(yamlBytes []byte, factories Factories) (*Config, error) {
var stringMap = map[string]interface{}{}
stringMap := map[string]interface{}{}
err := yaml.Unmarshal(yamlBytes, stringMap)
if err != nil {
return nil, err
}

View File

@ -77,7 +77,7 @@ func TestUnmarshal(t *testing.T) {
func TestUnmarshalError(t *testing.T) {
for _, tk := range testKinds {
t.Run(tk.kind, func(t *testing.T) {
var testCases = []struct {
testCases := []struct {
name string
conf *confmap.Conf
// string that the error must contain

View File

@ -71,7 +71,7 @@ func TestUnmarshalUnknownTopLevel(t *testing.T) {
}
func TestPipelineConfigUnmarshalError(t *testing.T) {
var testCases = []struct {
testCases := []struct {
// test case name (also file name containing config yaml)
name string
conf *confmap.Conf
@ -141,7 +141,7 @@ func TestPipelineConfigUnmarshalError(t *testing.T) {
}
func TestServiceUnmarshalError(t *testing.T) {
var testCases = []struct {
testCases := []struct {
// test case name (also file name containing config yaml)
name string
conf *confmap.Conf

View File

@ -46,7 +46,7 @@ type PackageInfo struct {
func (p *Package) GenerateFiles() error {
for _, s := range p.structs {
path := filepath.Join(p.info.path, "generated_"+strings.ToLower(s.getName())+".go")
if err := os.WriteFile(path, s.generate(p.info), 0600); err != nil {
if err := os.WriteFile(path, s.generate(p.info), 0o600); err != nil {
return err
}
}
@ -57,7 +57,7 @@ func (p *Package) GenerateFiles() error {
func (p *Package) GenerateTestFiles() error {
for _, s := range p.structs {
path := filepath.Join(p.info.path, "generated_"+strings.ToLower(s.getName())+"_test.go")
if err := os.WriteFile(path, s.generateTests(p.info), 0600); err != nil {
if err := os.WriteFile(path, s.generateTests(p.info), 0o600); err != nil {
return err
}
}
@ -72,7 +72,7 @@ func (p *Package) GenerateInternalFiles() error {
for _, s := range p.structs {
path := filepath.Join("internal", "generated_wrapper_"+strings.ToLower(s.getName())+".go")
if err := os.WriteFile(path, s.generateInternal(p.info), 0600); err != nil {
if err := os.WriteFile(path, s.generateInternal(p.info), 0o600); err != nil {
return err
}
}

View File

@ -517,6 +517,7 @@ var sumField = &optionalPrimitiveValue{
defaultVal: "float64(0.0)",
testVal: "float64(17.13)",
}
var minField = &optionalPrimitiveValue{
fieldName: "Min",
returnType: "float64",

View File

@ -398,6 +398,7 @@ var locationSlice = &sliceOfPtrs{
structName: "LocationSlice",
element: location,
}
var location = &messageValueStruct{
structName: "Location",
description: "// Location describes function and line table debug information.",

View File

@ -11,7 +11,7 @@ import (
)
func TestUnixNanosConverters(t *testing.T) {
t1 := time.Date(2020, 03, 24, 1, 13, 23, 789, time.UTC)
t1 := time.Date(2020, 3, 24, 1, 13, 23, 789, time.UTC)
// nolint:gosec
tun := Timestamp(t1.UnixNano())

View File

@ -8,9 +8,7 @@ import (
"testing"
)
var (
unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
)
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
func FuzzUnmarshalJsonLogs(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {

View File

@ -14,8 +14,10 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
)
var _ Marshaler = (*JSONMarshaler)(nil)
var _ Unmarshaler = (*JSONUnmarshaler)(nil)
var (
_ Marshaler = (*JSONMarshaler)(nil)
_ Unmarshaler = (*JSONUnmarshaler)(nil)
)
var logsOTLP = func() Logs {
ld := NewLogs()

View File

@ -8,9 +8,7 @@ import (
"testing"
)
var (
unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
)
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
func FuzzRequestUnmarshalJSON(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportRequest{}
var _ json.Marshaler = ExportRequest{}
var (
_ json.Unmarshaler = ExportRequest{}
_ json.Marshaler = ExportRequest{}
)
var logsRequestJSON = []byte(`
{

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportResponse{}
var _ json.Marshaler = ExportResponse{}
var (
_ json.Unmarshaler = ExportResponse{}
_ json.Marshaler = ExportResponse{}
)
func TestExportResponseJSON(t *testing.T) {
jsonStr := `{"partialSuccess": {"rejectedLogRecords":1, "errorMessage":"nothing"}}`

View File

@ -810,6 +810,7 @@ func generateTestProtoGaugeMetric() *otlpmetrics.Metric {
},
}
}
func generateTestProtoSumMetric() *otlpmetrics.Metric {
return &otlpmetrics.Metric{
Name: "my_metric_double",

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportRequest{}
var _ json.Marshaler = ExportRequest{}
var (
_ json.Unmarshaler = ExportRequest{}
_ json.Marshaler = ExportRequest{}
)
var metricsRequestJSON = []byte(`
{

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportResponse{}
var _ json.Marshaler = ExportResponse{}
var (
_ json.Unmarshaler = ExportResponse{}
_ json.Marshaler = ExportResponse{}
)
func TestExportResponseJSON(t *testing.T) {
jsonStr := `{"partialSuccess": {"rejectedDataPoints":1, "errorMessage":"nothing"}}`

View File

@ -8,9 +8,7 @@ import (
"testing"
)
var (
unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
)
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
func FuzzUnmarshalProfiles(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {

View File

@ -13,8 +13,10 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
)
var _ Marshaler = (*JSONMarshaler)(nil)
var _ Unmarshaler = (*JSONUnmarshaler)(nil)
var (
_ Marshaler = (*JSONMarshaler)(nil)
_ Unmarshaler = (*JSONUnmarshaler)(nil)
)
var profilesOTLP = func() Profiles {
startTimestamp := pcommon.Timestamp(1684617382541971000)

View File

@ -8,9 +8,7 @@ import (
"testing"
)
var (
unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
)
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
func FuzzRequestUnmarshalJSON(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportRequest{}
var _ json.Marshaler = ExportRequest{}
var (
_ json.Unmarshaler = ExportRequest{}
_ json.Marshaler = ExportRequest{}
)
var profilesRequestJSON = []byte(`
{

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportResponse{}
var _ json.Marshaler = ExportResponse{}
var (
_ json.Unmarshaler = ExportResponse{}
_ json.Marshaler = ExportResponse{}
)
func TestExportResponseJSON(t *testing.T) {
jsonStr := `{"partialSuccess": {"rejectedProfiles":1, "errorMessage":"nothing"}}`

View File

@ -8,9 +8,7 @@ import (
"testing"
)
var (
unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
)
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
func FuzzUnmarshalJSONTraces(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {

View File

@ -13,8 +13,10 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
)
var _ Marshaler = (*JSONMarshaler)(nil)
var _ Unmarshaler = (*JSONUnmarshaler)(nil)
var (
_ Marshaler = (*JSONMarshaler)(nil)
_ Unmarshaler = (*JSONUnmarshaler)(nil)
)
var tracesOTLP = func() Traces {
startTimestamp := pcommon.Timestamp(1684617382541971000)

View File

@ -8,9 +8,7 @@ import (
"testing"
)
var (
unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
)
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
func FuzzRequestUnmarshalJSON(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportRequest{}
var _ json.Marshaler = ExportRequest{}
var (
_ json.Unmarshaler = ExportRequest{}
_ json.Marshaler = ExportRequest{}
)
var tracesRequestJSON = []byte(`
{

View File

@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/require"
)
var _ json.Unmarshaler = ExportResponse{}
var _ json.Marshaler = ExportResponse{}
var (
_ json.Unmarshaler = ExportResponse{}
_ json.Marshaler = ExportResponse{}
)
func TestExportResponseJSON(t *testing.T) {
jsonStr := `{"partialSuccess": {"rejectedSpans":1, "errorMessage":"nothing"}}`

View File

@ -10,9 +10,7 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
)
var (
logTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC))
)
var logTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC))
func GenerateLogs(count int) plog.Logs {
ld := plog.NewLogs()

View File

@ -42,7 +42,7 @@ func TestMarshalText(t *testing.T) {
func TestUnmarshalText(t *testing.T) {
validSignal := globalsignal.MustNewSignal("valid")
var testCases = []struct {
testCases := []struct {
idStr string
expectedErr bool
expectedID ID

View File

@ -7,6 +7,4 @@ import (
"go.opentelemetry.io/collector/pipeline/internal/globalsignal"
)
var (
SignalProfiles = globalsignal.MustNewSignal("profiles")
)
var SignalProfiles = globalsignal.MustNewSignal("profiles")

View File

@ -218,9 +218,11 @@ func TestBatchProcessorSentBySize(t *testing.T) {
{
Attributes: attribute.NewSet(attribute.String("processor", "batch")),
Count: uint64(expectedBatchesNum),
Bounds: []float64{10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
Bounds: []float64{
10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
100_000, 200_000, 300_000, 400_000, 500_000, 600_000, 700_000, 800_000, 900_000,
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000},
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000,
},
BucketCounts: []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint64(expectedBatchesNum), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Sum: int64(sizeSum),
Min: metricdata.NewExtrema(int64(sizeSum / expectedBatchesNum)),
@ -343,9 +345,11 @@ func TestBatchProcessorSentBySizeWithMaxSize(t *testing.T) {
{
Attributes: attribute.NewSet(attribute.String("processor", "batch")),
Count: uint64(expectedBatchesNum),
Bounds: []float64{10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
Bounds: []float64{
10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
100_000, 200_000, 300_000, 400_000, 500_000, 600_000, 700_000, 800_000, 900_000,
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000},
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000,
},
BucketCounts: []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, uint64(expectedBatchesNum - 1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Sum: int64(sizeSum),
Min: metricdata.NewExtrema(int64(minSize)),
@ -601,9 +605,11 @@ func TestBatchMetricProcessorBatchSize(t *testing.T) {
{
Attributes: attribute.NewSet(attribute.String("processor", "batch")),
Count: uint64(expectedBatchesNum),
Bounds: []float64{10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
Bounds: []float64{
10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
100_000, 200_000, 300_000, 400_000, 500_000, 600_000, 700_000, 800_000, 900_000,
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000},
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000,
},
BucketCounts: []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint64(expectedBatchesNum), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Sum: int64(size),
Min: metricdata.NewExtrema(int64(size / int(expectedBatchesNum))),
@ -975,9 +981,11 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) {
{
Attributes: attribute.NewSet(attribute.String("processor", "batch")),
Count: uint64(expectedBatchesNum),
Bounds: []float64{10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
Bounds: []float64{
10, 25, 50, 75, 100, 250, 500, 750, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 20000, 30000, 50000,
100_000, 200_000, 300_000, 400_000, 500_000, 600_000, 700_000, 800_000, 900_000,
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000},
1000_000, 2000_000, 3000_000, 4000_000, 5000_000, 6000_000, 7000_000, 8000_000, 9000_000,
},
BucketCounts: []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint64(expectedBatchesNum), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
Sum: int64(size),
Min: metricdata.NewExtrema(int64(size / int(expectedBatchesNum))),

View File

@ -38,7 +38,6 @@ func newBatchProcessorTelemetry(set processor.Settings, currentMetadataCardinali
set.TelemetrySettings,
metadata.WithProcessorBatchMetadataCardinalityCallback(func() int64 { return int64(currentMetadataCardinality()) }, attrs),
)
if err != nil {
return nil, err
}

View File

@ -17,7 +17,7 @@ import (
)
func TestNewFactory(t *testing.T) {
var testType = component.MustNewType("test")
testType := component.MustNewType("test")
defaultCfg := struct{}{}
f := NewFactory(
testType,
@ -33,7 +33,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,

View File

@ -65,7 +65,6 @@ func NewTraces(
obs.recordInOut(ctx, spansIn, spansOut)
return nextConsumer.ConsumeTraces(ctx, td)
}, bs.consumerOptions...)
if err != nil {
return nil, err
}

View File

@ -16,7 +16,7 @@ import (
)
func TestNewFactoryWithProfiles(t *testing.T) {
var testType = component.MustNewType("test")
testType := component.MustNewType("test")
defaultCfg := struct{}{}
factory := NewFactory(
testType,