Skip to content

Commit c033c2d

Browse files
committed
refactor(core): migrate comp/core/flare to V2 component architecture
1 parent 4502297 commit c033c2d

66 files changed

Lines changed: 571 additions & 325 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BUILD.bazel

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ exports_files(glob(
9292
# gazelle:exclude comp/connectivitychecker/checker
9393
# gazelle:exclude comp/connectivitychecker/fx
9494
# gazelle:exclude comp/connectivitychecker/impl
95+
# gazelle:exclude comp/core/agenttelemetry/fx
96+
# gazelle:exclude comp/core/agenttelemetry/impl
97+
# gazelle:exclude comp/core/autodiscovery
9598
# gazelle:exclude comp/core/autodiscovery/autodiscoveryimpl
9699
# gazelle:exclude comp/core/autodiscovery/common/utils
97100
# gazelle:exclude comp/core/autodiscovery/configresolver
@@ -104,9 +107,8 @@ exports_files(glob(
104107
# gazelle:exclude comp/core/bundle_mock.go
105108
# gazelle:exclude comp/core/bundle_params.go
106109
# gazelle:exclude comp/core/bundle_test.go
107-
# gazelle:exclude comp/core/diagnose/fx
108-
# gazelle:exclude comp/core/diagnose/impl
109-
# gazelle:exclude comp/core/diagnose/local
110+
# gazelle:exclude comp/core/configstream
111+
# gazelle:exclude comp/core/diagnose
110112
# gazelle:exclude comp/core/flare/flareimpl
111113
# gazelle:exclude comp/core/flare/helpers
112114
# gazelle:exclude comp/core/gui/guiimpl
@@ -231,6 +233,8 @@ exports_files(glob(
231233
# gazelle:exclude comp/netflow/server/impl
232234
# gazelle:exclude comp/netflow/testutil
233235
# gazelle:exclude comp/netflow/topn
236+
# gazelle:exclude comp/networkdeviceconfig/fx
237+
# gazelle:exclude comp/networkdeviceconfig/impl
234238
# gazelle:exclude comp/networkconfigmanagement
235239
# gazelle:exclude comp/networkpath/npcollector/fx
236240
# gazelle:exclude comp/networkpath/npcollector/mock
@@ -576,6 +580,8 @@ exports_files(glob(
576580
# gazelle:exclude pkg/network/protocols/tls/gotls/testutil/gotls_server
577581
# gazelle:exclude pkg/network/protocols/tls/nodejs
578582
# gazelle:exclude pkg/network/sender
583+
# gazelle:exclude pkg/network/slice
584+
# gazelle:exclude pkg/network/testdata
579585
# gazelle:exclude pkg/network/tracer/connection
580586
# gazelle:exclude pkg/network/tracer/networkfilter
581587
# gazelle:exclude pkg/network/tracer/testutil/proxy
@@ -726,7 +732,9 @@ exports_files(glob(
726732
# gazelle:exclude pkg/util/kubernetes/kubelet
727733
# gazelle:exclude pkg/util/port
728734
# gazelle:exclude pkg/util/tags
735+
# gazelle:exclude pkg/util/tmplvar
729736
# gazelle:exclude pkg/windowsdriver/ddinjector
737+
# gazelle:exclude tasks
730738
# gazelle:exclude tasks/unit_tests
731739
# gazelle:exclude test/benchmarks
732740
# gazelle:exclude test/e2e-framework/common/utils

cmd/agent/subcommands/flare/command.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"github.com/DataDog/datadog-agent/comp/core/diagnose/format"
3535
diagnosefx "github.com/DataDog/datadog-agent/comp/core/diagnose/fx"
3636
diagnoseLocal "github.com/DataDog/datadog-agent/comp/core/diagnose/local"
37-
"github.com/DataDog/datadog-agent/comp/core/flare"
38-
"github.com/DataDog/datadog-agent/comp/core/flare/helpers"
37+
flaredef "github.com/DataDog/datadog-agent/comp/core/flare/def"
38+
flareFx "github.com/DataDog/datadog-agent/comp/core/flare/fx"
3939
flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types"
4040
"github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl"
4141
ipc "github.com/DataDog/datadog-agent/comp/core/ipc/def"
@@ -118,7 +118,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
118118
config.WithFleetPoliciesDirPath(globalParams.FleetPoliciesDirPath),
119119
)
120120

121-
flareParams := flare.NewLocalParams(
121+
flareParams := flaredef.NewLocalParams(
122122
defaultpaths.GetDistPath(),
123123
defaultpaths.PyChecksPath,
124124
defaultpaths.LogFile,
@@ -134,7 +134,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
134134
SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.SysProbeConfFilePath), sysprobeconfigimpl.WithFleetPoliciesDirPath(globalParams.FleetPoliciesDirPath)),
135135
LogParams: log.ForOneShot(command.LoggerName, cliParams.logLevelDefaultOff.Value(), false),
136136
}),
137-
flare.Module(flareParams),
137+
flareFx.Module(flareParams),
138138
flareprofilerfx.Module(),
139139
// workloadmeta setup
140140
wmcatalog.GetCatalog(),
@@ -196,7 +196,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
196196
return []*cobra.Command{flareCmd}
197197
}
198198

199-
func makeFlare(flareComp flare.Component,
199+
func makeFlare(flareComp flaredef.Component,
200200
lc log.Component,
201201
config config.Component,
202202
_ sysprobeconfig.Component,
@@ -316,7 +316,7 @@ func makeFlare(flareComp flare.Component,
316316
}
317317
}
318318

319-
response, e := flareComp.Send(filePath, caseID, customerEmail, helpers.NewLocalFlareSource())
319+
response, e := flareComp.Send(filePath, caseID, customerEmail, flaretypes.NewLocalFlareSource())
320320
fmt.Println(response)
321321
return e
322322
}
@@ -364,7 +364,7 @@ func requestArchive(pdata flaretypes.ProfileData, client ipc.HTTPClient, provide
364364
return string(r), nil
365365
}
366366

367-
func createArchive(flareComp flare.Component, pdata flaretypes.ProfileData, providerTimeout time.Duration, ipcError error, diagnoseResult []byte) (string, error) {
367+
func createArchive(flareComp flaredef.Component, pdata flaretypes.ProfileData, providerTimeout time.Duration, ipcError error, diagnoseResult []byte) (string, error) {
368368
fmt.Fprintln(color.Output, color.YellowString("Initiating flare locally."))
369369
filePath, err := flareComp.Create(pdata, providerTimeout, ipcError, diagnoseResult)
370370
if err != nil {

cmd/agent/subcommands/run/command.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ import (
7878
configstreamfx "github.com/DataDog/datadog-agent/comp/core/configstream/fx"
7979
diagnose "github.com/DataDog/datadog-agent/comp/core/diagnose/def"
8080
diagnosefx "github.com/DataDog/datadog-agent/comp/core/diagnose/fx"
81-
"github.com/DataDog/datadog-agent/comp/core/flare"
81+
flaredef "github.com/DataDog/datadog-agent/comp/core/flare/def"
82+
flareFx "github.com/DataDog/datadog-agent/comp/core/flare/fx"
8283
flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types"
8384
"github.com/DataDog/datadog-agent/comp/core/gui"
8485
"github.com/DataDog/datadog-agent/comp/core/gui/guiimpl"
@@ -265,7 +266,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
265266
// run starts the main loop.
266267
func run(log log.Component,
267268
cfg config.Component,
268-
flare flare.Component,
269+
flare flaredef.Component,
269270
tlm telemetry.Component,
270271
sysprobeConf sysprobeconfig.Component,
271272
server dogstatsdServer.Component,
@@ -404,7 +405,7 @@ func run(log log.Component,
404405

405406
func getSharedFxOption() fx.Option {
406407
return fx.Options(
407-
flare.Module(flare.NewParams(
408+
flareFx.Module(flaredef.NewParams(
408409
defaultpaths.GetDistPath(),
409410
defaultpaths.PyChecksPath,
410411
defaultpaths.LogFile,
@@ -588,7 +589,7 @@ func getSharedFxOption() fx.Option {
588589
// startAgent Initializes the agent process
589590
func startAgent(
590591
log log.Component,
591-
flare flare.Component,
592+
flare flaredef.Component,
592593
tlm telemetry.Component,
593594
server dogstatsdServer.Component,
594595
wmeta workloadmeta.Component,

cmd/agent/subcommands/run/command_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848
agenttelemetry "github.com/DataDog/datadog-agent/comp/core/agenttelemetry/def"
4949
"github.com/DataDog/datadog-agent/comp/core/autodiscovery"
5050
"github.com/DataDog/datadog-agent/comp/core/config"
51-
"github.com/DataDog/datadog-agent/comp/core/flare"
51+
flaredef "github.com/DataDog/datadog-agent/comp/core/flare/def"
5252
"github.com/DataDog/datadog-agent/comp/core/gui"
5353
"github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface"
5454
ipc "github.com/DataDog/datadog-agent/comp/core/ipc/def"
@@ -106,7 +106,7 @@ func StartAgentWithDefaults(ctxChan <-chan context.Context) (<-chan error, error
106106
err := fxutil.OneShot(func(
107107
log log.Component,
108108
config config.Component,
109-
flare flare.Component,
109+
flare flaredef.Component,
110110
telemetry telemetry.Component,
111111
sysprobeConf sysprobeconfig.Component,
112112
server dogstatsdServer.Component,

cmd/otel-agent/subcommands/flare/command.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ import (
3232
"github.com/DataDog/datadog-agent/cmd/otel-agent/subcommands"
3333
"github.com/DataDog/datadog-agent/comp/core"
3434
"github.com/DataDog/datadog-agent/comp/core/config"
35-
"github.com/DataDog/datadog-agent/comp/core/flare"
36-
"github.com/DataDog/datadog-agent/comp/core/flare/helpers"
35+
flaredef "github.com/DataDog/datadog-agent/comp/core/flare/def"
36+
flareFx "github.com/DataDog/datadog-agent/comp/core/flare/fx"
37+
flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types"
3738
ipcfx "github.com/DataDog/datadog-agent/comp/core/ipc/fx"
3839
log "github.com/DataDog/datadog-agent/comp/core/log/def"
3940
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
@@ -70,7 +71,7 @@ func MakeCommand(globalConfGetter func() *subcommands.GlobalParams) *cobra.Comma
7071
cliParams.GlobalParams = globalParams
7172
cliParams.args = args
7273

73-
flareParams := flare.NewLocalParams(
74+
flareParams := flaredef.NewLocalParams(
7475
"", // distPath - not used for OTel Agent
7576
"", // pyChecksPath - not used for OTel Agent
7677
"", // logFilePath - not used for OTel Agent
@@ -85,7 +86,7 @@ func MakeCommand(globalConfGetter func() *subcommands.GlobalParams) *cobra.Comma
8586
ConfigParams: config.NewAgentParams("", config.WithConfigName(globalParams.ConfigName)),
8687
LogParams: log.ForOneShot(globalParams.LoggerName, "info", false),
8788
}),
88-
flare.Module(flareParams),
89+
flareFx.Module(flareParams),
8990
core.Bundle(),
9091
// Provide empty option for workloadmeta (optional dependency)
9192
fx.Supply(option.None[workloadmeta.Component]()),
@@ -104,7 +105,7 @@ func MakeCommand(globalConfGetter func() *subcommands.GlobalParams) *cobra.Comma
104105
}
105106

106107
func makeFlare(
107-
flareComp flare.Component,
108+
flareComp flaredef.Component,
108109
_ log.Component,
109110
_ config.Component,
110111
cliParams *cliParams,
@@ -150,7 +151,7 @@ func makeFlare(
150151
}
151152

152153
// Upload flare
153-
response, e := flareComp.Send(filePath, caseID, customerEmail, helpers.NewLocalFlareSource())
154+
response, e := flareComp.Send(filePath, caseID, customerEmail, flaretypes.NewLocalFlareSource())
154155
fmt.Println(response)
155156
return e
156157
}

cmd/security-agent/subcommands/flare/command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/DataDog/datadog-agent/comp/core"
1919
"github.com/DataDog/datadog-agent/comp/core/config"
2020
"github.com/DataDog/datadog-agent/comp/core/flare/helpers"
21+
flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types"
2122
ipc "github.com/DataDog/datadog-agent/comp/core/ipc/def"
2223
ipcfx "github.com/DataDog/datadog-agent/comp/core/ipc/fx"
2324
log "github.com/DataDog/datadog-agent/comp/core/log/def"
@@ -117,7 +118,7 @@ func requestFlare(_ log.Component, config config.Component, _ secrets.Component,
117118
}
118119
}
119120

120-
response, e := helpers.SendFlare(config, filePath, params.caseID, params.customerEmail, helpers.NewLocalFlareSource())
121+
response, e := helpers.SendFlare(config, filePath, params.caseID, params.customerEmail, flaretypes.NewLocalFlareSource())
121122
fmt.Println(response)
122123
if e != nil {
123124
return e

cmd/systray/command/command.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
"github.com/DataDog/datadog-agent/comp/core"
2222
"github.com/DataDog/datadog-agent/comp/core/config"
2323
diagnosefx "github.com/DataDog/datadog-agent/comp/core/diagnose/fx"
24-
"github.com/DataDog/datadog-agent/comp/core/flare"
24+
flaredef "github.com/DataDog/datadog-agent/comp/core/flare/def"
25+
flareFx "github.com/DataDog/datadog-agent/comp/core/flare/fx"
2526
"github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl"
2627
ipcfx "github.com/DataDog/datadog-agent/comp/core/ipc/fx"
2728
log "github.com/DataDog/datadog-agent/comp/core/log/def"
@@ -100,7 +101,7 @@ func MakeCommand() *cobra.Command {
100101
core.Bundle(),
101102
hostnameimpl.Module(),
102103
// flare
103-
flare.Module(flare.NewParams(
104+
flareFx.Module(flaredef.NewParams(
104105
defaultpaths.GetDistPath(),
105106
defaultpaths.PyChecksPath,
106107
defaultpaths.LogFile,

comp/core/flare/component.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

comp/core/flare/def/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "def",
5+
srcs = ["component.go"],
6+
importpath = "github.com/DataDog/datadog-agent/comp/core/flare/def",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//comp/core/flare/types",
10+
],
11+
)

comp/core/flare/def/component.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
// Package flare defines the flare component interface and its parameters.
7+
package flare
8+
9+
import (
10+
"time"
11+
12+
"github.com/DataDog/datadog-agent/comp/core/flare/types"
13+
)
14+
15+
// team: agent-configuration
16+
17+
// Component is the component type.
18+
type Component interface {
19+
// Create creates a new flare locally and returns the path to the flare file.
20+
//
21+
// If providerTimeout is 0 or negative, the timeout from the configuration will be used.
22+
Create(pdata types.ProfileData, providerTimeout time.Duration, ipcError error, diagnoseResult []byte) (string, error)
23+
// CreateWithArgs creates a new flare locally and returns the path to the flare file.
24+
// This function is used to create a flare with specific arguments.
25+
CreateWithArgs(flareArgs types.FlareArgs, providerTimeout time.Duration, ipcError error, diagnoseResult []byte) (string, error)
26+
// Send sends a flare archive to Datadog. The local archive is removed after a successful upload unless the component was created with KeepArchiveAfterSend (e.g. CLI --keep-archive).
27+
Send(flarePath string, caseID string, email string, source types.FlareSource) (string, error)
28+
}
29+
30+
// Params defines the parameters for the flare component.
31+
type Params struct {
32+
// local is set to true when we could not contact a running Agent and the flare is created directly from the
33+
// CLI.
34+
Local bool
35+
36+
// KeepArchiveAfterSend when true keeps the local flare archive file after a successful upload (e.g. for CLI --keep-archive).
37+
KeepArchiveAfterSend bool
38+
39+
// DistPath is the fully qualified path to the 'dist' directory
40+
DistPath string
41+
42+
// PythonChecksPath is the path to the python checks shipped with the agent
43+
PythonChecksPath string
44+
45+
// DefaultLogFile the path to the default log file
46+
DefaultLogFile string
47+
48+
// DefaultJMXLogFile the path to the default JMX log file
49+
DefaultJMXLogFile string
50+
51+
// DefaultDogstatsdLogFile the path to the default dogstatsd log file
52+
DefaultDogstatsdLogFile string
53+
54+
// DefaultStreamlogsLogFile the path to the default Streamlogs log file
55+
DefaultStreamlogsLogFile string
56+
}
57+
58+
// NewLocalParams returns parameters to initialize a local flare component. Local flares are meant to be created by
59+
// the CLI process instead of the main Agent one.
60+
func NewLocalParams(distPath string, pythonChecksPath string, defaultLogFile string, defaultJMXLogFile string, defaultDogstatsdLogFile string, defaultStreamlogsLogFile string) Params {
61+
p := NewParams(distPath, pythonChecksPath, defaultLogFile, defaultJMXLogFile, defaultDogstatsdLogFile, defaultStreamlogsLogFile)
62+
p.Local = true
63+
return p
64+
}
65+
66+
// NewParams returns parameters to initialize a non local flare component.
67+
func NewParams(distPath string, pythonChecksPath string, defaultLogFile string, defaultJMXLogFile string, defaultDogstatsdLogFile string, defaultStreamlogsLogFile string) Params {
68+
return Params{
69+
Local: false,
70+
DistPath: distPath,
71+
PythonChecksPath: pythonChecksPath,
72+
DefaultLogFile: defaultLogFile,
73+
DefaultJMXLogFile: defaultJMXLogFile,
74+
DefaultDogstatsdLogFile: defaultDogstatsdLogFile,
75+
DefaultStreamlogsLogFile: defaultStreamlogsLogFile,
76+
}
77+
}

0 commit comments

Comments
 (0)