Log the source of every configuration key - #1389
Open
NoiceHax wants to merge 1 commit into
Open
Conversation
get_hierarchical_config only logged which .codecarbon.config files were read, so there was no way to tell which layer had set a given key. It now reads each layer on its own and keeps a key to source map while merging the global file, the local file and the CODECARBON_ environment variables. The two file level messages are replaced by a single line naming the source of every resolved key, with environment variables shown as CODECARBON_<KEY>. Values are never logged, as api_key and experiment_id live in this config space.
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.
Description
get_hierarchical_configonly logged which.codecarbon.configfiles it had read, so there was still no way to tell which layer set a given key. It now reads the global file, the local file and theCODECARBON_environment variables into separate dicts, merges them in the same order as before, and keeps a key to source map next to the result. The two file level messages are replaced by one line naming the source of each resolved key, with environment variables shown asCODECARBON_<KEY>.Only key names and their source are logged, never the values, because
api_keyandexperiment_idlive in this config space.Example output:
Related Issue
Closes #312
Motivation and Context
Config comes from three places that silently override each other. When a value was not what you expected, nothing in the log pointed at the file or the variable responsible. That is what the issue asks for, for example knowing where
experiment_idwas picked up from.How Has This Been Tested?
Two tests added to
tests/test_config.py. The first checks the key to source map for a key set only in the global file, a key overridden by the local file, and a key overridden by an environment variable. The second checks the log line names the sources and does not contain the value ofapi_key.Ran
CODECARBON_ALLOW_MULTIPLE_RUNS=True pytest tests/test_config.py tests/test_resource_tracker.py tests/cli, 114 passed. The full package suite gives 627 passed with one failure intest_task_energy_with_live_update_interference, which fails the same way on master on my machine, so it does not come from this change.Screenshots (if appropriate):
Types of changes
AI Usage Disclosure
I used an AI coding agent to write this patch and this description from an approach I decided on, and I reviewed the code and ran the tests locally before opening the PR.
Checklist: