Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Jan 17, 2024
1 parent 19c4792 commit ba5d523
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 62 deletions.
40 changes: 14 additions & 26 deletions cmd/agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ import (
_ "github.com/DataDog/datadog-agent/pkg/collector/corechecks/containers/kubelet"
_ "github.com/DataDog/datadog-agent/pkg/collector/corechecks/ebpf"
_ "github.com/DataDog/datadog-agent/pkg/collector/corechecks/embed"
_ "github.com/DataDog/datadog-agent/pkg/collector/corechecks/net"
_ "github.com/DataDog/datadog-agent/pkg/collector/corechecks/nvidia/jetson"
_ "github.com/DataDog/datadog-agent/pkg/collector/corechecks/oracle-dbm"
_ "github.com/DataDog/datadog-agent/pkg/collector/corechecks/orchestrator/pod"
Expand Down Expand Up @@ -329,42 +328,31 @@ func getSharedFxOption() fx.Option {
status.NewInformationProvider(jmxStatus.Provider{}),
status.NewInformationProvider(endpointsStatus.Provider{}),
),
fx.Provide(func(config config.Component) status.InformationProvider {
fx.Provide(func(config config.Component) []status.InformationProvider {
statusProviders := []status.InformationProvider{}

if traps.IsEnabled(config) {
return status.NewInformationProvider(snmpStatus.Provider{})
} else {
return status.NewInformationProvider(status.NoopProvider{})
statusProviders = append(statusProviders, status.NewInformationProvider(snmpStatus.Provider{}))
}
}),
fx.Provide(func(config config.Component) status.InformationProvider {
if config.GetBool("cluster_agent.enabled") || config.GetBool("cluster_checks.enabled") {
return status.NewInformationProvider(clusteragentStatus.Provider{})
} else {
return status.NewInformationProvider(status.NoopProvider{})
statusProviders = append(statusProviders, status.NewInformationProvider(clusteragentStatus.Provider{}))
}
}),
fx.Provide(func() status.InformationProvider {

if pkgconfig.SystemProbe.GetBool("system_probe_config.enabled") {
return status.NewInformationProvider(systemprobeStatus.Provider{
statusProviders = append(statusProviders, status.NewInformationProvider(systemprobeStatus.Provider{
SocketPath: pkgconfig.SystemProbe.GetString("system_probe_config.sysprobe_socket"),
})
} else {
return status.NewInformationProvider(status.NoopProvider{})
}))
}
}),
fx.Provide(func() status.InformationProvider {

if !pkgconfig.Datadog.GetBool("no_proxy_nonexact_match") {
return status.NewInformationProvider(httpproxyStatus.Provider{})
} else {
return status.NewInformationProvider(status.NoopProvider{})
statusProviders = append(statusProviders, status.NewInformationProvider(httpproxyStatus.Provider{}))
}
}),
fx.Provide(func() status.InformationProvider {

if pkgconfig.IsContainerized() {
return status.NewInformationProvider(autodiscoveryStatus.Provider{})
} else {
return status.NewInformationProvider(status.NoopProvider{})
statusProviders = append(statusProviders, status.NewInformationProvider(autodiscoveryStatus.Provider{}))
}

return statusProviders
}),
statusimpl.Module(),
apiimpl.Module(),
Expand Down
22 changes: 22 additions & 0 deletions comp/core/status/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,60 @@ type HeaderInformationProvider struct {
Provider HeaderProvider `group:"header_status"`
}

// NoopProvider implements the InformationProvider interface
// This provides is ignored by the status component
type NoopProvider struct{}

// Name returns the name
func (p NoopProvider) Name() string {
return ""
}

// Section return the section
func (p NoopProvider) Section() string {
return ""
}

// JSON populates the status map
func (p NoopProvider) JSON(_ bool, _ map[string]interface{}) error {
return nil
}

// Text renders the text output
func (p NoopProvider) Text(_ bool, _ io.Writer) error {
return nil
}

// HTML renders the html output
func (p NoopProvider) HTML(_ bool, _ io.Writer) error {
return nil
}

// NoopHeaderProvider implements the HeaderProvider interface
// This provides is ignored by the status component
type NoopHeaderProvider struct{}

// Name returns the name
func (p NoopHeaderProvider) Name() string {
return ""
}

// Index return index
func (p NoopHeaderProvider) Index() int {
return 0
}

// JSON populates the status map
func (p NoopHeaderProvider) JSON(_ bool, _ map[string]interface{}) error {
return nil
}

// Text renders the text output
func (p NoopHeaderProvider) Text(_ bool, _ io.Writer) error {
return nil
}

// HTML renders the html output
func (p NoopHeaderProvider) HTML(_ bool, _ io.Writer) error {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions comp/dogstatsd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,17 +844,17 @@ func (s *server) Section() string {
return "dogstatsd"
}

func (s *server) JSON(verbose bool, stats map[string]interface{}) error {
func (s *server) JSON(_ bool, stats map[string]interface{}) error {
s.populateStatus(stats)

return nil
}

func (s *server) Text(verbose bool, buffer io.Writer) error {
func (s *server) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, s.getStatusInfo())
}

func (s *server) HTML(verbose bool, buffer io.Writer) error {
func (s *server) HTML(_ bool, buffer io.Writer) error {
return renderHTML(buffer, s.getStatusInfo())
}

Expand Down
6 changes: 3 additions & 3 deletions comp/metadata/inventoryagent/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ func (ia *inventoryagent) Index() int {
return 3
}

func (ia *inventoryagent) JSON(verbose bool, stats map[string]interface{}) error {
func (ia *inventoryagent) JSON(_ bool, stats map[string]interface{}) error {
for k, v := range ia.Get() {
stats[k] = v
}

return nil
}

func (ia *inventoryagent) Text(verbose bool, buffer io.Writer) error {
func (ia *inventoryagent) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, ia.Get())
}

func (ia *inventoryagent) HTML(verbose bool, buffer io.Writer) error {
func (ia *inventoryagent) HTML(_ bool, buffer io.Writer) error {
return renderHTML(buffer, ia.Get())
}

Expand Down
4 changes: 3 additions & 1 deletion comp/netflow/server/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
//go:embed status_templates
var templatesFS embed.FS

// Provider provides the functionality to populate the status output with the collector information
// Provider provides the functionality to populate the status output
type Provider struct{}

// Name returns the name
Expand Down Expand Up @@ -57,10 +57,12 @@ func (Provider) JSON(_ bool, stats map[string]interface{}) error {
return nil
}

// Text renders the text output
func (Provider) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, GetStatus())
}

// HTML renders the html output
func (Provider) HTML(_ bool, buffer io.Writer) error {
return renderHTML(buffer, GetStatus())
}
Expand Down
11 changes: 6 additions & 5 deletions comp/process/forwarders/forwardersimpl/forwarders.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package forwardersimpl

import (
"go.uber.org/fx"

"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder"
Expand All @@ -16,7 +18,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/process/runner/endpoint"
apicfg "github.com/DataDog/datadog-agent/pkg/process/util/api/config"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"go.uber.org/fx"
)

// Module defines the fx options for this component.
Expand Down Expand Up @@ -63,10 +64,10 @@ func newForwarders(deps dependencies) (forwarders.Component, error) {
processForwarderOpts := createParams(deps.Config, deps.Logger, queueBytes, processAPIEndpoints)

return &forwardersComp{
eventForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, eventForwarderOpts),
processForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, processForwarderOpts),
rtProcessForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, processForwarderOpts),
connectionsForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, processForwarderOpts),
eventForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, eventForwarderOpts).Comp,
processForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, processForwarderOpts).Comp,
rtProcessForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, processForwarderOpts).Comp,
connectionsForwarder: defaultforwarder.NewForwarder(deps.Config, deps.Logger, processForwarderOpts).Comp,
}, nil

}
Expand Down
5 changes: 5 additions & 0 deletions pkg/aggregator/demultiplexer_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,24 +685,29 @@ func (d *AgentDemultiplexer) populateStatus(stats map[string]interface{}) {
}
}

