Skip to content

Refactor mage target configuration#12128

Open
swiatekm wants to merge 19 commits intomainfrom
chore/mage-config
Open

Refactor mage target configuration#12128
swiatekm wants to merge 19 commits intomainfrom
chore/mage-config

Conversation

@swiatekm
Copy link
Contributor

@swiatekm swiatekm commented Jan 7, 2026

What does this PR do?

Introduces a configuration struct holding all the configuration for mage targets. This configuration can be read once at the mage target level from environment variables and files, and then passed around. As a result, our local tooling code never calls os.Setenv to pass configuration, and only calls os.Getenv when loading the configuration.

The only place where this becomes problematic is with mage targets setting other mage targets as dependencies, but wanting to modify configuration for them. We deal with this by making all mage targets take a context parameter, and attaching the configuration to the context. Then, each mage target can try to read the configuration from context or environment, modify it, and pass it down to its dependencies.

It's worth noting that this change does not eliminate all global config from dev-tools, nor does it make all the config handling nice and clear. I'd like to address some of the remaining problems in follow-ups, here I erred on the side of making the PR reviewable.

Why is it important?

Configuring the local tooling is a mess, with environment variables being read and set all over the place. As a result, it's hard to understand how a given target behaves, and hard to test them. This is the first major step towards making this code more maintainable.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added an entry in ./changelog/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test

How to test this PR locally

Use the mage targets. :) The ones involving packaging are affected most.

Related issues

@mergify
Copy link
Contributor

mergify bot commented Jan 7, 2026

This pull request does not have a backport label. Could you fix it @swiatekm? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@swiatekm swiatekm added skip-changelog backport-active-all Automated backport with mergify to all the active branches labels Jan 7, 2026
@mergify
Copy link
Contributor

mergify bot commented Jan 8, 2026

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b chore/mage-config upstream/chore/mage-config
git merge upstream/main
git push upstream chore/mage-config

@swiatekm swiatekm force-pushed the chore/mage-config branch 2 times, most recently from 9f2ba9e to 7652b26 Compare January 8, 2026 15:15
@swiatekm swiatekm added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Jan 8, 2026
@swiatekm swiatekm force-pushed the chore/mage-config branch 3 times, most recently from 9832e34 to efdadd0 Compare January 20, 2026 11:17
@mergify
Copy link
Contributor

mergify bot commented Jan 21, 2026

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b chore/mage-config upstream/chore/mage-config
git merge upstream/main
git push upstream chore/mage-config

@mergify
Copy link
Contributor

mergify bot commented Jan 28, 2026

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b chore/mage-config upstream/chore/mage-config
git merge upstream/main
git push upstream chore/mage-config

@swiatekm swiatekm added the chore Tasks that just need to be done, they are neither bug, nor enhancements label Feb 10, 2026
@swiatekm swiatekm marked this pull request as ready for review February 10, 2026 15:07
@swiatekm swiatekm requested a review from a team as a code owner February 10, 2026 15:07
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@swiatekm swiatekm marked this pull request as draft February 10, 2026 16:17
@swiatekm swiatekm marked this pull request as ready for review February 10, 2026 18:23
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

cc @swiatekm

stateDir := filepath.Join(tmpdir, "state")
err := os.MkdirAll(stateDir, 0755)
require.NoError(t, err)
set, err := mage.LoadSettings()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could we please call this settings so it doesn't sound like a function that's doing some setting work?

@swiatekm swiatekm requested a review from ycombinator February 16, 2026 12:05
fmt.Sprintf("root@localhost:%s", r.destDir),
}
cmd := exec.Command("rsync", args...)
cmd := exec.CommandContext(context.TODO(), "rsync", args...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a plan to replace the TODO or should we just use Background?

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

Labels

backport-active-all Automated backport with mergify to all the active branches chore Tasks that just need to be done, they are neither bug, nor enhancements skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants