Skip to content

RFC: RethinkDB plugins #4785

Open
Open

Description

@danielmewes

There are a lot of features that are useful to have in a database which can be implemented on top of existing ReQL constructs. Some of them are not currently available out of the box.

To name a few:

Currently, implementing these features without modifying the server requires deploying and managing a separate application. You have to manage its configuration and state, you have to make sure that it runs on the right servers, you have to deal with application failures and server restarts etc. This can often be inconvenient.

This proposal is a work in progress. Its idea is to provide a "plugin" interface that allows running small extensions directly with the RethinkDB server process (credits to @mlucy who came up with the idea). Plugins can be easily enabled on a given RethinkDB server. They can provide additional ports and APIs to clients (e.g. for GraphQL queries). Their state and configuration will be stored in the RethinkDB cluster, so that it can be automatically synchronized across all servers.

We will develop some plugins ourselves. But we will also make it extremely easy for everyone to write their own plugins.

RethinkDB plugin proposal (RFC / WIP)

Initialization

Many plugins will need a separate setup phase for creating tables, initializing configuration etc.

Rather than trying to do this automatically when a plugin is first enabled (which can be tricky in a clustered environment), I think we should just have a "setup"/"initialization" phase that needs to be triggered manually.

Command line syntax

--setup-plugin <plugin name>
--load-plugin <plugin name>

Some plugins should launch by default (web UI). I suggest we just keep the current --no-http-admin command line option to disable it.

In the long term, we might want to allow starting, stopping etc. plugins without restarting the server. This should probably work through a ReQL admin table. I suggest we don't care about that for now.

State

Plugins shall only keep state in a single database.
All of their configuration shall be stored there.
The database and all required tables shall be created during the setup phase (this is important to avoid race conditions during table creation in a cluster).

We should standardize the naming scheme for the db.
Something like _plugin_<plugin_name>?

The nice thing about having all state in a database is that this allows admins to configure
replication, and to change the plugin configuration and state directly through ReQL (things like
which port a plugin should bind to etc.).

Connectivity

The RethinkDB server provides the required access credentials to the plugin.
Usually this would require passing in the port and the auth key.
I suggest we provide plugins with a Unix domain socket instead, so that we don't have to pass out an auth key (and it will also be more efficient and more secure). The domain socket would not require an auth key to connect.

The path of the domain socket can be passed into the plugin through environment variables.

Monitoring

