Add local dictionary support#61
Conversation
cratelyn
left a comment
There was a problem hiding this comment.
😻 This is incredible stuff! Thank you for opening this PR.
I have left assorted comments below; the two high-level points are that we should think about how we deserialize the configuration, and how we assign handles.
| use DictionaryConfigError::UnrecognizedKey; | ||
| static BAD_DEFAULT: &str = r#" | ||
| [dictionaries] | ||
| thing = { name = "thing", file = "./file.json", shrimp = true } |
There was a problem hiding this comment.
ya love to see a real shrimp-:a:ck in the wild
|
Thanks for the thorough review @cratelyn - I've added the I think this is ready for another round of reviewing now 😄 |
Huzzah! I've got the review baton for this next round, and will do that first thing tomorrow morning (Pacific). Thanks again for this work! |
aturon
left a comment
There was a problem hiding this comment.
Thanks again for taking this on! I made a review pass and left a few suggestions.
FWIW, I do think your impulse toward memoization was a good one, though I also agree that hot-reloading is nice. I think loading the file on every get is OK for now, but we should file a follow-up issue to preload dictionary contents and use file-watching to asynchronously reload on changes. That'll be helpful for people using really big dictionary files.
I didn't have a chance to carefully review the updated TOML loading and schema here. I know @cratelyn has thought more about that so I'll pass the baton back over on that one.
Cheers!
|
Thanks for the review @aturon - I have addressed all the issues now and I learnt about "deref coercion" The Dictionary Handles are now created on demand and not reused, to match C@E behaviour 👍 I also spotted some I believe this is ready for another round of reviews 🙂 |
aturon
left a comment
There was a problem hiding this comment.
Thank you, the changes look perfect!
I looked over the TOML deserialization now, and just left one tiny request there. Otherwise, I'm very happy with this PR!
That said, I believe that @cratelyn may have one further though re: the TOML schema (future-facing, thinking about "inline" dictionary definitions), but I'm not sure. I'll pass the baton back over to her to finish this out with you!
| let dictionary_max_len: usize = 1000; | ||
| let dictionary_item_key_max_len: usize = 256; | ||
| let dictionary_item_value_max_len: usize = 8000; |
There was a problem hiding this comment.
Could we pull these out into a dedicated limits.rs file? We're going to want to build more awareness of C@E limits in Viceroy like this, and having them in one place will make life easier for keeping them up to date.
There was a problem hiding this comment.
Done in b75566d (#61) 👍
Should these also go in the fastly-shared crate?
cratelyn
left a comment
There was a problem hiding this comment.
once again, great work! this is looking excellent 😻
i have provided a few more comments, but almost all of these are very minor quibbles. 🙂 this is looking just about complete!
cratelyn
left a comment
There was a problem hiding this comment.
one final comment, about structuring the fastly.toml data in a manner that'll be a bit more future-proof ✨
let me know if this part gives you trouble, i am more than happy to provide some help 👯
This reads a new section from the `local_server` part of fastly.toml named `dictionaries`.
The `local_server.dictionaries` section is an array of tables with two fields: name, and file.
The name field is a string which is used as the name of the dictionary and is used via the Dictionary.open method. This field uses the same validation rules asthe Fastly API (Name must start with alphabetical and contain only alphanumeric, underscore, and whitespace).
The file field is a string which is a file-path pointing to a JSON file which contains all the dictionary items within an object.
An example of a full local_server section of fastly.toml now looks like this:
```toml
[local_server]
[local_server.backends]
[local_server.backends.dog]
url = "http://localhost:7878/dog-mocks"
[local_server.dictionaries]
[local_server.dictionaries.a]
name="a"
file="./a.json"
```
…ame dictionary be faster and avoid re-reading the same file too many times
…s platform Currently the limits are: 1000 items per dictionary 256 characters for dictionary item keys 8000 characters for dictionary item values
This mimics the 'liveness' of edge dictionaries - a user can edit a dictionary file and see the changes immediately without having to restart viceroy
…eld is meant to point to a file
… to read the dictionary file
…gth is too small as this is behaviour that C@E does not do
…nto more idiomatic rust
…instead use `ok_or_else`
…ctionary file is within currently this only supports json, but more formats are planned to be added later on
cratelyn
left a comment
There was a problem hiding this comment.
thank you so much for implementing this @JakeChampion! this is wonderful, wonderful work ✨ ✔️
|
ah! it looks like the ci problems are due to formatting. |
The formatting issues should be fixed now 👍 |
|
Looks like Clippy is unhappy. If you run |
|
|
Looks like there are some dictionary-related test failures on Windows: https://github.com/fastly/Viceroy/pull/61/checks?check_run_id=3355092000 |
|
My best guess of what's happening:
|
|
The TOML spec indicates we should be using
Sidenote, this will be an issue for eventual inline dictionaries. |
|
Thanks for looking into the issue @aturon -- I've pushed a commit to fix this and can confirm that the tests pass on windows now 🎉 -- https://github.com/JakeChampion/Viceroy/runs/3369942476?check_suite_focus=true |
|
Passed CI and merged! 🎉 Thanks for both doing this work, and following through these rounds of review and CI issues. This is an important improvement that will benefit a lot of people! |
Resolves #11
This reads a new section from the
local_serverpart of fastly.toml nameddictionaries.The
local_server.dictionariessection is an array of tables with two fields: name, and file.The name field is a string which is used as the name of the dictionary and is used via the Dictionary.open method. This field uses the same validation rules asthe Fastly API (Name must start with alphabetical and contain only alphanumeric, underscore, and whitespace).
The file field is a string which is a file-path pointing to a JSON file which contains all the dictionary items within an object.
An example of a full local_server section of fastly.toml now looks like this:
Note for reviewers:
I couldn't figure out how the tests are implements for the wiggle abi parts such as
lib/src/wiggle_abi/dictionary_impl.rs. I assume they are implemented in an internal/private repo that Fastly has?local_serversection