Skip to content

Commit

Permalink
differenciate between mock and noop
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Nov 27, 2024
1 parent 1623419 commit 29aff33
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions comp/forwarder/eventplatform/fx-noop/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
// 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"
)

// Module defines the fx options for the mock component.
func Module() fxutil.Module {
return fxutil.Component(
fxutil.ProvideComponentConstructor(
eventplatformmock.NewMock,
eventplatformnoop.NewComponent,
),
)
}
6 changes: 4 additions & 2 deletions comp/forwarder/eventplatform/impl-noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down
24 changes: 22 additions & 2 deletions comp/forwarder/eventplatform/mock/epforwarder_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
4 changes: 2 additions & 2 deletions pkg/aggregator/check_sampler_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/aggregator/demultiplexer_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/aggregator/mocksender/mocksender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/aggregator/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 29aff33

Please sign in to comment.