Skip to content

Commit

Permalink
golangci fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Oct 21, 2024
1 parent 5037933 commit a59d229
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cmd/agent/subcommands/flare/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
InitHelper: common.GetWorkloadmetaInit(),
NoInstance: !cliParams.forceLocal, //if forceLocal is true, we want to run workloadmeta
}),
taggerimpl.OptionalModule(),
autodiscoveryimpl.OptionalModule(), // if forceLocal is true, we will start autodiscovery (loadComponents) later
taggerimpl.Module(),
autodiscoveryimpl.Module(), // if forceLocal is true, we will start autodiscovery (loadComponents) later
fx.Supply(optional.NewNoneOption[collector.Component]()),
compressionimpl.Module(),
diagnosesendermanagerimpl.Module(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster-agent/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,6 @@ func registerChecks(wlm workloadmeta.Component, tagger tagger.Component, cfg con
corecheckLoader.RegisterCheck(ksm.CheckName, ksm.Factory())
corecheckLoader.RegisterCheck(helm.CheckName, helm.Factory())
corecheckLoader.RegisterCheck(disk.CheckName, disk.Factory())
corecheckLoader.RegisterCheck(orchestrator.CheckName, orchestrator.Factory(wlm, cfg))
corecheckLoader.RegisterCheck(orchestrator.CheckName, orchestrator.Factory(wlm, cfg, tagger))
corecheckLoader.RegisterCheck(winproc.CheckName, winproc.Factory())
}
2 changes: 2 additions & 0 deletions cmd/systray/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/flare"
log "github.com/DataDog/datadog-agent/comp/core/log/def"
nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/noopimpl"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/comp/metadata/inventoryagent/inventoryagentimpl"
"github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl"
Expand Down Expand Up @@ -110,6 +111,7 @@ func MakeCommand() *cobra.Command {
fx.Supply(optional.NewNoneOption[collector.Component]()),
compressionimpl.Module(),
diagnosesendermanagerimpl.Module(),
nooptagger.Module(),
authtokenimpl.Module(),
// We need inventoryagent to fill the status page generated by the flare.
inventoryagentimpl.Module(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/hostname"
log "github.com/DataDog/datadog-agent/comp/core/log/def"
"github.com/DataDog/datadog-agent/comp/core/tagger"
"github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder"
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatform"
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl"
Expand All @@ -37,6 +38,7 @@ type dependencies struct {
Config config.Component
Hostname hostname.Component
Compressor compression.Component
Tagger tagger.Component
}

type diagnoseSenderManager struct {
Expand Down Expand Up @@ -77,6 +79,7 @@ func (sender *diagnoseSenderManager) LazyGetSenderManager() (sender.SenderManage
opts,
eventPlatformForwarder,
sender.deps.Compressor,
sender.deps.Tagger,
hostnameDetected)

sender.senderManager.Set(senderManager)
Expand Down
1 change: 1 addition & 0 deletions comp/core/tagger/noopimpl/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (n *noopTagger) DogstatsdCardinality() types.TagCardinality {
return types.LowCardinality
}

// NewTaggerClient returns a new noop tagger client
func NewTaggerClient() tagger.Component {
return &noopTagger{}
}
7 changes: 3 additions & 4 deletions pkg/aggregator/mocksender/mocksender.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import (

//nolint:revive // TODO(AML) Fix revive linter

nnoptagger "github.com/DataDog/datadog-agent/comp/core/tagger/noopimpl"
forwarder "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder"
nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/noopimpl"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id"
Expand All @@ -42,10 +41,10 @@ func CreateDefaultDemultiplexer() *aggregator.AgentDemultiplexer {
opts.FlushInterval = 1 * time.Hour
opts.DontStartForwarders = true
log := logimpl.NewTemporaryLoggerWithoutInit()
sharedForwarder := forwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, forwarder.NewOptions(pkgconfigsetup.Datadog(), log, nil))
sharedForwarder := defaultforwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, defaultforwarder.NewOptions(pkgconfigsetup.Datadog(), log, nil))
orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{})
eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostnameimpl.NewHostnameService()))
taggerComponent := nnoptagger.NewTaggerClient()
taggerComponent := nooptagger.NewTaggerClient()
return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, compressionimpl.NewMockCompressor(), taggerComponent, "")

}
Expand Down
7 changes: 5 additions & 2 deletions pkg/collector/corechecks/containers/containerd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"gopkg.in/yaml.v2"