// Name returns the name
func (d *AgentDemultiplexer) Name() string {
return "Aggregator"
}

// Section return the section
func (d *AgentDemultiplexer) Section() string {
return "aggregator"
}

// JSON populates the status map
func (d *AgentDemultiplexer) JSON(_ bool, stats map[string]interface{}) error {
d.populateStatus(stats)

return nil
}

// Text renders the text output
func (d *AgentDemultiplexer) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, d.getStatusInfo())
}

// HTML renders the html output
func (d *AgentDemultiplexer) HTML(_ bool, buffer io.Writer) error {
return renderHTML(buffer, d.getStatusInfo())
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/collector/corechecks/net/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
//go:embed status_templates
var templatesFS embed.FS

// Provider provides the functionality to populate the status output with the collector information
// Provider provides the functionality to populate the status output
type Provider struct{}

// Name returns the name
Expand Down Expand Up @@ -53,17 +53,19 @@ func (Provider) populateStatus(stats map[string]interface{}) {
}

// JSON populates the status map
func (p Provider) JSON(verbose bool, stats map[string]interface{}) error {
func (p Provider) JSON(_ bool, stats map[string]interface{}) error {
p.populateStatus(stats)

return nil
}

func (p Provider) Text(verbose bool, buffer io.Writer) error {
// Text renders the text output
func (p Provider) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, p.getStatusInfo())
}

func (p Provider) HTML(verbose bool, buffer io.Writer) error {
// HTML renders the html output
func (p Provider) HTML(_ bool, buffer io.Writer) error {
return renderHTML(buffer, p.getStatusInfo())
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/compliance/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
//go:embed status_templates
var templatesFS embed.FS

// Provider provides the functionality to populate the status output with the collector information
// Provider provides the functionality to populate the status output
type Provider struct{}

// Name returns the name
Expand Down Expand Up @@ -74,11 +74,13 @@ func (Provider) JSON(_ bool, stats map[string]interface{}) error {
return nil
}

// Text renders the text output
func (Provider) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, getStatus())
}

func (Provider) HTML(_ bool, buffer io.Writer) error {
// HTML renders the html output
func (Provider) HTML(_ bool, _ io.Writer) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/serverless/metrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (m *MetricConfig) GetMultipleEndpoints() (map[string][]string, error) {

// NewServer returns a running DogStatsD server
func (m *MetricDogStatsD) NewServer(demux aggregator.Demultiplexer) (dogstatsdServer.Component, error) {
s := dogstatsdServer.NewServerlessServer()
return s, s.Start(demux)
provides := dogstatsdServer.NewServerlessServer()
return provides.Comp, provides.Comp.Start(demux)
}

// Start starts the DogStatsD agent
Expand Down
6 changes: 3 additions & 3 deletions pkg/serverless/metrics/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ func TestRaceFlushVersusParsePacket(t *testing.T) {

demux := aggregator.InitAndStartServerlessDemultiplexer(nil, time.Second*1000)

s := dogstatsdServer.NewServerlessServer()
err = s.Start(demux)
provides := dogstatsdServer.NewServerlessServer()
err = provides.Comp.Start(demux)
require.NoError(t, err, "cannot start DSD")
defer s.Stop()
defer provides.Comp.Stop()

url := fmt.Sprintf("127.0.0.1:%d", config.Datadog.GetInt("dogstatsd_port"))
conn, err := net.Dial("udp", url)
Expand Down
4 changes: 3 additions & 1 deletion pkg/snmp/traps/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func GetStatus() map[string]interface{} {
//go:embed status_templates
var templatesFS embed.FS

// Provider provides the functionality to populate the status output with the collector information
// Provider provides the functionality to populate the status output
type Provider struct{}

// Name returns the name
Expand All @@ -121,10 +121,12 @@ func (Provider) JSON(_ bool, stats map[string]interface{}) error {
return nil
}

// Text renders the text output
func (Provider) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, GetStatus())
}

// HTML renders the html output
func (Provider) HTML(_ bool, buffer io.Writer) error {
return renderHTML(buffer, GetStatus())
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/status/autodiscovery/autodicovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func PopulateStatus(stats map[string]interface{}) {
//go:embed status_templates
var templatesFS embed.FS

// Provider provides the functionality to populate the status output
type Provider struct{}

func (p Provider) getStatusInfo() map[string]interface{} {
Expand All @@ -41,25 +42,30 @@ func (p Provider) getStatusInfo() map[string]interface{} {
return stats
}

// Name returns the name
func (p Provider) Name() string {
return "Autodiscovery"
}

// Section return the section
func (p Provider) Section() string {
return "Autodiscovery"
}

// JSON populates the status map
func (p Provider) JSON(_ bool, stats map[string]interface{}) error {
PopulateStatus(stats)

return nil
}

// Text renders the text output
func (p Provider) Text(_ bool, buffer io.Writer) error {
return renderText(buffer, p.getStatusInfo())
}

func (p Provider) HTML(_ bool, buffer io.Writer) error {
// HTML renders the html output
func (p Provider) HTML(_ bool, _ io.Writer) error {
return nil
}

Expand Down
Loading

0 comments on commit ba5d523

Please sign in to comment.