Documentation
¶
Overview ¶
Package health is the endpoint group for the controller's health: the liveness and readiness probes, and the status of each component.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Group = endpoint.Register(endpoint.Define( "health", "Check the health of the controller", endpoint.Area(area.Fleet), endpoint.Title("Health Check API"), endpoint.Tag("health", "Health", "Health check endpoints for liveness, readiness, and detailed status."), endpoint.Uses[Deps](), endpoint.Doc[types.ConditionType]("A condition that an agent or a component evaluates."), endpoint.Get[LivenessInput, Response]("liveness"). Handle(Liveness). ID("GetHealth"). Public(). Describe("Liveness probe"). Explain("Returns 200 if the process is alive. No checks performed."). Returns("Process is alive."). Command("Liveness probe", ""). Example(""). Prints(sampleLiveness). Example("--json"), endpoint.Get[ReadyInput, ReadyResponse]("ready"). Handle(Ready). Sub("ready"). ID("GetHealthReady"). Public(). Describe("Readiness probe"). Explain("Returns 200 when the service is ready to accept traffic."). Returns("Service is ready."). Answers(http.StatusServiceUnavailable, "Service is not ready."). Command("Readiness probe", "The command checks that the controller can reach NATS and the KV buckets."). Example(""). Prints(sampleReady). Example("--json"), endpoint.Get[StatusInput, StatusResponse]("status"). Handle(Status). Sub("status"). ID("GetHealthStatus"). Permission(types.PermHealthRead). Describe("System status and component health"). Explain("Returns per-component health status with system metrics. "+ "Requires authentication."). Returns("The status of each component. A component that is not healthy makes the overall status degraded; the request still succeeds."). Command("System status and component health", "The table has each component that registered: its status, its active\n"+ "conditions, its uptime, and the CPU and memory of its process."). Notes("Each sub-component is under its component, as a tree, with its address\n"+ "and its URL. The checks tell if the controller can reach NATS and the KV\n"+ "buckets. The output also has the counts of the job queue, the streams, the\n"+ "KV buckets and the Object Stores. The command needs a token. --component\n"+ "shows one type of component: controller, nats or agent. Use\n"+ "`osapi client agent list` for the labels and the OS of each agent. When a\n"+ "check fails, the overall status is `degraded`, and the check shows the error."). Example(""). Prints(sampleStatus). Example("--component agent"). Example("--json"). Fails("a component that is not controller, nats or agent", StatusInput{Component: "disk"}), ))
Group is the health group's definition.
Functions ¶
This section is empty.
Types ¶
type AgentDetail ¶
type AgentDetail struct {
Hostname string `json:"hostname" doc:"Agent hostname." example:"web-01"`
Labels string `json:"labels,omitempty" doc:"Formatted label string." example:"group=web.prod"`
Registered string `json:"registered" doc:"Time since last heartbeat registration." example:"15s ago"`
}
AgentDetail is one registered agent.
type AgentStats ¶
type AgentStats struct {
Total int `json:"total" doc:"Total number of registered agents." example:"5"`
Ready int `json:"ready" doc:"Number of agents with Ready status." example:"5"`
Agents []AgentDetail `json:"agents,omitempty" doc:"Per-agent registration details."`
}
AgentStats is the count of the agents, with each one.
type Check ¶
type Check struct {
Name string `json:"name" doc:"What was checked, such as nats." example:"nats"`
Status string `json:"status" doc:"ok, or error." example:"ok" render:"status"`
Error string `json:"error,omitempty" doc:"Why the check failed. Absent when it is ok."`
}
Check is one check that the controller made for its answer, such as its connection to NATS.
type ComponentEntry ¶
type ComponentEntry struct {
Type string `` /* 143-byte string literal not displayed */
Hostname string `` /* 144-byte string literal not displayed */
Status string `` /* 190-byte string literal not displayed */
Conditions []types.ConditionType `` /* 199-byte string literal not displayed */
Age string `` /* 143-byte string literal not displayed */
CPUPercent float32 `` /* 213-byte string literal not displayed */
MemBytes int64 `` /* 211-byte string literal not displayed */
Version string `` /* 174-byte string literal not displayed */
Address string `json:"address,omitempty" doc:"Listen address of a sub-component, such as :8080."`
URL string `json:"url,omitempty" doc:"Where a person opens a sub-component, from its url config key."`
Components []ComponentEntry `` /* 127-byte string literal not displayed */
}
ComponentEntry is one registered component, with its health.
type Deps ¶
type Deps struct {
// Health checks the controller's dependencies and reports the status
// of each component.
Health Reporter
}
Deps is what the health group's handlers use.
type JobStats ¶
type JobStats struct {
Total int `json:"total" doc:"Total number of jobs." example:"100"`
Submitted int `json:"submitted" doc:"Number of jobs that no agent has taken." example:"5"`
Processing int `json:"processing" doc:"Number of jobs currently processing." example:"2"`
Completed int `json:"completed" doc:"Number of completed jobs." example:"90"`
Failed int `json:"failed" doc:"Number of failed jobs." example:"3"`
DLQ int `json:"dlq" doc:"Number of jobs in the dead letter queue." example:"0"`
}
JobStats is the count of the jobs in each state.
type KVBucketInfo ¶
type KVBucketInfo struct {
Name string `json:"name" doc:"KV bucket name." example:"job-queue"`
Keys int `json:"keys" doc:"Number of keys in the bucket." example:"10"`
Bytes int `json:"bytes" doc:"Total bytes in the bucket." example:"2048" render:"bytes"`
}
KVBucketInfo is one KV bucket.
type LivenessInput ¶
type LivenessInput struct{}
LivenessInput is the input of the liveness probe, which has none.
type NATSInfo ¶
type NATSInfo struct {
URL string `json:"url" doc:"Connected NATS server URL." example:"nats://localhost:4222"`
Version string `json:"version" doc:"NATS server version." example:"2.10.0"`
}
NATSInfo is the NATS server the controller is connected to.
type ObjectStoreInfo ¶
type ObjectStoreInfo struct {
Name string `json:"name" doc:"Object Store bucket name." example:"file-objects"`
Size int `json:"size" doc:"Total bytes in the store." example:"5242880" render:"bytes"`
}
ObjectStoreInfo is one Object Store bucket.
type ReadyInput ¶
type ReadyInput struct{}
ReadyInput is the input of the readiness probe, which has none.
type ReadyResponse ¶
type ReadyResponse struct {
Status string `json:"status" doc:"Readiness status." example:"ready" render:"status"`
Error string `json:"error,omitempty" doc:"Error message when not ready."`
}
ReadyResponse is the readiness probe's answer.
func Ready ¶
func Ready( ctx context.Context, d Deps, _ ReadyInput, ) (ReadyResponse, error)
Ready says whether the controller can take traffic, and why not with a 503.
type Reporter ¶
type Reporter interface {
// Ready is nil when the controller can take traffic.
Ready(ctx context.Context) error
// Status is the health of each component. Its status is degraded when
// one is not healthy.
Status(ctx context.Context) StatusResponse
}
Reporter checks the controller's health. internal/controller/health is the controller's.
type Response ¶
type Response struct {
Status string `json:"status" doc:"Health status." example:"ok" render:"status"`
// contains filtered or unexported fields
}
Response is the liveness probe's answer.
type StatusInput ¶
type StatusInput struct {
Component types.ComponentType `` /* 171-byte string literal not displayed */
}
StatusInput is the input of status: the type of component to show.
type StatusResponse ¶
type StatusResponse struct {
Status string `` /* 190-byte string literal not displayed */
Version string `` /* 174-byte string literal not displayed */
Uptime string `` /* 174-byte string literal not displayed */
Checks []Check `` /* 158-byte string literal not displayed */
Registry []ComponentEntry `` /* 209-byte string literal not displayed */
Jobs *JobStats ` json:"jobs,omitempty"`
Streams []StreamInfo ` json:"streams,omitempty" doc:"JetStream stream statistics."`
KVBuckets []KVBucketInfo `` /* 209-byte string literal not displayed */
ObjectStores []ObjectStoreInfo ` json:"object_stores,omitempty" doc:"Object Store statistics."`
Consumers int `` /* 185-byte string literal not displayed */
NATS *NATSInfo `` /* 185-byte string literal not displayed */
Agents *AgentStats `` /* 185-byte string literal not displayed */
// contains filtered or unexported fields
}
StatusResponse is the health of each component, with the metrics of the system.
func Status ¶
func Status( ctx context.Context, d Deps, in StatusInput, ) (StatusResponse, error)
Status is the health of each component. A component that is not healthy makes the status degraded; the request still succeeds, because it is a report and not a probe. Ready is the probe.
type StreamInfo ¶
type StreamInfo struct {
Name string `json:"name" doc:"Stream name." example:"JOBS"`
Messages int `json:"messages" doc:"Number of messages in the stream." example:"42"`
Bytes int `json:"bytes" doc:"Total bytes in the stream." example:"1024" render:"bytes"`
Consumers int `json:"consumers" doc:"Number of consumers on the stream." example:"1"`
}
StreamInfo is one JetStream stream.