Skip to content
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

[health-check] Refactor the config usage #9662

Open
wants to merge 4 commits into
base: health-check-skeleton
Choose a base branch
from

Conversation

m-czernek
Copy link
Contributor

What does this PR change?

In this PR, I'm refactoring the config usage in the health check tool such that:

  • We use .toml conf file instead of .ini file
  • Callers don't have to instantiate the config object to parse properties
  • Code doesn't have to pass around config objects to parse properties

NOTE This is a PR into a feature branch, not the main branch.

Changelogs

Make sure the changelogs entries you are adding are compliant with https://github.com/uyuni-project/uyuni/wiki/Contributing#changelogs and https://github.com/uyuni-project/uyuni/wiki/Contributing#uyuni-projectuyuni-repository

If you don't need a changelog check, please mark this checkbox:

  • No changelog needed

If you uncheck the checkbox after the PR is created, you will need to re-run changelog_test (see below)

Re-run a test

If you need to re-run a test, please mark the related checkbox, it will be unchecked automatically once it has re-run:

  • Re-run test "changelog_test"
  • Re-run test "backend_unittests_pgsql"
  • Re-run test "java_pgsql_tests"
  • Re-run test "schema_migration_test_pgsql"
  • Re-run test "susemanager_unittests"
  • Re-run test "javascript_lint"
  • Re-run test "spacecmd_unittests"

Before you merge

Check How to branch and merge properly!

@m-czernek m-czernek requested a review from a team as a code owner January 22, 2025 09:58
@m-czernek m-czernek requested review from agraul and removed request for a team January 22, 2025 09:58
Copy link
Member

@agraul agraul left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, looks good! We're moving towards https://www.youtube.com/watch?v=1__lNTlj1_w and I like it 😄

I left a few questions and suggestions inline.

health-check/src/uyuni_health_check/main.py Outdated Show resolved Hide resolved
health-check/src/uyuni_health_check/config.py Outdated Show resolved Hide resolved
health-check/src/uyuni_health_check/config.py Outdated Show resolved Hide resolved
health-check/src/uyuni_health_check/config.py Outdated Show resolved Hide resolved
health-check/src/uyuni_health_check/config.py Show resolved Hide resolved
Comment on lines +34 to +35
except (AttributeError, ValueError):
res = None
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to turn access errors into None? This might silence errors caused by bad callers (or bad configs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you'd prefer we let the caller deal with the error in case it asks for non-existent value? In my mind, when you ask a config for a non-existent prop, the correct behavior is to return a non-existent value (i.e. None).

Copy link
Member

Choose a reason for hiding this comment

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

The caller always needs to deal with the case that it asks for something from the config that can't be found (load_prop(x) returns None).

The question is: do we force the caller to deal with it by raising an exception or are we okay with the caller ignoring that? Both ways are okay, but since we don't have any config validation, it might make sense to not silence lookup errors (e.g. because the config is incomplete and mandatory values are missing) at runtime

return jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATES_DIR))

@functools.lru_cache
def parse_config() -> Dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

So if I get it right, the idea is not to load the config once and then pass around the config object (which is in fact, nicer) but to allow the parsing function to be called every time needed and speed it up by caching the returned values, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants