Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASCII-1613] Split dogstatsd/replay into new component hierarchy #25512

Merged
merged 12 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/agent/subcommands/dogstatsdreplay/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/impl"
"github.com/DataDog/datadog-agent/pkg/api/security"
pkgconfig "github.com/DataDog/datadog-agent/pkg/config"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/core"
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/subcommands/jmx/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
serverdebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver"
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta/defaults"
"github.com/DataDog/datadog-agent/comp/dogstatsd"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
dogstatsddebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
dogstatsdStatusimpl "github.com/DataDog/datadog-agent/comp/dogstatsd/status/statusimpl"
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/subcommands/run/command_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/tagger"
"github.com/DataDog/datadog-agent/comp/core/telemetry"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
"github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder"
logsAgent "github.com/DataDog/datadog-agent/comp/logs/agent"
Expand Down
2 changes: 1 addition & 1 deletion comp/api/api/apiimpl/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/tagger"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
dogstatsddebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver"
Expand Down
7 changes: 4 additions & 3 deletions comp/api/api/apiimpl/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (
"github.com/DataDog/datadog-agent/comp/core/tagger"
"github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replaydef "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
pgimalac marked this conversation as resolved.
Show resolved Hide resolved
replaymock "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/fx-mock"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
dogstatsddebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
"github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug/serverdebugimpl"
Expand Down Expand Up @@ -67,7 +68,7 @@ type testdeps struct {
// TODO: remove these in the next PR once StartServer component arguments
// are part of the api component dependency struct
DogstatsdServer dogstatsdServer.Component
Capture replay.Component
Capture replaydef.Component
ServerDebug dogstatsddebug.Component
HostMetadata host.Component
InvAgent inventoryagent.Component
Expand Down Expand Up @@ -97,7 +98,7 @@ func getComponentDependencies(t *testing.T) testdeps {
hostnameimpl.MockModule(),
flareimpl.MockModule(),
dogstatsdServer.MockModule(),
replay.MockModule(),
replaymock.MockModule(),
serverdebugimpl.MockModule(),
hostimpl.MockModule(),
inventoryagentimpl.MockModule(),
Expand Down
2 changes: 1 addition & 1 deletion comp/api/api/apiimpl/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl/replay"
taggerserver "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl/server"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
dsdReplay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
dsdReplay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/core"
"github.com/DataDog/datadog-agent/pkg/util/grpc"
Expand Down
2 changes: 1 addition & 1 deletion comp/api/api/apiimpl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/tagger"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
dogstatsddebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver"
Expand Down
2 changes: 1 addition & 1 deletion comp/api/api/apiimpl/server_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
workloadmetaServer "github.com/DataDog/datadog-agent/comp/core/workloadmeta/server"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
dogstatsddebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver"
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package dogstatsd //nolint:revive // TODO(AML) Fix revive linter

import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap/pidmapimpl"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replayfx "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/fx"
"github.com/DataDog/datadog-agent/comp/dogstatsd/server"
"github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug/serverdebugimpl"
"github.com/DataDog/datadog-agent/comp/dogstatsd/statsd"
Expand All @@ -20,7 +20,7 @@ import (
func Bundle() fxutil.BundleOptions {
return fxutil.Bundle(
serverdebugimpl.Module(),
replay.Module(),
replayfx.Module(),
pidmapimpl.Module(),
server.Module())
}
Expand Down
4 changes: 2 additions & 2 deletions comp/dogstatsd/bundle_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package dogstatsd

import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap/pidmapimpl"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replayfx "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/fx"
"github.com/DataDog/datadog-agent/comp/dogstatsd/server"
"github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug/serverdebugimpl"
"github.com/DataDog/datadog-agent/comp/dogstatsd/statsd"
Expand All @@ -21,7 +21,7 @@ func MockBundle() fxutil.BundleOptions {
return fxutil.Bundle(
serverdebugimpl.MockModule(),
server.MockModule(),
replay.Module(),
replayfx.Module(),
pidmapimpl.Module())
}

Expand Down
2 changes: 1 addition & 1 deletion comp/dogstatsd/listeners/named_pipe_nowindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"errors"

"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
"github.com/DataDog/datadog-agent/pkg/config"
)

Expand Down
2 changes: 1 addition & 1 deletion comp/dogstatsd/listeners/named_pipe_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"go.uber.org/atomic"

"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"

Expand Down
2 changes: 1 addition & 1 deletion comp/dogstatsd/listeners/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
)
Expand Down
2 changes: 1 addition & 1 deletion comp/dogstatsd/listeners/uds_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/listeners/ratelimit"
"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/optional"
Expand Down
2 changes: 1 addition & 1 deletion comp/dogstatsd/listeners/uds_datagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/optional"
Expand Down
2 changes: 1 addition & 1 deletion comp/dogstatsd/listeners/uds_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
"github.com/DataDog/datadog-agent/pkg/util/cache"
"github.com/DataDog/datadog-agent/pkg/util/containers"
"github.com/DataDog/datadog-agent/pkg/util/containers/metrics/provider"
Expand Down
2 changes: 1 addition & 1 deletion comp/dogstatsd/listeners/uds_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/optional"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
// Package server implements a component to run the dogstatsd capture/replay
//
//nolint:revive // TODO(AML) Fix revive linter
package replay
package def
pgimalac marked this conversation as resolved.
Show resolved Hide resolved

import (
"sync"
"time"

"go.uber.org/fx"

"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

// team: agent-metrics-logs
Expand Down Expand Up @@ -46,19 +44,38 @@ type Component interface {
GetStartUpError() error
}

// Mock implements mock-specific methods.
type Mock interface {
Component
// UnixDogstatsdMsg mirrors the exported fields of pkg/proto/pbgo/core/model.pb.go 'UnixDogstatsdMsg
// to avoid forcing the import of pbgo on every user of dogstatsd.
type UnixDogstatsdMsg struct {
Timestamp int64
PayloadSize int32
Payload []byte
Pid int32
AncillarySize int32
Ancillary []byte
}

// Module defines the fx options for this component.
func Module() fxutil.Module {
return fxutil.Component(
fx.Provide(newTrafficCapture))
// CaptureBuffer holds pointers to captured packet's buffers (and oob buffer if required) and the protobuf
// message used for serialization.
type CaptureBuffer struct {
Pb UnixDogstatsdMsg
Oob *[]byte
Pid int32
ContainerID string
Buff *packets.Packet
}

// MockModule defines the fx options for the mock component.
func MockModule() fxutil.Module {
return fxutil.Component(
fx.Provide(newMockTrafficCapture))
const (
// GUID will be used as the GUID during capture replays
// This is a magic number chosen for no particular reason other than the fact its
// quite large an improbable to match an actual Group ID on any given box. We
// need this number to identify replayed Unix socket ancillary credentials.
GUID = 999888777
)

// CapPool is a pool of CaptureBuffer
var CapPool = sync.Pool{
pgimalac marked this conversation as resolved.
Show resolved Hide resolved
New: func() interface{} {
return new(CaptureBuffer)
},
}
25 changes: 25 additions & 0 deletions comp/dogstatsd/replay/fx-mock/module.go
Original file line number Diff line number Diff line change
@@ -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 2016-present Datadog, Inc.

//go:build test

// Package server implements a component to run the dogstatsd capture/replay
//
//nolint:revive // TODO(AML) Fix revive linter
package fxmock

import (
replaymock "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/mock"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

// MockModule defines the fx options for the mock component.
func MockModule() fxutil.Module {
return fxutil.Component(
fxutil.ProvideComponentConstructor(
replaymock.NewMockTrafficCapture,
),
)
}
23 changes: 23 additions & 0 deletions comp/dogstatsd/replay/fx/module.go
Original file line number Diff line number Diff line change
@@ -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 2016-present Datadog, Inc.

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

import (
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/impl"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

// team: agent-metrics-logs

// Module defines the fx options for this component.
func Module() fxutil.Module {
return fxutil.Component(
fxutil.ProvideComponentConstructor(
replay.NewTrafficCapture,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2021 Datadog, Inc.

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

import (
Expand All @@ -13,29 +14,21 @@ import (
"time"

"github.com/spf13/afero"
"go.uber.org/fx"

configComponent "github.com/DataDog/datadog-agent/comp/core/config"
compdef "github.com/DataDog/datadog-agent/comp/def"
"github.com/DataDog/datadog-agent/comp/dogstatsd/packets"
replaydef "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
pgimalac marked this conversation as resolved.
Show resolved Hide resolved
"github.com/DataDog/datadog-agent/pkg/config"
)

const (
// GUID will be used as the GUID during capture replays
// This is a magic number chosen for no particular reason other than the fact its
// quite large an improbable to match an actual Group ID on any given box. We
// need this number to identify replayed Unix socket ancillary credentials.
GUID = 999888777
)

type dependencies struct {
fx.In

Lc fx.Lifecycle
//nolint:revive // TODO(AML) Fix revive linter
type Requires struct {
Lc compdef.Lifecycle
Config configComponent.Component
}

// TrafficCapture allows capturing traffic from our listeners and writing it to file
// trafficCapture allows capturing traffic from our listeners and writing it to file
type trafficCapture struct {
writer *TrafficCaptureWriter
config config.Reader
Expand All @@ -47,16 +40,18 @@ type trafficCapture struct {
// TODO: (components) - remove once serverless is an FX app
//
//nolint:revive // TODO(AML) Fix revive linter
func NewServerlessTrafficCapture() Component {
func NewServerlessTrafficCapture() replaydef.Component {
tc := newTrafficCaptureCompat(config.Datadog)
_ = tc.configure(context.TODO())
return tc
}

// TODO: (components) - merge with newTrafficCaptureCompat once NewServerlessTrafficCapture is removed
func newTrafficCapture(deps dependencies) Component {
//
//nolint:revive // TODO(AML) Fix revive linter
func NewTrafficCapture(deps Requires) replaydef.Component {
tc := newTrafficCaptureCompat(deps.Config)
deps.Lc.Append(fx.Hook{
deps.Lc.Append(compdef.Hook{
OnStart: tc.configure,
})

Expand Down Expand Up @@ -134,7 +129,7 @@ func (tc *trafficCapture) RegisterOOBPoolManager(p *packets.PoolManager) error {
}

// Enqueue enqueues a capture buffer so it's written to file.
func (tc *trafficCapture) Enqueue(msg *CaptureBuffer) bool {
func (tc *trafficCapture) Enqueue(msg *replaydef.CaptureBuffer) bool {
tc.RLock()
defer tc.RUnlock()
return tc.writer.Enqueue(msg)
Expand Down
File renamed without changes.
Loading
Loading