demo

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Overview

Package demo builds and guards the read-only public demo instance: a seeded control plane with no Docker, ingress or agent listeners.

Index

Constants

View Source
const (
	// VisitorUserID is the read-only account every demo session signs in as.
	VisitorUserID = "user_demo_visitor"
	// VisitorUsername is the login name shown on the demo login form.
	VisitorUsername = "demo"
	// VisitorPassword is the published, read-only demo password.
	VisitorPassword = "demo-readonly"
)
View Source
const EnvDemoMode = "APP_DEMO_MODE"

EnvDemoMode is the explicit opt-in the demo entrypoint requires.

Variables

View Source
var (
	// ErrNotEmpty is returned when the target store already holds users but no demo marker.
	ErrNotEmpty = errors.New("demo: refusing to seed a store that already holds users")
	// ErrSeedMismatch is returned when the store was seeded with different options.
	ErrSeedMismatch = errors.New("demo: store was seeded with a different seed or anchor")
)
View Source
var ErrNotDemoInstance = errors.New("demo: data dir was not produced by the demo seeder")

ErrNotDemoInstance is returned when the data dir does not carry the seeder's marker.

Functions

func CheckEnvironment

func CheckEnvironment(getenv func(string) string) error

CheckEnvironment fails closed unless demo mode is explicitly enabled and nothing that reaches a real host (Docker, ingress, agents, a public bind) is configured.

func CheckStore

func CheckStore(ctx context.Context, db *store.DB) error

CheckStore requires the seeder's marker and that every user row is one the seeder created, so a real instance's data dir can never be served as a demo.

func Enabled

func Enabled(getenv func(string) string) bool

Enabled reports whether the explicit demo opt-in is set to a true value.

func IsSeededUserID

func IsSeededUserID(id string) bool

IsSeededUserID reports whether id belongs to a user the seeder creates.

func SeedAlerting

func SeedAlerting(ctx context.Context, adb *alerting.DB, opts Options) error

SeedAlerting writes alert rules, channels pointed at reserved hosts, and a history of fired and resolved events with one rule firing now.

func SeedTelemetry

func SeedTelemetry(ctx context.Context, db *store.DB, tdb *telemetry.DB, opts Options) error

SeedTelemetry writes deterministic metrics, deploy markers and log lines into the telemetry store, all anchored on opts.Anchor so the series ends at "now". The relational store must already be seeded.

Types

type Docker

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

Docker answers the API layer's narrow Docker-facing interfaces (pinger, image and container listers, disk usage) from seeded rows. It owns no socket and cannot reach a host.

func NewDocker

func NewDocker(db *store.DB, now func() time.Time) *Docker

NewDocker builds the fake; now stamps container creation times.

func (*Docker) DiskUsage

func (*Docker) DiskUsage(context.Context) (docker.DiskUsage, error)

DiskUsage returns fixed, plausible numbers.

func (*Docker) ListByPrefix

func (d *Docker) ListByPrefix(ctx context.Context, prefix string) ([]docker.ContainerState, error)

ListByPrefix reports one running container per seeded service whose name matches prefix.

func (*Docker) ListImages

func (d *Docker) ListImages(ctx context.Context, repo string) ([]docker.ImageInfo, error)

ListImages returns the tags the seeded deploy history produced for repo.

func (*Docker) Ping

func (*Docker) Ping(context.Context) error

Ping always succeeds so the doctor and status pages read as healthy.

type Finding

type Finding struct {
	Check  string
	Detail string
}

Finding is one seed lint violation.

func Lint

func Lint(ctx context.Context, st Stores, opts LintOptions) ([]Finding, error)

Lint checks a seeded data dir for dangling references, secret-looking values, non-example hostnames and timestamps after the seed anchor.

func (Finding) String

func (f Finding) String() string

type Generator

type Generator struct {
	Services []string
	Logs     LogPublisher
	Samples  SampleWriter
	Now      func() time.Time
	Seed     int64
	// LogEvery and SampleEvery default to 2s and 15s.
	LogEvery    time.Duration
	SampleEvery time.Duration
	// contains filtered or unexported fields
}

Generator keeps the demo visibly alive: a synthetic log line per service and a metric sample per service, both deterministic given the seed.

func (*Generator) Run

func (g *Generator) Run(ctx context.Context)

Run ticks until ctx is done.

func (*Generator) TickLogs

func (g *Generator) TickLogs(at time.Time)

TickLogs publishes one line per service. Roughly 70 percent are structured JSON.

func (*Generator) TickSamples

func (g *Generator) TickSamples(ctx context.Context, at time.Time) error

TickSamples writes a CPU and memory sample per service, a smooth value around a per-service baseline.

type LintOptions

type LintOptions struct {
	DomainSuffix string
}

LintOptions tunes the linter. DomainSuffix is the one extra hostname suffix (the brand demo domain) allowed beside the reserved example names.

type LogPublisher

type LogPublisher interface {
	Publish(entry telemetry.LogEntry)
}

LogPublisher is the slice of telemetry.LogBroadcaster the generator needs.

type Manifest

type Manifest struct {
	Services  []string
	Databases []string
	Nodes     []string
}

Manifest names what a seed produced, for the generator and fakes.

func Seed

func Seed(ctx context.Context, db *store.DB, opts Options) (Manifest, error)

Seed populates an empty store with the fictional demo estate and writes the marker last. Re-running with identical options is a no-op; a data dir that failed halfway must be discarded, not retried.

func SeedAll

func SeedAll(ctx context.Context, st Stores, opts Options) (Manifest, error)

SeedAll seeds the relational store, then telemetry and alerting. A store that already carries a matching marker is left untouched, so a restart never duplicates log lines.

type Options

type Options struct {
	Seed   int64
	Anchor time.Time
	// DomainSuffix is appended to every seeded hostname; defaults to a reserved example domain.
	DomainSuffix string
}

Options controls a seed run. The same Seed, Anchor and DomainSuffix always produce the same rows.

type SampleWriter

type SampleWriter interface {
	WriteSamples(ctx context.Context, samples []telemetry.Sample) error
}

SampleWriter is the slice of telemetry.DB the generator needs.

type Stores

type Stores struct {
	DB        *store.DB
	Telemetry *telemetry.DB
	Alerting  *alerting.DB
}

Stores groups the three SQLite files a demo estate spans.

Jump to

Keyboard shortcuts

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