Documentation
¶
Overview ¶
Package resource defines the core domain types for Kubernetes resource tracking. These types are independent of any TUI framework and can be used by the store, simulation, analysis, and presentation layers.
Index ¶
- Constants
- func CloneMap(m map[string]any) map[string]any
- func CompareRevisionsNewestFirst(a, b Revision) int
- func DeepEqual(a, b map[string]any) bool
- func FormatTimestamp(t time.Time) string
- func GroupTimelineByBurst(entries []TimelineEntry, window time.Duration) []any
- func MatchesSubstring(query string, r Resource) bool
- func RelativeTime(t time.Time) string
- func SortByKindName(rds []*Data)
- func SortTimelineNewestFirst(entries []TimelineEntry)
- func WindowHalfDuration(w WindowMode) time.Duration
- type AnalysisResult
- type BurstGroup
- type ChangeTag
- type CompareItem
- type CompareSelection
- type Data
- type EventType
- type Kind
- type KindGroup
- type LoopInfo
- type Resource
- type Revision
- type RevisionID
- type TimelineEntry
- type WindowMode
Constants ¶
const NearSimultaneousWindow = time.Second
NearSimultaneousWindow is the wall-clock gap below which two adjacent revisions are treated as near-simultaneous: their relative order is inferred (from resourceVersion, or arrival) rather than clearly separated in time.
Variables ¶
This section is empty.
Functions ¶
func CloneMap ¶
CloneMap performs a recursive clone of a map[string]any. It recursively clones nested maps and slices, but shares scalar values (which are immutable in Go). Non-JSON collection shapes other than map[string]any, []any, and []map[string]any are shared by reference; this is safe for the unstructured Kubernetes objects loog handles, which decode only into those shapes.
func CompareRevisionsNewestFirst ¶
CompareRevisionsNewestFirst orders two revisions newest-first. It prefers resourceVersion (a global, causal order on etcd-backed clusters) when both revisions carry one, and falls back to wall-clock time otherwise. Returns a value suitable for sort funcs (<0 if a should sort before b).
func DeepEqual ¶
DeepEqual compares two maps for equality using the fast path from diffmap (type-switch based) which avoids the cost of reflect.DeepEqual for the common types found in Kubernetes objects.
func FormatTimestamp ¶
FormatTimestamp returns a short timestamp like "14:32:05".
func GroupTimelineByBurst ¶
func GroupTimelineByBurst(entries []TimelineEntry, window time.Duration) []any
GroupTimelineByBurst groups timeline entries into bursts. Entries within the given window duration of each other are grouped together. Returns a slice of either TimelineEntry or BurstGroup values.
func MatchesSubstring ¶
MatchesSubstring returns true if the query (already lowercased) appears as a case-insensitive substring in any of the resource's name, kind, namespace, or kind/name combination. Returns true for an empty query.
func RelativeTime ¶
RelativeTime formats a time as a human-readable relative string (e.g., "5m", "2h").
func SortByKindName ¶
func SortByKindName(rds []*Data)
SortByKindName sorts a slice of *Data by kind then name (ascending).
func SortTimelineNewestFirst ¶
func SortTimelineNewestFirst(entries []TimelineEntry)
SortTimelineNewestFirst sorts timeline entries in place, newest-first, using causal order where resourceVersion is available (see CompareRevisionsNewestFirst).
func WindowHalfDuration ¶
func WindowHalfDuration(w WindowMode) time.Duration
WindowHalfDuration returns the half-span for a WindowMode. Returns 0 for WindowAll (no filter).
Types ¶
type AnalysisResult ¶
type AnalysisResult struct {
ResourceUID string
Tags map[RevisionID][]ChangeTag
LoopInfo LoopInfo
}
AnalysisResult holds the result of background analysis for a resource.
func Analyze ¶
func Analyze(rd *Data, loopWindowSize int) AnalysisResult
Analyze performs synchronous analysis on a Data: tags each revision and detects reconcile loops. This is a pure computation with no side effects.
type BurstGroup ¶
type BurstGroup struct {
Entries []TimelineEntry
}
BurstGroup represents a group of timeline entries that occurred within a short window, likely from a single operator reconciliation cycle.
type ChangeTag ¶
type ChangeTag string
ChangeTag classifies what kind of change a revision represents.
func TagRevision ¶
TagRevision classifies a revision by comparing two object states. Returns one or more tags describing what changed.
type CompareItem ¶
CompareItem is one side of a comparison.
type CompareSelection ¶
type CompareSelection struct {
Left *CompareItem
Right *CompareItem
}
CompareSelection holds the two items being compared.
type Data ¶
type Data struct {
Resource Resource
Revisions []Revision // sorted oldest-first (index 0 = oldest)
}
Data holds a resource and all its revisions.
func (*Data) AnalyzeLoop ¶
AnalyzeLoop performs detailed loop analysis on recent revisions.
func (*Data) ChangeFrequency ¶
ChangeFrequency returns changes per minute over the resource's lifetime.
func (*Data) CreationTime ¶
CreationTime returns the Kubernetes creationTimestamp from the first revision's object metadata. Returns zero time if unavailable.
func (*Data) DetectLoop ¶
DetectLoop checks if the resource is oscillating between states. It returns true if among the last windowSize revisions, the same object state appears more than once (indicating a reconcile loop).
func (*Data) LatestRevision ¶
LatestRevision returns the most recent revision, or nil if empty.
func (*Data) RevisionCount ¶
type Kind ¶
type Kind struct {
Kind string // e.g., "Pod", "Deployment", "Secret"
APIVersion string // e.g., "v1", "apps/v1"
Resource string // plural resource name, e.g., "pods", "deployments"
Namespaced bool // whether instances live in a namespace
}
Kind represents a Kubernetes resource type (CRD or built-in) available on the cluster.
type KindGroup ¶
KindGroup represents a collapsible group in the resource tree.
func BuildKindGroups ¶
BuildKindGroups organizes resources into kind groups for tree display. Groups are sorted in a preferred Kubernetes kind order, and resources within each group are sorted by name.
type LoopInfo ¶
type LoopInfo struct {
IsLoop bool
// DistinctStates is the number of unique object states in the loop (e.g., 2 for A<->B).
DistinctStates int
// Cycles counts complete oscillation cycles. For A->B->A->B->A, there are 2 full cycles.
Cycles int
// Period is the average duration of one full cycle.
Period time.Duration
FirstSeen time.Time
// LoopRevisions maps revision IDs to their state group label ("A", "B", ...).
LoopRevisions map[RevisionID]string
// PatternSample is a short pre-built sample of the oscillation pattern
// from the tail of the window, e.g., "A->B->A->B". At most 6 labels.
PatternSample string
}
LoopInfo holds detailed information about a detected reconcile loop.
type Resource ¶
Resource represents a tracked Kubernetes resource instance.
type Revision ¶
type Revision struct {
ID RevisionID
PreviousID RevisionID
EventType EventType
Time time.Time
Object map[string]any // full state at this revision
Patch map[string]any // diff from previous (nil for ADD/snapshots)
// ResourceVersion is the Kubernetes metadata.resourceVersion parsed as a
// uint64, or 0 if absent/unparseable. On etcd-backed clusters it is a
// global, monotonically increasing revision, so it orders changes across
// different resources by true causal order - unlike Time, which is only
// loog's observation time and can invert for near-simultaneous events on
// separate watch streams.
ResourceVersion uint64
}
Revision represents a single recorded version of a resource.
type RevisionID ¶
type RevisionID = store.RevisionID
RevisionID is a 64-bit revision identifier displayed as hex. It is a type alias for store.RevisionID so the two are interchangeable.
type TimelineEntry ¶
TimelineEntry represents a single entry in the unified timeline.
type WindowMode ¶
type WindowMode int
WindowMode represents a time window centered on a selected revision.
const ( WindowAll WindowMode = iota Window15s Window30s Window1m Window5m )
func NextWindowMode ¶
func NextWindowMode(current WindowMode) WindowMode
NextWindowMode cycles: all -> +/-15s -> +/-30s -> +/-1m -> +/-5m -> all.
func (WindowMode) String ¶
func (w WindowMode) String() string