Skip to content

Commit

Permalink
[chore]: enable gofumpt linter in internal, otelcol, pdata, pipeline …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
mmorel-35 and codeboten authored Dec 12, 2024
1 parent 96e860b commit 824c9f7
Show file tree
Hide file tree
Showing 37 changed files with 94 additions and 76 deletions.
1 change: 0 additions & 1 deletion internal/memorylimiter/cgroups/mountpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions internal/sharedcomponent/sharedcomponent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions internal/sharedcomponent/sharedcomponent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion otelcol/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions otelcol/configprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion otelcol/internal/configunmarshaler/configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions otelcol/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pdata/internal/cmd/pdatagen/internal/packages.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pdata/internal/cmd/pdatagen/internal/pmetric_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ var sumField = &optionalPrimitiveValue{
defaultVal: "float64(0.0)",
testVal: "float64(17.13)",
}

var minField = &optionalPrimitiveValue{
fieldName: "Min",
returnType: "float64",
Expand Down
1 change: 1 addition & 0 deletions pdata/internal/cmd/pdatagen/internal/pprofile_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion pdata/pcommon/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
4 changes: 1 addition & 3 deletions pdata/plog/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions pdata/plog/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions pdata/plog/plogotlp/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions pdata/plog/plogotlp/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
{
Expand Down
6 changes: 4 additions & 2 deletions pdata/plog/plogotlp/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}`
Expand Down
1 change: 1 addition & 0 deletions pdata/pmetric/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ func generateTestProtoGaugeMetric() *otlpmetrics.Metric {
},
}
}

func generateTestProtoSumMetric() *otlpmetrics.Metric {
return &otlpmetrics.Metric{
Name: "my_metric_double",
Expand Down
6 changes: 4 additions & 2 deletions pdata/pmetric/pmetricotlp/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
{
Expand Down
6 changes: 4 additions & 2 deletions pdata/pmetric/pmetricotlp/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}`
Expand Down
4 changes: 1 addition & 3 deletions pdata/pprofile/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions pdata/pprofile/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions pdata/pprofile/pprofileotlp/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions pdata/pprofile/pprofileotlp/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
{
Expand Down
6 changes: 4 additions & 2 deletions pdata/pprofile/pprofileotlp/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}`
Expand Down
4 changes: 1 addition & 3 deletions pdata/ptrace/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions pdata/ptrace/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions pdata/ptrace/ptraceotlp/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions pdata/ptrace/ptraceotlp/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
{
Expand Down
6 changes: 4 additions & 2 deletions pdata/ptrace/ptraceotlp/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}`
Expand Down
4 changes: 1 addition & 3 deletions pdata/testdata/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pipeline/pipelineprofiles/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ import (
"go.opentelemetry.io/collector/pipeline/internal/globalsignal"
)

var (
SignalProfiles = globalsignal.MustNewSignal("profiles")
)
var SignalProfiles = globalsignal.MustNewSignal("profiles")
Loading

0 comments on commit 824c9f7

Please sign in to comment.