wasm

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool maintains a pool of WebAssemly VM instances.

func NewPool

func NewPool(poolSize, memoryMinPages, memoryMaxPages uint32) *Pool

NewPool constructs a new pool with the pool and VM configuration provided.

func (*Pool) Acquire

func (p *Pool) Acquire(ctx context.Context, metrics metrics.Metrics) (*VM, error)

Acquire obtains a VM from the pool, waiting if all VMms are in use and building one as necessary. Returns either ErrNotReady or ErrInternal if an error.

func (*Pool) Close

func (p *Pool) Close()

Close waits for all the evaluations to finish and then releases the VMs.

func (*Pool) ParsedData

func (p *Pool) ParsedData() (int32, []byte)

ParsedData returns a reference to the pools parsed external data used to initialize new VM's.

func (*Pool) Policy

func (p *Pool) Policy() []byte

Policy returns the raw policy Wasm module used by VM's in the pool

func (*Pool) Release

func (p *Pool) Release(vm *VM, metrics metrics.Metrics)

Release releases the VM back to the pool.

func (*Pool) RemoveDataPath

func (p *Pool) RemoveDataPath(ctx context.Context, path []string) error

RemoveDataPath will update the current data on the VMs by removing the value at the specified path. If an error occurs the instance is still in a valid state, however the data will not have been modified.

func (*Pool) SetDataPath

func (p *Pool) SetDataPath(ctx context.Context, path []string, value interface{}) error

SetDataPath will update the current data on the VMs by setting the value at the specified path. If an error occurs the instance is still in a valid state, however the data will not have been modified.

func (*Pool) SetPolicyData

func (p *Pool) SetPolicyData(ctx context.Context, policy []byte, data []byte) error

SetPolicyData re-initializes the vms within the pool with the new policy and data. The re-initialization takes place atomically: all new vms are constructed in advance before touching the pool. Returns either ErrNotReady, ErrInvalidPolicy or ErrInternal if an error occurs.

func (*Pool) Size

func (p *Pool) Size() int

Size returns the current number of VM's in the pool

func (*Pool) Wait

func (p *Pool) Wait(i int) *VM

Wait steals the i'th VM instance. The VM has to be released afterwards.

type VM

type VM struct {
	// contains filtered or unexported fields
}

VM is a wrapper around a Wasm VM instance

func (*VM) Entrypoints

func (i *VM) Entrypoints() map[string]int32

Entrypoints returns a mapping of entrypoint name to ID for use by Eval().

func (*VM) Eval

func (i *VM) Eval(ctx context.Context,
	entrypoint int32,
	input *interface{},
	metrics metrics.Metrics,
	seed io.Reader,
	ns time.Time,
	iqbCache cache.InterQueryCache,
	ndbCache builtins.NDBCache,
	ph print.Hook,
	capabilities *ast.Capabilities) ([]byte, error)

Eval performs an evaluation of the specified entrypoint, with any provided input, and returns the resulting value dumped to a string.

func (*VM) Println

func (i *VM) Println(arg int32)

Println is invoked if the policy WASM code calls opa_println().

func (*VM) RemoveDataPath

func (i *VM) RemoveDataPath(ctx context.Context, path []string) error

RemoveDataPath will update the current data on the VM by removing the value at the specified path. If an error occurs the instance is still in a valid state, however the data will not have been modified.

func (*VM) SetDataPath

func (i *VM) SetDataPath(ctx context.Context, path []string, value interface{}) error

SetDataPath will update the current data on the VM by setting the value at the specified path. If an error occurs the instance is still in a valid state, however the data will not have been modified.

func (*VM) SetPolicyData

func (i *VM) SetPolicyData(ctx context.Context, opts vmOpts) error

SetPolicyData Will either update the VM's data or, if the policy changed, re-initialize the VM.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL