Documentation
¶
Overview ¶
Package controllercmd is the controller group: osapi controller start, which runs the REST API. The package is not named controller, which is the controller itself.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Defaults = config.Controller{ Client: config.Client{URL: "https://localhost:8080"}, API: config.APIServer{ Port: 8080, JobTimeout: "30s", TLS: config.ServerTLS{Enabled: true}, }, NATS: config.NATSConnection{ Host: "localhost", Port: 4222, ClientName: "osapi-controller", Namespace: "osapi", Auth: config.NATSAuth{Type: "none"}, TLS: config.ClientTLS{Enabled: true}, }, Metrics: config.MetricsServer{ Enabled: true, Host: "0.0.0.0", Port: 9090, TLS: config.ServerTLS{Enabled: true}, }, Notifications: config.NotificationsConfig{ Enabled: true, Notifier: "log", RenotifyInterval: "5m", }, UI: config.UIConfig{Enabled: true}, Join: config.ControllerJoin{ Callout: config.JoinCallout{Auth: config.NATSAuth{Type: "none"}}, }, PKI: config.ControllerPKI{ KeyDir: "/etc/osapi/pki", RotationGracePeriod: "24h", }, Secrets: config.ControllerSecrets{Vaults: []vault.Spec{{ Name: "default", Type: "nats", KeyFile: config.DefaultVaultKeyFile, }}}, }
Defaults are the defaults of the controller section of the config, which controller start owns: a key that the config file and the environment do not set takes its value from here. osapi config default get prints them.
var Group = command.Register(command.Define( "controller", "Run the controller", command.Flat(), command.Under(command.ParentController), command.Uses[Deps](), command.Config("controller", Defaults), command.Process("start"). Short("Start the controller"). Long("The controller serves the REST API, writes its heartbeat, and watches\n"+ "conditions to send notifications."). Example(""). Logs(StartLogs...). Example("--controller-api-port 9000"). Flag("controller.api.port"). Setup(Start), ))
Group is the controller group's definition. It is flat, Under controller, so its method is osapi controller start.
var StartLogs = []command.LogLine{ { Level: slog.LevelInfo, Msg: "CORS not configured, cross-origin browser requests will be refused", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "controller.api"), slog.String("configure", "controller.api.security.cors.allow_origins"), }, }, { Level: slog.LevelInfo, Msg: "metrics cache refresh started", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "controller.health"), slog.String("interval", "15s"), }, }, { Level: slog.LevelInfo, Msg: "embedded UI enabled", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("path", "/"), }, }, { Level: slog.LevelInfo, Msg: "condition watcher started", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "controller.notify"), }, }, { Level: slog.LevelInfo, Msg: "metrics server started", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "metrics"), slog.String("addr", "0.0.0.0:9090"), }, }, { Level: slog.LevelInfo, Msg: "http(s) server started", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "metrics"), slog.String("address", "[::]:9090"), }, }, { Level: slog.LevelInfo, Msg: "starting server", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "controller.api"), }, }, { Level: slog.LevelInfo, Msg: "http(s) server started", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "controller.api"), slog.String("address", "[::]:8080"), }, }, { Level: slog.LevelInfo, Msg: "metrics cache initialized", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "controller.health"), slog.String("next_in", "15s"), }, }, { Level: slog.LevelInfo, Msg: "registered in component registry", Attrs: []slog.Attr{ slog.String("component", "controller"), slog.String("subsystem", "controller.heartbeat"), slog.String("hostname", "web-03"), slog.String("type", "controller"), slog.String("key", "controller.web-03"), }, }, }
StartLogs are the lines that the controller writes at the info level when it starts with the default config, which the docs page of the command shows as the log handler writes them. osapi start writes them too.
Functions ¶
func Components ¶
Components makes the controller, and its metrics server when the config turns it on: the parts that osapi start runs too. The metrics server also serves the HTTP metrics of the API, so it is made first.
Types ¶
type Controller ¶
type Controller interface {
command.Component
CheckHealth(ctx context.Context) error
SubComponents() map[string]job.SubComponentInfo
}
Controller is the controller, which controller.New makes.
type Deps ¶
type Deps struct {
Config config.Config
ConfigFile string
Logger *slog.Logger
Version string
// Tracer starts the tracer of the service name, and returns what
// flushes and stops it.
Tracer func(ctx context.Context, name string) (func(context.Context) error, error)
NewController func(
ctx context.Context,
log *slog.Logger,
cfg config.Config,
opts ...controller.Option,
) (Controller, error)
}
Deps is what start uses: the config, the log, the version of the binary, and what starts the tracer and makes the controller.