Commit Graph

14 Commits

Author SHA1 Message Date
Torin Sandall d41ebeaab3 Makefile: Future proof the wasm runtime flag
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-12-03 12:28:10 -05:00
Patrick East 2ed8dde180 internal/wasm/sdk: Refactor Pool and VM to be exported
This refactors the vm and pool into separate internal packages, with
the required bits exported that we need for the `opa` package and the
various test packages.

This allows for more easily writing tests in separate packages which
can avoid import cycles, as well as (arguably) simplifying the `opa`
package which should be the main thing any usage of the "sdk" would
be interacting with.

While refactoring I moved the loaders, errors, and some shared code
out into their own packages as well. The new tree looks like:

```
internal/wasm/sdk
├─ internal
│  └─ wasm
│     ├─ bindings.go
│     ├─ pool.go
│     ├─ pool_test.go
│     ├─ util.go
│     └─ vm.go
└─ opa
   ├─ config.go
   ├─ errors
   │  └─ errors.go
   ├─ loader
   │  ├─ file
   │  │  ├─ config.go
   │  │  ├─ loader.go
   │  │  └─ loader_test.go
   │  ├─ http
   │  │  ├─ config.go
   │  │  ├─ loader.go
   │  │  ├─ loader_test.go
   │  │  └─ util.go
   │  └─ loader.go
   ├─ opa.go
   └─ opa_test.go
```

Where essentially everything under `opa` is public, with the
top level `opa` package being the main one, sub packages being
shared code or additional helpers.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-17 13:51:43 -08:00
Patrick East 9a73f1903b build: New flag for wasmer dependencies
We would previously gate building the wasm resolver (and in turn pull
in the wasmer stuff) based on whether or not cgo was enabled. However
for library use-cases this isn't ideal as someone might be using cgo
for an unrelated reason, and not wish to enabled the wasmer code in
opa.

There is now a new go tag for the files called "opa_wasmer" and a
makefile flag WASMER_ENABLED (default on) which will trigger it. This
means any libraries building OPA that want to have it enabled will
need to specify this tag with like `-tags=opa_wasmer ` or similar when
building.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-09 14:14:11 -05:00
Patrick East d85482115f internal/wasm/sdk: Improved vm data cloning
Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Patrick East 76f232c523 internal/wasm/sdk: Support for Set in input/output
Instead of round tripping through JSON we use the newer value parse
and dump helpers along with the value stringer and ast term parser
to round preserve the rego typing.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Patrick East af85ba6093 internal/wasm/sdk: Adjust metric names and placement
The naming is adjusted to be more inline with other OPA metrics, and
the timers are cleaned up to remove redundancies and consolidate
some portions. A new one for the VM pool release step is added too.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Patrick East 197c8387f7 wasm: Add metrics for wasm resolver evaluations
This plumbs through metrics to the wasm evaluation, adding several
new timers. They will show up when using a Wasm bundle with any of the
usual evaluation mechanisms (eg opa eval, bench, server requests etc)

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Torin Sandall f71dc2b209 resolver: Refactor wasmer dependency to be conditional
This commit updates the resolver package to make the wasmer dependency
conditional at build-time. If CGO is enabled then the wasmer
dependency will be included. If CGO is not enabled, the wasmer
dependency will be excluded and the OPA binary will not be able to run
wasm-compiled policies. This allows us to continue building statically
linked OPA executables that can be distributed and used.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-11-06 15:12:38 -05:00
Patrick East 332c686c50 wasm: Update resolver usage for multiple entrypoints
The wasm binaries support >1 entrypoint per module, this makes changes
to reflect that in the various data structures we keep references to
the modules and resolvers, mapping them to entrypoints.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Patrick East 748fd418c9 internal/wasm/sdk: Support multiple entrypoints
This updates the SDK to support retrieving and specifying an
entrypoint when evaluating with the OPA Wasm modules.

The examples have been updated to use the newer APIs, as well as
expanded to include instructions to generate the binaries from source
as opposed to keeping them in the repo.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Patrick East d938546dbd resolver/wasm: Swap to using in-tree SDK
Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Patrick East f84f4674a1 Add support for evaluating Wasm bundles
This is largely plumbing changes required to get Wasm modules loaded
from bundles and configured as external resolvers for evaluations.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Torin Sandall 506ad39c39 Initial wasm resolver
Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00
Torin Sandall d1c2173ca2 Add external resolvers API
This allows for resolving refs outside of the topdown eval or store.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-11-06 15:12:38 -05:00