fnenv

package
v0.0.0-...-98ba599 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fnenv provides interfaces to consistently communicate with 'function runtime environments' (fnenvs).

A fnenv is a component responsible for (part of) the execution of the tasks/functions, it commonly consists out of at least the following implemented interfaces: - resolver: resolves function references in workflow definitions to deterministic function IDs of the fnenv. - Runtime: executes a function in the fnenv given the task spec and returns the output.

The fnenv package avoids a single, huge interface, which would make new implementations constrained and expensive, by splitting up the functionality into small (optional) interfaces. There is no required combination of interfaces that a fnenv needs to implement, although a resolver and Runtime are considered the basic interfaces.

A fnenv could implement additional interfaces which would allow the workflow engine to improve the execution. For example, by implementing the Preparer interface, the workflow engine will notify the fnenv ahead of time of the incoming function request.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRuntime = errors.New("invalid runtime")

	FnActive = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: "workflows",
		Subsystem: "fnenv",
		Name:      "functions_active",
		Help:      "Number of Fission function executions that are currently active",
	}, []string{"fnenv"})

	FnCount = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: "fnenv",
		Subsystem: "fission",
		Name:      "functions_execution_total",
		Help:      "Total number of Fission function executions",
	}, []string{"fnenv"})

	FnExecTime = prometheus.NewSummaryVec(prometheus.SummaryOpts{
		Namespace: "fnenv",
		Subsystem: "fission",
		Name:      "function_execution_time_milliseconds",
		Help:      "Execution time summary of the Fission functions",
	}, []string{"fnenv"})
)

Functions

func ResolveTask

func ResolveTask(ps Resolver, tasks ...*types.TaskSpec) (map[string]*types.FnRef, error)

ResolveTask resolved the interpreted workflow from a given spec.

It returns a map consisting of the original functionRef as the key.

func ResolveTasks

func ResolveTasks(ps Resolver, tasks map[string]*types.TaskSpec) (map[string]*types.FnRef, error)

ResolveTask resolved all the tasks in the provided workflow spec.

In case there are no functions resolved, an empty slice is returned.

Types

type AsyncRuntime

type AsyncRuntime interface {
	// InvokeAsync invokes a function in the runtime based on the spec and returns an identifier to allow the caller
	// to reference the invocation.
	InvokeAsync(spec *types.TaskInvocationSpec, opts ...InvokeOption) (asyncID string, err error)

	// Cancel cancels a function invocation using the function invocation id.
	Cancel(asyncID string) error

	// Status fetches the status of a invocation.
	//
	// The interface user is responsible for determining whether the status indicates that a invocation has completed.
	Status(asyncID string) (*types.TaskInvocationStatus, error)
}

AsyncRuntime is a more extended interface that a runtime can optionally support. It allows for asynchronous invocations, allowing with progress tracking and invocation cancellations.

type InvokeConfig

type InvokeConfig struct {
	Ctx           context.Context
	AwaitWorkflow time.Duration
}

func ParseInvokeOptions

func ParseInvokeOptions(opts []InvokeOption) *InvokeConfig

type InvokeOption

type InvokeOption func(config *InvokeConfig)

func AwaitWorkflow

func AwaitWorkflow(timeout time.Duration) InvokeOption

func WithContext

func WithContext(ctx context.Context) InvokeOption

type MetaResolver

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

MetaResolver contacts function execution runtime clients to resolve the function definitions to concrete function ids.

ParseTask definitions (See types/TaskDef) can contain the following function reference: - `<name>` : the function is currently resolved to one of the clients - `<client>:<name>` : forces the client that the function needs to be resolved to.

Future:

  • Instead of resolving just to one client, resolve function for all clients, and apply a priority or policy for scheduling (overhead vs. load)

func NewMetaResolver

func NewMetaResolver(client map[string]RuntimeResolver) *MetaResolver

func (*MetaResolver) Resolve

func (ps *MetaResolver) Resolve(targetFn string) (types.FnRef, error)

type Preparer

type Preparer interface {
	// Prepare signals that a function invocation is expected at a specific point in time.
	//
	// expectedAt time should be in the future. Any time in the past is interpreted as
	// a signal that the function invocation will come (almost) immediately. fnId is an optional
	// identifier for the signal, which the implementation can use this to identify signals.
	// By default, if fnId is empty, it is not possible to later update the notification.
	Prepare(fn types.FnRef, expectedAt time.Time) error
}

Preparer allows signalling of a future function invocation.

This allows implementations to prepare for those invocations; performing the necessary resource provisioning or setup.

type Resolver

type Resolver interface {
	// ResolveTask resolved an ambiguous target function name to a unique identifier of a function
	//
	// If the targetFn does not exist an error will be displayed
	Resolve(targetFn string) (types.FnRef, error)
}

Resolver resolves a reference to a function to a deterministic, unique function id.

type Runtime

type Runtime interface {
	// Invoke executes the task in a blocking way.
	//
	// spec contains the complete configuration needed for the execution.
	// It returns the TaskInvocationStatus with a completed (FINISHED, FAILED, ABORTED) status.
	// An error is returned only when error occurs outside of the runtime's control.
	Invoke(spec *types.TaskInvocationSpec, opts ...InvokeOption) (*types.TaskInvocationStatus, error)
}

Runtime is the minimal interface that a function runtime environment needs to conform with to handle tasks.

type RuntimeResolver

type RuntimeResolver interface {
	// ResolveTask resolved an ambiguous target function name to a unique identifier of a function within the scope
	// of a runtime.
	Resolve(ref types.FnRef) (string, error)
}

RuntimeResolver is the runtime environment component that resolves a reference to a function to a deterministic, runtime-specific function UID.

Directories

Path Synopsis
Package mock contains a minimal, mocked implementation of a fnenv for test purposes
Package mock contains a minimal, mocked implementation of a fnenv for test purposes
Note: package is called 'native' because 'internal' is not an allowed package name.
Note: package is called 'native' because 'internal' is not an allowed package name.
package workflows exposes the workflow engine itself as a function environment to improve recursion.
package workflows exposes the workflow engine itself as a function environment to improve recursion.

Jump to

Keyboard shortcuts

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