Documentation
¶
Overview ¶
Package serverless provides serverless function executors for AWS Lambda, Azure Functions, and GCP Cloud Functions. These providers are EXPERIMENTAL and use raw HTTP — see individual provider files for details.
Index ¶
- type AWSLambdaProvider
- type AWSProviderConfig
- type AzureFunctionsProvider
- type AzureProviderConfig
- type CircuitBreaker
- type CircuitBreakerState
- type ExecutionMetrics
- type FunctionMetadata
- type GCPCloudFunctionsProvider
- type GCPProviderConfig
- type ProviderFactory
- type ProviderType
- type ServerlessConfig
- type ServerlessFunctionExecutor
- func (e *ServerlessFunctionExecutor) DeregisterFunction(name string) error
- func (e *ServerlessFunctionExecutor) Execute(ctx context.Context, functionName string, input any) (any, error)
- func (e *ServerlessFunctionExecutor) ExecuteAsync(ctx context.Context, functionName string, input any) (string, error)
- func (e *ServerlessFunctionExecutor) GetCircuitBreakerState(functionName string) (CircuitBreakerState, error)
- func (e *ServerlessFunctionExecutor) GetMetadata(functionName string) (*FunctionMetadata, error)
- func (e *ServerlessFunctionExecutor) GetMetrics(functionName string) (*ExecutionMetrics, error)
- func (e *ServerlessFunctionExecutor) GetResult(ctx context.Context, jobID string) (any, error)
- func (e *ServerlessFunctionExecutor) IsHealthy(ctx context.Context) bool
- func (e *ServerlessFunctionExecutor) ListFunctions() []string
- func (e *ServerlessFunctionExecutor) RegisterFunction(name string, fn port.FunctionHandler) error
- func (e *ServerlessFunctionExecutor) Start(ctx context.Context) error
- func (e *ServerlessFunctionExecutor) Stop(ctx context.Context) error
- type ServerlessProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AWSLambdaProvider ¶
type AWSLambdaProvider struct {
// contains filtered or unexported fields
}
AWSLambdaProvider implements ServerlessProvider for AWS Lambda
func NewAWSLambdaProvider ¶
func NewAWSLambdaProvider(config *AWSProviderConfig) *AWSLambdaProvider
NewAWSLambdaProvider creates a new AWS Lambda provider
func (*AWSLambdaProvider) GetEndpoint ¶
func (p *AWSLambdaProvider) GetEndpoint() string
GetEndpoint returns the configured endpoint
func (*AWSLambdaProvider) GetRegion ¶
func (p *AWSLambdaProvider) GetRegion() string
GetRegion returns the configured AWS region
type AWSProviderConfig ¶
type AWSProviderConfig struct {
Region string
AccessKeyID string
SecretAccessKey string
SessionToken string
Endpoint string // Optional: for local testing or custom endpoints
MaxConnections int
Timeout time.Duration
}
AWSProviderConfig contains AWS-specific configuration
type AzureFunctionsProvider ¶
type AzureFunctionsProvider struct {
// contains filtered or unexported fields
}
AzureFunctionsProvider implements ServerlessProvider for Azure Functions
func NewAzureFunctionsProvider ¶
func NewAzureFunctionsProvider(config *AzureProviderConfig) (*AzureFunctionsProvider, error)
NewAzureFunctionsProvider creates a new Azure Functions provider
func (*AzureFunctionsProvider) GetFunctionApp ¶
func (p *AzureFunctionsProvider) GetFunctionApp() string
GetFunctionApp returns the configured function app name
func (*AzureFunctionsProvider) GetResourceGroup ¶
func (p *AzureFunctionsProvider) GetResourceGroup() string
GetResourceGroup returns the configured resource group
type AzureProviderConfig ¶
type AzureProviderConfig struct {
ResourceGroup string
FunctionApp string
SubscriptionID string
ClientID string
ClientSecret string
TenantID string
MaxConnections int
Timeout time.Duration
}
AzureProviderConfig contains Azure-specific configuration
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker tracks failure state per function
func NewCircuitBreaker ¶
func NewCircuitBreaker(threshold float64, stateChangeTimeout time.Duration) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() CircuitBreakerState
GetState returns current circuit breaker state
func (*CircuitBreaker) IsOpen ¶
func (cb *CircuitBreaker) IsOpen() bool
IsOpen checks if circuit breaker is open or should try half-open
func (*CircuitBreaker) RecordFailure ¶
func (cb *CircuitBreaker) RecordFailure()
RecordFailure records a failed invocation
func (*CircuitBreaker) RecordSuccess ¶
func (cb *CircuitBreaker) RecordSuccess()
RecordSuccess records a successful invocation
type CircuitBreakerState ¶
type CircuitBreakerState string
CircuitBreakerState defines the state of the circuit breaker
const ( CircuitClosed CircuitBreakerState = "closed" CircuitOpen CircuitBreakerState = "open" CircuitHalf CircuitBreakerState = "half-open" )
type ExecutionMetrics ¶
type ExecutionMetrics struct {
TotalExecutions int64
SuccessfulCalls int64
FailedCalls int64
AverageLatency time.Duration
LastExecutedAt time.Time
P99Latency time.Duration
P95Latency time.Duration
}
ExecutionMetrics tracks execution statistics
type FunctionMetadata ¶
type FunctionMetadata struct {
Name string
Description string
InputType string
OutputType string
Timeout int // seconds
Retries int
Local bool
RegisteredAt time.Time
IsWarm bool // Whether function is currently warm
LastWarmed time.Time // Last time function was warmed
}
FunctionMetadata stores metadata about a registered function
type GCPCloudFunctionsProvider ¶
type GCPCloudFunctionsProvider struct {
// contains filtered or unexported fields
}
GCPCloudFunctionsProvider implements ServerlessProvider for Google Cloud Functions
func NewGCPCloudFunctionsProvider ¶
func NewGCPCloudFunctionsProvider(config *GCPProviderConfig) (*GCPCloudFunctionsProvider, error)
NewGCPCloudFunctionsProvider creates a new GCP Cloud Functions provider
func (*GCPCloudFunctionsProvider) GetProjectID ¶
func (p *GCPCloudFunctionsProvider) GetProjectID() string
GetProjectID returns the configured GCP project ID
func (*GCPCloudFunctionsProvider) GetRegion ¶
func (p *GCPCloudFunctionsProvider) GetRegion() string
GetRegion returns the configured GCP region
type GCPProviderConfig ¶
type GCPProviderConfig struct {
ProjectID string
Region string
ServiceAccountEmail string
ServiceAccountKeyJSON string // Base64 encoded or raw JSON
MaxConnections int
Timeout time.Duration
}
GCPProviderConfig contains GCP-specific configuration
type ProviderFactory ¶
type ProviderFactory struct{}
ProviderFactory creates the appropriate ServerlessProvider based on configuration
func (*ProviderFactory) CreateProvider ¶
func (pf *ProviderFactory) CreateProvider(config *ServerlessConfig) (ServerlessProvider, error)
CreateProvider creates a ServerlessProvider instance based on the provided config
type ProviderType ¶
type ProviderType string
ProviderType defines supported serverless providers
const ( ProviderAWS ProviderType = "aws" ProviderAzure ProviderType = "azure" ProviderGCP ProviderType = "gcp" )
type ServerlessConfig ¶
type ServerlessConfig struct {
Provider ProviderType
Region string
Credentials map[string]string
DefaultTimeout time.Duration
MaxConcurrent int
FunctionPrefix string
InitialBackoff time.Duration
MaxBackoff time.Duration
BackoffMultiplier float64
// Warming configuration
WarmingEnabled bool
WarmingInterval time.Duration // How often to warm functions (default 5m)
MaxPoolConnections int // Max HTTP connections (default 100)
// Circuit breaker configuration
CircuitBreakerThreshold float64 // Failure rate threshold (default 50%)
CircuitBreakerTimeout time.Duration // Time to attempt half-open (default 30s)
}
ServerlessConfig contains configuration for serverless executor
type ServerlessFunctionExecutor ¶
type ServerlessFunctionExecutor struct {
// contains filtered or unexported fields
}
ServerlessFunctionExecutor implements FunctionExecutorPort for serverless execution with production-grade features: metrics, timeouts, retries, concurrency limiting, function warming, circuit breakers, and connection pooling
func NewServerlessExecutorForProvider ¶
func NewServerlessExecutorForProvider(config *ServerlessConfig) (*ServerlessFunctionExecutor, error)
NewServerlessExecutorForProvider is a convenience function to create a serverless executor with automatic provider initialization
func NewServerlessFunctionExecutor ¶
func NewServerlessFunctionExecutor(config *ServerlessConfig, provider ServerlessProvider) *ServerlessFunctionExecutor
NewServerlessFunctionExecutor creates a new production-grade serverless function executor
func (*ServerlessFunctionExecutor) DeregisterFunction ¶
func (e *ServerlessFunctionExecutor) DeregisterFunction(name string) error
DeregisterFunction removes a serverless function reference
func (*ServerlessFunctionExecutor) Execute ¶
func (e *ServerlessFunctionExecutor) Execute(ctx context.Context, functionName string, input any) (any, error)
Execute synchronously invokes a serverless function with timeout and retry support
func (*ServerlessFunctionExecutor) ExecuteAsync ¶
func (e *ServerlessFunctionExecutor) ExecuteAsync(ctx context.Context, functionName string, input any) (string, error)
ExecuteAsync asynchronously invokes a serverless function
func (*ServerlessFunctionExecutor) GetCircuitBreakerState ¶
func (e *ServerlessFunctionExecutor) GetCircuitBreakerState(functionName string) (CircuitBreakerState, error)
GetCircuitBreakerState returns the current state of a function's circuit breaker
func (*ServerlessFunctionExecutor) GetMetadata ¶
func (e *ServerlessFunctionExecutor) GetMetadata(functionName string) (*FunctionMetadata, error)
GetMetadata returns function metadata
func (*ServerlessFunctionExecutor) GetMetrics ¶
func (e *ServerlessFunctionExecutor) GetMetrics(functionName string) (*ExecutionMetrics, error)
GetMetrics returns execution metrics for a function
func (*ServerlessFunctionExecutor) IsHealthy ¶
func (e *ServerlessFunctionExecutor) IsHealthy(ctx context.Context) bool
IsHealthy checks if executor is operational
func (*ServerlessFunctionExecutor) ListFunctions ¶
func (e *ServerlessFunctionExecutor) ListFunctions() []string
ListFunctions returns all registered function names
func (*ServerlessFunctionExecutor) RegisterFunction ¶
func (e *ServerlessFunctionExecutor) RegisterFunction(name string, fn port.FunctionHandler) error
RegisterFunction registers a serverless function reference