Documentation
¶
Overview ¶
Package agentcmd is the agent group: osapi agent start, which runs the agent on a managed host. The package is not named agent, which is the agent itself.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Defaults = config.AgentConfig{ NATS: config.NATSConnection{ Host: "localhost", Port: 4222, ClientName: "osapi-agent", Namespace: "osapi", Auth: config.NATSAuth{Type: "none"}, TLS: config.ClientTLS{Enabled: true}, }, Consumer: config.AgentConsumer{ Name: "jobs-agent", MaxDeliver: 5, AckWait: "2m", MaxAckPending: 1000, ReplayPolicy: "instant", BackOff: []string{"30s", "2m", "5m", "15m", "30m"}, InactiveThreshold: "24h", }, MaxJobs: 10, Facts: config.AgentFacts{Interval: "60s"}, Conditions: config.AgentConditions{ MemoryPressureThreshold: 90, HighLoadMultiplier: 2.0, DiskPressureThreshold: 90, }, Metrics: config.MetricsServer{ Enabled: true, Host: "0.0.0.0", Port: 9091, TLS: config.ServerTLS{Enabled: true}, }, PKI: config.AgentPKI{KeyDir: "/etc/osapi/pki/agent"}, }
Defaults are the defaults of the agent section of the config, which agent start owns. osapi config default get prints them.
var Group = command.Register(command.Define( "agent", "Run the agent", command.Flat(), command.Under(command.ParentAgent), command.Uses[Deps](), command.Config("agent", Defaults), command.Process("start"). Short("Start the node agent"). Long("The agent connects to NATS and subscribes to the job streams. It processes\n"+ "each job when the job arrives. It uses a provider for its platform to run\n"+ "each operation, for example node status, DNS queries and ping."). Example(""). Logs(StartLogs...). Example("--agent-max-jobs 20"). Flag( "agent.nats.host", "agent.nats.port", "agent.nats.client_name", "agent.hostname", "agent.max_jobs", "agent.consumer.max_deliver", "agent.consumer.ack_wait", "agent.consumer.max_ack_pending", "agent.consumer.replay_policy", "agent.consumer.back_off", "agent.consumer.inactive_threshold", ). Setup(Start), ))
Group is the agent group's definition. It is flat, Under agent, so its method is osapi agent start.
var StartLogs = []command.LogLine{ { Level: slog.LevelInfo, Msg: "starting node agent", Attrs: []slog.Attr{ slog.String("component", "agent"), slog.String("subsystem", "agent"), }, }, { Level: slog.LevelInfo, Msg: "agent configuration", Attrs: []slog.Attr{ slog.String("component", "agent"), slog.String("subsystem", "agent"), slog.String("machine_id", "d530664edc1c431eb5ef1e9dfd6617a5"), slog.String("hostname", "web-03"), slog.Int("max_jobs", 10), slog.Any("labels", map[string]string{"group": "web.dev.us-east"}), }, }, { Level: slog.LevelInfo, Msg: "registered in agent registry", Attrs: []slog.Attr{ slog.String("component", "agent"), slog.String("subsystem", "agent.heartbeat"), slog.String("machine_id", "d530664edc1c431eb5ef1e9dfd6617a5"), slog.String("hostname", "web-03"), slog.String("key", "agents.d530664edc1c431eb5ef1e9dfd6617a5"), slog.String("ttl", "30s"), }, }, { Level: slog.LevelInfo, Msg: "node agent started successfully", Attrs: []slog.Attr{ slog.String("component", "agent"), slog.String("subsystem", "agent"), }, }, { Level: slog.LevelInfo, Msg: "metrics server started", Attrs: []slog.Attr{ slog.String("component", "agent"), slog.String("subsystem", "metrics"), slog.String("addr", "0.0.0.0:9091"), }, }, { Level: slog.LevelInfo, Msg: "http(s) server started", Attrs: []slog.Attr{ slog.String("component", "agent"), slog.String("subsystem", "metrics"), slog.String("address", "[::]:9091"), }, }, }
StartLogs are the lines that the agent writes at the info level when it starts on Linux 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 agent, and its metrics server when the config turns it on: the parts that osapi start runs too. The cleanup closes the agent's NATS connection.
Types ¶
type Agent ¶
type Agent interface {
command.Component
IsReady() error
SetMeterProvider(mp *sdkmetric.MeterProvider)
SubComponents() map[string]job.SubComponentInfo
LastHeartbeatTime() time.Time
SetVersion(version string)
SetLogLevel(level *slog.LevelVar)
}
Agent is the node agent, which agent.Setup makes.
type Deps ¶
type Deps struct {
Config config.Config
ConfigFile string
Logger *slog.Logger
// LogLevel is the level of Logger, which the agent changes when the
// controller's config of the agent sets a log level. Nil leaves it.
LogLevel *slog.LevelVar
Version string
FS avfs.VFS
// CheckHost is an error when the agent does not support the host.
CheckHost func() error
// 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)
// NewAgent makes the agent, and what closes its NATS connection.
NewAgent func(
ctx context.Context,
log *slog.Logger,
fs avfs.VFS,
cfg config.Config,
mp *sdkmetric.MeterProvider,
) (Agent, func(), error)
}
Deps is what start uses: the config, the log, the version of the binary, the file system, and what checks the host, starts the tracer and makes the agent.