r.db('rethinkdb).table('server_status') will have a new field 'active_plugins' with an
array of all the running plugins.

Plugins can also write to the server log (see "Process details").

Process details

If a plugin is enabled, we simply launch a node.js instance with the right environment variables.
If it terminates, we print a log message and try restarting it after a certain time (30 seconds?).
Any line the process prints to stdout is forwarded to the rethinkdb log as "LOG_INF" entries. stderr is forwarded as "LOG_ERR" entries.

I suggest we ignore sandboxing and limiting permissions for the first revision. In the longer term, we might want to set process limits and put them in a chroot among others.

An open question is packaging. We can either bundle our own node.js server with RethinkDB, or rely on the system's one. The latter option might be preferable because it simplifies keeping node.js up to date. The downside is that some plugins might not work on all systems in case there are any incompatibilities between different node.js releases.

File structure

I think a plugin should just be a folder in a specific path (e.g. /usr/lib/rethinkdb/plugins/<plugin name>). The folder has to contain at least two files:
run.js and setup.js

For the web UI, we might want to do something special so we don't add new file dependencies (i.e. we might want to keep compiling it into the RethinkDB binary).

Activity

  1. added this to the subsequent milestone on Sep 2, 2015
  2. deontologician commented on Sep 2, 2015

    @deontologician
    Contributor

    Linking to #3861 the standalone webui issue

  3. marshall007 commented on Sep 3, 2015

    @marshall007
    Contributor

    This is very similar to how plugins are implemented in ElasticSearch. ElasticSearch has the concept of "Site Plugins" whereby the contents of a plugin's _site directory are served at /_plugins/<plugin_name>. Is something like this what you have in mind for the Web UI and similar plugins?

    If so, does this imply that connections over HTTP in the JS driver will need to be supported in some official capacity? There's been discussions around dropping that stuff entirely, but such plugins will need some way to execute arbitrary queries.

  4. danielmewes commented on Sep 3, 2015

    @danielmewes
    MemberAuthor

    I haven't looked into ElasticSearch site plugins, but they sound superficially similar.

    If so, does this imply that connections over HTTP in the JS driver will need to be supported in some official capacity?

    Since the plugins will run in a node.js container, they can use the regular JavaScript driver without a need for HTTP connections.
    The browser-side part of the web UI will still need to connect to the plugin somehow though, which might require keeping the current HTTP ReQL connection logic in place for a bit longer.
    What we can do with the plugins is remove the HTTP endpoint in the (C++) server. Instead the web UI plugin would receive the queries from the browser via HTTP, and would convert them into regular TCP-based ReQL requests before forwarding them to the server.

  5. deontologician commented on Sep 3, 2015

    @deontologician
    Contributor

    This is more similar to ElasticSearch rivers. The main difficulty they had with rivers, and why they're deprecating them, is that it gets into the hairy business of the database becoming a process supervisor for code with varying levels of quality. If the river you installed was buggy, suddenly your database was unreliable.

    Their little more in-depth discussion is at https://www.elastic.co/blog/deprecating-rivers . It's possible that we can avoid some of the issues they ran into by carefully handling process isolation

  6. deontologician commented on Sep 3, 2015

    @deontologician
    Contributor

    I should mention that rivers actually dynamically load code into the database itself, so it was much more tightly coupled than what @danielmewes is proposing here.

  7. marshall007 commented on Sep 3, 2015

    @marshall007
    Contributor

    @danielmewes @deontologician I think you should be able to write plugins that only consist of client-side HTML and JS. What you just suggested would require each plugin to create their own backend mechanism to evaluate queries from the browser. I think whatever the Web UI uses should be exposed for any plugin to use.

  8. marshall007 commented on Sep 3, 2015

    @marshall007
    Contributor

    @danielmewes to be clear, I think what you're saying about removing support for HTTP connections from the server makes sense to do. I just think that instead of having the Web UI plugin expose an endpoint for itself, the server (or another plugin) should expose an endpoint that the Web UI and any other plugins can use.

    Also, changefeeds would still need to be considered. An endpoint that parses and evaluates a plain-text query still wouldn't do you much good here.

  9. mlucy commented on Sep 8, 2015

    @mlucy
    Member

    The nice thing about having all state in a database is that this allows admins to configure
    replication, and to change the plugin configuration and state directly through ReQL (things like
    which port a plugin should bind to etc.).

    I'm not 100% sure plugin state should live in a table. You can get into weird situations that way. Say, for example, you add a plugin while your cluster is one node, then later you grow it to a 16 node cluster. Unless we automatically reconfigure the plugin tables when we add nodes, which we probably shouldn't because of availability loss, the plugin is now dependent on one of your 16 servers being up, and if that server goes down then the plugin stops working even if the rest of the cluster is healthy. The only way around this is to make users responsible for reconfiguring their plugin tables when they change their cluster, which is kind of a pain.

    I guess it depends on what sort of data plugins are storing. If they're storing gigabytes of user data, a table is clearly the appropriate place for that, but if they're storing a few kilobytes of configuration data then maybe something else is appropriate.

    Also, some plugins (like the web UI) might want purely local data storage so they keep working even if disconnected from the rest of the cluster.

    Maybe this is too complicated for the first version, though, and we should only support storing plugin data in tables at first?

    I suggest we provide plugins with a Unix domain socket instead

    This seems unnecessarily complicated to me. I think that if we just pass the plugins the port to connect on and the auth key that would be easier (we wouldn't have to add anything new to the server besides the ability to launch the plugin). That would also making porting to windows easier (unless they have an equivalent of Unix domain sockets, in which case ignore this point).


    Some of the intended plugins (document expiration, triggers) seem like they would run on only one machine rather than on every machine in the cluster. Should we just leave it up to users to pick which machines plugins are launched on by editing their command-line options, or are we going to be starting and stopping plugins in a centralized way?

  10. mlucy commented on Sep 8, 2015

    @mlucy
    Member

    If the river you installed was buggy, suddenly your database was unreliable.

    We can definitely make this better with resource limits for plugins, but I do think that plugins present a general problem that people will install a buggy plugin and then assume RethinkDB is buggy. (And nobody likes being kicked back and forth between the repo for a plugin and the repo for the main program when they have a bug report.)

    Still, I think it's worth the cost. We should consider having a way to endorse plugins that we think are stable so that people know what they're getting into.

  11. danielmewes commented on Sep 23, 2015

    @danielmewes
    MemberAuthor

    @marshall007 That sounds like a great idea. I think the web UI plugin would essentially have that functionality. In fact all the specific queries it's running are already encoded in the browser-side JS code, not in the backend.
    We could probably make it a library of some sort, so that you can very easily create plugins where you only need to provide the static HTML + browser JS code, without writing any additional code for the backend.

    @mlucy

    I'm not 100% sure plugin state should live in a table. You can get into weird situations that way. Say, for example, you add a plugin while your cluster is one node, then later you grow it to a 16 node cluster. Unless we automatically reconfigure the plugin tables when we add nodes, which we probably shouldn't because of availability loss, the plugin is now dependent on one of your 16 servers being up, and if that server goes down then the plugin stops working even if the rest of the cluster is healthy.

    I thought about that too. I couldn't really come up with a great solution. I think for the moment it would be ok if we left reconfiguring the plugin tables to the administrator. Note that adding and removing replicas doesn't impair availability though (with the exception of currently running queries and changefeeds being interrupted). Additionally, many plugins could probably use outdated reads to make sure that the plugin remains available as long as at least one replica is still around.

    Overall I think storing all configuration and plugin state into a table makes for a nicer user experience.

    1. You can represent both per-server as well as global state conveniently. If a certain configuration option is per server, the plugin can use one document (or field or whatever) per server.
    2. It allows modifying and querying the plugin configuration through ReQL. I think this is a very powerful argument in favor of this solution, because it fits well with our system table approach to cluster management.
    3. The configuration can be easily replicated, using the existing replica machinery.

    I agree that it probably depends a bit on the use case. The main scenario I had in mind was the GraphQL library.

    Configuration options would include:

    • the port to bind to, and maybe the interfaces to bind to (we could just take those from RethinkDB's server config though). The interfaces would need to be a per-server option, but the port in the simplest case could be cluster-wide.
    • the GraphQL schema. This should clearly be a cluster-wide setting
    • authentication and permission data. This also clearly needs to be a cluster-wide setting

    Especially for the latter two, being able to modify those settings through normal ReQL queries would be extremely useful I think. And we don't need to worry about providing a special API for configuration changes.

    My impression is that relying on tables as the only mean for storing state and configuration will be the best way to get us started. Once we have more experience about what plugins need, we can add additional storage options or add better abstractions around the tables. We can also think about how to automatically replica the state tables to additional servers then.

    This seems unnecessarily complicated to me. I think that if we just pass the plugins the port to connect on and the auth key that would be easier (we wouldn't have to add anything new to the server besides the ability to launch the plugin). That would also making porting to windows easier (unless they have an equivalent of Unix domain sockets, in which case ignore this point).

    Fair enough. I think that might be ok, though it feels less clean to me (especially the fact that we need to expose the auth key to plugins). We could make this an optional feature, depending on how much time we'll end up having left.
    I'm not sure about what Windows offers in this respect ( @AtnNn ?).

    Some of the intended plugins (document expiration, triggers) seem like they would run on only one machine rather than on every machine in the cluster. Should we just leave it up to users to pick which machines plugins are launched on by editing their command-line options, or are we going to be starting and stopping plugins in a centralized way?

    I think for the first version, it's enough if you have to explicitly enable a plugin on a given server by providing a command line option. Long-term we should probably make that more convenient and handle the different cases you mentioned.

  12. marshall007 commented on Sep 23, 2015

    @marshall007
    Contributor

    @danielmewes perfect! We have a lot of internal tools where I'd like to be able to allow users to execute (almost) arbitrary queries from the browser. With the client-side JS library and supporting endpoint, all I'd have to do is handle authentication in a proxy. This would also just be great for prototyping single-page apps before you write a backend.

    ... being able to modify those settings through normal ReQL queries would be extremely useful I think. And we don't need to worry about providing a special API for configuration changes.

    I agree with this. It means you could easily write plugins that "interact" with other plugins through ReQL. This way the Web UI (or a third-party) could manage plugins and their configuration. Another nice side affect is that plugin configuration and data could be backed up and restored.

  13. marshall007 commented on Sep 25, 2015

    @marshall007
    Contributor

    Will plugins be able to (optionally) defer the handling of requests? I can think of a couple scenarios where this would be useful.

    Authentication

    Rather than baking authentication into each plugin, it would be a lot nicer if that functionality were split out for reuse. Furthermore, since the authentication piece is pretty critical, it's not really something you want each plugin author implementing themselves.

    You could imagine "official" plugins that implement various authentication schemes like rethinkdb-oauth and rethinkdb-http-basic which could be configured to intercept and authenticate all or some subset of requests before deferring response handling to the intended receiver plugin.

    Logging

    You might want to intercept requests in order to generate a query log or track performance metrics.

  14. danielmewes commented on Sep 25, 2015

    @danielmewes
    MemberAuthor

    @marshall007 I had thought about these things too.
    I'm not sure how this is going to pan out in detail yet, but I imagine that we'll build a library of useful components over time, that you can use easily in your own plugins.

    Authentication and logging are definitely examples of things that should be re-usable.

    This can be done almost independently of how plugins are handled on the server side, since those libraries are going to exist in the form of node.js libraries that each plugin can just import. I agree that we should try to provide as many of those out of the box as possible over time. Partially because it makes writing plugins easier, and partially because it makes different plugins more consistent.

  15. 1 remaining item

  16. coffeemug commented on Oct 7, 2015

    @coffeemug
    Contributor

    @danielmewes asked me to comment on the proposal.

    I think we should adopt the following high level design goals for the first implementation:

    • Do the minimum possible amount of work (but no less) to support the WebUI and GraphQL as plugins. We should shoot to get a v1 plugin implementation in a month or so.
    • Don't get mired in various complexities. We can evolve and extend the system later on as the demands become more clear.
    • Build as much as we can on top of existing, commonly used infrastructure (i.e. npm)

    Here is some more specific feedback on a couple of key issues:

    • Don't worry about centralized/clustered plugin installs or turning plugins on/off at runtime for now. Let the setup/startup phase happen on per-server basis (tl;dr: I agree with Daniel's proposal wrt this).
    • I wouldn't do domain sockets for v1. I agree with @mlucy's comment -- we should just give the plugin what it needs to connect (either give it the host/port/auth key, or ideally just pass it a connection object we set up for it).
    • I think for installation, upgrades, etc. we should shell out to npm. Essentially our commands would be porcelain over npm. I think we should do it for two reasons. Firstly, they already do a great job with version management, and we don't want to write our own. Secondly, plugins will depend on many libraries, and npm already manages dependencies really well.
    • I'm not 100% sure whether we should bundle node with RethinkDB, or rely on the host. The problem with relying on the host is that when users first install RethinkDB, they'll need to install node for the WebUI to work, which would be a terrible user experience (we can make node a dependency on linux/brew, but probably not on OSX via a dmg unless we bundle it). Also, the plugins that ship out of the box might break on the user's version of node. I'm leaning toward shipping our own version of node, but allowing the user to point RethinkDB to the version on the host if they want to go that route.
    • 👍 for adding active_plugins field to r.db('rethinkdb).table('server_status').
    • I think for v1 we shouldn't prescribe where the plugins will store the data. We can't enforce this until we ship a permission system anyway, and by then we'll have a much better idea of the tradeoffs. The WebUI plugin won't need to store any data anyway, and for GraphQL we'll figure out where to store relevant configuration data as we develop it (it may be a file, or it may be a table; I think v1 plugin infrastructure should have nothing to say about that, and we'll develop the first pass at a convention in the GraphQL plugin).

    Command line args for plugins

    I think we should maintain our existing command line args for the webui, and I think we can make it generic. During startup each plugin will tell rethinkdb whether it's on or off by default, and how to turn it off. So the webui will say it's on by default, and you turn it off via --no-http-admin. GraphQL will tell rethinkdb it's off by default, and you turn it on via --graphql. Each plugin will also expose a set of command line args it accepts (e.g. for port management).

    I'm not entirely sure how to integrate port offsets into this, but it should be possible (e.g. the plugin can tell rethinkdb that a particular command line arg it wants is a port, and port offset will be added to all of those).

    Command line API

    I think we should avoid the name plugins (that's so 90s) and call them extensions. I propose the following CLI API (slightly different from Daniel's proposal; I think mine is better 😁):

    # install an extension (via an npm package)
    $ rethinkdb extend --install rdb-falcor
    
    # install a non-extension
    $ rethinkdb extend --install random-node-package
    ERROR: not a RethinkDB extension
    
    # list installed extensions
    $ rethinkdb extend --list
    rdb-graphql
    rdb-falcor
    rdb-admin-ui
    
    # Help for the command
    $ rethinkdb extend --help
    PRINTS HELP HERE
    
    # Help for the plugin
    $ rethinkdb extend --help rdb-admin-ui
    PRINTS HELP GENERATED BY EXTENSION HERE
    
    # Remove a extension
    $ rethinkdb extend --remove rdb-admin-ui
    
    # Turn extensions on/off on startup (note, no `extend`)
    $ rethinkdb --no-http-admin --graphql
    

    How's this lookin'?

  17. danielcompton commented on Oct 7, 2015

    @danielcompton
    Contributor

    Just to clarify, extensions (at least in the first version) will only be able to be written in JavaScript?

  18. danielmewes commented on Oct 7, 2015

    @danielmewes
    MemberAuthor
  19. marshall007 commented on Oct 7, 2015

    @marshall007
    Contributor

    Instead of cramming everything under the rethinkdb command, the package management stuff could itself be published as an npm package. I think this would have several advantages:

    1. Reduce complexity/scope of the rethinkdb command.
    2. CLI could be a more direct wrapper around npm, so extension developers and users already familiar with npms arguments wouldn't have to learn anything new.
    3. Have a sweet name like rpm or rem (ReM).
    4. Bug-fixes to the package manager could be shipped/installed independently of core.

    This is what Atom did for their package manager (atom/apm) and it's pretty nice, IMO.

  20. coffeemug commented on Oct 7, 2015

    @coffeemug
    Contributor

    @marshall007 -- that sounds like a good idea and is probably easier to do. 👍

  21. mlucy commented on Oct 8, 2015

    @mlucy
    Member

    I think you should be able to type rethinkdb <SOMETHING> to install and manage extensions, personally. That's what I would expect to be able to do, and it's consistent with existing extension-like-things like rethinkdb export.

    I don't particularly like rethinkdb extend as a prefix because rethinkdb extend --list reads weirdly, and it isn't clear what you're doing. I also don't like using --X to specify X where X is an action -- flags should be used for turning options on and off, and actions should be specified as plain words. (For example, it's git commit -a, not git --commit -a. The action is a word and the option is a flag. Same thing for apt-get install -- it's not apt-get --install.

    How about rethinkdb extension list, rethinkdb extension install, rethinkdb extension remove, etc?

  22. deontologician commented on Oct 8, 2015

    @deontologician
    Contributor

    I feel like "extension" isn't a good name. We aren't really extending the server so much as providing a built-in process monitor. While "plugin" isn't perfect, it's closer I think. I'd expect something called an extension to add new ReQL terms or artificial tables with special behavior maybe.

  23. mlucy commented on Oct 8, 2015

    @mlucy
    Member

    I think "extension" is a reasonable name because we're probably going to support a lot more things later, and we'd rather not have to change the name. "plugin" is probably fine too, though.

  24. dalanmiller commented on Oct 8, 2015

    @dalanmiller
    Contributor

    I disagree with this structure in particular:

    #Turn plugins on/off on startup (note, no extend)
    $ rethinkdb --no-http-admin --graphql

    I think that you should be able to do as @mlucy says and list all currently installed plugins with rethinkdb plugins list which will display a list of plugins that are activated or deactivated. It's awkward to add -no- to the plugin flag to signify that this plugin should not be loaded.

    Name Version Active
    graphql 0.1.5 [X]
    falcor 0.9 [ ]
    api 0.1 [X]
    ^ note it's hard to get the spacing right in Markdown

    One can activate or deactivate plugins, if everything went okay no response is given in proper GNU tool format.

    $ rethinkdb plugins activate graphql
    $ rethinkdb plugins deactivate graphql
    $

    If you'd like to start RethinkDB for debugging purposes with a specific set of plugins, you should also be able to pass an explicit list. RethinkDB will only use these plugins in this instance:

    $ rethinkdb --plugins graphql,falcor

  25. coffeemug commented on Oct 8, 2015

    @coffeemug
    Contributor

    I also don't like using --X to specify X where X is an action

    Note that this is a cultural thing. I don't necessarily disagree, but that was modelled after npm, and that's how npm does it (and also to some degree pip).

    We aren't really extending the server so much as providing a built-in process monitor.

    I think that's a little narrow -- it's true about v1, but there are much bigger things we can (and will) do with this system in the future.

    It's awkward to add -no- to the plugin flag to signify that this plugin should not be loaded.

    That makes sense, but the intention here was to be compatible with the existing flag to turn off the webui. I think I agree with the sentiment in general, though, and wouldn't mind breaking compatibility for this flag (since the new thing will be much more structured and will make more sense).

    rethinkdb plugins activate graphql

    I think for the graphql demo we really want a one-liner (which I realize is a little bit neurotic, but I do think saying "get graphql in one line" is better than giving a two line/command example). Another problem is that saying rethinkdb plugin activate/deactivate is tricky because I might have multiple instances of RethinkDB on my server, and it's not clear which server that applies to.

  26. deontologician commented on Oct 8, 2015

    @deontologician
    Contributor

    What about "pluglets" ? Imagine:

    "Did you get the new GraphQL pluglet?"
    "Oh yeah, it's great. I query all my graphs with it. I heard there was a falcor pluglet too."
    "Yeah, all my apps use pluglets"

  27. coffeemug commented on Oct 8, 2015

    @coffeemug
    Contributor

    "Actually, I wrote my app as a pluglet" 🍶

  28. dalanmiller commented on Oct 8, 2015

    @dalanmiller
    Contributor

    All I can think of when I hear that => 💻 🐷

  29. webmasterkai commented on Oct 8, 2015

    @webmasterkai

    More name ideas if plugin doesn't cut it: module, hinge, attachment, component, mixin, peripheral, add-on, xtra, child, method, middleware.

  30. dalanmiller commented on Oct 9, 2015

    @dalanmiller
    Contributor

    rethinkdb plugins activate graphql
    I think for the graphql demo we really want a one-liner (which I realize is a little bit neurotic, but I do think saying "get graphql in one line" is better than giving a two line/command example). Another problem is that saying rethinkdb plugin activate/deactivate is tricky because I might have multiple instances of RethinkDB on my server, and it's not clear which server that applies to.

    I guess this functionality will depend on whether or not the architecture will allow adding plugins to a RethinkDB instance that is already in flight / running. Otherwise, I'd say for specific toggle switching of plugins, you'll need to pass either the driver port or the cluster port explicitly of the instance you are reconfiguring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions