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

Validate tljh specific config #962

Merged
merged 27 commits into from
Apr 4, 2024

Conversation

jrdnbradford
Copy link
Contributor

@jrdnbradford jrdnbradford commented Feb 3, 2024

This is a stab at the FIXME in tljh/config.py for adding config.yaml validation. It uses jsonschema to validate the changes against it.

This is a work in progress; I've tried to use the tljh-config docs and configurer.py to fill it out the best I can.

Example of some current validation:

sudo tljh-config set user_environment.default_app jupyterlb
'jupyterlb' is not one of ['jupyterlab', 'classic']

Certainly not perfect, looking for input before I go any further! 🚀 Also trying to get these tests to pass.

@jrdnbradford
Copy link
Contributor Author

Looks like I've got most tests passing now.

@consideRatio consideRatio changed the title Validate config.yaml Validate tljh specific config Mar 18, 2024
@consideRatio consideRatio reopened this Mar 18, 2024
@consideRatio consideRatio added enhancement New feature or request breaking labels Mar 18, 2024
@consideRatio
Copy link
Member

Excellent work @jrdnbradford!

How should this behave if existing TLJH installations upgrade to get this validation? They could have invalid config already in place, and then making an unrelated config change may trigger a validation failure.

I'm not confident on what I think makes sense to do here. If we could, I'd like to error loudly and early on before we have actually upgraded anything. I'm not sure we can do that while making use of this validation logic inside the tljh python package, as then we have already upgraded to use it I figure.

At the same time, maybe not. The config could have been manually edited anyhow, and we should assume someone may have done that also...

@minrk
Copy link
Member

minrk commented Mar 19, 2024

One option to trial this is to have a flag to turn validation warnings into errors or vice versa (e.g. --no-validate for opt-out, or --strict for opt-in).

@jrdnbradford
Copy link
Contributor Author

jrdnbradford commented Mar 20, 2024

@minrk is the suggestion something like this:

  • add --no-validate and --strict flags for tljh-config CLI command
    • --no-validate will be the default and will allow edits that don't validate against the schema, but will print a warning
    • --strict will not allow edits that fail to validate and will exit with an error

Those with invalid configs who update TLJH will start to get warnings when they use tljh-config but won't get any breaking behavior.

We could also do something like:

parser.add_argument("--validate", action = argparse.BooleanOptionalAction)

which should handle --validate and --no-validate in a similar way.

I'm open to whatever you all think is best and will edit and test after feedback,

@minrk
Copy link
Member

minrk commented Mar 20, 2024

--[no-]validate sounds like a good plan (yes, the names should definitely match if we give flags for both ways), thanks @jrdnbradford!

I also think it's just fine to validate by default if that's what others would prefer. I wouldn't call this breaking, because the validation error message should include a message showing how to re-run without validation, along the lines of:

You can still apply this change without validation by re-running with --no-validate (whole copy-pasteable command-line if it's easy).
if you think this validation error is incorrect, please report it to https://github.com/jupyterhub/the-littlest-jupyterhub/issues

@consideRatio
Copy link
Member

consideRatio commented Mar 20, 2024

I agree on the idea to validate by default, so having a flag to opt out of the validation is my preference.

Flag naming decision, here are some ideas:

  • --no-validate
  • --no-validation
  • --no-config-validation
  • --skip-validation
  • --skip-config-validation

I'm leaning for the most verbose flags of either --no-config-validation or --skip-config-validation which clarifies that its about config validation specifically - because one could imagine other kinds of validation be made as well otherwise.

@minrk @jrdnbradford what do you think?

@minrk
Copy link
Member

minrk commented Mar 20, 2024

I like the verb forms, and I think it's best to stick the very standard no- prefix, and not uncommon skip-. So I'd go with --[no-]validate, or if you think it's really likely that we'll have more than one optional thing to validate, --[no-]validate-config.

@jrdnbradford
Copy link
Contributor Author

Got an initial working version using --[no-]validate. The one failed integration test is because Python v3.8 doesn't have the argparse.BooleanOptionalAction option.

I also bumped the Dockerfile image to 22.04.

@jrdnbradford
Copy link
Contributor Author

@consideRatio and @minrk if the failed Python 3.8 test is a blocker, I can rewrite to make it compatible. Let me know!

@minrk
Copy link
Member

minrk commented Apr 2, 2024

Yes, that would be great if you can make it work on 3.8. Thank you!

@jrdnbradford
Copy link
Contributor Author

jrdnbradford commented Apr 3, 2024

@consideRatio and @minrk the Python 3.8 test is now passing after removing argparse.BooleanOptionalAction. I also fixed the two unit tests that were failing (they were just missing pip so they couldn't install dependencies). Not sure if the Integration tests / Ubuntu 22.04, Py 3.10, from 0.2.0 (pull_request) test is still needed now that TLJH is 1.0.0. If not, I'm happy to remove it to get straight ✅ s across the board.

Let me know if I can do anything else here. 🚀

Copy link
Member

@consideRatio consideRatio left a comment

Choose a reason for hiding this comment

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

I think it could be nice to default functions to validate=True, but its a refactoring detail really.

I'm looking into the remaining test failure - which shows up in the main branch as well, so i think we can merge this anyhow.

tljh/config.py Outdated Show resolved Hide resolved
tljh/config.py Outdated Show resolved Hide resolved
tljh/config.py Outdated Show resolved Hide resolved
tljh/config.py Outdated Show resolved Hide resolved
tljh/config.py Outdated Show resolved Hide resolved
.github/workflows/unit-test.yaml Show resolved Hide resolved
integration-tests/test_proxy.py Outdated Show resolved Hide resolved
@consideRatio
Copy link
Member

@jrdnbradford a trick to combine multiple code suggestions is to visit "files changed", from there you can "add suggestion to batch" and add multiple code suggestions in one go.

I'm actively debugging the remaining test failures now btw

@jrdnbradford
Copy link
Contributor Author

@jrdnbradford a trick to combine multiple code suggestions is to visit "files changed", from there you can "add suggestion to batch" and add multiple code suggestions in one go.

I'm actively debugging the remaining test failures now btw

Ah, good tip, sorry for the spam. 😃

@jrdnbradford
Copy link
Contributor Author

Refactoring done. Good to merge when you're ready. Thanks, everyone!

Copy link
Member

@consideRatio consideRatio 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 @jrdnbradford!!!

I find robustifying contributions like these critical for the health of a open source projects - thank you ❤️ 🎉 🌻!!

@consideRatio consideRatio merged commit 7e39e99 into jupyterhub:main Apr 4, 2024
14 of 15 checks passed
@consideRatio consideRatio added new and removed enhancement New feature or request labels Apr 4, 2024
@jrdnbradford jrdnbradford deleted the validate-config-yaml branch April 6, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants