aggregate

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package aggregate holds cross-target rollup helpers for Phase 4 (ADR-0304). KollectClusterInventory uses MergeRows and ExportCoalesce on the export path; namespaced KollectInventory still marshals per-namespace snapshots directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentHash

func ContentHash(payload []byte) string

ContentHash returns a SHA-256 hex digest of an export payload.

func MergeRows

func MergeRows(items []collect.Item, mode DedupeMode) []collect.Item

MergeRows returns items deduped per mode. Order is stable: later items win on conflict.

Types

type DedupeMode

type DedupeMode int

DedupeMode selects how MergeRows collapses overlapping target rows.

const (
	// DedupeKeepAll retains one row per (target, uid) — current inventory behavior.
	DedupeKeepAll DedupeMode = iota
	// DedupeByResourceUID keeps the last row per (namespace, uid) across targets.
	DedupeByResourceUID
)

func DedupeModeFromSpec

DedupeModeFromSpec maps KollectClusterInventory.spec.dedupe to MergeRows mode (ADR-0305).

type ExportCoalesce

type ExportCoalesce struct {
	LastGeneration int64
	LastHash       string
	LastExport     time.Time
}

ExportCoalesce tracks the last successful export fingerprint for debouncing.

func (*ExportCoalesce) RecordExport

func (c *ExportCoalesce) RecordExport(now time.Time, generation int64, payload []byte)

RecordExport stores the fingerprint after a successful export.

func (*ExportCoalesce) ShouldSkip

func (c *ExportCoalesce) ShouldSkip(
	now time.Time,
	minInterval time.Duration,
	generation int64,
	payload []byte,
) bool

ShouldSkip reports whether an export can be coalesced within minInterval. Spec generation bumps and payload checksum changes bypass the interval (same rules as KollectInventory reconciler debounce).

type ResourceUID

type ResourceUID struct {
	Namespace string
	UID       string
}

ResourceUID is the cross-target collapse key when two targets watch the same object.

func ResourceKeyFromItem

func ResourceKeyFromItem(item collect.Item) ResourceUID

ResourceKeyFromItem returns the resource-level dedupe key (namespace + uid).

type RowIdentity

type RowIdentity struct {
	TargetNamespace string
	TargetName      string
	Namespace       string
	Name            string
	UID             string
}

RowIdentity is the stable key for one collected row across targets.

func IdentityFromItem

func IdentityFromItem(item collect.Item) RowIdentity

IdentityFromItem derives a row identity from a collected item.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL