-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Schema library for new platform: Joi vs @kbn/schema? #18818
Comments
We don't have to provide a comprehensive generic schema library on our own. We can choose to expose certain third party dependencies to plugins directly, if we feel those dependencies are valuable, stable, and not worth implementing ourselves. With a public plugin API though, we'll need to keep those dependencies locked on their major version throughout our major version. This is no different than Elasticsearch exposing log4j, for example. That said, we need far more control over our config validations than we get by relying on semver declarations of a third party plugin. At the moment, we make no distinction between generic schema validation and our config schemas, which is a little strange. For example, it may be appropriate for a generic schema library to support twenty different ways to specify a date, but it doesn't make as much sense for date values in kibana.yml to support twenty different formats. We may not even want plugins to have control over what date format(s) they support in their configuration in order to keep the overall kibana.yml consistent. So I see our config schema as a subset of the overall generic schema capabilities we have at our disposal, even though right now they are one in the same. For that reason, I don't think option 2 is the right move here. Schema validation is a tricky business, and if we can avoid getting bogged down in it, we'll probably be happier. Instead, we should probably adopt a library like joi internally and then work on limiting the feature set through a config-specific facade. |
I agree with @epixa, but it sounds like he's suggesting we go for option 3, not 2, which is what I think I'd prefer. Basically, expose methods for configuring It still feels like a lot of work to define the new interface and document it completely, but it's almost certainly work worth doing. |
Thanks for the input @epixa and @spalger! Could you please clarify a few points for me?
By internally you mean within something like
Does
I'm not sure I get the idea exactly, can you provide a quick example (exposing from where to where)?
I'm not scared :) But do you think this new interface will differ drastically from the schema-related stuff we have already in new platform? |
I vote 3. |
I think I get what Court is saying, so I can clarify too
I think he means inside of
For now we're talking about just config, right? If it makes sense to group things together here, like route validation, then fine. I think we should start with what we need for config schema.
The end user doesn't have to care about what version of Enabling ad hoc extensions is also possible because we're not tied to the particular things |
Thanks @archanid! Okay, it seems I confused you this time, sorry for that. I'm probably being too picky about wording, but better safe than sorry 🙈 So everything what @archanid is saying is already implied by proposed solution №3 and I'm glad we're on the same page, but that's exactly the source of my confusion:
|
I didn't mention option 3 explicitly because while it's close to what I'm proposing, it's not quite the same thing. At the moment, I didn't mention this part specifically, but we also need some sort of schema system for route validation, but does it need to be a public package at all? Route configuration happens during the lifecycle of plugins, so why not just expose the validation interface directly from that service? The config service validation stuff happens before the lifecycle begins (before If at some point we decided that we did want to expose a generic schema library to plugins for some other purposes (note, not as an end-user facing feature, just a generic library), we don't have to write it ourselves, and we don't even need to maintain a facade necessarily. We could choose to expose Joi as a supported dependency and lock its major version to ours. But let's not bother with that now because it's not even clear if we need a common, generic schema library. |
Yeah, the language I used is weird but that was my expectation as well.
By this I just meant that we can enable features like what you linked to here. Again, I think we're on the same page. |
Okay, great, thank you all. I believe I have enough info to move forward with the solution for config schema validation in new platform. We'll see how it goes. |
Handled in #19556 |
I tried to go through all places in Kibana where we use
Joi
to see what features we rely on exactly and compared them to the feature set provided by@kbn/schema
(currently@kbn/utils
). Here is the summary:Joi
features that we use, but currently aren't supported by@kbn/schema
@kbn/schema
correctly$dev
,$buildSha
etc.) - it's just a set of key/value pairs that are provided at run-time and can be used by any schema validator within the tree. The concept is easy to implement.string.insensitive
- easy to implementstring.guid
- may take some time to implement properlystring.uri
- may take some time to implement properlystring.hostname
- may take some time to implement properlynumber.integer
- easy to implementdate
- may take some time to implement properlydate.iso
- one-liner regex, easy to implementarray.single
- easy to implementobject.unknown
- easy to implementobject.pattern
- easy to implement, but very weird thing...any.notes
,any.allow
andany.func
- all are easy to implementJoi
doesn't haveDuration
orByteSize
validators out of the box like@kbn/schema
has, but it'd be straightforward to add them viaJoi.extend
. What I don't like inJoi
is a huuuuuge API surface and absence of a way to define custom validator functions right in the schema without going throughJoi.extend
unless I missed that (example from new platform).So right now I can think of three ways to move forward:
Joi
in new platform and get rid of@kbn/schema
- it will require some time, but not much. The major downside is that we'll haveJoi
in our "public" interface with its entire huge API@kbn/schema
and implement missing features one by one, only when particular feature blocks someone from migrating to new platform. The major downside is amount of required "reinvent-the-wheel" work@kbn/schema
, but rely onJoi
under the hood. With this we'll still have power ofJoi
but won't spend too much time replicating it in@kbn/schema
and will have full control over our public API without exposingJoi
there. The major downside I see here is kind of weird undecided temporal solution for schema management.@elastic/kibana-platform and @epixa please vote or offer alternative solution :) Let me know if there is not enough data for you to decide, I'll try get more.
The text was updated successfully, but these errors were encountered: