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
- Variables
- func CheckEnvironment(getenv func(string) string) error
- func CheckStore(ctx context.Context, db *store.DB) error
- func Enabled(getenv func(string) string) bool
- func IsSeededUserID(id string) bool
- func ParseScenario(name string) (string, error)
- func SeedAlerting(ctx context.Context, adb *alerting.DB, opts Options) error
- func SeedTelemetry(ctx context.Context, db *store.DB, tdb *telemetry.DB, opts Options) error
- type Docker
- type Finding
- type Generator
- type LintOptions
- type LogPublisher
- type Manifest
- type Options
- type SampleWriter
- type Stores
Constants ¶
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" )
const ( // ScenarioIncident is the public demo storyline. ScenarioIncident = "incident" // ScenarioCalm is a healthy fleet for screenshots. ScenarioCalm = "calm" )
const EnvDemoMode = "APP_DEMO_MODE"
EnvDemoMode is the explicit opt-in the demo entrypoint requires.
Variables ¶
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") )
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 ¶
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 ¶
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 IsSeededUserID ¶
IsSeededUserID reports whether id belongs to a user the seeder creates.
func ParseScenario ¶
ParseScenario validates a scenario name; empty means incident.
func SeedAlerting ¶
SeedAlerting writes alert rules, channels pointed at reserved hosts, and a history of fired and resolved events with one rule firing now.
func SeedTelemetry ¶
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 (*Docker) ListByPrefix ¶
ListByPrefix reports one running container per seeded service whose name matches prefix.
func (*Docker) ListImages ¶
ListImages returns the tags the seeded deploy history produced for repo.
type Finding ¶
Finding is one seed lint violation.
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.
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 ¶
LogPublisher is the slice of telemetry.LogBroadcaster the generator needs.
type Manifest ¶
Manifest names what a seed produced, for the generator and fakes.
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
// Scenario picks the storyline: ScenarioIncident (default) or ScenarioCalm.
Scenario string
}
Options controls a seed run. The same Seed, Anchor and DomainSuffix always produce the same rows.
type SampleWriter ¶
SampleWriter is the slice of telemetry.DB the generator needs.