-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Systematic validation of Synapse's config #12651
Comments
Thoughts: jsonschema, pydantic. Other options? |
We tend to use jsonschema for the config already. See also, the synapse/synapse/config/_util.py Lines 22 to 40 in 4b965c8
|
I am not sure if this also related: |
Maybe we just need more schemas for the config subsections then? (I see 42 matches for With that said: for fuller annotations, we'd have to manually maintain a type in the schema and a type in the config class itself. (That's the only reason I mention pydantic.) |
Yes, my vision here was that we would add more jsonschema validation over time, and that we should make sure new config sections at least have validation. Ultimately we might be able to join up the bits of jsonschema into a single big schema.
I had a bit of a go at automatic validation when I wrote the parser for the One of the problems is that there is often a bit of pre-parsing between reading the YAML and storing it in the Config class. That's not necessarily a barrier to doing things differently, though. I wouldn't be averse to switching to pydantic if it
If you're interested in pursuing pydantic, it might be worth trying an alternative implementation for |
I'm giving this a go on https://github.com/matrix-org/synapse/tree/dmr/oidc-config-pydantic in spare moments. There's some investigation to be done though. pydantic/pydantic#4087 for starters! |
It would be nice if it was possible to validate the syntax of config file without running synapse (and possibly without having access to the network, database, certificates etc). It allows to validate config before restarting synapse and possibly having it not restart because of a typo. It would also allow config validation at "build time" before deployment for example on NixOS. Random examples of prior work: nginx has a similar possibility but it insists in reading all certificates so you can't do the syntax check on another machine pre-deployment. |
https://github.com/matrix-org/synapse/blob/44ac98422ce242d2ca7b383a33274fb4f47b980b/synapse/config/oidc2.py is a first pass at this. There are plenty of TODOs and it's a bit more verbose than I'd've liked. Maybe it's enough to see if people like the syntax. On error messages: I've been checking that the model behaves as I expect it to here: https://github.com/matrix-org/synapse/blob/44ac98422ce242d2ca7b383a33274fb4f47b980b/tests/config/test_oidc2.py . I'd like to tweak that test case so that it can be invoked in a way which will print out all |
@symphorien: it's not well documented, but you can:
(or equivalent under poetry), which does exactly that. Nevertheless we should replace it with a "check mode" for synapse itself (and the worker apps) |
I'd love to see something does all of our config key checking and typechecking at startup time. Ideally this would give us useful type annotations which could flow through the rest of the program; but I think we should optimise for something which produces good error messages for the server owner.
The text was updated successfully, but these errors were encountered: