Documentation
¶
Index ¶
- type IngestService
- type K8sAlertCallback
- type K8sAlertChecker
- type K8sClusterOverview
- type K8sCondition
- type K8sContainerStatus
- type K8sEvent
- type K8sEventRef
- type K8sNamespaceSummary
- type K8sNode
- type K8sPod
- type K8sPodStatusBreakdown
- type K8sResourceQuantity
- type K8sWorkload
- type K8sWorkloadGroup
- type NamespaceFilter
- type NodeResourceMetrics
- type PodFilters
- type PodResourceMetrics
- type Runtime
- func (r *Runtime) Close() error
- func (r *Runtime) ClusterOverview(ctx context.Context) (*K8sClusterOverview, error)
- func (r *Runtime) Connect(ctx context.Context) error
- func (r *Runtime) DiscoverAll(ctx context.Context) ([]*cmodel.Container, error)
- func (r *Runtime) FetchLogSnippet(ctx context.Context, externalID string) (string, error)
- func (r *Runtime) FetchLogs(ctx context.Context, externalID string, lines int, timestamps bool) ([]string, error)
- func (r *Runtime) GetHealthInfo(ctx context.Context, externalID string) (*runtime.HealthInfo, error)
- func (r *Runtime) GetNodeMetrics(ctx context.Context, name string) (*NodeResourceMetrics, error)
- func (r *Runtime) GetPodDetail(ctx context.Context, namespace, name string) (*K8sPod, []K8sEvent, error)
- func (r *Runtime) GetPodMetrics(ctx context.Context, namespace, name string) (*PodResourceMetrics, error)
- func (r *Runtime) GetWorkload(ctx context.Context, id string) (*K8sWorkload, []K8sPod, []K8sEvent, error)
- func (r *Runtime) IsConnected() bool
- func (r *Runtime) ListAllEvents(ctx context.Context) ([]K8sEventRef, error)
- func (r *Runtime) ListContainerNames(ctx context.Context, externalID string) ([]string, error)
- func (r *Runtime) ListNamespaces(ctx context.Context) ([]string, error)
- func (r *Runtime) ListNodes(ctx context.Context) ([]K8sNode, error)
- func (r *Runtime) ListPods(ctx context.Context, namespaces []string, filters PodFilters) ([]K8sPod, error)
- func (r *Runtime) ListWorkloads(ctx context.Context, namespaces []string) ([]K8sWorkloadGroup, error)
- func (r *Runtime) MetricsAvailable() bool
- func (r *Runtime) Name() string
- func (r *Runtime) SetDisconnected()
- func (r *Runtime) StatsSnapshot(ctx context.Context, externalID string) (*runtime.RawStats, error)
- func (r *Runtime) StreamEvents(ctx context.Context) <-chan runtime.RuntimeEvent
- func (r *Runtime) StreamLogs(ctx context.Context, externalID string, lines int, timestamps bool) (io.ReadCloser, error)
- func (r *Runtime) TryConnect(ctx context.Context) error
- type SnapshotSource
- type TopologySnapshot
- type TopologyStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IngestService ¶ added in v1.3.0
type IngestService struct {
// contains filtered or unexported fields
}
IngestService reconciles a Kubernetes topology snapshot reported by an agent (or by the server's own local runtime under the LocalAgent id) into the store. It implements agentserver.KubernetesTopologyHandler.
func NewIngestService ¶ added in v1.3.0
func NewIngestService(store TopologyStore, logger *slog.Logger) *IngestService
NewIngestService wires the Kubernetes topology ingest service.
func (*IngestService) HandleAgentEvent ¶ added in v1.3.0
func (s *IngestService) HandleAgentEvent(ctx context.Context, agentID string, ev *agentpb.KubernetesTopology) error
HandleAgentEvent reconciles a full Kubernetes topology snapshot reported by a remote agent over gRPC.
func (*IngestService) Reconcile ¶ added in v1.3.0
func (s *IngestService) Reconcile(ctx context.Context, agentID string, snap TopologySnapshot) error
Reconcile hard-reconciles a domain snapshot for agentID into the store. Used directly by the server's local-runtime reconcile loop (under LocalAgent) and indirectly by HandleAgentEvent for remote agents.
func (*IngestService) SetBroadcaster ¶ added in v1.3.0
func (s *IngestService) SetBroadcaster(fn func(eventType string, data any))
SetBroadcaster wires an SSE broadcaster. When set, a kubernetes.topology_changed event carrying the agent id is emitted after a remote agent's snapshot is reconciled, so connected clients scoped to that agent refetch.
type K8sAlertCallback ¶ added in v1.2.0
K8sAlertCallback is the function signature for emitting alert events.
type K8sAlertChecker ¶ added in v1.2.0
type K8sAlertChecker struct {
// contains filtered or unexported fields
}
K8sAlertChecker detects alert conditions in Kubernetes workloads and nodes.
func NewK8sAlertChecker ¶ added in v1.2.0
func NewK8sAlertChecker(logger *slog.Logger) *K8sAlertChecker
NewK8sAlertChecker creates a new K8sAlertChecker.
func (*K8sAlertChecker) CheckCrashLoopBackOff ¶ added in v1.2.0
func (c *K8sAlertChecker) CheckCrashLoopBackOff(pods []K8sPod)
CheckCrashLoopBackOff checks pods for crash-loop patterns based on restart counts. A pod is considered in crash-loop when it accumulates defaultCrashLoopRestarts or more restart increments within defaultCrashLoopWindow.
func (*K8sAlertChecker) CheckNodeConditions ¶ added in v1.2.0
func (c *K8sAlertChecker) CheckNodeConditions(nodes []K8sNode)
CheckNodeConditions checks nodes for unhealthy conditions: NotReady, MemoryPressure, DiskPressure, PIDPressure.
func (*K8sAlertChecker) CheckWorkloadReplicas ¶ added in v1.2.0
func (c *K8sAlertChecker) CheckWorkloadReplicas(workloads []K8sWorkload)
CheckWorkloadReplicas checks for workloads where ready < desired for longer than the grace period. Returns IDs of workloads that should alert.
func (*K8sAlertChecker) SetAlertCallback ¶ added in v1.2.0
func (c *K8sAlertChecker) SetAlertCallback(cb K8sAlertCallback)
SetAlertCallback sets the callback for emitting alerts.
type K8sClusterOverview ¶ added in v1.2.0
type K8sClusterOverview struct {
NamespaceCount int `json:"namespace_count"`
NodeCount int `json:"node_count"`
NodeReadyCount int `json:"node_ready_count"`
PodStatus K8sPodStatusBreakdown `json:"pod_status"`
WorkloadCount int `json:"workload_count"`
WorkloadHealthy int `json:"workload_healthy"`
ClusterHealth string `json:"cluster_health"` // healthy, degraded, unhealthy
Namespaces []K8sNamespaceSummary `json:"namespaces"`
}
K8sClusterOverview holds aggregated cluster state for the dashboard.
type K8sCondition ¶ added in v1.2.0
type K8sCondition struct {
Type string
Status string // True, False, Unknown
Reason string
Message string
LastTransition time.Time
}
K8sCondition represents a single Kubernetes condition.
type K8sContainerStatus ¶ added in v1.2.0
type K8sContainerStatus struct {
Name string
Image string
Ready bool
RestartCount int32
State string // running, waiting, terminated
StateReason string
StartedAt *time.Time
}
K8sContainerStatus holds per-container runtime state within a pod.
type K8sEvent ¶ added in v1.2.0
type K8sEvent struct {
Type string
Reason string
Message string
Source string
FirstSeen time.Time
LastSeen time.Time
Count int32
}
K8sEvent is a summarised Kubernetes event (v1.Event).
type K8sEventRef ¶ added in v1.3.0
type K8sEventRef struct {
K8sEvent
InvolvedKind string
InvolvedNamespace string
InvolvedName string
}
K8sEventRef is a K8sEvent plus the object it concerns, so the server can store it per-agent and serve it back for the matching workload or pod detail view.
type K8sNamespaceSummary ¶ added in v1.2.0
type K8sNamespaceSummary struct {
Name string `json:"name"`
WorkloadCount int `json:"workload_count"`
PodCount int `json:"pod_count"`
Healthy bool `json:"healthy"`
}
K8sNamespaceSummary holds per-namespace workload and pod counts.
type K8sNode ¶ added in v1.2.0
type K8sNode struct {
AgentID string // reporting agent; empty/LocalAgent for the server's own cluster
Name string
Roles []string
Conditions []K8sCondition
Status string // ready, not-ready, unknown
Capacity K8sResourceQuantity
Allocatable K8sResourceQuantity
RunningPods int
KubernetesVersion string
OSImage string
Architecture string
CreatedAt time.Time
}
K8sNode represents a Kubernetes cluster node.
type K8sPod ¶ added in v1.2.0
type K8sPod struct {
AgentID string // reporting agent; empty/LocalAgent for the server's own cluster
Name string
Namespace string
Status string // Running, Pending, Succeeded, Failed, Unknown
StatusReason string // CrashLoopBackOff, ImagePullBackOff, etc.
RestartCount int32
NodeName string
PodIP string
HostIP string
Containers []K8sContainerStatus
WorkloadRef string // owning workload ID
CreatedAt time.Time
}
K8sPod represents a single Kubernetes pod.
type K8sPodStatusBreakdown ¶ added in v1.2.0
type K8sPodStatusBreakdown struct {
Running int `json:"running"`
Pending int `json:"pending"`
Failed int `json:"failed"`
Succeeded int `json:"succeeded"`
Unknown int `json:"unknown"`
}
K8sPodStatusBreakdown counts pods by phase.
type K8sResourceQuantity ¶ added in v1.2.0
K8sResourceQuantity holds parsed resource capacity values.
type K8sWorkload ¶ added in v1.2.0
type K8sWorkload struct {
ID string // "{namespace}/{kind}/{name}"
AgentID string // reporting agent; empty/LocalAgent for the server's own cluster
Name string
Namespace string
Kind string // Deployment, StatefulSet, DaemonSet, Job
Images []string
ReadyReplicas int32
DesiredReplicas int32
Status string // healthy, degraded, progressing, failed
Conditions []K8sCondition
Labels map[string]string
CreatedAt time.Time
LastTransition time.Time
}
K8sWorkload represents a Kubernetes controller.
type K8sWorkloadGroup ¶ added in v1.2.0
type K8sWorkloadGroup struct {
Namespace string
Workloads []K8sWorkload
}
K8sWorkloadGroup groups workloads by namespace.
type NamespaceFilter ¶
type NamespaceFilter struct {
// contains filtered or unexported fields
}
NamespaceFilter controls which namespaces maintenant monitors.
func NewNamespaceFilter ¶
func NewNamespaceFilter(allowCSV, excludeCSV string) *NamespaceFilter
NewNamespaceFilter creates a filter from env var values. allowCSV = MAINTENANT_K8S_NAMESPACES (comma-separated allowlist). excludeCSV = MAINTENANT_K8S_EXCLUDE_NAMESPACES (comma-separated blocklist, appended to defaults).
func (*NamespaceFilter) IsAllowed ¶
func (f *NamespaceFilter) IsAllowed(namespace string) bool
IsAllowed returns true if the namespace should be monitored.
type NodeResourceMetrics ¶ added in v1.2.0
type NodeResourceMetrics struct {
Name string
CPUMillicores int64
CPUCapacityMillicores int64
MemBytes int64
MemCapacityBytes int64
Timestamp time.Time
}
NodeResourceMetrics holds resource metrics for a single node.
type PodFilters ¶ added in v1.2.0
type PodFilters struct {
Workload string // owning workload ID prefix
Node string // node name
Status string // Running, Pending, etc.
}
PodFilters are optional filters for ListPods.
type PodResourceMetrics ¶ added in v1.2.0
type PodResourceMetrics struct {
Name string
Namespace string
CPUMillicores int64
MemBytes int64
MemLimitBytes int64
Timestamp time.Time
}
PodResourceMetrics holds aggregated resource metrics for a single pod.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime implements runtime.Runtime for Kubernetes.
func NewRuntime ¶
func NewRuntime(logger *slog.Logger, nsFilter *NamespaceFilter) (*Runtime, error)
NewRuntime creates a Kubernetes runtime. Connection is deferred to Connect().
func (*Runtime) ClusterOverview ¶ added in v1.2.0
func (r *Runtime) ClusterOverview(ctx context.Context) (*K8sClusterOverview, error)
ClusterOverview aggregates cluster-wide state from namespaces, nodes, workloads, and pods into a single overview structure.
func (*Runtime) DiscoverAll ¶
func (*Runtime) FetchLogSnippet ¶
FetchLogSnippet retrieves the last 50 lines for die event snippets. Satisfies container.LogFetcher interface.
func (*Runtime) GetHealthInfo ¶
func (*Runtime) GetNodeMetrics ¶ added in v1.2.0
GetNodeMetrics queries metrics-server for a node's CPU and memory usage.
func (*Runtime) GetPodDetail ¶ added in v1.2.0
func (r *Runtime) GetPodDetail(ctx context.Context, namespace, name string) (*K8sPod, []K8sEvent, error)
GetPodDetail returns details for a single pod plus recent events.
func (*Runtime) GetPodMetrics ¶ added in v1.2.0
func (r *Runtime) GetPodMetrics(ctx context.Context, namespace, name string) (*PodResourceMetrics, error)
GetPodMetrics queries metrics-server for a pod's CPU and memory usage.
func (*Runtime) GetWorkload ¶ added in v1.2.0
func (r *Runtime) GetWorkload(ctx context.Context, id string) (*K8sWorkload, []K8sPod, []K8sEvent, error)
GetWorkload returns the detail for a single workload, its pods, and recent events. id format: "namespace/Kind/name".
func (*Runtime) IsConnected ¶
func (*Runtime) ListAllEvents ¶ added in v1.3.0
func (r *Runtime) ListAllEvents(ctx context.Context) ([]K8sEventRef, error)
ListAllEvents returns recent events across all allowed namespaces, each tagged with the object it concerns, so the server can persist them per-agent and serve them back on workload/pod detail views.
func (*Runtime) ListContainerNames ¶
ListContainerNames returns the container names in a workload's pod spec. For controllers, resolves to a pod's spec. For bare pods, reads the pod directly.
func (*Runtime) ListNamespaces ¶ added in v1.2.0
ListNamespaces returns the allowed namespace names from the cluster. The result respects the allowlist/blocklist configured via env vars.
func (*Runtime) ListNodes ¶ added in v1.2.0
ListNodes returns all cluster nodes with their resource capacity and status.
func (*Runtime) ListPods ¶ added in v1.2.0
func (r *Runtime) ListPods(ctx context.Context, namespaces []string, filters PodFilters) ([]K8sPod, error)
ListPods returns a flat pod list optionally filtered by workload, node, and status.
func (*Runtime) ListWorkloads ¶ added in v1.2.0
func (r *Runtime) ListWorkloads(ctx context.Context, namespaces []string) ([]K8sWorkloadGroup, error)
ListWorkloads returns workloads grouped by namespace. When namespaces is non-empty only those namespaces are queried; otherwise all allowed namespaces are included.
func (*Runtime) MetricsAvailable ¶ added in v1.2.0
MetricsAvailable reports whether the metrics-server API was detected on startup.
func (*Runtime) SetDisconnected ¶
func (r *Runtime) SetDisconnected()
func (*Runtime) StatsSnapshot ¶
func (*Runtime) StreamEvents ¶
func (r *Runtime) StreamEvents(ctx context.Context) <-chan runtime.RuntimeEvent
func (*Runtime) StreamLogs ¶
type SnapshotSource ¶ added in v1.3.0
type SnapshotSource interface {
ListNamespaces(ctx context.Context) ([]string, error)
ListWorkloads(ctx context.Context, namespaces []string) ([]K8sWorkloadGroup, error)
ListPods(ctx context.Context, namespaces []string, filters PodFilters) ([]K8sPod, error)
ListNodes(ctx context.Context) ([]K8sNode, error)
ListAllEvents(ctx context.Context) ([]K8sEventRef, error)
}
SnapshotSource is the subset of the Kubernetes runtime needed to build a topology snapshot. *Runtime satisfies it.
type TopologySnapshot ¶ added in v1.3.0
type TopologySnapshot struct {
Namespaces []string
Workloads []K8sWorkload
Pods []K8sPod
Nodes []K8sNode
Events []K8sEventRef
}
TopologySnapshot is a full point-in-time view of an agent's Kubernetes cluster. The server reconciles it against the rows already held for that agent, hard-deleting anything absent from the snapshot. Produced by the server's local runtime (under the LocalAgent id) and by remote agents (under their own id).
func SnapshotFromRuntime ¶ added in v1.3.0
func SnapshotFromRuntime(ctx context.Context, src SnapshotSource) (TopologySnapshot, error)
SnapshotFromRuntime queries the live cluster for namespaces, workloads, pods and nodes. Nodes are best-effort: a cluster-scoped RBAC denial on nodes does not fail the whole snapshot (the agent may only be granted namespaced access).
type TopologyStore ¶ added in v1.3.0
type TopologyStore interface {
ReplaceNamespacesForAgent(ctx context.Context, agentID string, namespaces []string) error
ReplaceWorkloadsForAgent(ctx context.Context, agentID string, workloads []K8sWorkload) error
ReplacePodsForAgent(ctx context.Context, agentID string, pods []K8sPod) error
ReplaceNodesForAgent(ctx context.Context, agentID string, nodes []K8sNode) error
ReplaceEventsForAgent(ctx context.Context, agentID string, events []K8sEventRef) error
}
TopologyStore persists per-agent Kubernetes topology (SQLite-backed).