Skip to content

Comments

[9.3] (backport #12128) Refactor mage target configuration#12836

Open
mergify[bot] wants to merge 1 commit into9.3from
mergify/bp/9.3/pr-12128
Open

[9.3] (backport #12128) Refactor mage target configuration#12836
mergify[bot] wants to merge 1 commit into9.3from
mergify/bp/9.3/pr-12128

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Feb 18, 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


This is an automatic backport of pull request #12128 done by [Mergify](https://mergify.com).

* Add config struct for mage

* Don't use env variables to pass config

# Conflicts:
#	dev-tools/mage/settings.go

# Conflicts:
#	dev-tools/mage/packageversion.go

* remove global config

* Fix linter warnings

* Rename some functions back to their original names

* Remove remaining calls to os.Getenv

* Additional cleanups

* Move and rename the new config struct

* Add unit tests for the new config loading

* Fix mage target name

* Drop remaining usages of MustLoadSettings

* Refactor integration tester configuration

* Stop settings tests from loading from env

* Drop unused envOr

* Adjust osqueryd strip targets

* Drop unnecessary line

* Rename npcapImageSelector

* Rename variable

(cherry picked from commit 1a8a5f5)
@mergify mergify bot requested a review from a team as a code owner February 18, 2026 16:30
@mergify mergify bot requested review from blakerouse and swiatekm and removed request for a team February 18, 2026 16:30
@mergify mergify bot added the backport label Feb 18, 2026
@mergify mergify bot mentioned this pull request Feb 18, 2026
3 tasks
@github-actions github-actions bot added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team skip-changelog chore Tasks that just need to be done, they are neither bug, nor enhancements labels Feb 18, 2026
@elasticmachine
Copy link
Contributor

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

@mergify
Copy link
Contributor Author

mergify bot commented Feb 23, 2026

This pull request has not been merged yet. Could you please review and merge it @swiatekm? 🙏

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

Labels

backport 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.

2 participants