"github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration"
"github.com/DataDog/datadog-agent/comp/core/tagger"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/collector/check"
Expand Down Expand Up @@ -52,6 +53,7 @@ type ContainerdCheck struct {
client cutil.ContainerdItf
httpClient http.Client
store workloadmeta.Component
tagger tagger.Component
}

// ContainerdConfig contains the custom options and configurations set by the user.
Expand All @@ -62,12 +64,13 @@ type ContainerdConfig struct {
}

// Factory is used to create register the check and initialize it.
func Factory(store workloadmeta.Component) optional.Option[func() check.Check] {
func Factory(store workloadmeta.Component, tagger tagger.Component) optional.Option[func() check.Check] {
return optional.NewOption(func() check.Check {
return &ContainerdCheck{
CheckBase: corechecks.NewCheckBase(CheckName),
instance: &ContainerdConfig{},
store: store,
tagger: tagger,
}
})
}
Expand Down Expand Up @@ -99,7 +102,7 @@ func (c *ContainerdCheck) Configure(senderManager sender.SenderManager, _ uint64
}

c.httpClient = http.Client{Timeout: time.Duration(1) * time.Second}
c.processor = generic.NewProcessor(metrics.GetProvider(optional.NewOption(c.store)), generic.NewMetadataContainerAccessor(c.store), metricsAdapter{}, getProcessorFilter(c.containerFilter, c.store))
c.processor = generic.NewProcessor(metrics.GetProvider(optional.NewOption(c.store)), generic.NewMetadataContainerAccessor(c.store), metricsAdapter{}, getProcessorFilter(c.containerFilter, c.store), c.tagger)
c.processor.RegisterExtension("containerd-custom-metrics", &containerdCustomMetricsExtension{})
c.subscriber = createEventSubscriber("ContainerdCheck", c.client, cutil.FiltersWithNamespaces(c.instance.ContainerdFilters))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package containerd
import (
"time"

"github.com/DataDog/datadog-agent/comp/core/tagger"
taggerUtils "github.com/DataDog/datadog-agent/comp/core/tagger/utils"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
Expand Down Expand Up @@ -65,6 +66,6 @@ func (cext *containerdCustomMetricsExtension) Process(tags []string, container *
}

// PostProcess is called once during each check run, after all calls to `Process`
func (cext *containerdCustomMetricsExtension) PostProcess() {
func (cext *containerdCustomMetricsExtension) PostProcess(tagger.Component) {
// Nothing to do here
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestContainerdCheckGenericPart(t *testing.T) {
}

// Inject mock processor in check
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil))
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil), fakeTagger)
processor.RegisterExtension("containerd-custom-metrics", &containerdCustomMetricsExtension{})

// Mock the containerd endpoint
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/corechecks/containers/containerd/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package containerd

