From af96a9414d7bdf58027e5aedb654756306495209 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Mon, 18 Nov 2024 12:24:30 +0100 Subject: [PATCH 01/27] [haagent] Add haagent component --- .github/CODEOWNERS | 1 + cmd/agent/subcommands/run/command.go | 2 + comp/haagent/def/component.go | 25 +++++++++ comp/haagent/fx/fx.go | 23 +++++++++ comp/haagent/impl/config.go | 22 ++++++++ comp/haagent/impl/haagent.go | 44 ++++++++++++++++ comp/haagent/impl/haagent_comp.go | 33 ++++++++++++ comp/haagent/impl/haagent_test.go | 57 +++++++++++++++++++++ comp/haagent/impl/haagent_testutils_test.go | 32 ++++++++++++ comp/haagent/mock/mock.go | 45 ++++++++++++++++ pkg/config/setup/config.go | 4 ++ 11 files changed, 288 insertions(+) create mode 100644 comp/haagent/def/component.go create mode 100644 comp/haagent/fx/fx.go create mode 100644 comp/haagent/impl/config.go create mode 100644 comp/haagent/impl/haagent.go create mode 100644 comp/haagent/impl/haagent_comp.go create mode 100644 comp/haagent/impl/haagent_test.go create mode 100644 comp/haagent/impl/haagent_testutils_test.go create mode 100644 comp/haagent/mock/mock.go diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index cd9cafea971f8..86aeb529e652f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -320,6 +320,7 @@ /comp/rdnsquerier @DataDog/ndm-integrations /comp/serializer/compression @DataDog/agent-metrics-logs /comp/snmpscan @DataDog/ndm-core +/comp/haagent @DataDog/network-device-monitoring @DataDog/remote-config @DataDog/fleet # END COMPONENTS # Additional notification to @iglendd about Agent Telemetry changes for optional approval and governance acknowledgement diff --git a/cmd/agent/subcommands/run/command.go b/cmd/agent/subcommands/run/command.go index 986ff25c5349f..e23e94d67a3f7 100644 --- a/cmd/agent/subcommands/run/command.go +++ b/cmd/agent/subcommands/run/command.go @@ -30,6 +30,7 @@ import ( internalsettings "github.com/DataDog/datadog-agent/cmd/agent/subcommands/run/internal/settings" agenttelemetry "github.com/DataDog/datadog-agent/comp/core/agenttelemetry/def" agenttelemetryfx "github.com/DataDog/datadog-agent/comp/core/agenttelemetry/fx" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" // checks implemented as components @@ -472,6 +473,7 @@ func getSharedFxOption() fx.Option { agenttelemetryfx.Module(), networkpath.Bundle(), remoteagentregistryfx.Module(), + haagentfx.Module(), ) } diff --git a/comp/haagent/def/component.go b/comp/haagent/def/component.go new file mode 100644 index 0000000000000..e20be4b3d0c81 --- /dev/null +++ b/comp/haagent/def/component.go @@ -0,0 +1,25 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + +// Package haagent handles states for HA Agent feature. +package haagent + +// team: network-device-monitoring + +// Component is the component type. +type Component interface { + // Enabled returns true if ha_agent.enabled is set to true + Enabled() bool + + // GetGroup returns the value of ha_agent.group + GetGroup() string + + // IsLeader returns true if the current Agent is leader + IsLeader() bool + + // SetLeader takes the leader agent hostname as input, if it matches the current agent hostname, + // the isLeader state is set to true, otherwise false. + SetLeader(leaderAgentHostname string) +} diff --git a/comp/haagent/fx/fx.go b/comp/haagent/fx/fx.go new file mode 100644 index 0000000000000..a60f314250169 --- /dev/null +++ b/comp/haagent/fx/fx.go @@ -0,0 +1,23 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + +// Package fx provides the fx module for the haagent component +package fx + +import ( + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl" + "github.com/DataDog/datadog-agent/pkg/util/fxutil" +) + +// Module defines the fx options for this component +func Module() fxutil.Module { + return fxutil.Component( + fxutil.ProvideComponentConstructor( + haagentimpl.NewComponent, + ), + fxutil.ProvideOptional[haagent.Component](), + ) +} diff --git a/comp/haagent/impl/config.go b/comp/haagent/impl/config.go new file mode 100644 index 0000000000000..2417106455a7d --- /dev/null +++ b/comp/haagent/impl/config.go @@ -0,0 +1,22 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + +package haagentimpl + +import ( + "github.com/DataDog/datadog-agent/comp/core/config" +) + +type haAgentConfigs struct { + enabled bool + group string +} + +func newHaAgentConfigs(agentConfig config.Component) *haAgentConfigs { + return &haAgentConfigs{ + enabled: agentConfig.GetBool("ha_agent.enabled"), + group: agentConfig.GetString("ha_agent.group"), + } +} diff --git a/comp/haagent/impl/haagent.go b/comp/haagent/impl/haagent.go new file mode 100644 index 0000000000000..4b51f09d69fe1 --- /dev/null +++ b/comp/haagent/impl/haagent.go @@ -0,0 +1,44 @@ +package haagentimpl + +import ( + "context" + + log "github.com/DataDog/datadog-agent/comp/core/log/def" + "github.com/DataDog/datadog-agent/pkg/util/hostname" + "go.uber.org/atomic" +) + +type haAgentImpl struct { + log log.Component + haAgentConfigs *haAgentConfigs + isLeader *atomic.Bool +} + +func newHaAgentImpl(log log.Component, haAgentConfigs *haAgentConfigs) *haAgentImpl { + return &haAgentImpl{ + log: log, + haAgentConfigs: haAgentConfigs, + isLeader: atomic.NewBool(false), + } +} + +func (h *haAgentImpl) Enabled() bool { + return h.haAgentConfigs.enabled +} + +func (h *haAgentImpl) GetGroup() string { + return h.haAgentConfigs.group +} + +func (h *haAgentImpl) IsLeader() bool { + return h.isLeader.Load() +} + +func (h *haAgentImpl) SetLeader(leaderAgentHostname string) { + agentHostname, err := hostname.Get(context.TODO()) + if err != nil { + h.log.Warnf("Error getting the hostname: %v", err) + return + } + h.isLeader.Store(agentHostname == leaderAgentHostname) +} diff --git a/comp/haagent/impl/haagent_comp.go b/comp/haagent/impl/haagent_comp.go new file mode 100644 index 0000000000000..24f591741fa0d --- /dev/null +++ b/comp/haagent/impl/haagent_comp.go @@ -0,0 +1,33 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + +// Package haagentimpl implements the haagent component interface +package haagentimpl + +import ( + "github.com/DataDog/datadog-agent/comp/core/config" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" +) + +// Requires defines the dependencies for the haagent component +type Requires struct { + Logger log.Component + AgentConfig config.Component +} + +// Provides defines the output of the haagent component +type Provides struct { + Comp haagent.Component +} + +// NewComponent creates a new haagent component +func NewComponent(reqs Requires) (Provides, error) { + haAgentConfigs := newHaAgentConfigs(reqs.AgentConfig) + provides := Provides{ + Comp: newHaAgentImpl(reqs.Logger, haAgentConfigs), + } + return provides, nil +} diff --git a/comp/haagent/impl/haagent_test.go b/comp/haagent/impl/haagent_test.go new file mode 100644 index 0000000000000..63011aa645e44 --- /dev/null +++ b/comp/haagent/impl/haagent_test.go @@ -0,0 +1,57 @@ +package haagentimpl + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_Enabled(t *testing.T) { + tests := []struct { + name string + configs map[string]interface{} + expectedEnabled bool + }{ + { + name: "enabled", + configs: map[string]interface{}{ + "ha_agent.enabled": true, + }, + expectedEnabled: true, + }, + { + name: "disabled", + configs: map[string]interface{}{ + "ha_agent.enabled": false, + }, + expectedEnabled: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + haAgent := newTestHaAgentComponent(t, tt.configs) + assert.Equal(t, tt.expectedEnabled, haAgent.Enabled()) + }) + } +} + +func Test_GetGroup(t *testing.T) { + agentConfigs := map[string]interface{}{ + "ha_agent.group": "my-group-01", + } + haAgent := newTestHaAgentComponent(t, agentConfigs) + assert.Equal(t, "my-group-01", haAgent.GetGroup()) +} + +func Test_IsLeader_SetLeader(t *testing.T) { + agentConfigs := map[string]interface{}{ + "hostname": "my-agent-hostname", + } + haAgent := newTestHaAgentComponent(t, agentConfigs) + + haAgent.SetLeader("another-agent") + assert.False(t, haAgent.IsLeader()) + + haAgent.SetLeader("my-agent-hostname") + assert.True(t, haAgent.IsLeader()) +} diff --git a/comp/haagent/impl/haagent_testutils_test.go b/comp/haagent/impl/haagent_testutils_test.go new file mode 100644 index 0000000000000..bdeb90cee7155 --- /dev/null +++ b/comp/haagent/impl/haagent_testutils_test.go @@ -0,0 +1,32 @@ +package haagentimpl + +import ( + "testing" + + "github.com/DataDog/datadog-agent/comp/core/config" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" + "github.com/DataDog/datadog-agent/pkg/util/fxutil" + "github.com/stretchr/testify/require" + "go.uber.org/fx" +) + +func newTestHaAgentComponent(t *testing.T, agentConfigs map[string]interface{}) haagent.Component { + logComponent := logmock.New(t) + agentConfigComponent := fxutil.Test[config.Component](t, fx.Options( + config.MockModule(), + fx.Replace(config.MockParams{Overrides: agentConfigs}), + )) + + requires := Requires{ + Logger: logComponent, + AgentConfig: agentConfigComponent, + } + + provides, err := NewComponent(requires) + require.NoError(t, err) + + comp := provides.Comp + require.NotNil(t, comp) + return comp +} diff --git a/comp/haagent/mock/mock.go b/comp/haagent/mock/mock.go new file mode 100644 index 0000000000000..6ee0c733361f7 --- /dev/null +++ b/comp/haagent/mock/mock.go @@ -0,0 +1,45 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + +//go:build test + +// Package mock provides a mock for the haagent component +package mock + +import ( + "testing" + + log "github.com/DataDog/datadog-agent/comp/core/log/def" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" +) + +type mock struct { + Logger log.Component +} + +func (m *mock) GetGroup() string { + return "mockGroup01" +} + +func (m *mock) Enabled() bool { + return true +} + +func (m *mock) SetLeader(_ string) { +} + +func (m *mock) IsLeader() bool { return false } + +// Provides that defines the output of mocked snmpscan component +type Provides struct { + comp haagent.Component +} + +// Mock returns a mock for haagent component. +func Mock(_ *testing.T) Provides { + return Provides{ + comp: &mock{}, + } +} diff --git a/pkg/config/setup/config.go b/pkg/config/setup/config.go index 27215e0975243..9a790ca22e3fe 100644 --- a/pkg/config/setup/config.go +++ b/pkg/config/setup/config.go @@ -474,6 +474,10 @@ func InitConfig(config pkgconfigmodel.Setup) { config.BindEnvAndSetDefault("network_path.collector.reverse_dns_enrichment.timeout", 5000) bindEnvAndSetLogsConfigKeys(config, "network_path.forwarder.") + // HA Agent + config.BindEnvAndSetDefault("ha_agent.enabled", false) + config.BindEnv("ha_agent.group") + // Kube ApiServer config.BindEnvAndSetDefault("kubernetes_kubeconfig_path", "") config.BindEnvAndSetDefault("kubernetes_apiserver_ca_path", "") From e3bd8e5ae2d9a3348dcabe1596da3ec02958f5a7 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Mon, 18 Nov 2024 12:25:14 +0100 Subject: [PATCH 02/27] [haagent] Add agent group tag to datadog.agent.running --- comp/aggregator/bundle_test.go | 2 + .../demultiplexerimpl/demultiplexer.go | 3 + .../demultiplexerimpl/status_test.go | 2 + .../test_agent_demultiplexer.go | 3 +- .../sendermanager.go | 2 + comp/haagent/impl-noop/noophaagent.go | 44 +++++++++++++++ comp/haagent/mock/mock.go | 55 ++++++++++++++----- pkg/aggregator/aggregator.go | 8 ++- pkg/aggregator/aggregator_test.go | 28 ++++++++-- pkg/aggregator/check_sampler_bench_test.go | 3 +- pkg/aggregator/demultiplexer_agent.go | 10 ++-- pkg/aggregator/demultiplexer_agent_test.go | 10 +++- pkg/aggregator/demultiplexer_mock.go | 4 +- pkg/aggregator/demultiplexer_test.go | 4 +- pkg/aggregator/mocksender/mocksender.go | 3 +- pkg/aggregator/sender_test.go | 3 +- .../snmp/integration_profile_bundle_test.go | 2 +- .../snmp/integration_profile_metadata_test.go | 2 +- .../snmp/integration_topology_test.go | 6 +- .../snmp/internal/checkconfig/config_test.go | 4 +- .../corechecks/systemd/systemd_test.go | 2 +- test/benchmarks/kubernetes_state/main.go | 2 +- 22 files changed, 158 insertions(+), 44 deletions(-) create mode 100644 comp/haagent/impl-noop/noophaagent.go diff --git a/comp/aggregator/bundle_test.go b/comp/aggregator/bundle_test.go index 3a426385bccef..2879750ebf4a2 100644 --- a/comp/aggregator/bundle_test.go +++ b/comp/aggregator/bundle_test.go @@ -14,6 +14,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -26,5 +27,6 @@ func TestBundleDependencies(t *testing.T) { orchestratorForwarderImpl.MockModule(), eventplatformimpl.MockModule(), nooptagger.Module(), + noophaagent.Module(), ) } diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go index c50c6528029a8..80a4817d42804 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go @@ -20,6 +20,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" @@ -42,6 +43,7 @@ type dependencies struct { SharedForwarder defaultforwarder.Component OrchestratorForwarder orchestratorforwarder.Component EventPlatformForwarder eventplatform.Component + HaAgent haagent.Component Compressor compression.Component Tagger tagger.Component @@ -86,6 +88,7 @@ func newDemultiplexer(deps dependencies) (provides, error) { deps.OrchestratorForwarder, options, deps.EventPlatformForwarder, + deps.HaAgent, deps.Compressor, deps.Tagger, hostnameDetected, diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go index e66c099ac36aa..cfd81d9c8033c 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go @@ -10,6 +10,7 @@ import ( "bytes" "testing" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/stretchr/testify/require" "go.uber.org/fx" @@ -61,6 +62,7 @@ func TestStatusOutPut(t *testing.T) { core.MockBundle(), compressionimpl.MockModule(), defaultforwarder.MockModule(), + noophaagent.Module(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), fx.Provide(func() tagger.Component { diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go index 4ac27d7d64460..de6248f81c9d2 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go @@ -18,6 +18,7 @@ import ( "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" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" @@ -185,6 +186,6 @@ func initTestAgentDemultiplexerWithFlushInterval(log log.Component, hostname hos sharedForwarder := defaultforwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, sharedForwarderOptions) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostname)) - demux := aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, compressor, noopimpl.NewComponent(), "hostname") + demux := aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), compressor, noopimpl.NewComponent(), "hostname") return NewTestAgentDemultiplexer(demux) } diff --git a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go index 73de2ac99cca7..5561ed840fd49 100644 --- a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go +++ b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go @@ -9,6 +9,7 @@ package diagnosesendermanagerimpl import ( "context" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" @@ -78,6 +79,7 @@ func (sender *diagnoseSenderManager) LazyGetSenderManager() (sender.SenderManage orchestratorForwarder, opts, eventPlatformForwarder, + noophaagent.NewNoopHaAgent(), sender.deps.Compressor, sender.deps.Tagger, hostnameDetected) diff --git a/comp/haagent/impl-noop/noophaagent.go b/comp/haagent/impl-noop/noophaagent.go new file mode 100644 index 0000000000000..f194c62491f68 --- /dev/null +++ b/comp/haagent/impl-noop/noophaagent.go @@ -0,0 +1,44 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + +// Package noophaagent provides a noop haagent component +package noophaagent + +import ( + "go.uber.org/fx" + + log "github.com/DataDog/datadog-agent/comp/core/log/def" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" + "github.com/DataDog/datadog-agent/pkg/util/fxutil" +) + +type noopHaAgent struct { + Logger log.Component +} + +func (m *noopHaAgent) GetGroup() string { return "" } + +func (m *noopHaAgent) Enabled() bool { return false } + +func (m *noopHaAgent) SetLeader(_ string) {} + +func (m *noopHaAgent) IsLeader() bool { return false } + +// Provides that defines the output of mocked snmpscan component +type Provides struct { + comp haagent.Component +} + +// NewNoopHaAgent returns a new Mock +func NewNoopHaAgent() haagent.Component { + return &noopHaAgent{} +} + +// Module defines the fx options for the noopHaAgent component. +func Module() fxutil.Module { + return fxutil.Component( + fx.Provide(NewNoopHaAgent), + ) +} diff --git a/comp/haagent/mock/mock.go b/comp/haagent/mock/mock.go index 6ee0c733361f7..f4bd713137b07 100644 --- a/comp/haagent/mock/mock.go +++ b/comp/haagent/mock/mock.go @@ -9,37 +9,64 @@ package mock import ( - "testing" - log "github.com/DataDog/datadog-agent/comp/core/log/def" haagent "github.com/DataDog/datadog-agent/comp/haagent/def" + "github.com/DataDog/datadog-agent/pkg/util/fxutil" + "go.uber.org/fx" ) -type mock struct { +type mockHaAgent struct { Logger log.Component + + group string + enabled bool +} + +func (m *mockHaAgent) GetGroup() string { + return m.group } -func (m *mock) GetGroup() string { - return "mockGroup01" +func (m *mockHaAgent) Enabled() bool { + return m.enabled } -func (m *mock) Enabled() bool { - return true +func (m *mockHaAgent) SetLeader(_ string) { } -func (m *mock) SetLeader(_ string) { +func (m *mockHaAgent) IsLeader() bool { return false } + +func (m *mockHaAgent) SetGroup(group string) { + m.group = group } -func (m *mock) IsLeader() bool { return false } +func (m *mockHaAgent) SetEnabled(enabled bool) { + m.enabled = enabled +} + +// MockComponent is the component type. +type MockComponent interface { + haagent.Component + + SetGroup(string) + SetEnabled(bool) +} // Provides that defines the output of mocked snmpscan component type Provides struct { - comp haagent.Component + comp MockComponent } -// Mock returns a mock for haagent component. -func Mock(_ *testing.T) Provides { - return Provides{ - comp: &mock{}, +// NewMockHaAgent returns a new Mock +func NewMockHaAgent() MockComponent { + return &mockHaAgent{ + enabled: false, + group: "group01", } } + +// MockModule defines the fx options for the mockHaAgent component. +func MockModule() fxutil.Module { + return fxutil.Component( + fx.Provide(NewMockHaAgent), + ) +} diff --git a/pkg/aggregator/aggregator.go b/pkg/aggregator/aggregator.go index d42ac89d50e47..e8ac4fd425d13 100644 --- a/pkg/aggregator/aggregator.go +++ b/pkg/aggregator/aggregator.go @@ -16,6 +16,7 @@ import ( tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def" "github.com/DataDog/datadog-agent/comp/core/tagger/types" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "github.com/DataDog/datadog-agent/pkg/aggregator/internal/tags" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" "github.com/DataDog/datadog-agent/pkg/config/model" @@ -252,6 +253,7 @@ type BufferedAggregator struct { flushMutex sync.Mutex // to start multiple flushes in parallel serializer serializer.MetricSerializer eventPlatformForwarder eventplatform.Component + haAgent haagent.Component hostname string hostnameUpdate chan string hostnameUpdateDone chan struct{} // signals that the hostname update is finished @@ -283,7 +285,7 @@ func NewFlushAndSerializeInParallel(config model.Config) FlushAndSerializeInPara } // NewBufferedAggregator instantiates a BufferedAggregator -func NewBufferedAggregator(s serializer.MetricSerializer, eventPlatformForwarder eventplatform.Component, tagger tagger.Component, hostname string, flushInterval time.Duration) *BufferedAggregator { +func NewBufferedAggregator(s serializer.MetricSerializer, eventPlatformForwarder eventplatform.Component, haAgent haagent.Component, tagger tagger.Component, hostname string, flushInterval time.Duration) *BufferedAggregator { bufferSize := pkgconfigsetup.Datadog().GetInt("aggregator_buffer_size") agentName := flavor.GetFlavor() @@ -326,6 +328,7 @@ func NewBufferedAggregator(s serializer.MetricSerializer, eventPlatformForwarder flushInterval: flushInterval, serializer: s, eventPlatformForwarder: eventPlatformForwarder, + haAgent: haAgent, hostname: hostname, hostnameUpdate: make(chan string), hostnameUpdateDone: make(chan struct{}), @@ -861,6 +864,9 @@ func (agg *BufferedAggregator) tags(withVersion bool) []string { tags = append(tags, "package_version:"+version.AgentPackageVersion) } } + if agg.haAgent.Enabled() { + tags = append(tags, "agent_group:"+agg.haAgent.GetGroup()) + } // nil to empty string // This is expected by other components/tests if tags == nil { diff --git a/pkg/aggregator/aggregator_test.go b/pkg/aggregator/aggregator_test.go index 64c33496891c7..e043064e4cade 100644 --- a/pkg/aggregator/aggregator_test.go +++ b/pkg/aggregator/aggregator_test.go @@ -27,6 +27,8 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + mockhaagent "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" configmock "github.com/DataDog/datadog-agent/pkg/config/mock" @@ -146,7 +148,7 @@ func TestAddServiceCheckDefaultValues(t *testing.T) { s := &MockSerializerIterableSerie{} taggerComponent := taggerMock.SetupFakeTagger(t) - agg := NewBufferedAggregator(s, nil, taggerComponent, "resolved-hostname", DefaultFlushInterval) + agg := NewBufferedAggregator(s, nil, nil, taggerComponent, "resolved-hostname", DefaultFlushInterval) agg.addServiceCheck(servicecheck.ServiceCheck{ // leave Host and Ts fields blank @@ -179,7 +181,7 @@ func TestAddEventDefaultValues(t *testing.T) { s := &MockSerializerIterableSerie{} taggerComponent := taggerMock.SetupFakeTagger(t) - agg := NewBufferedAggregator(s, nil, taggerComponent, "resolved-hostname", DefaultFlushInterval) + agg := NewBufferedAggregator(s, nil, nil, taggerComponent, "resolved-hostname", DefaultFlushInterval) agg.addEvent(event.Event{ // only populate required fields @@ -229,7 +231,7 @@ func TestDefaultData(t *testing.T) { s := &MockSerializerIterableSerie{} taggerComponent := taggerMock.SetupFakeTagger(t) - agg := NewBufferedAggregator(s, nil, taggerComponent, "hostname", DefaultFlushInterval) + agg := NewBufferedAggregator(s, nil, noophaagent.NewNoopHaAgent(), taggerComponent, "hostname", DefaultFlushInterval) start := time.Now() @@ -512,6 +514,7 @@ func TestTags(t *testing.T) { agentTags func(types.TagCardinality) ([]string, error) globalTags func(types.TagCardinality) ([]string, error) withVersion bool + haAgentEnabled bool want []string }{ { @@ -577,6 +580,16 @@ func TestTags(t *testing.T) { withVersion: true, want: []string{"container_name:agent", "version:" + version.AgentVersion, "kube_cluster_name:foo"}, }, + { + name: "tags disabled, without version, ha agent enabled", + hostname: "hostname", + tlmContainerTagsEnabled: false, + agentTags: func(types.TagCardinality) ([]string, error) { return nil, errors.New("disabled") }, + globalTags: func(types.TagCardinality) ([]string, error) { return nil, errors.New("disabled") }, + withVersion: false, + haAgentEnabled: true, + want: []string{"agent_group:group01"}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -585,7 +598,10 @@ func TestTags(t *testing.T) { taggerComponent := taggerMock.SetupFakeTagger(t) - agg := NewBufferedAggregator(nil, nil, taggerComponent, tt.hostname, time.Second) + mockHaAgent := mockhaagent.NewMockHaAgent() + mockHaAgent.SetEnabled(tt.haAgentEnabled) + + agg := NewBufferedAggregator(nil, nil, mockHaAgent, taggerComponent, tt.hostname, time.Second) agg.agentTags = tt.agentTags agg.globalTags = tt.globalTags assert.ElementsMatch(t, tt.want, agg.tags(tt.withVersion)) @@ -619,7 +635,7 @@ func TestAddDJMRecurrentSeries(t *testing.T) { s := &MockSerializerIterableSerie{} // NewBufferedAggregator with DJM enable will create a new recurrentSeries taggerComponent := taggerMock.SetupFakeTagger(t) - NewBufferedAggregator(s, nil, taggerComponent, "hostname", DefaultFlushInterval) + NewBufferedAggregator(s, nil, nil, taggerComponent, "hostname", DefaultFlushInterval) expectedRecurrentSeries := metrics.Series{&metrics.Serie{ Name: "datadog.djm.agent_host", @@ -728,7 +744,7 @@ type aggregatorDeps struct { } func createAggrDeps(t *testing.T) aggregatorDeps { - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), noophaagent.Module()) opts := demuxTestOptions() return aggregatorDeps{ diff --git a/pkg/aggregator/check_sampler_bench_test.go b/pkg/aggregator/check_sampler_bench_test.go index dbb6e8b57bf45..720dc5ea70329 100644 --- a/pkg/aggregator/check_sampler_bench_test.go +++ b/pkg/aggregator/check_sampler_bench_test.go @@ -17,6 +17,7 @@ import ( "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" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" //nolint:revive // TODO(AML) Fix revive linter @@ -51,7 +52,7 @@ func benchmarkAddBucket(bucketValue int64, b *testing.B) { sharedForwarder := forwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), deps.Log, forwarderOpts) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(deps.Hostname)) - demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, deps.Compressor, taggerComponent, "hostname") + demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), deps.Compressor, taggerComponent, "hostname") defer demux.Stop(true) checkSampler := newCheckSampler(1, true, true, 1000, tags.NewStore(true, "bench"), checkid.ID("hello:world:1234"), taggerComponent) diff --git a/pkg/aggregator/demultiplexer_agent.go b/pkg/aggregator/demultiplexer_agent.go index a420537fccd25..36528b374b745 100644 --- a/pkg/aggregator/demultiplexer_agent.go +++ b/pkg/aggregator/demultiplexer_agent.go @@ -17,6 +17,7 @@ import ( forwarder "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator/internal/tags" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" @@ -125,20 +126,21 @@ func InitAndStartAgentDemultiplexer( orchestratorForwarder orchestratorforwarder.Component, options AgentDemultiplexerOptions, eventPlatformForwarder eventplatform.Component, + haAgent haagent.Component, compressor compression.Component, tagger tagger.Component, hostname string) *AgentDemultiplexer { - demux := initAgentDemultiplexer(log, sharedForwarder, orchestratorForwarder, options, eventPlatformForwarder, compressor, tagger, hostname) + demux := initAgentDemultiplexer(log, sharedForwarder, orchestratorForwarder, options, eventPlatformForwarder, haAgent, compressor, tagger, hostname) go demux.run() return demux } -func initAgentDemultiplexer( - log log.Component, +func initAgentDemultiplexer(log log.Component, sharedForwarder forwarder.Forwarder, orchestratorForwarder orchestratorforwarder.Component, options AgentDemultiplexerOptions, eventPlatformForwarder eventplatform.Component, + haAgent haagent.Component, compressor compression.Component, tagger tagger.Component, hostname string) *AgentDemultiplexer { @@ -157,7 +159,7 @@ func initAgentDemultiplexer( // prepare the embedded aggregator // -- - agg := NewBufferedAggregator(sharedSerializer, eventPlatformForwarder, tagger, hostname, options.FlushInterval) + agg := NewBufferedAggregator(sharedSerializer, eventPlatformForwarder, haAgent, tagger, hostname, options.FlushInterval) // statsd samplers // --------------- diff --git a/pkg/aggregator/demultiplexer_agent_test.go b/pkg/aggregator/demultiplexer_agent_test.go index f2703abc6ec17..b932540e16258 100644 --- a/pkg/aggregator/demultiplexer_agent_test.go +++ b/pkg/aggregator/demultiplexer_agent_test.go @@ -23,6 +23,8 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/metrics" @@ -65,7 +67,7 @@ func TestDemuxNoAggOptionDisabled(t *testing.T) { opts := demuxTestOptions() deps := createDemultiplexerAgentTestDeps(t) - demux := initAgentDemultiplexer(deps.Log, NewForwarderTest(deps.Log), deps.OrchestratorFwd, opts, deps.EventPlatform, deps.Compressor, deps.Tagger, "") + demux := initAgentDemultiplexer(deps.Log, NewForwarderTest(deps.Log), deps.OrchestratorFwd, opts, deps.EventPlatform, deps.HaAgent, deps.Compressor, deps.Tagger, "") batch := testDemuxSamples(t) @@ -87,7 +89,7 @@ func TestDemuxNoAggOptionEnabled(t *testing.T) { mockSerializer.On("AreSketchesEnabled").Return(true) opts.EnableNoAggregationPipeline = true deps := createDemultiplexerAgentTestDeps(t) - demux := initAgentDemultiplexer(deps.Log, NewForwarderTest(deps.Log), deps.OrchestratorFwd, opts, deps.EventPlatform, deps.Compressor, deps.Tagger, "") + demux := initAgentDemultiplexer(deps.Log, NewForwarderTest(deps.Log), deps.OrchestratorFwd, opts, deps.EventPlatform, deps.HaAgent, deps.Compressor, deps.Tagger, "") demux.statsd.noAggStreamWorker.serializer = mockSerializer // the no agg pipeline will use our mocked serializer go demux.run() @@ -112,7 +114,7 @@ func TestDemuxNoAggOptionEnabled(t *testing.T) { func TestDemuxNoAggOptionIsDisabledByDefault(t *testing.T) { opts := demuxTestOptions() - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), noophaagent.Module()) demux := InitAndStartAgentDemultiplexerForTest(deps, opts, "") require.False(t, demux.Options().EnableNoAggregationPipeline, "the no aggregation pipeline should be disabled by default") @@ -157,6 +159,7 @@ type DemultiplexerAgentTestDeps struct { EventPlatform eventplatform.Component Compressor compression.Component Tagger tagger.Component + HaAgent haagent.Component } func createDemultiplexerAgentTestDeps(t *testing.T) DemultiplexerAgentTestDeps { @@ -168,6 +171,7 @@ func createDemultiplexerAgentTestDeps(t *testing.T) DemultiplexerAgentTestDeps { core.MockBundle(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), + noophaagent.Module(), compressionimpl.MockModule(), fx.Provide(func() tagger.Component { return taggerComponent }), ) diff --git a/pkg/aggregator/demultiplexer_mock.go b/pkg/aggregator/demultiplexer_mock.go index 917a788795957..c6511f7eb6890 100644 --- a/pkg/aggregator/demultiplexer_mock.go +++ b/pkg/aggregator/demultiplexer_mock.go @@ -16,6 +16,7 @@ import ( "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" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/util/optional" ) @@ -27,11 +28,12 @@ type TestDeps struct { Hostname hostname.Component SharedForwarder defaultforwarder.Component Compressor compression.Component + HaAgent haagent.Component } // InitAndStartAgentDemultiplexerForTest initializes an aggregator for tests. func InitAndStartAgentDemultiplexerForTest(deps TestDeps, options AgentDemultiplexerOptions, hostname string) *AgentDemultiplexer { orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(deps.Hostname)) - return InitAndStartAgentDemultiplexer(deps.Log, deps.SharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, deps.Compressor, nooptagger.NewComponent(), hostname) + return InitAndStartAgentDemultiplexer(deps.Log, deps.SharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, deps.HaAgent, deps.Compressor, nooptagger.NewComponent(), hostname) } diff --git a/pkg/aggregator/demultiplexer_test.go b/pkg/aggregator/demultiplexer_test.go index 6c3dd77976bdf..6ffce51e72404 100644 --- a/pkg/aggregator/demultiplexer_test.go +++ b/pkg/aggregator/demultiplexer_test.go @@ -173,7 +173,7 @@ func TestDemuxFlushAggregatorToSerializer(t *testing.T) { opts := demuxTestOptions() opts.FlushInterval = time.Hour deps := createDemuxDeps(t, opts, eventplatformimpl.NewDefaultParams()) - demux := initAgentDemultiplexer(deps.Log, deps.SharedForwarder, deps.OrchestratorFwd, opts, deps.EventPlatformFwd, deps.Compressor, nooptagger.NewComponent(), "") + demux := initAgentDemultiplexer(deps.Log, deps.SharedForwarder, deps.OrchestratorFwd, opts, deps.EventPlatformFwd, deps.HaAgent, deps.Compressor, nooptagger.NewComponent(), "") demux.Aggregator().tlmContainerTagsEnabled = false require.NotNil(demux) require.NotNil(demux.aggregator) @@ -300,7 +300,7 @@ func createDemuxDepsWithOrchestratorFwd( return aggregatorDeps{ TestDeps: deps.TestDeps, - Demultiplexer: InitAndStartAgentDemultiplexer(deps.Log, deps.SharedForwarder, deps.OrchestratorForwarder, opts, deps.Eventplatform, deps.Compressor, nooptagger.NewComponent(), ""), + Demultiplexer: InitAndStartAgentDemultiplexer(deps.Log, deps.SharedForwarder, deps.OrchestratorForwarder, opts, deps.Eventplatform, deps.HaAgent, deps.Compressor, nooptagger.NewComponent(), ""), OrchestratorFwd: deps.OrchestratorForwarder, EventPlatformFwd: deps.Eventplatform, } diff --git a/pkg/aggregator/mocksender/mocksender.go b/pkg/aggregator/mocksender/mocksender.go index e4403bdc352ef..21c9bf7e92a4b 100644 --- a/pkg/aggregator/mocksender/mocksender.go +++ b/pkg/aggregator/mocksender/mocksender.go @@ -10,6 +10,7 @@ package mocksender import ( "time" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/stretchr/testify/mock" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" @@ -43,7 +44,7 @@ func CreateDefaultDemultiplexer() *aggregator.AgentDemultiplexer { orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostnameimpl.NewHostnameService())) taggerComponent := nooptagger.NewComponent() - return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, compressionimpl.NewMockCompressor(), taggerComponent, "") + return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), taggerComponent, "") } diff --git a/pkg/aggregator/sender_test.go b/pkg/aggregator/sender_test.go index 17713653a59bc..ce2e182bb51e1 100644 --- a/pkg/aggregator/sender_test.go +++ b/pkg/aggregator/sender_test.go @@ -23,6 +23,7 @@ import ( "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" + noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" "github.com/DataDog/datadog-agent/pkg/metrics" @@ -58,7 +59,7 @@ func testDemux(log log.Component, hostname hostname.Component) *AgentDemultiplex opts.DontStartForwarders = true orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostname)) - demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventPlatformForwarder, compressionimpl.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) + demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) return demux } diff --git a/pkg/collector/corechecks/snmp/integration_profile_bundle_test.go b/pkg/collector/corechecks/snmp/integration_profile_bundle_test.go index 720f4f713a35b..6e7c55f230fcc 100644 --- a/pkg/collector/corechecks/snmp/integration_profile_bundle_test.go +++ b/pkg/collector/corechecks/snmp/integration_profile_bundle_test.go @@ -25,7 +25,7 @@ import ( func TestProfileBundleJsonZip(t *testing.T) { timeNow = common.MockTimeNow - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) invalidPath, _ := filepath.Abs(filepath.Join("internal", "test", "zipprofiles.d")) pkgconfigsetup.Datadog().SetWithoutSource("confd_path", invalidPath) diff --git a/pkg/collector/corechecks/snmp/integration_profile_metadata_test.go b/pkg/collector/corechecks/snmp/integration_profile_metadata_test.go index 06b55c7df2180..68e82058528dd 100644 --- a/pkg/collector/corechecks/snmp/integration_profile_metadata_test.go +++ b/pkg/collector/corechecks/snmp/integration_profile_metadata_test.go @@ -32,7 +32,7 @@ import ( func TestProfileMetadata_f5(t *testing.T) { timeNow = common.MockTimeNow - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) invalidPath, _ := filepath.Abs(filepath.Join("internal", "test", "metadata.d")) pkgconfigsetup.Datadog().SetWithoutSource("confd_path", invalidPath) diff --git a/pkg/collector/corechecks/snmp/integration_topology_test.go b/pkg/collector/corechecks/snmp/integration_topology_test.go index 0f5ccfbc2e5f4..b4f0f42ceb6d0 100644 --- a/pkg/collector/corechecks/snmp/integration_topology_test.go +++ b/pkg/collector/corechecks/snmp/integration_topology_test.go @@ -32,7 +32,7 @@ import ( func TestTopologyPayload_LLDP(t *testing.T) { timeNow = common.MockTimeNow - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) invalidPath, _ := filepath.Abs(filepath.Join("internal", "test", "metadata.d")) pkgconfigsetup.Datadog().SetWithoutSource("confd_path", invalidPath) @@ -734,7 +734,7 @@ profiles: func TestTopologyPayload_CDP(t *testing.T) { timeNow = common.MockTimeNow - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) invalidPath, _ := filepath.Abs(filepath.Join("internal", "test", "metadata.d")) pkgconfigsetup.Datadog().SetWithoutSource("confd_path", invalidPath) @@ -1427,7 +1427,7 @@ profiles: // we have different data for LLDP and CDP to test that we're only using LLDP to build the links func TestTopologyPayload_LLDP_CDP(t *testing.T) { timeNow = common.MockTimeNow - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) invalidPath, _ := filepath.Abs(filepath.Join("internal", "test", "metadata.d")) pkgconfigsetup.Datadog().SetWithoutSource("confd_path", invalidPath) diff --git a/pkg/collector/corechecks/snmp/internal/checkconfig/config_test.go b/pkg/collector/corechecks/snmp/internal/checkconfig/config_test.go index 997aadd210390..2dc78dd76b547 100644 --- a/pkg/collector/corechecks/snmp/internal/checkconfig/config_test.go +++ b/pkg/collector/corechecks/snmp/internal/checkconfig/config_test.go @@ -25,7 +25,7 @@ import ( func TestConfigurations(t *testing.T) { profile.SetConfdPathAndCleanProfiles() - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) // language=yaml rawInstanceConfig := []byte(` @@ -326,7 +326,7 @@ profiles: func TestInlineProfileConfiguration(t *testing.T) { profile.SetConfdPathAndCleanProfiles() - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) // language=yaml rawInstanceConfig := []byte(` diff --git a/pkg/collector/corechecks/systemd/systemd_test.go b/pkg/collector/corechecks/systemd/systemd_test.go index 6f91dc4edd2fe..7fb9d67df981a 100644 --- a/pkg/collector/corechecks/systemd/systemd_test.go +++ b/pkg/collector/corechecks/systemd/systemd_test.go @@ -1087,7 +1087,7 @@ unit_names: func TestCheckID(t *testing.T) { check1 := newCheck() check2 := newCheck() - aggregator.NewBufferedAggregator(nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, nil, nil, nooptagger.NewComponent(), "", 1*time.Hour) // language=yaml rawInstanceConfig1 := []byte(` diff --git a/test/benchmarks/kubernetes_state/main.go b/test/benchmarks/kubernetes_state/main.go index 08b83d358855e..a1ea844898a9b 100644 --- a/test/benchmarks/kubernetes_state/main.go +++ b/test/benchmarks/kubernetes_state/main.go @@ -207,7 +207,7 @@ func main() { * As it has a `nil` serializer, it will panic if it tries to flush the metrics. * That’s why we need a big enough flush interval */ - aggregator.NewBufferedAggregator(nil, "", 1*time.Hour) + aggregator.NewBufferedAggregator(nil, "", nil, 1*time.Hour) /* * Wait for informers to get populated From 6aa49e7ca5058767031c1bd81bb58592b0225333 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 15:03:32 +0100 Subject: [PATCH 03/27] add copy --- comp/haagent/impl/haagent.go | 5 +++++ comp/haagent/impl/haagent_test.go | 5 +++++ comp/haagent/impl/haagent_testutils_test.go | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/comp/haagent/impl/haagent.go b/comp/haagent/impl/haagent.go index 4b51f09d69fe1..7974867596547 100644 --- a/comp/haagent/impl/haagent.go +++ b/comp/haagent/impl/haagent.go @@ -1,3 +1,8 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + package haagentimpl import ( diff --git a/comp/haagent/impl/haagent_test.go b/comp/haagent/impl/haagent_test.go index 63011aa645e44..3be3d2d6341ee 100644 --- a/comp/haagent/impl/haagent_test.go +++ b/comp/haagent/impl/haagent_test.go @@ -1,3 +1,8 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + package haagentimpl import ( diff --git a/comp/haagent/impl/haagent_testutils_test.go b/comp/haagent/impl/haagent_testutils_test.go index bdeb90cee7155..a401d9bdd8a61 100644 --- a/comp/haagent/impl/haagent_testutils_test.go +++ b/comp/haagent/impl/haagent_testutils_test.go @@ -1,3 +1,8 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2024-present Datadog, Inc. + package haagentimpl import ( From 0bba3f8b04e8491b6e75c232066cbb76bd80a762 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 15:04:56 +0100 Subject: [PATCH 04/27] fix comp --- .github/CODEOWNERS | 2 +- comp/README.md | 6 ++++++ comp/haagent/def/component.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 86aeb529e652f..7cc35ab0a34bb 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -316,11 +316,11 @@ /comp/trace/etwtracer @DataDog/windows-agent /comp/autoscaling/datadogclient @DataDog/container-integrations /comp/etw @DataDog/windows-agent +/comp/haagent @DataDog/network-device-monitoring @DataDog/remote-config @DataDog/fleet /comp/languagedetection/client @DataDog/container-platform /comp/rdnsquerier @DataDog/ndm-integrations /comp/serializer/compression @DataDog/agent-metrics-logs /comp/snmpscan @DataDog/ndm-core -/comp/haagent @DataDog/network-device-monitoring @DataDog/remote-config @DataDog/fleet # END COMPONENTS # Additional notification to @iglendd about Agent Telemetry changes for optional approval and governance acknowledgement diff --git a/comp/README.md b/comp/README.md index d6d7902fd7b34..f67d761626989 100644 --- a/comp/README.md +++ b/comp/README.md @@ -597,6 +597,12 @@ Package datadogclient provides a client to query the datadog API Package etw provides an ETW tracing interface +### [comp/haagent](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/haagent) + +*Datadog Team*: network-device-monitoring remote-config fleet + +Package haagent handles states for HA Agent feature. + ### [comp/languagedetection/client](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/languagedetection/client) *Datadog Team*: container-platform diff --git a/comp/haagent/def/component.go b/comp/haagent/def/component.go index e20be4b3d0c81..5f00284c9f210 100644 --- a/comp/haagent/def/component.go +++ b/comp/haagent/def/component.go @@ -6,7 +6,7 @@ // Package haagent handles states for HA Agent feature. package haagent -// team: network-device-monitoring +// team: network-device-monitoring remote-config fleet // Component is the component type. type Component interface { From 48f08865d96a3e58a321dc35d56f6cb4bcd15040 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 15:07:21 +0100 Subject: [PATCH 05/27] add reno --- .../notes/add_haagent_comp-060918c70bcadb08.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 releasenotes/notes/add_haagent_comp-060918c70bcadb08.yaml diff --git a/releasenotes/notes/add_haagent_comp-060918c70bcadb08.yaml b/releasenotes/notes/add_haagent_comp-060918c70bcadb08.yaml new file mode 100644 index 0000000000000..14d0ca1570690 --- /dev/null +++ b/releasenotes/notes/add_haagent_comp-060918c70bcadb08.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +features: + - | + [ha-agent] Add haagent component used for HA Agent feature. From 98c3152ddae900252b60ee4900688bbd9e8931dc Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 15:32:38 +0100 Subject: [PATCH 06/27] rename package --- comp/aggregator/bundle_test.go | 4 +-- .../demultiplexerimpl/status_test.go | 4 +-- .../test_agent_demultiplexer.go | 27 ++++++++++++++----- .../sendermanager.go | 4 +-- comp/haagent/impl-noop/noophaagent.go | 25 +++++++---------- pkg/aggregator/aggregator_test.go | 6 ++--- pkg/aggregator/check_sampler_bench_test.go | 4 +-- pkg/aggregator/demultiplexer_agent_test.go | 6 ++--- pkg/aggregator/demultiplexer_test.go | 11 ++++++-- pkg/aggregator/mocksender/mocksender.go | 4 +-- pkg/aggregator/sender_test.go | 4 +-- 11 files changed, 58 insertions(+), 41 deletions(-) diff --git a/comp/aggregator/bundle_test.go b/comp/aggregator/bundle_test.go index 2879750ebf4a2..f4df02b6c549f 100644 --- a/comp/aggregator/bundle_test.go +++ b/comp/aggregator/bundle_test.go @@ -14,7 +14,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -27,6 +27,6 @@ func TestBundleDependencies(t *testing.T) { orchestratorForwarderImpl.MockModule(), eventplatformimpl.MockModule(), nooptagger.Module(), - noophaagent.Module(), + haagentimpl.NoopModule(), ) } diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go index cfd81d9c8033c..794fddf3ad8b8 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go @@ -10,7 +10,7 @@ import ( "bytes" "testing" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/stretchr/testify/require" "go.uber.org/fx" @@ -62,7 +62,7 @@ func TestStatusOutPut(t *testing.T) { core.MockBundle(), compressionimpl.MockModule(), defaultforwarder.MockModule(), - noophaagent.Module(), + haagentimpl.NoopModule(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), fx.Provide(func() tagger.Component { diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go index de6248f81c9d2..aceb054c43c47 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go @@ -18,7 +18,7 @@ import ( "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" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" @@ -108,7 +108,10 @@ func (a *TestAgentDemultiplexer) WaitForSamples(timeout time.Duration) (ontime [ // WaitForNumberOfSamples returns the samples received by the demultiplexer. // Note that it waits until at least the requested number of samples are // available in both the live metrics buffer and the late metrics one. -func (a *TestAgentDemultiplexer) WaitForNumberOfSamples(ontimeCount, timedCount int, timeout time.Duration) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { +func (a *TestAgentDemultiplexer) WaitForNumberOfSamples( + ontimeCount, timedCount int, + timeout time.Duration, +) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { return a.waitForSamples(timeout, func(ontime, timed []metrics.MetricSample) bool { return (len(ontime) >= ontimeCount || ontimeCount == 0) && (len(timed) >= timedCount || timedCount == 0) @@ -117,7 +120,10 @@ func (a *TestAgentDemultiplexer) WaitForNumberOfSamples(ontimeCount, timedCount // waitForSamples returns the samples received by the demultiplexer. // It returns once the given foundFunc returns true or the timeout is reached. -func (a *TestAgentDemultiplexer) waitForSamples(timeout time.Duration, foundFunc func([]metrics.MetricSample, []metrics.MetricSample) bool) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { +func (a *TestAgentDemultiplexer) waitForSamples( + timeout time.Duration, + foundFunc func([]metrics.MetricSample, []metrics.MetricSample) bool, +) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { ticker := time.NewTicker(10 * time.Millisecond) defer ticker.Stop() timeoutOn := time.Now().Add(timeout) @@ -142,7 +148,11 @@ func (a *TestAgentDemultiplexer) waitForSamples(timeout time.Duration, foundFunc } // WaitEventPlatformEvents waits for timeout and eventually returns the event platform events samples received by the demultiplexer. -func (a *TestAgentDemultiplexer) WaitEventPlatformEvents(eventType string, minEvents int, timeout time.Duration) ([]*message.Message, error) { +func (a *TestAgentDemultiplexer) WaitEventPlatformEvents( + eventType string, + minEvents int, + timeout time.Duration, +) ([]*message.Message, error) { ticker := time.NewTicker(10 * time.Millisecond) defer ticker.Stop() timeoutOn := time.Now().Add(timeout) @@ -176,7 +186,12 @@ func (a *TestAgentDemultiplexer) Reset() { } // initTestAgentDemultiplexerWithFlushInterval inits a TestAgentDemultiplexer with the given flush interval. -func initTestAgentDemultiplexerWithFlushInterval(log log.Component, hostname hostname.Component, compressor compression.Component, flushInterval time.Duration) *TestAgentDemultiplexer { +func initTestAgentDemultiplexerWithFlushInterval( + log log.Component, + hostname hostname.Component, + compressor compression.Component, + flushInterval time.Duration, +) *TestAgentDemultiplexer { opts := aggregator.DefaultAgentDemultiplexerOptions() opts.FlushInterval = flushInterval opts.DontStartForwarders = true @@ -186,6 +201,6 @@ func initTestAgentDemultiplexerWithFlushInterval(log log.Component, hostname hos sharedForwarder := defaultforwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, sharedForwarderOptions) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostname)) - demux := aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), compressor, noopimpl.NewComponent(), "hostname") + demux := aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), compressor, noopimpl.NewComponent(), "hostname") return NewTestAgentDemultiplexer(demux) } diff --git a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go index 5561ed840fd49..74fa7ab81de13 100644 --- a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go +++ b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go @@ -9,7 +9,7 @@ package diagnosesendermanagerimpl import ( "context" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" @@ -79,7 +79,7 @@ func (sender *diagnoseSenderManager) LazyGetSenderManager() (sender.SenderManage orchestratorForwarder, opts, eventPlatformForwarder, - noophaagent.NewNoopHaAgent(), + haagentimpl.NewNoopHaAgent(), sender.deps.Compressor, sender.deps.Tagger, hostnameDetected) diff --git a/comp/haagent/impl-noop/noophaagent.go b/comp/haagent/impl-noop/noophaagent.go index f194c62491f68..29658df41e7cb 100644 --- a/comp/haagent/impl-noop/noophaagent.go +++ b/comp/haagent/impl-noop/noophaagent.go @@ -3,8 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2024-present Datadog, Inc. -// Package noophaagent provides a noop haagent component -package noophaagent +// Package haagentimpl provides a noop haagent component +package haagentimpl import ( "go.uber.org/fx" @@ -14,30 +14,25 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) -type noopHaAgent struct { +type haagentimpl struct { Logger log.Component } -func (m *noopHaAgent) GetGroup() string { return "" } +func (m *haagentimpl) GetGroup() string { return "" } -func (m *noopHaAgent) Enabled() bool { return false } +func (m *haagentimpl) Enabled() bool { return false } -func (m *noopHaAgent) SetLeader(_ string) {} +func (m *haagentimpl) SetLeader(_ string) {} -func (m *noopHaAgent) IsLeader() bool { return false } - -// Provides that defines the output of mocked snmpscan component -type Provides struct { - comp haagent.Component -} +func (m *haagentimpl) IsLeader() bool { return false } // NewNoopHaAgent returns a new Mock func NewNoopHaAgent() haagent.Component { - return &noopHaAgent{} + return &haagentimpl{} } -// Module defines the fx options for the noopHaAgent component. -func Module() fxutil.Module { +// NoopModule defines the fx options for the haagentimpl component. +func NoopModule() fxutil.Module { return fxutil.Component( fx.Provide(NewNoopHaAgent), ) diff --git a/pkg/aggregator/aggregator_test.go b/pkg/aggregator/aggregator_test.go index e043064e4cade..415de7c92c50f 100644 --- a/pkg/aggregator/aggregator_test.go +++ b/pkg/aggregator/aggregator_test.go @@ -27,7 +27,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" mockhaagent "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" @@ -231,7 +231,7 @@ func TestDefaultData(t *testing.T) { s := &MockSerializerIterableSerie{} taggerComponent := taggerMock.SetupFakeTagger(t) - agg := NewBufferedAggregator(s, nil, noophaagent.NewNoopHaAgent(), taggerComponent, "hostname", DefaultFlushInterval) + agg := NewBufferedAggregator(s, nil, haagentimpl.NewNoopHaAgent(), taggerComponent, "hostname", DefaultFlushInterval) start := time.Now() @@ -744,7 +744,7 @@ type aggregatorDeps struct { } func createAggrDeps(t *testing.T) aggregatorDeps { - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), noophaagent.Module()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentimpl.NoopModule()) opts := demuxTestOptions() return aggregatorDeps{ diff --git a/pkg/aggregator/check_sampler_bench_test.go b/pkg/aggregator/check_sampler_bench_test.go index 720dc5ea70329..578aa4dd07c3b 100644 --- a/pkg/aggregator/check_sampler_bench_test.go +++ b/pkg/aggregator/check_sampler_bench_test.go @@ -17,7 +17,7 @@ import ( "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" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" //nolint:revive // TODO(AML) Fix revive linter @@ -52,7 +52,7 @@ func benchmarkAddBucket(bucketValue int64, b *testing.B) { sharedForwarder := forwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), deps.Log, forwarderOpts) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(deps.Hostname)) - demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), deps.Compressor, taggerComponent, "hostname") + demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), deps.Compressor, taggerComponent, "hostname") defer demux.Stop(true) checkSampler := newCheckSampler(1, true, true, 1000, tags.NewStore(true, "bench"), checkid.ID("hello:world:1234"), taggerComponent) diff --git a/pkg/aggregator/demultiplexer_agent_test.go b/pkg/aggregator/demultiplexer_agent_test.go index b932540e16258..baab1b9cebbcc 100644 --- a/pkg/aggregator/demultiplexer_agent_test.go +++ b/pkg/aggregator/demultiplexer_agent_test.go @@ -24,7 +24,7 @@ import ( orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" haagent "github.com/DataDog/datadog-agent/comp/haagent/def" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/metrics" @@ -114,7 +114,7 @@ func TestDemuxNoAggOptionEnabled(t *testing.T) { func TestDemuxNoAggOptionIsDisabledByDefault(t *testing.T) { opts := demuxTestOptions() - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), noophaagent.Module()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentimpl.NoopModule()) demux := InitAndStartAgentDemultiplexerForTest(deps, opts, "") require.False(t, demux.Options().EnableNoAggregationPipeline, "the no aggregation pipeline should be disabled by default") @@ -171,7 +171,7 @@ func createDemultiplexerAgentTestDeps(t *testing.T) DemultiplexerAgentTestDeps { core.MockBundle(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), - noophaagent.Module(), + haagentimpl.NoopModule(), compressionimpl.MockModule(), fx.Provide(func() tagger.Component { return taggerComponent }), ) diff --git a/pkg/aggregator/demultiplexer_test.go b/pkg/aggregator/demultiplexer_test.go index 6ffce51e72404..401a137cbe11a 100644 --- a/pkg/aggregator/demultiplexer_test.go +++ b/pkg/aggregator/demultiplexer_test.go @@ -11,6 +11,7 @@ import ( "testing" "time" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core" @@ -272,7 +273,11 @@ func TestGetDogStatsDWorkerAndPipelineCount(t *testing.T) { assert.Equal(4, pipelines) } -func createDemuxDeps(t *testing.T, opts AgentDemultiplexerOptions, eventPlatformParams eventplatformimpl.Params) aggregatorDeps { +func createDemuxDeps( + t *testing.T, + opts AgentDemultiplexerOptions, + eventPlatformParams eventplatformimpl.Params, +) aggregatorDeps { return createDemuxDepsWithOrchestratorFwd(t, opts, orchestratorForwarderImpl.NewDefaultParams(), eventPlatformParams) } @@ -287,7 +292,8 @@ func createDemuxDepsWithOrchestratorFwd( t *testing.T, opts AgentDemultiplexerOptions, orchestratorParams orchestratorForwarderImpl.Params, - eventPlatformParams eventplatformimpl.Params) aggregatorDeps { + eventPlatformParams eventplatformimpl.Params, +) aggregatorDeps { modules := fx.Options( defaultforwarder.MockModule(), core.MockBundle(), @@ -295,6 +301,7 @@ func createDemuxDepsWithOrchestratorFwd( eventplatformimpl.Module(eventPlatformParams), eventplatformreceiverimpl.Module(), compressionimpl.MockModule(), + haagentimpl.NoopModule(), ) deps := fxutil.Test[internalDemutiplexerDeps](t, modules) diff --git a/pkg/aggregator/mocksender/mocksender.go b/pkg/aggregator/mocksender/mocksender.go index 21c9bf7e92a4b..3978c45d8354a 100644 --- a/pkg/aggregator/mocksender/mocksender.go +++ b/pkg/aggregator/mocksender/mocksender.go @@ -10,7 +10,7 @@ package mocksender import ( "time" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/stretchr/testify/mock" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" @@ -44,7 +44,7 @@ func CreateDefaultDemultiplexer() *aggregator.AgentDemultiplexer { orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostnameimpl.NewHostnameService())) taggerComponent := nooptagger.NewComponent() - return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), taggerComponent, "") + return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), taggerComponent, "") } diff --git a/pkg/aggregator/sender_test.go b/pkg/aggregator/sender_test.go index ce2e182bb51e1..b443ef3bbccd3 100644 --- a/pkg/aggregator/sender_test.go +++ b/pkg/aggregator/sender_test.go @@ -23,7 +23,7 @@ import ( "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" - noophaagent "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" "github.com/DataDog/datadog-agent/pkg/metrics" @@ -59,7 +59,7 @@ func testDemux(log log.Component, hostname hostname.Component) *AgentDemultiplex opts.DontStartForwarders = true orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostname)) - demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventPlatformForwarder, noophaagent.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) + demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) return demux } From f13ec2af15ce4b0bc4e8b6ace54911ca2d8acf48 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 15:41:47 +0100 Subject: [PATCH 07/27] revert func sig --- .../test_agent_demultiplexer.go | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go index aceb054c43c47..22ae5869419f5 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go @@ -108,10 +108,7 @@ func (a *TestAgentDemultiplexer) WaitForSamples(timeout time.Duration) (ontime [ // WaitForNumberOfSamples returns the samples received by the demultiplexer. // Note that it waits until at least the requested number of samples are // available in both the live metrics buffer and the late metrics one. -func (a *TestAgentDemultiplexer) WaitForNumberOfSamples( - ontimeCount, timedCount int, - timeout time.Duration, -) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { +func (a *TestAgentDemultiplexer) WaitForNumberOfSamples(ontimeCount, timedCount int, timeout time.Duration) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { return a.waitForSamples(timeout, func(ontime, timed []metrics.MetricSample) bool { return (len(ontime) >= ontimeCount || ontimeCount == 0) && (len(timed) >= timedCount || timedCount == 0) @@ -120,10 +117,7 @@ func (a *TestAgentDemultiplexer) WaitForNumberOfSamples( // waitForSamples returns the samples received by the demultiplexer. // It returns once the given foundFunc returns true or the timeout is reached. -func (a *TestAgentDemultiplexer) waitForSamples( - timeout time.Duration, - foundFunc func([]metrics.MetricSample, []metrics.MetricSample) bool, -) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { +func (a *TestAgentDemultiplexer) waitForSamples(timeout time.Duration, foundFunc func([]metrics.MetricSample, []metrics.MetricSample) bool) (ontime []metrics.MetricSample, timed []metrics.MetricSample) { ticker := time.NewTicker(10 * time.Millisecond) defer ticker.Stop() timeoutOn := time.Now().Add(timeout) @@ -148,11 +142,7 @@ func (a *TestAgentDemultiplexer) waitForSamples( } // WaitEventPlatformEvents waits for timeout and eventually returns the event platform events samples received by the demultiplexer. -func (a *TestAgentDemultiplexer) WaitEventPlatformEvents( - eventType string, - minEvents int, - timeout time.Duration, -) ([]*message.Message, error) { +func (a *TestAgentDemultiplexer) WaitEventPlatformEvents(eventType string, minEvents int, timeout time.Duration) ([]*message.Message, error) { ticker := time.NewTicker(10 * time.Millisecond) defer ticker.Stop() timeoutOn := time.Now().Add(timeout) @@ -186,12 +176,7 @@ func (a *TestAgentDemultiplexer) Reset() { } // initTestAgentDemultiplexerWithFlushInterval inits a TestAgentDemultiplexer with the given flush interval. -func initTestAgentDemultiplexerWithFlushInterval( - log log.Component, - hostname hostname.Component, - compressor compression.Component, - flushInterval time.Duration, -) *TestAgentDemultiplexer { +func initTestAgentDemultiplexerWithFlushInterval(log log.Component, hostname hostname.Component, compressor compression.Component, flushInterval time.Duration) *TestAgentDemultiplexer { opts := aggregator.DefaultAgentDemultiplexerOptions() opts.FlushInterval = flushInterval opts.DontStartForwarders = true From 6f7a6b88377a270924ae6027bd77c1b12458fcbd Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 15:45:31 +0100 Subject: [PATCH 08/27] sort import --- .../diagnosesendermanagerimpl/sendermanager.go | 2 +- comp/haagent/mock/mock.go | 3 ++- pkg/aggregator/demultiplexer_test.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go index 74fa7ab81de13..d52c69356a847 100644 --- a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go +++ b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go @@ -9,7 +9,6 @@ package diagnosesendermanagerimpl import ( "context" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" @@ -20,6 +19,7 @@ import ( "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" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" diff --git a/comp/haagent/mock/mock.go b/comp/haagent/mock/mock.go index f4bd713137b07..91910055c9817 100644 --- a/comp/haagent/mock/mock.go +++ b/comp/haagent/mock/mock.go @@ -9,10 +9,11 @@ package mock import ( + "go.uber.org/fx" + log "github.com/DataDog/datadog-agent/comp/core/log/def" haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "github.com/DataDog/datadog-agent/pkg/util/fxutil" - "go.uber.org/fx" ) type mockHaAgent struct { diff --git a/pkg/aggregator/demultiplexer_test.go b/pkg/aggregator/demultiplexer_test.go index 401a137cbe11a..8998804aef5dc 100644 --- a/pkg/aggregator/demultiplexer_test.go +++ b/pkg/aggregator/demultiplexer_test.go @@ -11,7 +11,6 @@ import ( "testing" "time" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core" @@ -22,6 +21,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl" orchestratorForwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" From 6ae30cd0fe6f2a019bec47b369975b11dd58a994 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 15:49:11 +0100 Subject: [PATCH 09/27] rename to noopHaAgent --- comp/haagent/impl-noop/noophaagent.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/comp/haagent/impl-noop/noophaagent.go b/comp/haagent/impl-noop/noophaagent.go index 29658df41e7cb..7c3ad366fc844 100644 --- a/comp/haagent/impl-noop/noophaagent.go +++ b/comp/haagent/impl-noop/noophaagent.go @@ -14,21 +14,21 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) -type haagentimpl struct { +type noopHaAgent struct { Logger log.Component } -func (m *haagentimpl) GetGroup() string { return "" } +func (m *noopHaAgent) GetGroup() string { return "" } -func (m *haagentimpl) Enabled() bool { return false } +func (m *noopHaAgent) Enabled() bool { return false } -func (m *haagentimpl) SetLeader(_ string) {} +func (m *noopHaAgent) SetLeader(_ string) {} -func (m *haagentimpl) IsLeader() bool { return false } +func (m *noopHaAgent) IsLeader() bool { return false } // NewNoopHaAgent returns a new Mock func NewNoopHaAgent() haagent.Component { - return &haagentimpl{} + return &noopHaAgent{} } // NoopModule defines the fx options for the haagentimpl component. From e05263504ee29f3f51b46475852973e01433ee92 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 20 Nov 2024 17:52:59 +0100 Subject: [PATCH 10/27] update .github/CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7cc35ab0a34bb..66cddbe7d168d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -316,7 +316,7 @@ /comp/trace/etwtracer @DataDog/windows-agent /comp/autoscaling/datadogclient @DataDog/container-integrations /comp/etw @DataDog/windows-agent -/comp/haagent @DataDog/network-device-monitoring @DataDog/remote-config @DataDog/fleet +/comp/haagent @DataDog/network-device-monitoring /comp/languagedetection/client @DataDog/container-platform /comp/rdnsquerier @DataDog/ndm-integrations /comp/serializer/compression @DataDog/agent-metrics-logs From c7da32da0ffebf6f8f08db0ecfb9c7ef62d6575a Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 09:18:47 +0100 Subject: [PATCH 11/27] update team --- comp/README.md | 2 +- comp/haagent/def/component.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/comp/README.md b/comp/README.md index f67d761626989..df42d1c5aff83 100644 --- a/comp/README.md +++ b/comp/README.md @@ -599,7 +599,7 @@ Package etw provides an ETW tracing interface ### [comp/haagent](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/haagent) -*Datadog Team*: network-device-monitoring remote-config fleet +*Datadog Team*: network-device-monitoring Package haagent handles states for HA Agent feature. diff --git a/comp/haagent/def/component.go b/comp/haagent/def/component.go index 5f00284c9f210..e20be4b3d0c81 100644 --- a/comp/haagent/def/component.go +++ b/comp/haagent/def/component.go @@ -6,7 +6,7 @@ // Package haagent handles states for HA Agent feature. package haagent -// team: network-device-monitoring remote-config fleet +// team: network-device-monitoring // Component is the component type. type Component interface { From 0721a71664e1c6f4727740d9c395867921f6367d Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:00:21 +0100 Subject: [PATCH 12/27] simplify mock --- comp/aggregator/bundle_test.go | 4 +- .../demultiplexerimpl/status_test.go | 4 +- .../test_agent_demultiplexer.go | 4 +- .../sendermanager.go | 6 ++- comp/haagent/impl-noop/noophaagent.go | 39 ------------------- comp/haagent/mock/mock.go | 2 +- pkg/aggregator/aggregator_test.go | 9 ++--- pkg/aggregator/check_sampler_bench_test.go | 5 ++- pkg/aggregator/demultiplexer_agent_test.go | 6 +-- pkg/aggregator/demultiplexer_test.go | 4 +- pkg/aggregator/mocksender/mocksender.go | 4 +- pkg/aggregator/sender_test.go | 4 +- 12 files changed, 27 insertions(+), 64 deletions(-) delete mode 100644 comp/haagent/impl-noop/noophaagent.go diff --git a/comp/aggregator/bundle_test.go b/comp/aggregator/bundle_test.go index f4df02b6c549f..d47a33f4ff4ef 100644 --- a/comp/aggregator/bundle_test.go +++ b/comp/aggregator/bundle_test.go @@ -14,7 +14,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -27,6 +27,6 @@ func TestBundleDependencies(t *testing.T) { orchestratorForwarderImpl.MockModule(), eventplatformimpl.MockModule(), nooptagger.Module(), - haagentimpl.NoopModule(), + haagentmock.MockModule(), ) } diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go index 794fddf3ad8b8..47d2340abb282 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go @@ -10,7 +10,6 @@ import ( "bytes" "testing" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/stretchr/testify/require" "go.uber.org/fx" @@ -21,6 +20,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -62,7 +62,7 @@ func TestStatusOutPut(t *testing.T) { core.MockBundle(), compressionimpl.MockModule(), defaultforwarder.MockModule(), - haagentimpl.NoopModule(), + haagentmock.MockModule(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), fx.Provide(func() tagger.Component { diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go index 22ae5869419f5..9e051328c961d 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go @@ -18,7 +18,7 @@ import ( "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" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" @@ -186,6 +186,6 @@ func initTestAgentDemultiplexerWithFlushInterval(log log.Component, hostname hos sharedForwarder := defaultforwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, sharedForwarderOptions) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostname)) - demux := aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), compressor, noopimpl.NewComponent(), "hostname") + demux := aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, haagentmock.NewMockHaAgent(), compressor, noopimpl.NewComponent(), "hostname") return NewTestAgentDemultiplexer(demux) } diff --git a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go index d52c69356a847..90966a33fc61c 100644 --- a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go +++ b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go @@ -9,6 +9,7 @@ package diagnosesendermanagerimpl import ( "context" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" @@ -19,7 +20,6 @@ import ( "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" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" @@ -40,6 +40,7 @@ type dependencies struct { Hostname hostname.Component Compressor compression.Component Tagger tagger.Component + HaAgent haagent.Component } type diagnoseSenderManager struct { @@ -70,6 +71,7 @@ func (sender *diagnoseSenderManager) LazyGetSenderManager() (sender.SenderManage log := sender.deps.Log config := sender.deps.Config + haAgent := sender.deps.HaAgent forwarder := defaultforwarder.NewDefaultForwarder(config, log, defaultforwarder.NewOptions(config, log, nil)) orchestratorForwarder := optional.NewOptionPtr[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(sender.deps.Hostname)) @@ -79,7 +81,7 @@ func (sender *diagnoseSenderManager) LazyGetSenderManager() (sender.SenderManage orchestratorForwarder, opts, eventPlatformForwarder, - haagentimpl.NewNoopHaAgent(), + haAgent, sender.deps.Compressor, sender.deps.Tagger, hostnameDetected) diff --git a/comp/haagent/impl-noop/noophaagent.go b/comp/haagent/impl-noop/noophaagent.go deleted file mode 100644 index 7c3ad366fc844..0000000000000 --- a/comp/haagent/impl-noop/noophaagent.go +++ /dev/null @@ -1,39 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2024-present Datadog, Inc. - -// Package haagentimpl provides a noop haagent component -package haagentimpl - -import ( - "go.uber.org/fx" - - log "github.com/DataDog/datadog-agent/comp/core/log/def" - haagent "github.com/DataDog/datadog-agent/comp/haagent/def" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" -) - -type noopHaAgent struct { - Logger log.Component -} - -func (m *noopHaAgent) GetGroup() string { return "" } - -func (m *noopHaAgent) Enabled() bool { return false } - -func (m *noopHaAgent) SetLeader(_ string) {} - -func (m *noopHaAgent) IsLeader() bool { return false } - -// NewNoopHaAgent returns a new Mock -func NewNoopHaAgent() haagent.Component { - return &noopHaAgent{} -} - -// NoopModule defines the fx options for the haagentimpl component. -func NoopModule() fxutil.Module { - return fxutil.Component( - fx.Provide(NewNoopHaAgent), - ) -} diff --git a/comp/haagent/mock/mock.go b/comp/haagent/mock/mock.go index 91910055c9817..484aceea1530c 100644 --- a/comp/haagent/mock/mock.go +++ b/comp/haagent/mock/mock.go @@ -58,7 +58,7 @@ type Provides struct { } // NewMockHaAgent returns a new Mock -func NewMockHaAgent() MockComponent { +func NewMockHaAgent() haagent.Component { return &mockHaAgent{ enabled: false, group: "group01", diff --git a/pkg/aggregator/aggregator_test.go b/pkg/aggregator/aggregator_test.go index 415de7c92c50f..8227f9e9a4116 100644 --- a/pkg/aggregator/aggregator_test.go +++ b/pkg/aggregator/aggregator_test.go @@ -27,8 +27,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" - mockhaagent "github.com/DataDog/datadog-agent/comp/haagent/mock" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" configmock "github.com/DataDog/datadog-agent/pkg/config/mock" @@ -231,7 +230,7 @@ func TestDefaultData(t *testing.T) { s := &MockSerializerIterableSerie{} taggerComponent := taggerMock.SetupFakeTagger(t) - agg := NewBufferedAggregator(s, nil, haagentimpl.NewNoopHaAgent(), taggerComponent, "hostname", DefaultFlushInterval) + agg := NewBufferedAggregator(s, nil, haagentmock.NewMockHaAgent(), taggerComponent, "hostname", DefaultFlushInterval) start := time.Now() @@ -598,7 +597,7 @@ func TestTags(t *testing.T) { taggerComponent := taggerMock.SetupFakeTagger(t) - mockHaAgent := mockhaagent.NewMockHaAgent() + mockHaAgent := haagentmock.NewMockHaAgent().(haagentmock.MockComponent) mockHaAgent.SetEnabled(tt.haAgentEnabled) agg := NewBufferedAggregator(nil, nil, mockHaAgent, taggerComponent, tt.hostname, time.Second) @@ -744,7 +743,7 @@ type aggregatorDeps struct { } func createAggrDeps(t *testing.T) aggregatorDeps { - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentimpl.NoopModule()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentmock.MockModule()) opts := demuxTestOptions() return aggregatorDeps{ diff --git a/pkg/aggregator/check_sampler_bench_test.go b/pkg/aggregator/check_sampler_bench_test.go index 578aa4dd07c3b..daac7d2c251f6 100644 --- a/pkg/aggregator/check_sampler_bench_test.go +++ b/pkg/aggregator/check_sampler_bench_test.go @@ -17,7 +17,7 @@ import ( "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" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression" //nolint:revive // TODO(AML) Fix revive linter @@ -52,7 +52,8 @@ func benchmarkAddBucket(bucketValue int64, b *testing.B) { sharedForwarder := forwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), deps.Log, forwarderOpts) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(deps.Hostname)) - demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), deps.Compressor, taggerComponent, "hostname") + haAgent := haagentmock.NewMockHaAgent() + demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventPlatformForwarder, haAgent, deps.Compressor, taggerComponent, "hostname") defer demux.Stop(true) checkSampler := newCheckSampler(1, true, true, 1000, tags.NewStore(true, "bench"), checkid.ID("hello:world:1234"), taggerComponent) diff --git a/pkg/aggregator/demultiplexer_agent_test.go b/pkg/aggregator/demultiplexer_agent_test.go index baab1b9cebbcc..57a344d7182d3 100644 --- a/pkg/aggregator/demultiplexer_agent_test.go +++ b/pkg/aggregator/demultiplexer_agent_test.go @@ -24,7 +24,7 @@ import ( orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" haagent "github.com/DataDog/datadog-agent/comp/haagent/def" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/metrics" @@ -114,7 +114,7 @@ func TestDemuxNoAggOptionEnabled(t *testing.T) { func TestDemuxNoAggOptionIsDisabledByDefault(t *testing.T) { opts := demuxTestOptions() - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentimpl.NoopModule()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentmock.MockModule()) demux := InitAndStartAgentDemultiplexerForTest(deps, opts, "") require.False(t, demux.Options().EnableNoAggregationPipeline, "the no aggregation pipeline should be disabled by default") @@ -171,7 +171,7 @@ func createDemultiplexerAgentTestDeps(t *testing.T) DemultiplexerAgentTestDeps { core.MockBundle(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), - haagentimpl.NoopModule(), + haagentmock.MockModule(), compressionimpl.MockModule(), fx.Provide(func() tagger.Component { return taggerComponent }), ) diff --git a/pkg/aggregator/demultiplexer_test.go b/pkg/aggregator/demultiplexer_test.go index 8998804aef5dc..32f23e8e4eee2 100644 --- a/pkg/aggregator/demultiplexer_test.go +++ b/pkg/aggregator/demultiplexer_test.go @@ -21,7 +21,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl" orchestratorForwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" @@ -301,7 +301,7 @@ func createDemuxDepsWithOrchestratorFwd( eventplatformimpl.Module(eventPlatformParams), eventplatformreceiverimpl.Module(), compressionimpl.MockModule(), - haagentimpl.NoopModule(), + haagentmock.MockModule(), ) deps := fxutil.Test[internalDemutiplexerDeps](t, modules) diff --git a/pkg/aggregator/mocksender/mocksender.go b/pkg/aggregator/mocksender/mocksender.go index 3978c45d8354a..309a07ae0b3bf 100644 --- a/pkg/aggregator/mocksender/mocksender.go +++ b/pkg/aggregator/mocksender/mocksender.go @@ -10,7 +10,6 @@ package mocksender import ( "time" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" "github.com/stretchr/testify/mock" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" @@ -21,6 +20,7 @@ import ( "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/impl-noop" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "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" @@ -44,7 +44,7 @@ func CreateDefaultDemultiplexer() *aggregator.AgentDemultiplexer { orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostnameimpl.NewHostnameService())) taggerComponent := nooptagger.NewComponent() - return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), taggerComponent, "") + return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventPlatformForwarder, haagentmock.NewMockHaAgent(), compressionimpl.NewMockCompressor(), taggerComponent, "") } diff --git a/pkg/aggregator/sender_test.go b/pkg/aggregator/sender_test.go index b443ef3bbccd3..68045d0d04715 100644 --- a/pkg/aggregator/sender_test.go +++ b/pkg/aggregator/sender_test.go @@ -23,7 +23,7 @@ import ( "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" - haagentimpl "github.com/DataDog/datadog-agent/comp/haagent/impl-noop" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" "github.com/DataDog/datadog-agent/pkg/metrics" @@ -59,7 +59,7 @@ func testDemux(log log.Component, hostname hostname.Component) *AgentDemultiplex opts.DontStartForwarders = true orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) eventPlatformForwarder := optional.NewOptionPtr[eventplatform.Forwarder](eventplatformimpl.NewNoopEventPlatformForwarder(hostname)) - demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventPlatformForwarder, haagentimpl.NewNoopHaAgent(), compressionimpl.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) + demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventPlatformForwarder, haagentmock.NewMockHaAgent(), compressionimpl.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) return demux } From f4939370714b5af4fde9c50988a50d53a83831f4 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:02:38 +0100 Subject: [PATCH 13/27] fix cmd/agent/subcommands/diagnose/command.go --- cmd/agent/subcommands/diagnose/command.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/agent/subcommands/diagnose/command.go b/cmd/agent/subcommands/diagnose/command.go index 98250bb370787..3cb0c3ee6b8a4 100644 --- a/cmd/agent/subcommands/diagnose/command.go +++ b/cmd/agent/subcommands/diagnose/command.go @@ -28,6 +28,7 @@ import ( wmcatalog "github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors/catalog" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafx "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" @@ -104,6 +105,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { autodiscoveryimpl.Module(), compressionimpl.Module(), diagnosesendermanagerimpl.Module(), + haagentfx.Module(), ) }, } From 65d8ac64aad519d6b99ece4a7d77caf7103d4cff Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:03:39 +0100 Subject: [PATCH 14/27] fix team --- comp/README.md | 2 +- comp/haagent/def/component.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/comp/README.md b/comp/README.md index f67d761626989..df42d1c5aff83 100644 --- a/comp/README.md +++ b/comp/README.md @@ -599,7 +599,7 @@ Package etw provides an ETW tracing interface ### [comp/haagent](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/haagent) -*Datadog Team*: network-device-monitoring remote-config fleet +*Datadog Team*: network-device-monitoring Package haagent handles states for HA Agent feature. diff --git a/comp/haagent/def/component.go b/comp/haagent/def/component.go index 5f00284c9f210..e20be4b3d0c81 100644 --- a/comp/haagent/def/component.go +++ b/comp/haagent/def/component.go @@ -6,7 +6,7 @@ // Package haagent handles states for HA Agent feature. package haagent -// team: network-device-monitoring remote-config fleet +// team: network-device-monitoring // Component is the component type. type Component interface { From 2e6078b20d673ff0064de6a1c838268c37f29332 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:11:21 +0100 Subject: [PATCH 15/27] update owner --- .github/CODEOWNERS | 2 +- comp/README.md | 2 +- comp/haagent/def/component.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 66cddbe7d168d..71eb1447b5e3f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -316,7 +316,7 @@ /comp/trace/etwtracer @DataDog/windows-agent /comp/autoscaling/datadogclient @DataDog/container-integrations /comp/etw @DataDog/windows-agent -/comp/haagent @DataDog/network-device-monitoring +/comp/haagent @DataDog/ndm-core /comp/languagedetection/client @DataDog/container-platform /comp/rdnsquerier @DataDog/ndm-integrations /comp/serializer/compression @DataDog/agent-metrics-logs diff --git a/comp/README.md b/comp/README.md index df42d1c5aff83..d9c2cf8ab27d4 100644 --- a/comp/README.md +++ b/comp/README.md @@ -599,7 +599,7 @@ Package etw provides an ETW tracing interface ### [comp/haagent](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/haagent) -*Datadog Team*: network-device-monitoring +*Datadog Team*: ndm-core Package haagent handles states for HA Agent feature. diff --git a/comp/haagent/def/component.go b/comp/haagent/def/component.go index e20be4b3d0c81..2472322d9a400 100644 --- a/comp/haagent/def/component.go +++ b/comp/haagent/def/component.go @@ -6,7 +6,7 @@ // Package haagent handles states for HA Agent feature. package haagent -// team: network-device-monitoring +// team: ndm-core // Component is the component type. type Component interface { From dae3005f0fed900e7b41e6b2977729b844bff3e7 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:17:12 +0100 Subject: [PATCH 16/27] clean up --- .../diagnosesendermanagerimpl/sendermanager.go | 2 +- comp/haagent/mock/mock.go | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go index 90966a33fc61c..b48e237937c57 100644 --- a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go +++ b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go @@ -9,7 +9,6 @@ package diagnosesendermanagerimpl import ( "context" - haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" @@ -20,6 +19,7 @@ import ( "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" + haagent "github.com/DataDog/datadog-agent/comp/haagent/def" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" diff --git a/comp/haagent/mock/mock.go b/comp/haagent/mock/mock.go index 484aceea1530c..5561af6de9ab8 100644 --- a/comp/haagent/mock/mock.go +++ b/comp/haagent/mock/mock.go @@ -52,11 +52,6 @@ type MockComponent interface { SetEnabled(bool) } -// Provides that defines the output of mocked snmpscan component -type Provides struct { - comp MockComponent -} - // NewMockHaAgent returns a new Mock func NewMockHaAgent() haagent.Component { return &mockHaAgent{ From 9b29cc94052b2abf7d3bec21023160509e335893 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:20:02 +0100 Subject: [PATCH 17/27] revert unintended changes --- pkg/aggregator/demultiplexer_test.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/aggregator/demultiplexer_test.go b/pkg/aggregator/demultiplexer_test.go index 32f23e8e4eee2..0f065c2eeed80 100644 --- a/pkg/aggregator/demultiplexer_test.go +++ b/pkg/aggregator/demultiplexer_test.go @@ -273,11 +273,7 @@ func TestGetDogStatsDWorkerAndPipelineCount(t *testing.T) { assert.Equal(4, pipelines) } -func createDemuxDeps( - t *testing.T, - opts AgentDemultiplexerOptions, - eventPlatformParams eventplatformimpl.Params, -) aggregatorDeps { +func createDemuxDeps(t *testing.T, opts AgentDemultiplexerOptions, eventPlatformParams eventplatformimpl.Params) aggregatorDeps { return createDemuxDepsWithOrchestratorFwd(t, opts, orchestratorForwarderImpl.NewDefaultParams(), eventPlatformParams) } @@ -292,8 +288,7 @@ func createDemuxDepsWithOrchestratorFwd( t *testing.T, opts AgentDemultiplexerOptions, orchestratorParams orchestratorForwarderImpl.Params, - eventPlatformParams eventplatformimpl.Params, -) aggregatorDeps { + eventPlatformParams eventplatformimpl.Params) aggregatorDeps { modules := fx.Options( defaultforwarder.MockModule(), core.MockBundle(), From b1c7cf0e78fe63435af67966c7c1e383737e6148 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:47:15 +0100 Subject: [PATCH 18/27] fix lint --- comp/aggregator/bundle_test.go | 2 +- .../demultiplexer/demultiplexerimpl/status_test.go | 2 +- comp/haagent/mock/mock.go | 8 ++++---- pkg/aggregator/aggregator_test.go | 4 ++-- pkg/aggregator/demultiplexer_agent_test.go | 4 ++-- pkg/aggregator/demultiplexer_test.go | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/comp/aggregator/bundle_test.go b/comp/aggregator/bundle_test.go index d47a33f4ff4ef..9b31c53698d21 100644 --- a/comp/aggregator/bundle_test.go +++ b/comp/aggregator/bundle_test.go @@ -27,6 +27,6 @@ func TestBundleDependencies(t *testing.T) { orchestratorForwarderImpl.MockModule(), eventplatformimpl.MockModule(), nooptagger.Module(), - haagentmock.MockModule(), + haagentmock.Module(), ) } diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go index 47d2340abb282..e5c620f88db3c 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/status_test.go @@ -62,7 +62,7 @@ func TestStatusOutPut(t *testing.T) { core.MockBundle(), compressionimpl.MockModule(), defaultforwarder.MockModule(), - haagentmock.MockModule(), + haagentmock.Module(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), fx.Provide(func() tagger.Component { diff --git a/comp/haagent/mock/mock.go b/comp/haagent/mock/mock.go index 5561af6de9ab8..b64e46aa5974d 100644 --- a/comp/haagent/mock/mock.go +++ b/comp/haagent/mock/mock.go @@ -44,8 +44,8 @@ func (m *mockHaAgent) SetEnabled(enabled bool) { m.enabled = enabled } -// MockComponent is the component type. -type MockComponent interface { +// Component is the component type. +type Component interface { haagent.Component SetGroup(string) @@ -60,8 +60,8 @@ func NewMockHaAgent() haagent.Component { } } -// MockModule defines the fx options for the mockHaAgent component. -func MockModule() fxutil.Module { +// Module defines the fx options for the mockHaAgent component. +func Module() fxutil.Module { return fxutil.Component( fx.Provide(NewMockHaAgent), ) diff --git a/pkg/aggregator/aggregator_test.go b/pkg/aggregator/aggregator_test.go index 8227f9e9a4116..c08aff0278bb1 100644 --- a/pkg/aggregator/aggregator_test.go +++ b/pkg/aggregator/aggregator_test.go @@ -597,7 +597,7 @@ func TestTags(t *testing.T) { taggerComponent := taggerMock.SetupFakeTagger(t) - mockHaAgent := haagentmock.NewMockHaAgent().(haagentmock.MockComponent) + mockHaAgent := haagentmock.NewMockHaAgent().(haagentmock.Component) mockHaAgent.SetEnabled(tt.haAgentEnabled) agg := NewBufferedAggregator(nil, nil, mockHaAgent, taggerComponent, tt.hostname, time.Second) @@ -743,7 +743,7 @@ type aggregatorDeps struct { } func createAggrDeps(t *testing.T) aggregatorDeps { - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentmock.MockModule()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentmock.Module()) opts := demuxTestOptions() return aggregatorDeps{ diff --git a/pkg/aggregator/demultiplexer_agent_test.go b/pkg/aggregator/demultiplexer_agent_test.go index 57a344d7182d3..0d0d1af8a4ef8 100644 --- a/pkg/aggregator/demultiplexer_agent_test.go +++ b/pkg/aggregator/demultiplexer_agent_test.go @@ -114,7 +114,7 @@ func TestDemuxNoAggOptionEnabled(t *testing.T) { func TestDemuxNoAggOptionIsDisabledByDefault(t *testing.T) { opts := demuxTestOptions() - deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentmock.MockModule()) + deps := fxutil.Test[TestDeps](t, defaultforwarder.MockModule(), core.MockBundle(), compressionimpl.MockModule(), haagentmock.Module()) demux := InitAndStartAgentDemultiplexerForTest(deps, opts, "") require.False(t, demux.Options().EnableNoAggregationPipeline, "the no aggregation pipeline should be disabled by default") @@ -171,7 +171,7 @@ func createDemultiplexerAgentTestDeps(t *testing.T) DemultiplexerAgentTestDeps { core.MockBundle(), orchestratorimpl.MockModule(), eventplatformimpl.MockModule(), - haagentmock.MockModule(), + haagentmock.Module(), compressionimpl.MockModule(), fx.Provide(func() tagger.Component { return taggerComponent }), ) diff --git a/pkg/aggregator/demultiplexer_test.go b/pkg/aggregator/demultiplexer_test.go index 0f065c2eeed80..f95ab7020d3c8 100644 --- a/pkg/aggregator/demultiplexer_test.go +++ b/pkg/aggregator/demultiplexer_test.go @@ -296,7 +296,7 @@ func createDemuxDepsWithOrchestratorFwd( eventplatformimpl.Module(eventPlatformParams), eventplatformreceiverimpl.Module(), compressionimpl.MockModule(), - haagentmock.MockModule(), + haagentmock.Module(), ) deps := fxutil.Test[internalDemutiplexerDeps](t, modules) From d8d39659e8952d436e6c61b4d1a5ded6b7c29978 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 10:48:55 +0100 Subject: [PATCH 19/27] rename --- comp/haagent/mock/mock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comp/haagent/mock/mock.go b/comp/haagent/mock/mock.go index b64e46aa5974d..52142737704c9 100644 --- a/comp/haagent/mock/mock.go +++ b/comp/haagent/mock/mock.go @@ -60,7 +60,7 @@ func NewMockHaAgent() haagent.Component { } } -// Module defines the fx options for the mockHaAgent component. +// Module defines the fx options for the mock component. func Module() fxutil.Module { return fxutil.Component( fx.Provide(NewMockHaAgent), From e9ffed6c144dc2fac300b978625bfd32173189a5 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 15:53:52 +0100 Subject: [PATCH 20/27] fix tests --- cmd/agent/subcommands/flare/command.go | 2 ++ cmd/agent/subcommands/jmx/command.go | 2 ++ cmd/agent/subcommands/snmp/command.go | 10 +++++++--- .../subcommands/run/command.go | 2 ++ cmd/cluster-agent/subcommands/start/command.go | 2 ++ cmd/dogstatsd/subcommands/start/command.go | 2 ++ pkg/cli/subcommands/check/command.go | 2 ++ 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/agent/subcommands/flare/command.go b/cmd/agent/subcommands/flare/command.go index 8b75e3aa8226c..cc7197d223e18 100644 --- a/cmd/agent/subcommands/flare/command.go +++ b/cmd/agent/subcommands/flare/command.go @@ -43,6 +43,7 @@ import ( wmcatalog "github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors/catalog" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafx "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" "github.com/DataDog/datadog-agent/comp/metadata/host/hostimpl" "github.com/DataDog/datadog-agent/comp/metadata/inventoryagent/inventoryagentimpl" "github.com/DataDog/datadog-agent/comp/metadata/inventoryhost/inventoryhostimpl" @@ -143,6 +144,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { return nil }), core.Bundle(), + haagentfx.Module(), ) }, } diff --git a/cmd/agent/subcommands/jmx/command.go b/cmd/agent/subcommands/jmx/command.go index d7021dd32720b..c7df8718fa799 100644 --- a/cmd/agent/subcommands/jmx/command.go +++ b/cmd/agent/subcommands/jmx/command.go @@ -53,6 +53,7 @@ import ( "github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap" replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def" dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" "github.com/DataDog/datadog-agent/comp/remote-config/rcservice" "github.com/DataDog/datadog-agent/comp/remote-config/rcservicemrf" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" @@ -167,6 +168,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { proccontainers.InitSharedContainerProvider(wmeta, tagger) }), fx.Provide(func() remoteagentregistry.Component { return nil }), + haagentfx.Module(), ) } diff --git a/cmd/agent/subcommands/snmp/command.go b/cmd/agent/subcommands/snmp/command.go index a6436c90951a2..c75a6eaeba48d 100644 --- a/cmd/agent/subcommands/snmp/command.go +++ b/cmd/agent/subcommands/snmp/command.go @@ -9,6 +9,10 @@ package snmp import ( "errors" "fmt" + "net" + "os" + "strconv" + "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/aggregator" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" @@ -22,14 +26,12 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl" "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" snmpscan "github.com/DataDog/datadog-agent/comp/snmpscan/def" snmpscanfx "github.com/DataDog/datadog-agent/comp/snmpscan/fx" "github.com/DataDog/datadog-agent/pkg/snmp/snmpparse" "github.com/DataDog/datadog-agent/pkg/util/fxutil" - "net" - "os" - "strconv" "github.com/spf13/cobra" "go.uber.org/fx" @@ -99,6 +101,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { nooptagger.Module(), compressionimpl.Module(), eventplatformreceiverimpl.Module(), + haagentfx.Module(), ) if err != nil { var ue configErr @@ -160,6 +163,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { nooptagger.Module(), compressionimpl.Module(), snmpscanfx.Module(), + haagentfx.Module(), ) if err != nil { var ue configErr diff --git a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go index 305b872133d7d..de5c2a6251426 100644 --- a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go +++ b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go @@ -49,6 +49,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" integrations "github.com/DataDog/datadog-agent/comp/logs/integrations/def" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/clusteragent" @@ -126,6 +127,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Invoke(func(wmeta workloadmeta.Component, tagger tagger.Component) { proccontainers.InitSharedContainerProvider(wmeta, tagger) }), + haagentfx.Module(), ) }, } diff --git a/cmd/cluster-agent/subcommands/start/command.go b/cmd/cluster-agent/subcommands/start/command.go index c4cd5d83276b9..e474997485de5 100644 --- a/cmd/cluster-agent/subcommands/start/command.go +++ b/cmd/cluster-agent/subcommands/start/command.go @@ -60,6 +60,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" integrations "github.com/DataDog/datadog-agent/comp/logs/integrations/def" rccomp "github.com/DataDog/datadog-agent/comp/remote-config/rcservice" "github.com/DataDog/datadog-agent/comp/remote-config/rcservice/rcserviceimpl" @@ -203,6 +204,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Invoke(func(wmeta workloadmeta.Component, tagger tagger.Component) { proccontainers.InitSharedContainerProvider(wmeta, tagger) }), + haagentfx.Module(), ) }, } diff --git a/cmd/dogstatsd/subcommands/start/command.go b/cmd/dogstatsd/subcommands/start/command.go index cd7dea61251b7..1b67382c861a3 100644 --- a/cmd/dogstatsd/subcommands/start/command.go +++ b/cmd/dogstatsd/subcommands/start/command.go @@ -43,6 +43,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" "github.com/DataDog/datadog-agent/comp/metadata/host" "github.com/DataDog/datadog-agent/comp/metadata/host/hostimpl" "github.com/DataDog/datadog-agent/comp/metadata/inventoryagent" @@ -173,6 +174,7 @@ func RunDogstatsdFct(cliParams *CLIParams, defaultConfPath string, defaultLogFil } }), healthprobefx.Module(), + haagentfx.Module(), ) } diff --git a/pkg/cli/subcommands/check/command.go b/pkg/cli/subcommands/check/command.go index f88bd1b8a2dc2..2da70cead3066 100644 --- a/pkg/cli/subcommands/check/command.go +++ b/pkg/cli/subcommands/check/command.go @@ -61,6 +61,7 @@ import ( "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl" orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" logagent "github.com/DataDog/datadog-agent/comp/logs/agent" integrations "github.com/DataDog/datadog-agent/comp/logs/integrations/def" "github.com/DataDog/datadog-agent/comp/metadata/inventorychecks" @@ -212,6 +213,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { getPlatformModules(), jmxloggerimpl.Module(jmxloggerimpl.NewDisabledParams()), + haagentfx.Module(), ) }, } From d33125a7d0bb0bd6ed43881bbec0e18483f5785d Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 16:04:25 +0100 Subject: [PATCH 21/27] add reno --- ...-comp-agent-group-metric-tag-66893d099fe880cc.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 releasenotes/notes/NDMII-3154-ha-agent-comp-agent-group-metric-tag-66893d099fe880cc.yaml diff --git a/releasenotes/notes/NDMII-3154-ha-agent-comp-agent-group-metric-tag-66893d099fe880cc.yaml b/releasenotes/notes/NDMII-3154-ha-agent-comp-agent-group-metric-tag-66893d099fe880cc.yaml new file mode 100644 index 0000000000000..80412f488753f --- /dev/null +++ b/releasenotes/notes/NDMII-3154-ha-agent-comp-agent-group-metric-tag-66893d099fe880cc.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +enhancements: + - | + [ha-agent] Add agent_group tag to datadog.agent.running metric From f1e9353f6ab5910ae7217fd84ef4748256556010 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 16:31:53 +0100 Subject: [PATCH 22/27] remove dep --- cmd/serverless/dependencies_linux_amd64.txt | 1 + cmd/serverless/dependencies_linux_arm64.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/cmd/serverless/dependencies_linux_amd64.txt b/cmd/serverless/dependencies_linux_amd64.txt index 4bcca62d0f61c..e7d1aec5bf4e5 100644 --- a/cmd/serverless/dependencies_linux_amd64.txt +++ b/cmd/serverless/dependencies_linux_amd64.txt @@ -110,6 +110,7 @@ github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction github.com/DataDog/datadog-agent/comp/forwarder/eventplatform github.com/DataDog/datadog-agent/comp/forwarder/orchestrator github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorinterface +github.com/DataDog/datadog-agent/comp/haagent/def github.com/DataDog/datadog-agent/comp/logs/agent github.com/DataDog/datadog-agent/comp/logs/agent/agentimpl github.com/DataDog/datadog-agent/comp/logs/agent/config diff --git a/cmd/serverless/dependencies_linux_arm64.txt b/cmd/serverless/dependencies_linux_arm64.txt index edda30b758215..b1e33005efe39 100644 --- a/cmd/serverless/dependencies_linux_arm64.txt +++ b/cmd/serverless/dependencies_linux_arm64.txt @@ -110,6 +110,7 @@ github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction github.com/DataDog/datadog-agent/comp/forwarder/eventplatform github.com/DataDog/datadog-agent/comp/forwarder/orchestrator github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorinterface +github.com/DataDog/datadog-agent/comp/haagent/def github.com/DataDog/datadog-agent/comp/logs/agent github.com/DataDog/datadog-agent/comp/logs/agent/agentimpl github.com/DataDog/datadog-agent/comp/logs/agent/config From ae4f2eb1dfcee0a06af249992a268e07595f8287 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 16:32:57 +0100 Subject: [PATCH 23/27] revert cmd/serverless/dependencies_linux* --- cmd/serverless/dependencies_linux_amd64.txt | 1 - cmd/serverless/dependencies_linux_arm64.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/cmd/serverless/dependencies_linux_amd64.txt b/cmd/serverless/dependencies_linux_amd64.txt index e7d1aec5bf4e5..4bcca62d0f61c 100644 --- a/cmd/serverless/dependencies_linux_amd64.txt +++ b/cmd/serverless/dependencies_linux_amd64.txt @@ -110,7 +110,6 @@ github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction github.com/DataDog/datadog-agent/comp/forwarder/eventplatform github.com/DataDog/datadog-agent/comp/forwarder/orchestrator github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorinterface -github.com/DataDog/datadog-agent/comp/haagent/def github.com/DataDog/datadog-agent/comp/logs/agent github.com/DataDog/datadog-agent/comp/logs/agent/agentimpl github.com/DataDog/datadog-agent/comp/logs/agent/config diff --git a/cmd/serverless/dependencies_linux_arm64.txt b/cmd/serverless/dependencies_linux_arm64.txt index b1e33005efe39..edda30b758215 100644 --- a/cmd/serverless/dependencies_linux_arm64.txt +++ b/cmd/serverless/dependencies_linux_arm64.txt @@ -110,7 +110,6 @@ github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction github.com/DataDog/datadog-agent/comp/forwarder/eventplatform github.com/DataDog/datadog-agent/comp/forwarder/orchestrator github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorinterface -github.com/DataDog/datadog-agent/comp/haagent/def github.com/DataDog/datadog-agent/comp/logs/agent github.com/DataDog/datadog-agent/comp/logs/agent/agentimpl github.com/DataDog/datadog-agent/comp/logs/agent/config From be0d8ea15489e8c59f09fc63490d72a1af856058 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Thu, 21 Nov 2024 16:33:35 +0100 Subject: [PATCH 24/27] add dep --- cmd/serverless/dependencies_linux_amd64.txt | 1 + cmd/serverless/dependencies_linux_arm64.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/cmd/serverless/dependencies_linux_amd64.txt b/cmd/serverless/dependencies_linux_amd64.txt index 4bcca62d0f61c..e7d1aec5bf4e5 100644 --- a/cmd/serverless/dependencies_linux_amd64.txt +++ b/cmd/serverless/dependencies_linux_amd64.txt @@ -110,6 +110,7 @@ github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction github.com/DataDog/datadog-agent/comp/forwarder/eventplatform github.com/DataDog/datadog-agent/comp/forwarder/orchestrator github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorinterface +github.com/DataDog/datadog-agent/comp/haagent/def github.com/DataDog/datadog-agent/comp/logs/agent github.com/DataDog/datadog-agent/comp/logs/agent/agentimpl github.com/DataDog/datadog-agent/comp/logs/agent/config diff --git a/cmd/serverless/dependencies_linux_arm64.txt b/cmd/serverless/dependencies_linux_arm64.txt index edda30b758215..b1e33005efe39 100644 --- a/cmd/serverless/dependencies_linux_arm64.txt +++ b/cmd/serverless/dependencies_linux_arm64.txt @@ -110,6 +110,7 @@ github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction github.com/DataDog/datadog-agent/comp/forwarder/eventplatform github.com/DataDog/datadog-agent/comp/forwarder/orchestrator github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorinterface +github.com/DataDog/datadog-agent/comp/haagent/def github.com/DataDog/datadog-agent/comp/logs/agent github.com/DataDog/datadog-agent/comp/logs/agent/agentimpl github.com/DataDog/datadog-agent/comp/logs/agent/config From 25a2bc3b9d9b8e69e107fe4eef2d6e2e3e51c800 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Sun, 24 Nov 2024 17:14:02 +0100 Subject: [PATCH 25/27] try fix TestFxRunCommand --- cmd/systray/command/command.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/systray/command/command.go b/cmd/systray/command/command.go index b91fa3eac86df..df2415c7164ef 100644 --- a/cmd/systray/command/command.go +++ b/cmd/systray/command/command.go @@ -27,6 +27,7 @@ import ( log "github.com/DataDog/datadog-agent/comp/core/log/def" nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/fx-noop" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" + haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx" "github.com/DataDog/datadog-agent/comp/metadata/inventoryagent/inventoryagentimpl" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/comp/systray/systray" @@ -125,6 +126,7 @@ func MakeCommand() *cobra.Command { systrayimpl.Module(), // require the systray component, causing it to start fx.Invoke(func(_ systray.Component) {}), + haagentfx.Module(), ) }, } From 5d03ac073fac7f3b4f41ea0c8630e5a0fa58e3e9 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Sun, 24 Nov 2024 17:31:04 +0100 Subject: [PATCH 26/27] test demultiplexer_mock.go --- .../demultiplexer/demultiplexerimpl/demultiplexer_mock.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go index f7dc85d7beb18..eb8cfb684bc75 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go @@ -15,6 +15,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/hostname" log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" + haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" @@ -76,6 +77,7 @@ func newMock(deps mockDependencies) MockProvides { Hostname: deps.Hostname, SharedForwarder: defaultforwarder.NoopForwarder{}, Compressor: compressionimpl.NewMockCompressor(), + HaAgent: haagentmock.NewMockHaAgent(), } instance := &mock{AgentDemultiplexer: aggregator.InitAndStartAgentDemultiplexerForTest(aggDeps, opts, "")} From 79ddc2cc6b87ec7c9a6b5475fae73dca89f052c1 Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Sun, 24 Nov 2024 18:31:46 +0100 Subject: [PATCH 27/27] empty