Skip to content

[AGTHEAL-115] refactor(core): migrate comp/core/flare to V2 component architecture - #49769

Draft
louis-cqrl wants to merge 1 commit into
mainfrom
louis-cqrl/refactor-core-flare-to-v2
Draft

[AGTHEAL-115] refactor(core): migrate comp/core/flare to V2 component architecture#49769
louis-cqrl wants to merge 1 commit into
mainfrom
louis-cqrl/refactor-core-flare-to-v2

Conversation

@louis-cqrl

@louis-cqrl louis-cqrl commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fully migrates `comp/core/flare` from the V1 component architecture to V2:

  • `comp/core/flare/def/component.go` — `Component` interface, `Params` struct, `NewParams`/`NewLocalParams` constructors
  • `comp/core/flare/impl/` — full implementation moved from root package: `flareImpl` struct, `NewComponent` constructor, all flare creation/send logic, provider collection
  • `comp/core/flare/fx/fx.go` — uses `fxutil.ProvideComponentConstructor(impl.NewComponent)`
  • `comp/core/flare/mock/` — new V2 mock replacing the old `flareimpl/mock.go`
  • `comp/core/flare/types/` — `FlareSource` moved here from `helpers/` (types package is explicitly designed for "types without implementation dependencies"); all callers updated
  • Deleted all V1 root-level files: `flare.go`, `component.go`, `params.go`, `providers.go`, `flare_test.go`, and the entire `flareimpl/` directory
  • All external callers updated to import from `def/`, `fx/`, and `mock/` directly (no backward-compat shims)

Motivation

Align `comp/core/flare` with the V2 component architecture used across the codebase. This is a complete migration — no V1 relics remain.

Describe how you validated your changes

  • All pre-commit hooks pass (go-fmt, go-linter, go-mod-tidy)
  • Implementation is a direct move of existing logic with only package/naming changes required by the V2 pattern
  • All callers across `cmd/`, `comp/`, and `pkg/` updated to new import paths

Additional Notes

`FlareSource` was moved from `comp/core/flare/helpers` to `comp/core/flare/types` as part of this migration — `types` is the correct home for types that should be usable without pulling in implementation dependencies.

@github-actions github-actions Bot added the medium review PR review might take time label Apr 23, 2026
@github-actions github-actions Bot removed the medium review PR review might take time label Apr 23, 2026
@github-actions github-actions Bot added the long review PR is complex, plan time to review it label Apr 23, 2026
@louis-cqrl louis-cqrl added changelog/no-changelog No changelog entry needed qa/done QA done before merge and regressions are covered by tests labels Apr 24, 2026
@louis-cqrl louis-cqrl changed the title refactor(core): migrate comp/core/flare to V2 component architecture [AGTHEAL-115] refactor(core): migrate comp/core/flare to V2 component architecture Apr 24, 2026
louis-cqrl

This comment was marked as resolved.

louis-cqrl

This comment was marked as resolved.

louis-cqrl

This comment was marked as resolved.

louis-cqrl

This comment was marked as resolved.

@dd-octo-sts dd-octo-sts Bot added stale and removed stale labels May 9, 2026
@louis-cqrl
louis-cqrl force-pushed the louis-cqrl/refactor-core-flare-to-v2 branch 2 times, most recently from 442b4ed to c033c2d Compare May 12, 2026 15:58
@DataDog DataDog deleted a comment from dd-octo-sts Bot May 13, 2026
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1-2 Bot May 13, 2026
@DataDog DataDog deleted a comment from dd-octo-sts Bot May 13, 2026
@DataDog DataDog deleted a comment from cit-pr-commenter-54b7da Bot May 13, 2026
@DataDog DataDog deleted a comment from dd-octo-sts Bot May 13, 2026
@DataDog DataDog deleted a comment from dd-octo-sts Bot May 13, 2026
@louis-cqrl
louis-cqrl requested review from NouhaManai96 and mackjmr and removed request for a team June 8, 2026 12:46
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
@github-actions github-actions Bot deleted a comment from chatgpt-codex-connector Bot Jun 8, 2026
Comment thread cmd/agent/subcommands/flare/command.go Outdated
Comment on lines +138 to +139
fx.Supply(flareParams),
flarfx.Module(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use Supply please ! It divide the init for params into two calls that can be widely apart in different helpers making troubleshooting the init very complicated. The idea of taking the params in the module init is intentional.

Comment thread comp/core/flare/impl/impl_test.go Outdated
fillerModule := fxutil.Component(fillers...)
// testDeps mirrors Requires but embeds fx.In so fxutil.Test can populate it field-by-field.
type testDeps struct {
fx.In

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use FX in the tests. FX should remain contained to the fx* folders.

@louis-cqrl
louis-cqrl force-pushed the louis-cqrl/refactor-core-flare-to-v2 branch from 8892dbb to 0a73cc0 Compare June 9, 2026 09:45
Comment thread comp/core/flare/mock/mock.go Outdated
@@ -15,12 +15,16 @@ import (
"go.uber.org/fx"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mock/ must not import go.uber.org/fx. From the component docs: fx/ must be the only folder importing and referencing Fx. MockModule() and MockProvides{fx.Out ...} belong in fx/, not in mock/. The mock/ folder should only implement flare.Component and expose a plain New(t *testing.T) Provides constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — removed go.uber.org/fx, fxutil, MockModule(), and MockProvides{fx.Out} from mock/mock.go. The mock package now has zero fx dependency.

Comment thread comp/core/flare/mock/mock.go Outdated
}

// MockModule defines the fx options for the mock component.
func MockModule() fxutil.Module {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MockModule() belongs in fx/ (or a fx-mock/ sub-package), not in mock/. The mock/ package should have zero fx dependency.

Also: NewMock() has no *testing.T parameter. The component docs require the standalone constructor to be:

func New(t *testing.T) Provides {
    return Provides{Comp: &MockFlare{}}
}

This lets impl/ tests call flaremock.New(t) directly without going through fx.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — MockModule() removed entirely (no callers). NewMock() renamed to New(t \*testing.T) Provides with a plain Provides struct (no fx.Out). The single caller in agentprofiling_test.go updated to flaremock.New(t).Comp.


api "github.com/DataDog/datadog-agent/comp/api/api/def"
apiutils "github.com/DataDog/datadog-agent/comp/api/api/utils"
"github.com/DataDog/datadog-agent/comp/core/config"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This imports the root comp/core/config package instead of comp/core/config/def.

Per the component import graph rules: impl/ must depend on other components only through their def/ package — never the root package or impl/. Change to:

config "github.com/DataDog/datadog-agent/comp/core/config/def"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged — comp/core/config/def doesn't exist on main yet (it's in a separate pending PR #49787). Added a TODO comment in impl.go to migrate to config/def once that PR is merged. Will update this import then.

Split comp/core/flare into def/impl/mock/fx sub-packages following the V2
component pattern, removing fx.In/fx.Out from impl and exporting Requires/Provides
structs. Update all callers to import from the new sub-packages.
log: deps.Log,
config: deps.Config,
params: deps.Params,
providers: fxutil.GetAndFilterGroup(deps.Providers),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replace the function by an internal helper ?

Comment thread pkg/flare/archive.go
Comment on lines +489 to +503

// Module returns an fxutil.Module that registers the extra flare providers
// (providers not owned by a specific component) into the flare group.
func Module() fxutil.Module {
return fxutil.Component(
fx.Provide(
fx.Annotate(
func(wm option.Option[workloadmeta.Component], ipcComp ipc.Component) []*flaretypes.FlareFiller {
return ExtraFlareProviders(wm, ipcComp)
},
fx.ResultTags(`group:"flare,flatten"`),
),
),
)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using FX within pkg should be avoided. We want to move toward a state where pkg is a bunch of stateless helpers.

Why can't we move this within the flare comp ? This is the legacy part of the flare that will, maybe one day, be migrated by each teams in within their comp.

@nathan-b nathan-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARUN files look clean. I like that you pulled the tests along on this one.

@dd-octo-sts

dd-octo-sts Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the past 15 days.

It will be closed in 30 days if no further activity occurs. If this pull request is still relevant, adding a comment or pushing new commits will keep it open. Also, you can always reopen the pull request if you missed the window.

Thank you for your contributions!

1 similar comment
@dd-octo-sts

dd-octo-sts Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the past 15 days.

It will be closed in 30 days if no further activity occurs. If this pull request is still relevant, adding a comment or pushing new commits will keep it open. Also, you can always reopen the pull request if you missed the window.

Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.