Documentation
¶
Index ¶
- Constants
- Variables
- type API
- type ConfigProvider
- type EventBus
- type Handler
- func (h *Handler) API() *API
- func (h *Handler) Addr() string
- func (h *Handler) ExtractOperation(*echo.Context) string
- func (h *Handler) ExtractResource(*echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) IngressAddr() string
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) CreateFunction(in *functionspb.CreateFunctionRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) DeleteFunction(in *functionspb.DeleteFunctionRequest) (*longrunningpb.Operation, error)
- func (b *InMemoryBackend) Drain()
- func (b *InMemoryBackend) GenerateDownloadURL(in *functionspb.GenerateDownloadUrlRequest) (*functionspb.GenerateDownloadUrlResponse, error)
- func (b *InMemoryBackend) GenerateUploadURL(in *functionspb.GenerateUploadUrlRequest) (*functionspb.GenerateUploadUrlResponse, error)
- func (b *InMemoryBackend) GetFunction(name string) (*functionspb.Function, error)
- func (b *InMemoryBackend) IngressHandler() http.Handler
- func (b *InMemoryBackend) ListFunctions(in *functionspb.ListFunctionsRequest) ([]*functionspb.Function, string, error)
- func (b *InMemoryBackend) ListRuntimes(in *functionspb.ListRuntimesRequest) (*functionspb.ListRuntimesResponse, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetEventBus(e EventBus)
- func (b *InMemoryBackend) SetIngressPort(p int)
- func (b *InMemoryBackend) SetLogSink(sink gcpserve.LogSink)
- func (b *InMemoryBackend) SetObjectReader(o ObjectReader)
- func (b *InMemoryBackend) SetOnClose(fn func())
- func (b *InMemoryBackend) SetPortPool(p PortPool)
- func (b *InMemoryBackend) SetRunContext(ctx context.Context)
- func (b *InMemoryBackend) SetRuntime(fn func() (Runner, error))
- func (b *InMemoryBackend) SetStartupTimeout(d time.Duration)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) UpdateFunction(in *functionspb.UpdateFunctionRequest) (*longrunningpb.Operation, error)
- type InvokeRequest
- type InvokeResult
- type ObjectReader
- type PortPool
- type Provider
- type Runner
- type Settings
Constants ¶
const ( // DefaultPort is the dedicated gRPC listener's default TCP port. DefaultPort = 8128 // DefaultIngressPort is the default TCP port of the HTTP listener that fronts deployed functions. DefaultIngressPort = 8129 // EngineAuto runs functions in the container runtime when one is reachable. EngineAuto = "auto" // EngineNone never starts containers: functions deploy but invocations return 503. EngineNone = "none" // DefaultStartupTimeout bounds how long a function container may take to accept connections. DefaultStartupTimeout = 5 * time.Minute )
const (
// EventTypePubSub is the only event type the emulator delivers.
EventTypePubSub = "google.cloud.pubsub.topic.v1.messagePublished"
)
Variables ¶
var ErrNilAppContext = errors.New("gcpfunctions: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
Functions functionspb.FunctionServiceServer
// contains filtered or unexported fields
}
API exposes the Functions server for in-process callers (dashboard proxy).
func (*API) Invoke ¶
func (a *API) Invoke(ctx context.Context, name string, in InvokeRequest) (*InvokeResult, error)
Invoke calls the function's HTTP endpoint in-process.
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPFunctionsSettings() Settings
}
ConfigProvider extracts Cloud Functions configuration from the AppContext Config.
type EventBus ¶
type EventBus interface {
GetTopic(name string) (*pubsubpb.Topic, error)
CreateSubscription(in *pubsubpb.Subscription) (*pubsubpb.Subscription, error)
DeleteSubscription(name string) error
}
EventBus is the Pub/Sub surface event-triggered functions subscribe through.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
// Port is the gRPC port; IngressPort the HTTP ingress port. Zero binds an ephemeral port, negative disables ingress.
Port int
IngressPort int
// contains filtered or unexported fields
}
Handler serves the Cloud Functions API (v2) on a dedicated gRPC listener and an HTTP ingress for functions.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override the ports from Settings.
func (*Handler) ExtractOperation ¶
ExtractOperation is unused: requests never reach the shared router.
func (*Handler) ExtractResource ¶
ExtractResource is unused: requests never reach the shared router.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported gRPC methods.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns a 404 handler; the real API is gRPC on the dedicated port.
func (*Handler) IngressAddr ¶
IngressAddr returns the bound ingress address, or "" when ingress is off.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: Cloud Functions runs on its own listeners.
func (*Handler) Shutdown ¶
Shutdown stops both listeners, aborts running workloads and removes their containers.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend holds all Cloud Functions state under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend with no container runtime.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close stops all containers and releases idle connections.
func (*InMemoryBackend) CreateFunction ¶
func (b *InMemoryBackend) CreateFunction(in *functionspb.CreateFunctionRequest) (*longrunningpb.Operation, error)
CreateFunction stores a function and deploys it in the background.
func (*InMemoryBackend) DeleteFunction ¶
func (b *InMemoryBackend) DeleteFunction(in *functionspb.DeleteFunctionRequest) (*longrunningpb.Operation, error)
DeleteFunction removes a function, its container and its trigger subscription in the background.
func (*InMemoryBackend) Drain ¶
func (b *InMemoryBackend) Drain()
Drain blocks until every background deployment has finished.
func (*InMemoryBackend) GenerateDownloadURL ¶
func (b *InMemoryBackend) GenerateDownloadURL(in *functionspb.GenerateDownloadUrlRequest) ( *functionspb.GenerateDownloadUrlResponse, error, )
GenerateDownloadURL returns a URL serving the deployed source archive of a function.
func (*InMemoryBackend) GenerateUploadURL ¶
func (b *InMemoryBackend) GenerateUploadURL(in *functionspb.GenerateUploadUrlRequest) ( *functionspb.GenerateUploadUrlResponse, error, )
GenerateUploadURL issues a one-shot upload slot in the location's source bucket.
func (*InMemoryBackend) GetFunction ¶
func (b *InMemoryBackend) GetFunction(name string) (*functionspb.Function, error)
GetFunction returns a function.
func (*InMemoryBackend) IngressHandler ¶
func (b *InMemoryBackend) IngressHandler() http.Handler
IngressHandler serves <function>-<hash>-<region>.localhost invocations plus the reserved /_gcf/ endpoints (source upload and download, Pub/Sub push delivery).
func (*InMemoryBackend) ListFunctions ¶
func (b *InMemoryBackend) ListFunctions(in *functionspb.ListFunctionsRequest) ([]*functionspb.Function, string, error)
ListFunctions lists functions under a location, or every location with "-".
func (*InMemoryBackend) ListRuntimes ¶
func (b *InMemoryBackend) ListRuntimes(in *functionspb.ListRuntimesRequest) (*functionspb.ListRuntimesResponse, error)
ListRuntimes lists the runtimes the emulator can run.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset stops every function and clears all state.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot. Deployments in flight at snapshot time fail, and containers start again on first use.
func (*InMemoryBackend) SetEventBus ¶
func (b *InMemoryBackend) SetEventBus(e EventBus)
SetEventBus wires the Pub/Sub emulator that event triggers subscribe through.
func (*InMemoryBackend) SetIngressPort ¶
func (b *InMemoryBackend) SetIngressPort(p int)
SetIngressPort records the bound ingress port used to build URLs.
func (*InMemoryBackend) SetLogSink ¶
func (b *InMemoryBackend) SetLogSink(sink gcpserve.LogSink)
SetLogSink wires Cloud Logging: container output and invocations are written to sink; nil disables it. Only the 2nd-gen environment exists here, so entries use the cloud_run_revision resource.
func (*InMemoryBackend) SetObjectReader ¶
func (b *InMemoryBackend) SetObjectReader(o ObjectReader)
SetObjectReader wires the object store that storage_source archives are read from.
func (*InMemoryBackend) SetOnClose ¶
func (b *InMemoryBackend) SetOnClose(fn func())
SetOnClose registers a hook run by Close after every container is stopped.
func (*InMemoryBackend) SetPortPool ¶
func (b *InMemoryBackend) SetPortPool(p PortPool)
SetPortPool wires the host port source for published function containers.
func (*InMemoryBackend) SetRunContext ¶
func (b *InMemoryBackend) SetRunContext(ctx context.Context)
SetRunContext sets the context containers run under; cancel it to abort starts in flight.
func (*InMemoryBackend) SetRuntime ¶
func (b *InMemoryBackend) SetRuntime(fn func() (Runner, error))
SetRuntime wires the container runtime source; nil disables functions.
func (*InMemoryBackend) SetStartupTimeout ¶
func (b *InMemoryBackend) SetStartupTimeout(d time.Duration)
SetStartupTimeout bounds how long a function container may take to accept connections.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises all functions and sources; containers are not part of it.
func (*InMemoryBackend) UpdateFunction ¶
func (b *InMemoryBackend) UpdateFunction(in *functionspb.UpdateFunctionRequest) (*longrunningpb.Operation, error)
UpdateFunction applies the masked fields and redeploys in the background.
type InvokeRequest ¶
InvokeRequest is an HTTP call made to a function through the ingress.
type InvokeResult ¶
InvokeResult is the function's HTTP response; Body is capped at 1 MiB.
type ObjectReader ¶
ObjectReader reads source archives from an object store (the GCS emulator).
type Provider ¶
type Provider struct{}
Provider implements service.Provider for Google Cloud Functions. It serves gRPC on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the ports are bound in StartWorker.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 208-byte string literal not displayed */
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 226-byte string literal not displayed */
IngressPort int `` //nolint:lll // config struct tags are intentionally verbose
/* 286-byte string literal not displayed */
StartupTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
/* 206-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPFunctions.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.