From 29aff33fe68eb4919f6953b68258d2fa8307ca1d Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Wed, 27 Nov 2024 11:38:31 +0100 Subject: [PATCH] differenciate between mock and noop --- .../test_agent_demultiplexer.go | 4 ++-- .../sendermanager.go | 4 ++-- comp/forwarder/eventplatform/fx-noop/fx.go | 6 ++--- .../forwarder/eventplatform/impl-noop/noop.go | 6 +++-- .../eventplatform/mock/epforwarder_mock.go | 24 +++++++++++++++++-- pkg/aggregator/check_sampler_bench_test.go | 4 ++-- pkg/aggregator/demultiplexer_mock.go | 4 ++-- pkg/aggregator/mocksender/mocksender.go | 4 ++-- pkg/aggregator/sender_test.go | 4 ++-- 9 files changed, 41 insertions(+), 19 deletions(-) diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go index 0bb031f0500520..f33ab36b0bf08c 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go @@ -16,7 +16,7 @@ import ( noopimpl "github.com/DataDog/datadog-agent/comp/core/tagger/impl-noop" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" eventplatform "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/def" - eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" + eventplatformock "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/mock" haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" compression "github.com/DataDog/datadog-agent/comp/serializer/compression/def" "github.com/DataDog/datadog-agent/pkg/aggregator" @@ -184,7 +184,7 @@ func initTestAgentDemultiplexerWithFlushInterval(log log.Component, compressor c sharedForwarderOptions := defaultforwarder.NewOptions(pkgconfigsetup.Datadog(), log, nil) sharedForwarder := defaultforwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, sharedForwarderOptions) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) - eventPlatformForwarder := eventplatformnoop.NewComponent() + eventPlatformForwarder := eventplatformock.NewMock() 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 afb0a6c8691051..4fae1ba7abe0ea 100644 --- a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go +++ b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go @@ -17,7 +17,7 @@ import ( log "github.com/DataDog/datadog-agent/comp/core/log/def" tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" - eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" + eventplatfornoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" haagent "github.com/DataDog/datadog-agent/comp/haagent/def" compression "github.com/DataDog/datadog-agent/comp/serializer/compression/def" "github.com/DataDog/datadog-agent/pkg/aggregator" @@ -73,7 +73,7 @@ func (sender *diagnoseSenderManager) LazyGetSenderManager() (sender.SenderManage haAgent := sender.deps.HaAgent forwarder := defaultforwarder.NewDefaultForwarder(config, log, defaultforwarder.NewOptions(config, log, nil)) orchestratorForwarder := optional.NewOptionPtr[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) - eventPlatformForwarder := eventplatformnoop.NewComponent() + eventPlatformForwarder := eventplatfornoop.NewComponent() senderManager = aggregator.InitAndStartAgentDemultiplexer( log, forwarder, diff --git a/comp/forwarder/eventplatform/fx-noop/fx.go b/comp/forwarder/eventplatform/fx-noop/fx.go index 37a2af23cc82c9..76e656b46ef53a 100644 --- a/comp/forwarder/eventplatform/fx-noop/fx.go +++ b/comp/forwarder/eventplatform/fx-noop/fx.go @@ -3,11 +3,11 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2024-present Datadog, Inc. -// Package fx provides the fxmock module for the rdnsquerier component +// Package fx provides the fxnoop module for the rdnsquerier component package fx import ( - eventplatformmock "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/mock" + eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -15,7 +15,7 @@ import ( func Module() fxutil.Module { return fxutil.Component( fxutil.ProvideComponentConstructor( - eventplatformmock.NewMock, + eventplatformnoop.NewComponent, ), ) } diff --git a/comp/forwarder/eventplatform/impl-noop/noop.go b/comp/forwarder/eventplatform/impl-noop/noop.go index 3b2426d6205aed..7d6ed39c049404 100644 --- a/comp/forwarder/eventplatform/impl-noop/noop.go +++ b/comp/forwarder/eventplatform/impl-noop/noop.go @@ -7,6 +7,8 @@ package eventplatformimpl import ( + "errors" + eventplatform "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/def" "github.com/DataDog/datadog-agent/pkg/logs/message" ) @@ -17,13 +19,13 @@ type noopForwarder struct { // SendEventPlatformEvent sends messages to the event platform intake. // SendEventPlatformEvent will drop messages and return an error if the input channel is already full. func (s *noopForwarder) SendEventPlatformEvent(*message.Message, string) error { - return nil + return errors.New("noop forwarder does not support SendEventPlatformEvent") } // SendEventPlatformEventBlocking sends messages to the event platform intake. // SendEventPlatformEventBlocking will block if the input channel is already full. func (s *noopForwarder) SendEventPlatformEventBlocking(*message.Message, string) error { - return nil + return errors.New("noop forwarder does not support SendEventPlatformEventBlocking") } // Purge clears out all pipeline channels, returning a map of eventType to list of messages in that were removed from each channel diff --git a/comp/forwarder/eventplatform/mock/epforwarder_mock.go b/comp/forwarder/eventplatform/mock/epforwarder_mock.go index ff0989c7632f74..659a458a61a005 100644 --- a/comp/forwarder/eventplatform/mock/epforwarder_mock.go +++ b/comp/forwarder/eventplatform/mock/epforwarder_mock.go @@ -7,10 +7,30 @@ package mock import ( eventplatform "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/def" - eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" + message "github.com/DataDog/datadog-agent/pkg/logs/message" ) +type mock struct { +} + +// SendEventPlatformEvent sends messages to the event platform intake. +// SendEventPlatformEvent will drop messages and return an error if the input channel is already full. +func (s *mock) SendEventPlatformEvent(*message.Message, string) error { + return nil +} + +// SendEventPlatformEventBlocking sends messages to the event platform intake. +// SendEventPlatformEventBlocking will block if the input channel is already full. +func (s *mock) SendEventPlatformEventBlocking(*message.Message, string) error { + return nil +} + +// Purge clears out all pipeline channels, returning a map of eventType to list of messages in that were removed from each channel +func (s *mock) Purge() map[string][]*message.Message { + return map[string][]*message.Message{} +} + // NewMock returns a new mock component. func NewMock() eventplatform.Component { - return eventplatformnoop.NewComponent() + return &mock{} } diff --git a/pkg/aggregator/check_sampler_bench_test.go b/pkg/aggregator/check_sampler_bench_test.go index 5aed923ad40a37..9a562434c955b2 100644 --- a/pkg/aggregator/check_sampler_bench_test.go +++ b/pkg/aggregator/check_sampler_bench_test.go @@ -15,7 +15,7 @@ import ( log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/tagger/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" - eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" + eventplatformock "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/mock" haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" //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{}) haAgent := haagentmock.NewMockHaAgent() - demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventplatformnoop.NewComponent(), haAgent, deps.Compressor, taggerComponent, "hostname") + demux := InitAndStartAgentDemultiplexer(deps.Log, sharedForwarder, &orchestratorForwarder, options, eventplatformock.NewMock(), 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_mock.go b/pkg/aggregator/demultiplexer_mock.go index 28de1429f37e88..84108c6cd9b924 100644 --- a/pkg/aggregator/demultiplexer_mock.go +++ b/pkg/aggregator/demultiplexer_mock.go @@ -14,7 +14,7 @@ import ( log "github.com/DataDog/datadog-agent/comp/core/log/def" nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/impl-noop" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" - eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" + eventplatformock "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/mock" haagent "github.com/DataDog/datadog-agent/comp/haagent/def" compression "github.com/DataDog/datadog-agent/comp/serializer/compression/def" "github.com/DataDog/datadog-agent/pkg/util/optional" @@ -33,5 +33,5 @@ type TestDeps struct { // InitAndStartAgentDemultiplexerForTest initializes an aggregator for tests. func InitAndStartAgentDemultiplexerForTest(deps TestDeps, options AgentDemultiplexerOptions, hostname string) *AgentDemultiplexer { orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) - return InitAndStartAgentDemultiplexer(deps.Log, deps.SharedForwarder, &orchestratorForwarder, options, eventplatformnoop.NewComponent(), deps.HaAgent, deps.Compressor, nooptagger.NewComponent(), hostname) + return InitAndStartAgentDemultiplexer(deps.Log, deps.SharedForwarder, &orchestratorForwarder, options, eventplatformock.NewMock(), deps.HaAgent, deps.Compressor, nooptagger.NewComponent(), hostname) } diff --git a/pkg/aggregator/mocksender/mocksender.go b/pkg/aggregator/mocksender/mocksender.go index 2cdfe6899ffbe9..340298442247f5 100644 --- a/pkg/aggregator/mocksender/mocksender.go +++ b/pkg/aggregator/mocksender/mocksender.go @@ -15,7 +15,7 @@ import ( logimpl "github.com/DataDog/datadog-agent/comp/core/log/impl" nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/impl-noop" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" - eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" + eventplatformock "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/mock" haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" compressionmock "github.com/DataDog/datadog-agent/comp/serializer/compression/fx-mock" "github.com/DataDog/datadog-agent/pkg/aggregator" @@ -40,7 +40,7 @@ func CreateDefaultDemultiplexer() *aggregator.AgentDemultiplexer { sharedForwarder := defaultforwarder.NewDefaultForwarder(pkgconfigsetup.Datadog(), log, defaultforwarder.NewOptions(pkgconfigsetup.Datadog(), log, nil)) orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) taggerComponent := nooptagger.NewComponent() - return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventplatformnoop.NewComponent(), haagentmock.NewMockHaAgent(), compressionmock.NewMockCompressor(), taggerComponent, "") + return aggregator.InitAndStartAgentDemultiplexer(log, sharedForwarder, &orchestratorForwarder, opts, eventplatformock.NewMock(), haagentmock.NewMockHaAgent(), compressionmock.NewMockCompressor(), taggerComponent, "") } // NewMockSenderWithSenderManager returns a functional mocked Sender for testing diff --git a/pkg/aggregator/sender_test.go b/pkg/aggregator/sender_test.go index 0cc533206afc7d..ae791c41b02d17 100644 --- a/pkg/aggregator/sender_test.go +++ b/pkg/aggregator/sender_test.go @@ -21,7 +21,7 @@ import ( log "github.com/DataDog/datadog-agent/comp/core/log/def" nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/impl-noop" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" - eventplatformnoop "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/impl-noop" + eventplatformock "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/mock" haagentmock "github.com/DataDog/datadog-agent/comp/haagent/mock" compressionmock "github.com/DataDog/datadog-agent/comp/serializer/compression/fx-mock" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" @@ -57,7 +57,7 @@ func testDemux(log log.Component) *AgentDemultiplexer { opts := DefaultAgentDemultiplexerOptions() opts.DontStartForwarders = true orchestratorForwarder := optional.NewOption[defaultforwarder.Forwarder](defaultforwarder.NoopForwarder{}) - demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventplatformnoop.NewComponent(), haagentmock.NewMockHaAgent(), compressionmock.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) + demux := initAgentDemultiplexer(log, NewForwarderTest(log), &orchestratorForwarder, opts, eventplatformock.NewMock(), haagentmock.NewMockHaAgent(), compressionmock.NewMockCompressor(), nooptagger.NewComponent(), defaultHostname) return demux }