deislabs / hippo

The WebAssembly Platform
https://docs.hippofactory.dev
Other
415 stars 38 forks source link

Implement app bindings/service broker registration #298

Open bacongobbler opened 2 years ago

bacongobbler commented 2 years ago

Service Brokers

A service broker is a wrapper to common web services for centralized service creation (known as provisioning). It can work with common on-premise services such as a local PostgreSQL database, or with external software such as Amazon RDS for PostgreSQL.

Service brokers provide commands such as:

Administrators no longer have to manually provision and delegate access to services. Instead, they simply configure a "marketplace" of services and service plans available to users. From there, developers can self-serve, reducing the administrative overhead. Billing information can be generated so that the administrators know how much each team (or app) is spending on services.

Implementation

An administrator can manage all of the service brokers registered with Hippo. They can view the brokers that are connected to the Hippo through the AdminController, which requires that you have been granted the "Administrator" role to access.

(images pulled from https://www.openservicebrokerapi.org/)

To help illustrate the point...

image

In this image, Hippo's administration portal would be where the administrator "adds it to your CF Marketplace".

Once registered, service brokers are made available to developers as App Bindings (explained below).

App Bindings

Bindings declare how services connect to a function when invoked. For example, a function may wish to read tables from a database, or schedule jobs on a message queue.

Bindings let application developers avoid hard-coding connection information directly in their apps, following 12 factor best practices.

Developers interact with these services through the Hippo CLI:

$ hippo create myapp
$ hippo channels add development
$ hippo addons list
| Name                  | Plan   |
+-----------------------|--------+
| mysql                 | free   |
| postgresql            | free   |
| amazon-rds-postgresql | small  |
| amazon-rds-postgresql | medium |
| amazon-rds-postgresql | large  |

Users can add new "addons" to their apps using the hippo addons add command.

$ hippo addons add amazon-rds-postgresql --plan small
Adding amazon-rds-postgresql:small to myapp:development... done
Use `hippo addons docs amazon-rds-postgresql --plan small` to view the documentation

Provisioning an add-on will tell the host runtime to expose certain hostcalls to the webassembly runtime (in the meantime, this will be up to the host runtime). e.g. with hostcalls:

fn main() {
    let database = postgresql();
    let output = database.query("SELECT * FROM Applications;")?;
    ...
}

Once outbound HTTP support is made available to WASI, environment variables are made available during the function's execution which can be used to establish connections. Applications can then use their own standard libraries to interact with these services. e.g.

fn main() {
    let database = postgresql::connect(env::from("POSTGRESQL_URL"));
    let rows = database.from("Applications").select("*")?;
    ...
}

Removing an add-on is as easy as adding it:

$ hippo addons remove amazon-rds-postgresql
Removing amazon-rds-postgresql:small from myapp:development... done

Users can also switch plans by going up or down tiers. The service broker will handle the service migration to the new tier and update billing appropriately.

$ hippo addons update amazon-rds-postgresql --plan medium
Updating amazon-rds-postgresql for myapp:development... done
You are now being billed for this addon at $0.06/hour

Users can view an addon's management portal by using hippo addons dashboard (opens a new browser tab).

$ hippo addons dashboard amazon-rds-postgresql
Opening amazon-rds-postgresql for myapp... done

Documentation about the addon can be provided with the hippo addons docs command (opens a new browser tab).

$ hippo addons docs amazon-rds-postgresql
Opening documentation on amazon-rds-postgresql for myapp... done

Rough sketch of an architecture diagram:

+-------------+  hippo addons add mysql --plan=free        +--------+
|             |--------------------------------------------| Client |
|  Hippo      |  POST /addons { name: mysql, plan: free }  +--------+
|             |  RETURN { status: 200 }
+-------------+
      |
      |                CREATE DATABASE 746017aa; GRANT USER ...;
      |                                          |
      | POST / { plan: free }                    |
      | RETURN { status: 200, creds: {...} }     |
      |            |                             |
      |            |           192.168.0.2       |      192.168.0.3:3306
      |            |        +---------------+    |      +---------------+
      |            V        |               |    V      |               |
      +---------------------|    Gateway    |-----------|   MySQL       |
      |                     |               |           |               |
      |                     +---------------+           +---------------+
      |                        192.168.0.4              192.168.0.3:5432
      |                     +---------------+           +---------------+
      |                     |               |           |               |
      +---------------------|    Gateway    |-----------|   PostgreSQL  |
      |                     |               |           |               |
      |                     +---------------+           +---------------+
      |                        192.168.0.5              https://aws.amazon.com/
      |                     +---------------+           +---------------+
      |                     |               |           |               |
      +---------------------|    Gateway    |-----------|   Amazon RDS  |
                            |               |           |               |
                            +---------------+           +---------------+
itowlson commented 2 years ago

We should be sure to leverage lessons from other cloud service broker projects such as OSBA - they found this space harder than it looks and it would be good to have the benefit of their experience of where the problems were.