Documentation
¶
Overview ¶
Package entity — K8s ENTITY KATMANI (v0.10.129, AŞAMA 3 adım 3; docs/plans/entity-layer-design-2026-08-28.md).
cluster > node > namespace > workload > pod > container hiyerarşisi + ayrı service ekseni. Kök kimlik Remote Cluster kaydının id'si (thanos.ClusterConfig.EffectiveID) — keşfedilmez, konfigürasyondan gelir. Bu paket saf çekirdekleri (kimlik, normalizasyon, ömür farkı) ve senkronizasyon işçisini taşır; CH okuma/yazma chstore'da.
Index ¶
- Constants
- func AllowedLabels(in map[string]string) map[string]string
- func ClosedRowsForDead(cid string, dead []SeenRow) ([]EntityRow, []RelationRow)
- func ClusterID(cid string) string
- func ContainerID(cid, ns, pod, ctr string) string
- func GroupSeenByCluster(rows []SeenRow, refs []ClusterRef) (map[string][]SeenRow, map[string]int)
- func NamespaceID(cid, ns string) string
- func NodeID(cid, node string) string
- func Normalize(cid string, s Snapshot) ([]Entity, []Relation)
- func ParseIDOK(id string) bool
- func PodID(cid, ns, pod string) string
- func ResolveWorkload(ns, pod string, idx OwnerIndex) (kind, name string, ok bool)
- func ServiceID(name string) string
- func SnapshotQueries(nsMatcher string) map[string]string
- func SpanSeenToEntities(cid string, rows []SeenRow, known map[string]Entity) ([]Entity, []Relation)
- func WorkloadID(cid, ns, kind, name string) string
- type CHSeen
- type CHStore
- type Change
- type ClusterRef
- type ContainerInfo
- type Entity
- type EntityRow
- type JobOwner
- type Lifetime
- type NodeInfo
- type Observability
- type OwnerIndex
- type PodInfo
- type PodOwner
- type RSOwner
- type Ref
- type Relation
- type RelationRow
- type Resolved
- type Run
- type Sample
- type SampleSets
- type SeenReader
- type SeenRow
- type Settings
- type SettingsService
- func (s *SettingsService) Configure(cfg Settings)
- func (s *SettingsService) Current() Settings
- func (s *SettingsService) LoadPersisted(ctx context.Context, store settingsStore) error
- func (s *SettingsService) Resolved() Resolved
- func (s *SettingsService) SavePersisted(ctx context.Context, store settingsStore, cfg Settings) error
- func (s *SettingsService) StartConfigRefresh(ctx context.Context, store settingsStore, interval time.Duration)
- type Snapshot
- type Source
- type Store
- type Syncer
- func (s *Syncer) Observability() Observability
- func (s *Syncer) Run(ctx context.Context, isLeader func() bool)
- func (s *Syncer) SetLeaderCheck(f func() bool)
- func (s *Syncer) SetSeenReader(r SeenReader)
- func (s *Syncer) Tick(ctx context.Context) bool
- func (s *Syncer) TryTick(ctx context.Context) (ran bool, reason string)
- type ThanosSource
Constants ¶
const ( TypeCluster = "cluster" TypeNode = "node" TypeNamespace = "namespace" TypeWorkload = "workload" TypePod = "pod" TypeContainer = "container" TypeService = "service" )
Varlık tipleri (entities.entity_type).
const ( RelParent = "parent" // cluster→node, cluster→ns, ns→wl, wl→pod, ns→pod (iş yüksüz), pod→ctr RelRunsOn = "runs_on" // pod→node RelRuns = "runs" // pod→service )
İlişki tipleri (entity_relations.rel_type).
const ( SourceThanos = "thanos" SourceSpan = "span" )
Kaynak damgaları (entities.source).
const ( RunOK = "ok" RunPartial = "partial" RunFailed = "failed" RunSkipped = "skipped" )
const BackfillLookback = 24 * time.Hour
BackfillLookback — Tick'in span geçişi penceresi: atama sonrası kısa bir süre (BackfillUntil) 24 saat, sonra normal seenLookback.
const SettingsKey = "entity_layer"
const UnmappedClusterID = "(unmapped)"
UnmappedClusterID — eşlenemeyen span cluster değerlerinin koşu satırı.
Variables ¶
This section is empty.
Functions ¶
func AllowedLabels ¶
AllowedLabels — allow-list süzgeci (+ app.kubernetes.io/* öneki).
func ClosedRowsForDead ¶ added in v0.10.141
func ClosedRowsForDead(cid string, dead []SeenRow) ([]EntityRow, []RelationRow)
ClosedRowsForDead — saf: ölü satırlardan yalnız POD entity'leri (kapalı ömür) + ilişkileri (parent ns→pod, runs pod→svc, runs_on pod→node; hepsi kapalı). Namespace/servis/node kayıtları canlı yoldan gelir; burada üretilmez. Aynı pod'un birden çok satırı (servis başına) birleşir.
func ContainerID ¶
func GroupSeenByCluster ¶
GroupSeenByCluster — satırları cluster_id'ye göre böler; eşlenemeyenleri sayar.
func NamespaceID ¶
func ResolveWorkload ¶
func ResolveWorkload(ns, pod string, idx OwnerIndex) (kind, name string, ok bool)
ResolveWorkload — pod'un iş yükü (tür, ad). ok=false: iş yükü yok (static pod, sahipsiz, bilinmeyen pod).
func SnapshotQueries ¶
SnapshotQueries — seri adı → PromQL. Her sorgu seçici taşır (filtresiz seri taraması YOK); nsMatcher `,namespace=~"…"` biçiminde (thanos. nsMatcher çıktısı) ya da boş. kube_node_info namespace etiketi taşımaz.
func SpanSeenToEntities ¶
SpanSeenToEntities — bir cluster'ın span satırları → ek varlık/ilişki. known: Thanos'un bu tick ürettiği varlıklar (pod çakışmasında kazanır).
func WorkloadID ¶
Types ¶
type CHSeen ¶
type CHSeen interface {
EntitySeenRecent(ctx context.Context, since time.Time) ([]SeenRow, error)
EntitySeenRecentFor(ctx context.Context, since time.Time, clusterValue string) ([]SeenRow, error)
}
CHSeen — chstore.EntitySeenRecent (yapısal tipleme).
type CHStore ¶
type CHStore interface {
EntityOpenLifetimes(ctx context.Context, cid string) (map[string]Lifetime, error)
EntityApply(ctx context.Context, cid string, rows []EntityRow, rels []RelationRow) error
EntityRecordRun(ctx context.Context, run Run) error
EntityIDsExisting(ctx context.Context, cid string, ids []string) (map[string]bool, error)
}
type Change ¶
type Change struct {
Open []Lifetime // yeni ömürler (valid_from = now)
Close []Lifetime // kapanan ömürler (valid_to = eski last_seen)
Refresh []Lifetime // last_seen tazelenen açık ömürler
}
Change — bir tick'in yazım kararı.
type ClusterRef ¶
type ClusterRef struct {
ID string
Name string
NamespaceFilter string // thanos.nsMatcher çıktısı DEĞİL, ham regex
SpanClusterValue string // span `cluster` kolonundaki birincil değer (boş = Name)
// SpanClusterValues — v0.10.139: tüm değerler (teklik Settings'te).
SpanClusterValues []string
}
ClusterRef — Remote Cluster kaydının syncer'a gereken kısmı.
type ContainerInfo ¶
type ContainerInfo struct{ Namespace, Pod, Container, Image string }
type Entity ¶
type Entity struct {
Type string
ClusterID string
ID string
Namespace string
Name string
UID string
ParentID string
Labels map[string]string
Source string
}
Entity — entities satırının yazım-öncesi hâli (ömür alanları diff'te).
type EntityRow ¶
type EntityRow struct {
Type, ClusterID, ID, Namespace, Name, UID, ParentID string
ValidFrom, ValidTo, FirstSeen, LastSeen time.Time
LabelKeys, LabelValues []string
Source string
Stale bool
}
EntityRow / RelationRow — chstore'a giden tam satırlar.
type Lifetime ¶
type Lifetime struct {
ID string
UID string
ValidFrom time.Time
ValidTo time.Time // sıfır = açık
LastSeen time.Time
}
Lifetime — açık ya da kapanmış bir ömür.
type NodeInfo ¶
type NodeInfo struct {
Node, InternalIP, KernelVersion, OSImage, SystemUUID string
}
Thanos etiket setleri (etiket adları = KSM'nin kendi adları).
type Observability ¶
type Observability struct {
Ticks int64
ClustersOK int64
ClustersFailed int64
EntitiesWritten int64
RelationsWritten int64
LastTickMs int64
LastTickAt time.Time
}
Observability — /api/admin/entities/sync + SystemStats.
type OwnerIndex ¶
type OwnerIndex struct {
// contains filtered or unexported fields
}
OwnerIndex — owner zinciri arama tabloları (namespace-kapsamlı).
func IndexOwners ¶
func IndexOwners(s Snapshot) OwnerIndex
IndexOwners — anlık görüntüden arama tabloları.
type Ref ¶
type Ref struct {
Type string
ClusterID string
Namespace string
Kind string // workload türü (Deployment/StatefulSet/…)
Pod string // container için sahibi
Name string
}
Ref — çözülmüş entity_id.
type RelationRow ¶
type Resolved ¶
type Resolved struct {
Enabled bool
SyncInterval time.Duration
PodGap time.Duration
StaleAfter time.Duration
ParallelClusters int
BackfillUntil time.Time // sıfır = yok
BackfillValue string
}
Resolved — kelepçelenmiş, çözülmüş vidalar.
type Run ¶
type Run struct {
ClusterID, Status string
StartedAt time.Time
FinishedAt time.Time
EntitiesWritten int
RelationsWritten int
Closed int
UnmappedKeys []string
UnmappedCounts []uint32
ThanosMs, CHMs int
Error string
}
Run — entity_sync_runs satırı.
type Sample ¶
Sample — bir anlık-sorgu satırı (thanos.Sample'ın paket-içi aynası; thanos paketine bağımlılık taşımamak için kopya).
type SampleSets ¶
type SampleSets struct {
NodeInfo, PodInfo, PodOwner, RSOwner, JobOwner, ContainerInfo []Sample
}
SampleSets — altı serinin yanıtları (kısmi olabilir).
type SeenReader ¶
type SeenReader interface {
RecentSeen(ctx context.Context, since time.Time) ([]SeenRow, error)
// RecentSeenFor — v0.10.141: yalnız bir span cluster değerinin satırları
// (backfill; kesim tavanı o değere uygulanır).
RecentSeenFor(ctx context.Context, since time.Time, clusterValue string) ([]SeenRow, error)
}
SeenReader — chstore.EntitySeenRecent adaptörü.
func SeenFromCH ¶
func SeenFromCH(ch CHSeen) SeenReader
type SeenRow ¶
type SeenRow struct {
ClusterValue, Namespace, Pod, Node, Service string
Spans int
FirstSeen, LastSeen time.Time
}
SeenRow — entity_seen_5m'den bir (cluster, ns, pod, servis) satırı.
func SplitBackfillRows ¶ added in v0.10.141
SplitBackfillRows — saf: değere süz, canlı/ölü ayır. Karar POD başına: aynı pod'un bir satırı (servis) canlıysa TÜM satırları canlıdır — satır başına karar, canlı pod'a eski bir servis satırı yüzünden kapalı ömür yazdırırdı.
type Settings ¶
type Settings struct {
Enabled bool `json:"enabled"`
SyncInterval string `json:"syncInterval,omitempty"`
PodGap string `json:"podGap,omitempty"`
StaleAfter string `json:"staleAfter,omitempty"`
ParallelClusters int `json:"parallelClusters,omitempty"`
// UpdatedAt — v0.10.129: yazım damgası (UnixNano). LoadPersisted daha
// eski bir blobu bellekteki yeninin üstüne yazmaz — PUT'un kendi reload
// sinyali replike olmamış eski satırı okuyup değeri geri alıyordu.
UpdatedAt int64 `json:"updatedAt,omitempty"`
// BackfillUntil — v0.10.141 (otomatik eşleme brief'i): bu ana (ms) kadar
// span geçişi 24 saatlik pencereyle koşar — bir span cluster değeri bir
// kayda ATANDIĞINDA geriye dönük pod/servis entity'leri üretilsin.
// Rol-güvenli: blob üzerinden yayılır, lider Tick'i okur.
BackfillUntil int64 `json:"backfillUntil,omitempty"`
// BackfillValue — geriye dönük geçiş YALNIZ bu span cluster değeri için
// (inceleme: küresel 24 s pencere her cluster'ın ölü pod'larını canlı
// olarak yeniden açıyordu). Boş = backfill yok.
BackfillValue string `json:"backfillValue,omitempty"`
}
Settings — kayıtlı blob.
func DefaultSettings ¶
func DefaultSettings() Settings
type SettingsService ¶
type SettingsService struct {
// contains filtered or unexported fields
}
SettingsService — bellekteki ayar + kalıcılık.
func NewSettingsService ¶
func NewSettingsService() *SettingsService
func (*SettingsService) Configure ¶
func (s *SettingsService) Configure(cfg Settings)
func (*SettingsService) Current ¶
func (s *SettingsService) Current() Settings
func (*SettingsService) LoadPersisted ¶
func (s *SettingsService) LoadPersisted(ctx context.Context, store settingsStore) error
LoadPersisted — boot: blob yoksa varsayılan (kapalı).
func (*SettingsService) Resolved ¶
func (s *SettingsService) Resolved() Resolved
func (*SettingsService) SavePersisted ¶
func (s *SettingsService) SavePersisted(ctx context.Context, store settingsStore, cfg Settings) error
SavePersisted — admin PUT: tam blob + canlı swap.
func (*SettingsService) StartConfigRefresh ¶
func (s *SettingsService) StartConfigRefresh(ctx context.Context, store settingsStore, interval time.Duration)
StartConfigRefresh — çok-pod blob eşitlemesi (30 s).
type Snapshot ¶
type Snapshot struct {
Nodes []NodeInfo
Pods []PodInfo
PodOwners []PodOwner
RSOwners []RSOwner
JobOwners []JobOwner
Containers []ContainerInfo
}
Snapshot — bir cluster'ın tek tick'lik görüntüsü.
func SnapshotFromSamples ¶
func SnapshotFromSamples(ss SampleSets) Snapshot
SnapshotFromSamples — etiket setleri → Snapshot; namespace'siz/adsız satır düşer, tekrarlar tekilleşir (ilk görülen kazanır).
type Source ¶
type Source interface {
Clusters() []ClusterRef
Fetch(ctx context.Context, c ClusterRef, queries map[string]string) (SampleSets, error)
}
Source — Thanos kapısı (thanos.Service adaptörü; testte sahte).
type Store ¶
type Store interface {
OpenLifetimes(ctx context.Context, cid string) (map[string]Lifetime, error)
Apply(ctx context.Context, cid string, rows []EntityRow, rels []RelationRow) error
RecordRun(ctx context.Context, run Run) error
// Existing — v0.10.141: bu id'lerden HERHANGİ bir ömrü olanlar (backfill
// yalnız hiç kaydı olmayan ölü pod'ları yazar; yeniden koşum idempotent).
Existing(ctx context.Context, cid string, ids []string) (map[string]bool, error)
}
Store — CH kapısı (chstore adaptörü; testte bellek).
func StoreFromCH ¶
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
Syncer — durumlu işçi.
func (*Syncer) Observability ¶
func (s *Syncer) Observability() Observability
func (*Syncer) SetLeaderCheck ¶ added in v0.10.141
SetLeaderCheck — main.go LeaderHolder.IsLeader'ı bağlar.
func (*Syncer) SetSeenReader ¶
func (s *Syncer) SetSeenReader(r SeenReader)
SetSeenReader — span-türevli geçiş kaynağı (chstore.EntitySeenRecent).
func (*Syncer) Tick ¶
Tick — bir senkronizasyon turu (bayrak kapalıysa no-op). Tick — bir senkronizasyon turu; aynı pod'da örtüşen tur koşmaz (false döner). Tüm çağıranlar (Run, SetOnAcquire, Run now, TryTick) bu kapıdan geçer — inceleme: kapı yalnız TryTick'teyken API tick'i periyodik tick'le çakışıp aynı ömrü iki kez açabiliyordu.
func (*Syncer) TryTick ¶ added in v0.10.141
TryTick — API tarafından tetiklenen anlık tick: lider değilse koşmaz (inceleme: lider olmayan pod'un tick'i liderin tick'iyle yarışıp aynı ömrü iki kez açıyordu). Örtüşme koruması Tick'in kendisinde — periyodik Run, SetOnAcquire ve "Run now" ucu da aynı kapıdan geçer.
type ThanosSource ¶
type ThanosSource struct {
// contains filtered or unexported fields
}
func NewThanosSource ¶
func NewThanosSource(svc *thanos.Service) *ThanosSource
func (*ThanosSource) Clusters ¶
func (t *ThanosSource) Clusters() []ClusterRef
func (*ThanosSource) Fetch ¶
func (t *ThanosSource) Fetch(ctx context.Context, c ClusterRef, queries map[string]string) (SampleSets, error)