import (
"github.com/DataDog/datadog-agent/comp/core/tagger"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/collector/check"
"github.com/DataDog/datadog-agent/pkg/util/optional"
Expand All @@ -20,6 +21,6 @@ const (
)

// Factory is used to create register the check and initialize it.
func Factory(_ workloadmeta.Component) optional.Option[func() check.Check] {
func Factory(workloadmeta.Component, tagger.Component) optional.Option[func() check.Check] {
return optional.NewNoneOption[func() check.Check]()
}
7 changes: 5 additions & 2 deletions pkg/collector/corechecks/containers/cri/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
yaml "gopkg.in/yaml.v2"

"github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration"
"github.com/DataDog/datadog-agent/comp/core/tagger"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/collector/check"
Expand Down Expand Up @@ -44,15 +45,17 @@ type CRICheck struct {
instance *CRIConfig
processor generic.Processor
store workloadmeta.Component
tagger tagger.Component
}

// Factory is exported for integration testing
func Factory(store workloadmeta.Component) optional.Option[func() check.Check] {
func Factory(store workloadmeta.Component, tagger tagger.Component) optional.Option[func() check.Check] {
return optional.NewOption(func() check.Check {
return &CRICheck{
CheckBase: core.NewCheckBase(CheckName),
instance: &CRIConfig{},
store: store,
tagger: tagger,
}
})
}
Expand Down Expand Up @@ -81,7 +84,7 @@ func (c *CRICheck) Configure(senderManager sender.SenderManager, _ uint64, confi
log.Warnf("Can't get container include/exclude filter, no filtering will be applied: %v", err)
}

c.processor = generic.NewProcessor(metrics.GetProvider(optional.NewOption(c.store)), generic.NewMetadataContainerAccessor(c.store), metricsAdapter{}, getProcessorFilter(containerFilter, c.store))
c.processor = generic.NewProcessor(metrics.GetProvider(optional.NewOption(c.store)), generic.NewMetadataContainerAccessor(c.store), metricsAdapter{}, getProcessorFilter(containerFilter, c.store), c.tagger)
if c.instance.CollectDisk {
c.processor.RegisterExtension("cri-custom-metrics", &criCustomMetricsExtension{criGetter: func() (cri.CRIClient, error) {
return cri.GetUtil()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package cri
import (
"time"

"github.com/DataDog/datadog-agent/comp/core/tagger"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/containers/generic"
Expand Down Expand Up @@ -61,6 +62,6 @@ func (cext *criCustomMetricsExtension) Process(tags []string, container *workloa
}

// PostProcess is called once during each check run, after all calls to `Process`
func (cext *criCustomMetricsExtension) PostProcess() {
func (cext *criCustomMetricsExtension) PostProcess(tagger.Component) {
cext.criContainerStats = nil
}
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/containers/cri/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestCriCheck(t *testing.T) {

// Inject mock processor in check
mockCri := &crimock.MockCRIClient{}
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil))
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil), fakeTagger)
processor.RegisterExtension("cri-custom-metrics", &criCustomMetricsExtension{criGetter: func() (cri.CRIClient, error) { return mockCri, nil }})

mockCri.On("ListContainerStats").Return(map[string]*criTypes.ContainerStats{
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/corechecks/containers/cri/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package cri

import (
"github.com/DataDog/datadog-agent/comp/core/tagger"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/collector/check"
"github.com/DataDog/datadog-agent/pkg/util/optional"
Expand All @@ -20,6 +21,6 @@ const (
)

// Factory creates a new check instance
func Factory(_ workloadmeta.Component) optional.Option[func() check.Check] {
func Factory(workloadmeta.Component, tagger.Component) optional.Option[func() check.Check] {
return optional.NewNoneOption[func() check.Check]()
}
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/containers/docker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (d *DockerCheck) Configure(senderManager sender.SenderManager, _ uint64, co
log.Warnf("Can't get container include/exclude filter, no filtering will be applied: %v", err)
}

d.processor = generic.NewProcessor(metrics.GetProvider(optional.NewOption(d.store)), generic.NewMetadataContainerAccessor(d.store), metricsAdapter{}, getProcessorFilter(d.containerFilter, d.store))
d.processor = generic.NewProcessor(metrics.GetProvider(optional.NewOption(d.store)), generic.NewMetadataContainerAccessor(d.store), metricsAdapter{}, getProcessorFilter(d.containerFilter, d.store), d.tagger)
d.processor.RegisterExtension("docker-custom-metrics", &dockerCustomMetricsExtension{})
d.configureNetworkProcessor(&d.processor)
d.setOkExitCodes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
dockerTypes "github.com/docker/docker/api/types"
dockerNetworkTypes "github.com/docker/docker/api/types/network"

nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/noopimpl"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/containers/generic"
Expand Down Expand Up @@ -244,7 +245,7 @@ func TestDockerNetworkExtension(t *testing.T) {
dockerNetworkExtension.Process(tags, container1, mockCollector, 0)
dockerNetworkExtension.Process(tags, container2, mockCollector, 0)
dockerNetworkExtension.Process(tags, container4, mockCollector, 0)
dockerNetworkExtension.PostProcess()
dockerNetworkExtension.PostProcess(nooptagger.NewTaggerClient())

// Running the custom part
dockerNetworkExtension.preRun()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math"
"time"

"github.com/DataDog/datadog-agent/comp/core/tagger"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/containers/generic"
Expand Down Expand Up @@ -108,7 +109,7 @@ func (dn *dockerCustomMetricsExtension) Process(tags []string, container *worklo
}

// PostProcess is called once during each check run, after all calls to `Process`
func (dn *dockerCustomMetricsExtension) PostProcess() {
func (dn *dockerCustomMetricsExtension) PostProcess(tagger.Component) {
// Nothing to do here
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/corechecks/containers/docker/check_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

dockerTypes "github.com/docker/docker/api/types"

"github.com/DataDog/datadog-agent/comp/core/tagger"
taggerUtils "github.com/DataDog/datadog-agent/comp/core/tagger/utils"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (dn *dockerNetworkExtension) Process(tags []string, container *workloadmeta
}

// PostProcess is called once during each check run, after all calls to `Process`
func (dn *dockerNetworkExtension) PostProcess() {
func (dn *dockerNetworkExtension) PostProcess(tagger.Component) {
// Nothing to do here
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/collector/corechecks/containers/docker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestDockerCheckGenericPart(t *testing.T) {
}

// Inject mock processor in check
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil))
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil), fakeTagger)
processor.RegisterExtension("docker-custom-metrics", &dockerCustomMetricsExtension{})

// Create Docker check
Expand Down Expand Up @@ -303,6 +303,9 @@ func TestContainersRunning(t *testing.T) {
}

func TestProcess_CPUSharesMetric(t *testing.T) {
fakeTagger := taggerimpl.SetupFakeTagger(t)
defer fakeTagger.ResetTagger()

containersMeta := []*workloadmeta.Container{
generic.CreateContainerMeta("docker", "cID100"),
generic.CreateContainerMeta("docker", "cID101"),
Expand Down Expand Up @@ -334,7 +337,7 @@ func TestProcess_CPUSharesMetric(t *testing.T) {
}

// Inject mock processor in check
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil))
mockSender, processor, _ := generic.CreateTestProcessor(containersMeta, containersStats, metricsAdapter{}, getProcessorFilter(nil, nil), fakeTagger)
processor.RegisterExtension("docker-custom-metrics", &dockerCustomMetricsExtension{})

// Create Docker check
Expand Down
3 changes: 2 additions & 1 deletion pkg/collector/corechecks/containers/docker/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package docker

import (
"github.com/DataDog/datadog-agent/comp/core/tagger"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/collector/check"
"github.com/DataDog/datadog-agent/pkg/util/optional"
Expand All @@ -19,6 +20,6 @@ const (
CheckName = "docker"
)

func Factory(_ workloadmeta.Component) optional.Option[func() check.Check] {
func Factory(workloadmeta.Component, tagger.Component) optional.Option[func() check.Check] {
return optional.NewNoneOption[func() check.Check]()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration"
nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/noopimpl"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
Expand All @@ -24,7 +25,7 @@ import (

func TestProfileBundleJsonZip(t *testing.T) {
timeNow = common.MockTimeNow
aggregator.NewBufferedAggregator(nil, nil, "", 1*time.Hour)
aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewTaggerClient(), "", 1*time.Hour)
invalidPath, _ := filepath.Abs(filepath.Join("internal", "test", "zipprofiles.d"))
pkgconfigsetup.Datadog().SetWithoutSource("confd_path", invalidPath)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/stretchr/testify/mock"

"github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration"
nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/noopimpl"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
Expand All @@ -31,7 +32,7 @@ import (

func TestProfileMetadata_f5(t *testing.T) {
timeNow = common.MockTimeNow
aggregator.NewBufferedAggregator(nil, nil, "", 1*time.Hour)
aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewTaggerClient(), "", 1*time.Hour)
invalidPath, _ := filepath.Abs(filepath.Join("internal", "test", "metadata.d"))
pkgconfigsetup.Datadog().SetWithoutSource("confd_path", invalidPath)

Expand Down
Loading

0 comments on commit a59d229

Please sign in to comment.