compose

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 60 Imported by: 0

Documentation

Overview

Package compose assembles a replica: it builds the application's handlers on their PostgreSQL and other outbound adapters and mounts the APIs on the edge. The serve command and the test kit's in-process server both use it, so tests exercise the replica that runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap(d Deps) *appaccess.Bootstrap

Bootstrap returns the use case creating the first instance admin.

func Console

func Console(edge *flaghttp.Server, defaultLocale string) (bool, error)

Console mounts the embedded console on edge, its entry document naming defaultLocale, and reports whether the binary holds a build of the console rather than the placeholder page.

func CreateInstanceAdmin

func CreateInstanceAdmin(d Deps) *appaccess.CreateInstanceAdmin

CreateInstanceAdmin returns the use case adding an instance admin from the command line.

func Hasher

func Hasher() *password.Hasher

Hasher returns the password hasher of a command line, which hashes one password and needs no bound.

func InstanceAdminExists

func InstanceAdminExists(d Deps) *appaccess.InstanceAdminExists

InstanceAdminExists returns the query telling whether the instance has an instance admin.

func PromoteMember

func PromoteMember(d Deps) *appaccess.PromoteMember

PromoteMember returns the use case making a member an instance admin from the command line.

func Unlock added in v0.3.0

func Unlock(d Deps) *appaccess.Unlock

Unlock returns the use case opening the instance again to passwords from the command line.

Types

type Background

type Background struct {
	// Workers are registered with the replica's runner.
	Workers []worker.Worker
	// Listeners are started on the replica's notification listeners.
	Listeners []Listener
	// Close ends the work the replica's use cases started on their own, such
	// as the ruleset loads in flight; whoever runs the replica calls it once
	// the requests are done. What the requests counted is written first, then
	// the mail still leaving is awaited until ctx ends, so a mail that does
	// not finish never holds back what was counted.
	Close func(ctx context.Context)
	// Wait returns once the work the requests started after their answers,
	// such as mails and the records of failed sign-ins, has ended, or ctx
	// ends.
	Wait func(ctx context.Context)
}

Background is the work a replica does besides answering requests, which whoever runs the replica starts.

func Management

func Management(edge *flaghttp.Server, d Deps, reg prometheus.Registerer, o Options) Background

Management mounts the management API and the SDK API on edge, their metrics on reg, and returns the background work their use cases need.

type Deps

type Deps struct {
	Pool  *pgxpool.Pool
	Clock clock.Clock
	IDs   *id.Source
}

Deps are what a replica's use cases run on.

func NewDeps

func NewDeps(pool *pgxpool.Pool, c clock.Clock) Deps

NewDeps returns the dependencies of a replica on pool, timed by c, minting identifiers from c.

type Listener

type Listener struct {
	Channel string
	Handler pglisten.Handler
}

Listener is a handler of the notifications of one channel.

type Options

type Options struct {
	// Keyring holds the instance's secret key, which session cookies are
	// signed under.
	Keyring *secret.Keyring
	// PasswordHashConcurrency bounds the password hashes and verifications
	// the replica runs at once.
	PasswordHashConcurrency int
	// WrapPasswordHasher, when set, wraps the replica's password hasher, which
	// lets a test count the hashes and verifications a sign-in does; nil
	// in production.
	WrapPasswordHasher func(appaccess.PasswordVerifier) appaccess.PasswordVerifier
	// RulesetLoadFault lets a test stall the replica's ruleset
	// materializations; nil in production.
	RulesetLoadFault *pgdelivery.RulesetLoadFault
	// IngestHold lets a test keep a batch's transaction open; nil in
	// production.
	IngestHold *pgevents.IngestHold
	// RateLimits are the limits of the SDK API.
	RateLimits config.RateLimits
	// EventsRetention is how long raw events are kept.
	EventsRetention time.Duration
	// EventsLossWarning is how long before retention drops a row a sink that
	// has not delivered it is at risk.
	EventsLossWarning time.Duration
	// EventsPartitionsAhead is how many days after today the raw event
	// tables' partitions are created ahead of time.
	EventsPartitionsAhead int
	// AliasLinksLimit is the most alias links an environment keeps.
	AliasLinksLimit int
	// FirstExposuresLimit is the most first exposures an experiment keeps
	// in an environment.
	FirstExposuresLimit int
	// SDKInventoryRetention is how long the SDK inventory keeps an SDK
	// after it was last seen.
	SDKInventoryRetention time.Duration
	// WebhookTargets is what the operator allows a webhook subscription's
	// target to be.
	WebhookTargets governance.TargetPolicy
	// Resolver resolves the names of webhook and sink targets; nil is the
	// system's resolver.
	Resolver TargetResolver
	// WebhookTick is how often the replica fans the outbox out and sends the
	// webhook deliveries that are due.
	WebhookTick time.Duration
	// SinkFault lets a test lose a sink stream's commit; nil in production.
	SinkFault *pgsinks.Fault
	// SinkTick is how often the replica looks for sink streams that are due
	// and delivers their next batch.
	SinkTick time.Duration
	// SinkLagWarning is how old the oldest event a sink has not delivered
	// may be before the sink is lagging.
	SinkLagWarning time.Duration
	// SinkRejectionAttempts is how many times a target must reject a batch
	// for it to be set aside as a dead letter, and SinkStopAfterDeadLetters
	// how many dead letters in a row on one stream stop the sink.
	SinkRejectionAttempts, SinkStopAfterDeadLetters int
	// WebhookSecretOverlap is how long a webhook subscription's rotated
	// secret signs beside the new one.
	WebhookSecretOverlap time.Duration
	// Schedule is how change requests are scheduled and applied at their
	// time.
	Schedule Schedule
	// AuditExportMaxEntries is the most entries one download of the audit
	// log may hold.
	AuditExportMaxEntries int
	// AuditExportMaxConcurrent is how many downloads of the audit log the
	// replica serves at once.
	AuditExportMaxConcurrent int
	// DigestSlot is when the weekly stale-flag digest is sent.
	DigestSlot governance.DigestSlot
	// DefaultLocale is the language of a mail whose recipient has not chosen
	// one.
	DefaultLocale string
	// MailRootCAs are the roots an SMTP server's certificate is verified
	// against; the system's when nil. The test kit sets it for the servers
	// it starts.
	MailRootCAs *x509.CertPool
	management.Options
}

Options are how a replica serves, as its configuration sets them.

type Schedule added in v0.2.0

type Schedule struct {
	MinLead     time.Duration
	Tick        time.Duration
	MaxFailures int
}

Schedule is how change requests are scheduled: how far ahead an apply time is at least, how often the scheduler runs, and after how many failures in a row it stops trying a change request.

type TargetResolver added in v0.7.0

type TargetResolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

TargetResolver resolves the host name of a webhook or sink target to its addresses.

Jump to

Keyboard shortcuts

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