-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
By hashing the config values and files, only restart services on differences #31
Open
addyess
wants to merge
5
commits into
main
Choose a base branch
from
akd/config-hashing-speedup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a97748f
By hashing the config values and files, only restart services when co…
addyess 5c7fe83
Confirm changes to a config file produce different has values
addyess 39d841e
check file existence with Path.is_file
addyess 768eb06
improved set operations
addyess c1ebc5e
enable/disable cache calculation feature with env var
addyess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,6 +478,12 @@ def configure_scheduler(extra_args_config, kubeconfig): | |
) | ||
|
||
|
||
def _enable_config_hashing() -> bool: | ||
"""This is a debug option to enable config hashing.""" | ||
env = os.environ.get("JUJU_FEATURE_KUBERNETES_SNAP_CONFIG_HASHING") or "" | ||
return env.lower() == "on" | ||
|
||
|
||
def _sha256_file(config_file: str) -> hashlib.sha256: | ||
h = hashlib.sha256() | ||
h.update(config_file.encode()) | ||
|
@@ -510,6 +516,13 @@ def _dict_compare(d1, d2): | |
def _calculate_config_difference(service: str, args, config_files): | ||
args_hash = _snap_common_path(service) / "args-hash.txt" | ||
|
||
if not _enable_config_hashing(): | ||
log.debug("Config hashing disabled, skipping config change detection") | ||
yield True | ||
args_hash.unlink(missing_ok=True) | ||
return | ||
Comment on lines
+519
to
+523
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if hashing isn't enabled, this method declares there are changes, and we should reconfigure the service (as before this feature existed) and it also clears the cache file if one exists. |
||
|
||
log.debug("Checking for config changes for %s", service) | ||
# gather existing config hash | ||
current, updated = {}, {} | ||
if Path.is_file(args_hash): | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows the charm at runtime (per hook even!!!) decide whether or not it wants to enable hashing.
Now an upgrade action could restart the service even if there aren't any config changes. We could even expose via charm config (though i think that'd be going too far).