[9.3] (backport #12128) Refactor mage target configuration#12836
Open
mergify[bot] wants to merge 1 commit into9.3from
Open
[9.3] (backport #12128) Refactor mage target configuration#12836mergify[bot] wants to merge 1 commit into9.3from
mergify[bot] wants to merge 1 commit into9.3from
Conversation
* 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)
3 tasks
Contributor
|
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
Contributor
Author
|
This pull request has not been merged yet. Could you please review and merge it @swiatekm? 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Setenvto pass configuration, and only callsos.Getenvwhen 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 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/fragmentsusing the changelog tool[ ] I have added an integration test or an E2E testHow 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).