Skip to content

Commit

Permalink
[chore]: enable gofumpt linter for receiver
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 11, 2024
1 parent 64bcbb3 commit 91f05bb
Show file tree
Hide file tree
Showing 251 changed files with 954 additions and 753 deletions.
1 change: 0 additions & 1 deletion receiver/activedirectorydsreceiver/factory_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func createMetricsReceiver(
scraperhelper.WithStart(adds.start),
scraperhelper.WithShutdown(adds.shutdown),
)

if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions receiver/activedirectorydsreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/activedirectorydsreceiver/internal/metadata"
)

var goldenScrapePath = filepath.Join("testdata", "golden_scrape.yaml")
var partialScrapePath = filepath.Join("testdata", "partial_scrape.yaml")
var (
goldenScrapePath = filepath.Join("testdata", "golden_scrape.yaml")
partialScrapePath = filepath.Join("testdata", "partial_scrape.yaml")
)

func TestScrape(t *testing.T) {
t.Run("Fully successful scrape", func(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions receiver/aerospikereceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ type recordsCheckable interface {
Results() <-chan *as.Result
}

type aeroDoneFunc func() (doneCheckable, as.Error)
type aeroRecordsFunc func() (recordsCheckable, as.Error)
type (
aeroDoneFunc func() (doneCheckable, as.Error)
aeroRecordsFunc func() (recordsCheckable, as.Error)
)

func doneWaitAndCheck(f aeroDoneFunc) error {
chk, err := f()
Expand Down
4 changes: 1 addition & 3 deletions receiver/apachesparkreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const (
defaultEndpoint = "http://localhost:4040"
)

var (
errInvalidEndpoint = errors.New("'endpoint' must be in the form of <scheme>://<hostname>:<port>")
)
var errInvalidEndpoint = errors.New("'endpoint' must be in the form of <scheme>://<hostname>:<port>")

// Config defines the configuration for the various elements of the receiver agent.
type Config struct {
Expand Down
14 changes: 8 additions & 6 deletions receiver/apachesparkreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ func TestScraper(t *testing.T) {
expectedMetricGen: func(*testing.T) pmetric.Metrics {
return pmetric.NewMetrics()
},
config: &Config{ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: defaultCollectionInterval,
},
config: &Config{
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: defaultCollectionInterval,
},
ApplicationNames: []string{"local-123", "local-987"},
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Expand Down Expand Up @@ -212,9 +213,10 @@ func TestScraper(t *testing.T) {
require.NoError(t, err)
return expectedMetrics
},
config: &Config{ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: defaultCollectionInterval,
},
config: &Config{
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: defaultCollectionInterval,
},
ApplicationNames: []string{"streaming-example"},
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Expand Down
4 changes: 1 addition & 3 deletions receiver/awscloudwatchmetricsreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"time"
)

var (
defaultPollInterval = 5 * time.Minute
)
var defaultPollInterval = 5 * time.Minute

// Config is the overall config structure for the awscloudwatchmetricsreceiver
type Config struct {
Expand Down
16 changes: 9 additions & 7 deletions receiver/awscloudwatchmetricsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ func TestValidate(t *testing.T) {
Region: "eu-west-1",
PollInterval: time.Minute * 5,
Metrics: &MetricsConfig{
Names: []*NamedConfig{{
Namespace: "AWS/EC2",
MetricName: "CPUUtilizaition",
Period: time.Second * 60,
AwsAggregation: "TS99",
},
Names: []*NamedConfig{
{
Namespace: "AWS/EC2",
MetricName: "CPUUtilizaition",
Period: time.Second * 60,
AwsAggregation: "TS99",
},
{
Namespace: "AWS/EC2",
MetricName: "CPUUtilizaition",
Period: time.Second * 60,
AwsAggregation: "TS99"},
AwsAggregation: "TS99",
},
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion receiver/awscloudwatchreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func TestValidate(t *testing.T) {
AutodiscoverConfig: &AutodiscoverConfig{
Limit: -10000,
},
}},
},
},
},
expectedErr: errInvalidAutodiscoverLimit,
},
Expand Down
2 changes: 1 addition & 1 deletion receiver/awscloudwatchreceiver/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (l *logsReceiver) discoverGroups(ctx context.Context, auto *AutodiscoverCon
}

numGroups := 0
var nextToken = aws.String("")
nextToken := aws.String("")
for nextToken != nil {
if numGroups >= auto.Limit {
break
Expand Down
1 change: 0 additions & 1 deletion receiver/awscontainerinsightreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

// Config defines configuration for aws ecs container metrics receiver.
type Config struct {

// CollectionInterval is the interval at which metrics should be collected. The default is 60 second.
CollectionInterval time.Duration `mapstructure:"collection_interval"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ type createCadvisorManager func(*memory.InMemoryCache, sysfs.SysFs, manager.Hous
// a better way to mock the cadvisor related part in the future.
var defaultCreateManager = func(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, housekeepingConfig manager.HousekeepingConfig,
includedMetricsSet cadvisormetrics.MetricSet, collectorHTTPClient *http.Client, rawContainerCgroupPathPrefixWhiteList []string,
perfEventsFile string) (cadvisorManager, error) {
perfEventsFile string,
) (cadvisorManager, error) {
return manager.New(memoryCache, sysfs, housekeepingConfig, includedMetricsSet, collectorHTTPClient, rawContainerCgroupPathPrefixWhiteList, []string{}, perfEventsFile, 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (m *mockCadvisorManager) SubcontainersInfo(_ string, _ *info.ContainerInfoR
return containerInfos, nil
}

type mockCadvisorManager2 struct {
}
type mockCadvisorManager2 struct{}

func (m *mockCadvisorManager2) Start() error {
return errors.New("new error")
Expand All @@ -52,25 +51,27 @@ func (m *mockCadvisorManager2) SubcontainersInfo(_ string, _ *info.ContainerInfo
func newMockCreateManager(t *testing.T) createCadvisorManager {
return func(_ *memory.InMemoryCache, _ sysfs.SysFs, _ manager.HousekeepingConfig,
_ container.MetricSet, _ *http.Client, _ []string,
_ string) (cadvisorManager, error) {
_ string,
) (cadvisorManager, error) {
return &mockCadvisorManager{t: t}, nil
}
}

var mockCreateManager2 = func(_ *memory.InMemoryCache, _ sysfs.SysFs, _ manager.HousekeepingConfig,
_ container.MetricSet, _ *http.Client, _ []string,
_ string) (cadvisorManager, error) {
_ string,
) (cadvisorManager, error) {
return &mockCadvisorManager2{}, nil
}

var mockCreateManagerWithError = func(_ *memory.InMemoryCache, _ sysfs.SysFs, _ manager.HousekeepingConfig,
_ container.MetricSet, _ *http.Client, _ []string,
_ string) (cadvisorManager, error) {
_ string,
) (cadvisorManager, error) {
return nil, errors.New("error")
}

type MockK8sDecorator struct {
}
type MockK8sDecorator struct{}

func (m *MockK8sDecorator) Decorate(metric *extractors.CAdvisorMetric) *extractors.CAdvisorMetric {
return metric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ type HostInfo interface {
}

// Cadvisor is a dummy struct for windows
type Cadvisor struct {
}
type Cadvisor struct{}

type Decorator interface {
Decorate(*extractors.CAdvisorMetric) *extractors.CAdvisorMetric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func newFloat64RateCalculator() awsmetrics.MetricCalculator {
}

func assignRateValueToField(rateCalculator *awsmetrics.MetricCalculator, fields map[string]any, metricName string,
cinfoName string, curVal any, curTime time.Time, multiplier float64) {
cinfoName string, curVal any, curTime time.Time, multiplier float64,
) {
mKey := awsmetrics.NewKey(cinfoName+metricName, nil)
if val, ok := rateCalculator.Calculate(mKey, curVal, curTime); ok {
fields[metricName] = val.(float64) * multiplier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func LoadContainerInfo(t *testing.T, file string) []*cinfo.ContainerInfo {
return result
}

type MockCPUMemInfo struct {
}
type MockCPUMemInfo struct{}

func (m MockCPUMemInfo) GetNumCores() int64 {
return 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func readInt64(dirpath string, file string) (int64, error) {

return val, nil
}

func getCGroupMountPoint(mountConfigPath string) (string, error) {
f, err := os.Open(mountConfigPath)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestGetCGroupMountPoint(t *testing.T) {
}

func TestGetCPUReservedInTask(t *testing.T) {
var ctx, cancel = context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
taskinfo := &MockTaskInfo{
tasks: []ECSTask{},
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestGetCPUReservedInTask(t *testing.T) {
}

func TestGetMEMReservedInTask(t *testing.T) {
var ctx, cancel = context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
taskinfo := &MockTaskInfo{
tasks: []ECSTask{},
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestGetMEMReservedInTask(t *testing.T) {
}

func TestGetCPUReservedAndMemReserved(t *testing.T) {
var ctx, cancel = context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
var tasks []ECSTask
var containers []ECSContainer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type ContainerInstance struct {
}

func newECSInstanceInfo(ctx context.Context, ecsAgentEndpointProvider hostIPProvider,
refreshInterval time.Duration, logger *zap.Logger, httpClient doer, readyC chan bool) containerInstanceInfoProvider {
refreshInterval time.Duration, logger *zap.Logger, httpClient doer, readyC chan bool,
) containerInstanceInfoProvider {
cii := &containerInstanceInfo{
logger: logger,
httpClient: httpClient,
Expand Down Expand Up @@ -76,7 +77,6 @@ func (cii *containerInstanceInfo) refresh(ctx context.Context) {

cluster := containerInstance.Cluster
instanceID, err := GetContainerInstanceIDFromArn(containerInstance.ContainerInstanceArn)

if err != nil {
cii.logger.Warn("Failed to get instance id from arn, error: ", zap.Error(err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ type MockHostInfo struct{}
func (mi *MockHostInfo) GetInstanceIP() string {
return "0.0.0.0"
}

func (mi *MockHostInfo) GetInstanceIPReadyC() chan bool {
readyC := make(chan bool)
return readyC
}

func TestECSInstanceInfo(t *testing.T) {
var ctx, cancel = context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
instanceReadyC := make(chan bool)
hostIPProvider := &MockHostInfo{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type taskInfo struct {
}

func newECSTaskInfo(ctx context.Context, ecsTaskEndpointProvider hostIPProvider,
refreshInterval time.Duration, logger *zap.Logger, httpClient doer, readyC chan bool) ecsTaskInfoProvider {
refreshInterval time.Duration, logger *zap.Logger, httpClient doer, readyC chan bool,
) ecsTaskInfoProvider {
ti := &taskInfo{
logger: logger,
httpClient: httpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func NewECSInfo(refreshInterval time.Duration, hostIPProvider hostIPProvider, ho
ctx, cancel := context.WithCancel(context.Background())

client, err := setting.ToClient(ctx, host, settings)

if err != nil {
settings.Logger.Warn("Failed to create a http client for ECS info!")
cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ type FakehostInfo struct{}
func (hi *FakehostInfo) GetInstanceIP() string {
return "host-ip-address"
}

func (hi *FakehostInfo) GetClusterName() string {
return ""
}

func (hi *FakehostInfo) GetInstanceIPReadyC() chan bool {
readyC := make(chan bool)
close(readyC)
Expand All @@ -35,6 +37,7 @@ type MockInstanceInfo struct {
func (ii *MockInstanceInfo) GetClusterName() string {
return ii.clusterName
}

func (ii *MockInstanceInfo) GetContainerInstanceID() string {
return ii.instanceID
}
Expand All @@ -47,6 +50,7 @@ type MockTaskInfo struct {
func (ii *MockTaskInfo) getRunningTaskCount() int64 {
return ii.runningTaskCount
}

func (ii *MockTaskInfo) getRunningTasksInfo() []ECSTask {
return ii.tasks
}
Expand Down Expand Up @@ -85,7 +89,8 @@ func TestNewECSInfo(t *testing.T) {

taskinfoCreatorOpt := func(ei *EcsInfo) {
ei.ecsTaskInfoCreator = func(context.Context, hostIPProvider, time.Duration, *zap.Logger, doer,
chan bool) ecsTaskInfoProvider {
chan bool,
) ecsTaskInfoProvider {
var tasks []ECSTask
return &MockTaskInfo{
tasks: tasks,
Expand All @@ -96,7 +101,8 @@ func TestNewECSInfo(t *testing.T) {

cgroupScannerCreatorOpt := func(ei *EcsInfo) {
ei.cgroupScannerCreator = func(context.Context, *zap.Logger, ecsTaskInfoProvider, containerInstanceInfoProvider,
time.Duration) cgroupScannerProvider {
time.Duration,
) cgroupScannerProvider {
return &MockCgroupScanner{
cpuReserved: int64(20),
memReserved: int64(1024),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type ebsVolume struct {
type ebsVolumeOption func(*ebsVolume)

func newEBSVolume(ctx context.Context, session *session.Session, instanceID string, region string,
refreshInterval time.Duration, logger *zap.Logger, options ...ebsVolumeOption) ebsVolumeProvider {
refreshInterval time.Duration, logger *zap.Logger, options ...ebsVolumeOption,
) ebsVolumeProvider {
e := &ebsVolume{
dev2Vol: make(map[string]string),
instanceID: instanceID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type mockEBSVolumeClient struct {
}

func (m *mockEBSVolumeClient) DescribeVolumesWithContext(context.Context, *ec2.DescribeVolumesInput,
...request.Option) (*ec2.DescribeVolumesOutput, error) {
...request.Option,
) (*ec2.DescribeVolumesOutput, error) {
m.mu.Lock()
defer m.mu.Unlock()
m.count++
Expand Down Expand Up @@ -99,8 +100,7 @@ func (m *mockEBSVolumeClient) DescribeVolumesWithContext(context.Context, *ec2.D
}, nil
}

type mockFileInfo struct {
}
type mockFileInfo struct{}

func (m *mockFileInfo) Name() string {
return "mockFileInfo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type ec2Metadata struct {
type ec2MetadataOption func(*ec2Metadata)

func newEC2Metadata(ctx context.Context, session *session.Session, refreshInterval time.Duration,
instanceIDReadyC chan bool, instanceIPReadyC chan bool, logger *zap.Logger, options ...ec2MetadataOption) ec2MetadataProvider {
instanceIDReadyC chan bool, instanceIPReadyC chan bool, logger *zap.Logger, options ...ec2MetadataOption,
) ec2MetadataProvider {
emd := &ec2Metadata{
client: awsec2metadata.New(session),
refreshInterval: refreshInterval,
Expand Down
Loading

0 comments on commit 91f05bb

Please sign in to comment.