Documentation
¶
Index ¶
- Variables
- func ValidateConnectionTarget(clusterIdentifier, workgroupName string) error
- func ValidateListStatementsStatus(status string) error
- type ConfigProvider
- type Handler
- func (h *Handler) ChaosOperations() []string
- func (h *Handler) ChaosRegions() []string
- func (h *Handler) ChaosServiceName() string
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- 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) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- func (h *Handler) WithJanitor(interval, statementTTL time.Duration, taskTimeout ...time.Duration) *Handler
- type InMemoryBackend
- func (b *InMemoryBackend) AccountID() string
- func (b *InMemoryBackend) BatchExecuteStatement(ctx context.Context, sqls []string, ...) (*Statement, error)
- func (b *InMemoryBackend) CancelStatement(ctx context.Context, id string) error
- func (b *InMemoryBackend) DescribeStatement(ctx context.Context, id string) (*Statement, error)
- func (b *InMemoryBackend) EvictExpiredStatements(cutoff time.Time) int
- func (b *InMemoryBackend) ExecuteStatement(ctx context.Context, ...) (*Statement, error)
- func (b *InMemoryBackend) ListStatements(ctx context.Context, filter ListStatementsFilter) ([]*Statement, string, error)
- func (b *InMemoryBackend) Region() string
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- type Janitor
- type ListStatementsFilter
- type Provider
- type SQLParameter
- type Settings
- type Statement
- type StorageBackend
- type SubStatementData
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a statement does not exist. ErrNotFound = awserr.New("ResourceNotFoundException", awserr.ErrNotFound) // ErrTerminalState is returned when cancelling a statement that is already in a terminal state. ErrTerminalState = awserr.New("ValidationException", awserr.ErrConflict) // ErrValidation is returned when input validation fails. ErrValidation = awserr.New("ValidationException", awserr.ErrInvalidParameter) // ErrNoResultSet is returned when fetching results for a statement with no result set. ErrNoResultSet = awserr.New("ValidationException", awserr.ErrInvalidParameter) )
var ErrNilAppContext = errors.New("nil AppContext passed to RedshiftData Provider.Init")
ErrNilAppContext is returned by Init when a nil AppContext is passed.
Functions ¶
func ValidateConnectionTarget ¶
ValidateConnectionTarget verifies that exactly one of clusterIdentifier or workgroupName is provided, matching the AWS constraint.
func ValidateListStatementsStatus ¶
ValidateListStatementsStatus returns ErrValidation if status is not a known value. An empty string is also accepted (matches FINISHED per AWS default).
Types ¶
type ConfigProvider ¶
type ConfigProvider interface {
GetRedshiftDataSettings() Settings
}
ConfigProvider is a private interface to extract Redshift Data configuration from the abstract AppContext Config.
type Handler ¶
type Handler struct {
Backend StorageBackend
AccountID string
Region string
// contains filtered or unexported fields
}
Handler is the HTTP handler for the AWS Redshift Data API.
func NewHandler ¶
func NewHandler(backend StorageBackend) *Handler
NewHandler creates a new Redshift Data handler.
func (*Handler) ChaosOperations ¶
ChaosOperations returns all operations that can be fault-injected.
func (*Handler) ChaosRegions ¶
ChaosRegions returns all regions this handler handles.
func (*Handler) ChaosServiceName ¶
ChaosServiceName returns the lowercase AWS service name for fault rule matching.
func (*Handler) ExtractOperation ¶
ExtractOperation extracts the operation name from the X-Amz-Target header.
func (*Handler) ExtractResource ¶
ExtractResource extracts the statement ID from the request body.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations returns the list of supported Redshift Data operations.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler function for Redshift Data requests.
func (*Handler) MatchPriority ¶
MatchPriority returns the routing priority.
func (*Handler) Reset ¶
func (h *Handler) Reset()
Reset clears all backend state. Useful for test isolation.
func (*Handler) RouteMatcher ¶
RouteMatcher returns a function that matches Redshift Data API requests. Requests are identified by the X-Amz-Target header prefix "RedshiftData.".
func (*Handler) Snapshot ¶
Snapshot implements persistence.Persistable by delegating to the backend. Before this, Handler had no Snapshot/Restore of its own, so redshiftdata was silently excluded from Gopherstack's persistence.Manager (it type- asserts each service's Registerable to persistence.Persistable) even though InMemoryBackend fully implemented both methods -- a dead-wiring bug fixed as part of the Phase 3.3 rollout.
func (*Handler) StartWorker ¶
StartWorker starts the background janitor if configured.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend is an in-memory store for Redshift Data API statements. All regional resource maps are nested by region (outer key = region) so that the same-named statement in two regions are fully isolated.
func NewInMemoryBackend ¶
func NewInMemoryBackend(accountID, region string) *InMemoryBackend
NewInMemoryBackend creates a new in-memory Redshift Data backend.
func (*InMemoryBackend) AccountID ¶
func (b *InMemoryBackend) AccountID() string
AccountID returns the AWS account ID this backend is configured for.
func (*InMemoryBackend) BatchExecuteStatement ¶
func (b *InMemoryBackend) BatchExecuteStatement( ctx context.Context, sqls []string, clusterIdentifier, workgroupName, database, dbUser, secretARN, statementName string, withEvent bool, resultFormat string, ) (*Statement, error)
BatchExecuteStatement creates and immediately completes a batch SQL statement.
func (*InMemoryBackend) CancelStatement ¶
func (b *InMemoryBackend) CancelStatement(ctx context.Context, id string) error
CancelStatement marks a statement as aborted.
func (*InMemoryBackend) DescribeStatement ¶
DescribeStatement returns the details of a statement by ID.
func (*InMemoryBackend) EvictExpiredStatements ¶
func (b *InMemoryBackend) EvictExpiredStatements(cutoff time.Time) int
EvictExpiredStatements removes terminal statements whose UpdatedAt is older than the given cutoff across all regions. Returns the number of evicted statements. Only terminal states (FINISHED, FAILED, ABORTED) are eligible for eviction.
func (*InMemoryBackend) ExecuteStatement ¶
func (b *InMemoryBackend) ExecuteStatement( ctx context.Context, sql, clusterIdentifier, workgroupName, database, dbUser, secretARN, statementName string, withEvent bool, resultFormat string, parameters []SQLParameter, ) (*Statement, error)
ExecuteStatement creates and immediately completes a SQL statement.
func (*InMemoryBackend) ListStatements ¶
func (b *InMemoryBackend) ListStatements( ctx context.Context, filter ListStatementsFilter, ) ([]*Statement, string, error)
ListStatements returns statements sorted by creation time (newest first). An omitted Status matches AWS by returning only finished statements. Returns the page slice and a next-token string (non-empty when more pages exist).
func (*InMemoryBackend) Region ¶
func (b *InMemoryBackend) Region() string
Region returns the AWS region this backend is configured for.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset clears all stored statements across all regions.
type Janitor ¶
type Janitor struct {
Backend *InMemoryBackend
Interval time.Duration
StatementTTL time.Duration
// TaskTimeout bounds each individual sweep task. When zero, each task runs
// without a deadline. When non-zero, a child context with this timeout is
// created for each sweep pass, preventing a stalled operation from blocking
// the janitor loop indefinitely.
TaskTimeout time.Duration
}
Janitor is the Redshift Data background worker that evicts completed statements after a configurable TTL to prevent unbounded growth of in-memory state. It complements the ring-buffer cap: the ring buffer evicts by count, the janitor evicts by age.
func NewJanitor ¶
func NewJanitor(backend *InMemoryBackend, interval, statementTTL time.Duration) *Janitor
NewJanitor creates a new Janitor for the given backend. Zero values for interval or statementTTL fall back to package defaults.
type ListStatementsFilter ¶
type ListStatementsFilter struct {
ClusterIdentifier string
WorkgroupName string
Database string
StatementName string
Status string
NextToken string
MaxResults int
}
ListStatementsFilter controls statement filtering and pagination.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for AWS Redshift Data.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init initializes the Redshift Data service backend and handler.
type SQLParameter ¶
SQLParameter is a named SQL parameter for use in parameterized queries, matching the SQLParameter type in the AWS Redshift Data API.
type Settings ¶
type Settings struct {
JanitorInterval time.Duration `json:"janitor_interval" env:"REDSHIFTDATA_JANITOR_INTERVAL" default:"1m" help:"Janitor tick interval."` //nolint:lll // Kong struct tag makes this line long
StatementTTL time.Duration `` //nolint:lll // Kong struct tag makes this line long
/* 134-byte string literal not displayed */
}
Settings holds service-level configuration for the Redshift Data backend. Fields are picked up by the Kong CLI parser when this struct is embedded in the root CLI command.
type Statement ¶
type Statement struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Database string `json:"database"`
ID string `json:"id"`
ClusterIdentifier string `json:"clusterIdentifier"`
WorkgroupName string `json:"workgroupName"`
QueryString string `json:"queryString"`
DBUser string `json:"dbUser"`
SecretARN string `json:"secretARN"`
StatementName string `json:"statementName"`
ResultFormat string `json:"resultFormat"`
Status string `json:"status"`
Error string `json:"error"`
QueryStrings []string `json:"queryStrings"`
Parameters []SQLParameter `json:"parameters,omitempty"`
SubStatements []SubStatementData `json:"subStatements,omitempty"`
// DurationMs is the total wall-clock execution time in milliseconds. Populated
// when the statement reaches a terminal state (FINISHED / FAILED / ABORTED).
DurationMs int64 `json:"durationMs"`
ResultRows int64 `json:"resultRows"`
ResultSize int64 `json:"resultSize"`
HasResultSet bool `json:"hasResultSet"`
IsBatchStatement bool `json:"isBatchStatement"`
// WithEvent indicates whether an EventBridge event is generated on completion.
WithEvent bool `json:"withEvent"`
}
Statement represents an AWS Redshift Data API SQL statement.
type StorageBackend ¶
type StorageBackend interface {
// Statement execution
ExecuteStatement(
ctx context.Context,
sql, clusterIdentifier, workgroupName, database, dbUser, secretARN, statementName string,
withEvent bool, resultFormat string,
parameters []SQLParameter,
) (*Statement, error)
BatchExecuteStatement(
ctx context.Context,
sqls []string, clusterIdentifier, workgroupName, database, dbUser, secretARN, statementName string,
withEvent bool, resultFormat string,
) (*Statement, error)
// Statement inspection
DescribeStatement(ctx context.Context, id string) (*Statement, error)
CancelStatement(ctx context.Context, id string) error
// ListStatements returns a page of statements and a next-token for pagination.
ListStatements(ctx context.Context, filter ListStatementsFilter) (
[]*Statement, string, error,
)
// Maintenance
// EvictExpiredStatements removes terminal statements older than cutoff.
// Returns the number of evicted statements.
EvictExpiredStatements(cutoff time.Time) int
// Lifecycle
Reset()
Region() string
AccountID() string
Snapshot(ctx context.Context) []byte
Restore(ctx context.Context, data []byte) error
}
StorageBackend defines the interface for Redshift Data backend implementations. All methods must be safe for concurrent use.
type SubStatementData ¶
type SubStatementData struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
QueryString string `json:"queryString"`
Status string `json:"status"`
Error string `json:"error"`
HasResultSet bool `json:"hasResultSet"`
ResultRows int64 `json:"resultRows"`
ResultSize int64 `json:"resultSize"`
DurationMs int64 `json:"durationMs"`
}
SubStatementData represents a single sub-statement within a batch, matching the SubStatementData shape returned by AWS DescribeStatement for batch runs.