rollout

package
v0.10.459 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusInProgress = "in_progress"
	StatusCompleted  = "completed"
	StatusRolledBack = "rolled_back"
	StatusStalled    = "stalled"
	// StatusSuperseded — v0.10.199: çekilen revizyonun satırı terminal (devralındı).
	StatusSuperseded = "superseded"
)
View Source
const (
	RunOK      = "ok"
	RunPartial = "partial"
	RunFailed  = "failed"
	RunSkipped = "skipped" // kapanışta (ctx iptali) yarıda kesilen tik — arıza değil
)
View Source
const (
	MatchService = "service" // workload_revision_activity_1m: servis bu revizyonda span üretti
	MatchPod     = "pod"     // problemin pod'u revizyonun ReplicaSet'ine ait
)

MatchedBy — adayın Problem'e nasıl bağlandığı.

View Source
const (
	BandHigh = "high"
	BandLow  = "low"

	HighBandMaxMin         = 30
	LowBandMaxMin          = 120
	AfterOnsetToleranceMin = 5

	// MaxScored — Rank'ın döndürdüğü en fazla aday (RootCausePanel 3 satır).
	MaxScored = 3
)
View Source
const SettingsKey = "rollouts"

Variables

This section is empty.

Functions

func AlignBucket

func AlignBucket(t time.Time, d time.Duration) time.Time

AlignBucket — EPOCH hizalı kova başı: CH `toStartOfInterval` ile aynı ızgara. Go `Truncate` yıl-1'e göre hizalar; 1/5/10/15/30 dk dışındaki kovalarda iki ızgara ayrışır ve aynı MV satırı iki farklı karar kovasına düşerdi.

func JoinKSM added in v0.10.212

func JoinKSM(clusterID string, sets map[string][]KSMSample) (map[Key]map[string]KSMRev, error)

JoinKSM — SAF: örnek kümeleri → Key(cluster,ns,workload) → RS → KSMRev. Sahipsiz RS (owner eşleşmesi yok) atlanır: iş yüküne bağlanamaz.

func KSMQueries added in v0.10.212

func KSMQueries() map[string]string

KSMQueries — sorgu haritası; adlar audit §7 doğrulama listesiyle birebir. Seçiciler cluster matcher TAŞIMAZ — thanos.doQuery enjekte eder.

func MapFirstSeen

func MapFirstSeen(rows []FirstSeenRow, refs []ClusterRef) (map[Key]map[string]time.Time, map[string]time.Time)

MapFirstSeen — span cluster değeri → registry id (MapClusters ile aynı eşleme). İkinci dönüş: küme (ClusterID) başına MV veri başlangıcı. SAF.

func RevisionKey added in v0.10.242

func RevisionKey(r Rollout) string

RevisionKey — (cluster, ns, workload, revision) kimliği; tekilleştirme anahtarı. (reconcile.go'daki Key tipi kova-düzeyi anahtar; bu string.)

func SubjectID added in v0.10.242

func SubjectID(r Rollout) string

SubjectID — ScoredCause.Service alanına yazılan özne ("rollout:" öneki ile FE ayırt eder; problemSubject.ts ext: emsali).

func ValidateSettings added in v0.10.200

func ValidateSettings(s Settings) error

ValidateSettings — PUT kapısı: anlaşılmaz girdi 400 olsun (kelepçe yine okumada — Resolved; operatör girdiğini geri görür, uygulananı resolved'da).

Types

type Activity

type Activity struct {
	ClusterID string // Remote Cluster EffectiveID (çağıran eşler; eşlenmeyen düşürülür ve sayılır)
	Namespace string
	Workload  string
	Kind      string
	Revision  string
	Bucket    time.Time // KARAR kovasının başı; çağıran 1 dk satırlarını hizalar (AlignBucket)
	Spans     int64
	FirstSeen time.Time
	LastSeen  time.Time
	Image     string
	ImageTag  string
}

Activity — MV'den okunan bir (cluster, ns, workload, revision, kova) satırı.

func MapClusters

func MapClusters(rows []ActivityRow, refs []ClusterRef) ([]Activity, map[string]int)

MapClusters — span cluster değeri → registry id (entity.GroupSeenByCluster deseni). SAF.

type ActivityRow

type ActivityRow struct {
	ClusterValue, Namespace, Workload, Kind, Revision string
	Bucket                                            time.Time
	Spans                                             int64
	FirstSeen, LastSeen                               time.Time
	Image, ImageTag                                   string
}

ActivityRow — chstore.RolloutActivityRow'un paket-içi ikizi (cluster = span DEĞERİ).

type Candidate added in v0.10.242

type Candidate struct {
	Rollout   Rollout
	MatchedBy string
}

Candidate — puanlanacak ham aday.

type ClusterRef

type ClusterRef struct {
	ID                string
	Name              string
	SpanClusterValue  string
	SpanClusterValues []string
}

ClusterRef — registry kaydı (entity.ClusterRef ile aynı şekil; import döngüsü olmasın diye kopya).

type ClusterSource

type ClusterSource interface {
	Clusters() []ClusterRef
}

ClusterSource — registry (thanos.Service adaptörü; testte sahte).

type Config

type Config struct {
	Bucket         time.Duration // karar kovası (5 dk)
	Threshold      int64         // kovada aktif sayılmak için span (10)
	Hysteresis     int           // GİRİŞ: ardışık kova (2)
	ExitHysteresis int           // ÇIKIŞ: "çekildi" için ardışık inaktif kova (6 = 30 dk)
	OverlapMax     time.Duration // bu süreden uzun çakışma → çok-revizyonlu notu (30 dk)
	WeakSignal     bool          // zayıf sinyal notu (varsayılan açık)
	StalledMin     time.Duration // KSM: ready < istenen bu süreden uzun → stalled (0 = kapalı)
}

Config — ayarlanabilir eşikler (system_settings["rollouts"]).

func DefaultConfig

func DefaultConfig() Config

type FirstSeenRow

type FirstSeenRow struct {
	ClusterValue, Namespace, Workload, Revision string
	First                                       time.Time
}

FirstSeenRow — chstore.RolloutFirstSeen satırı (cluster = span DEĞERİ).

type Input

type Input struct {
	Now time.Time
	// WindowStart — etkinlik sorgusunun GERÇEK başı (align(now − lookback));
	// sıfırsa anahtarın ilk verili kovası (test kolaylığı).
	WindowStart time.Time
	Prev        []Rollout
	Acts        []Activity
	// FirstSeen — 6 g ufkunda (MV TTL − 1) revizyonun ilk görüldüğü kova (Key → revision →
	// kova); pencere dışı geçmiş. nil = ufuk yok (yalnız tablo satırları).
	FirstSeen map[Key]map[string]time.Time
	// DataStart — kümenin (ClusterID) MV geçmişinin ilk kovası (ufuk içinde).
	DataStart map[string]time.Time
	// Truncated — etkinlik okuması tavana takıldı: etkinliği görünmeyen iş
	// yükleri için "yokluk" kanıt DEĞİLDİR (bayat satır notu atlanır).
	Truncated bool
	// KSM — Faz 5 (v0.10.212): Thanos/kube-state-metrics RS anlık görüntüsü
	// (Key → revizyon(RS adı) → KSMRev). nil/eksik anahtar = aile yok →
	// spans tek kaynak, stalled üretilmez (audit §7 kabulü).
	KSM map[Key]map[string]KSMRev
}

Input — Reconcile girdisi.

type KSMRev added in v0.10.212

type KSMRev struct {
	Spec, Ready float64
	CreatedAt   time.Time // kube_replicaset_created (0 = seri yok)
}

KSMRev — bir ReplicaSet'in KSM anlık görüntüsü.

type KSMSample added in v0.10.212

type KSMSample struct {
	Labels map[string]string
	Value  float64
}

KSMSample — thanos.Sample'ın paket-içi aynası (entity.Sample emsali).

type KSMSource added in v0.10.212

type KSMSource interface {
	FetchKSM(ctx context.Context, ref ClusterRef) (map[Key]map[string]KSMRev, error)
}

KSMSource — Thanos adaptörü (main.go rolloutKSMSource; testte sahte).

type Key

type Key struct{ ClusterID, Namespace, Workload string }

Key — iş yükü kimliği.

type Reconciler

type Reconciler struct {
	// contains filtered or unexported fields
}

Reconciler — tek yazıcı.

func New

func New(store Store, clusters ClusterSource, resolved func() Resolved) *Reconciler

func (*Reconciler) LastRun

func (r *Reconciler) LastRun() (Run, bool)

LastRun — son tikin KOPYASI (canlı işaretçi dışarı sızmaz).

func (*Reconciler) Run

func (r *Reconciler) Run(ctx context.Context)

Run — periyodik döngü; aralık ayardan, uyku 30 s adımlarla (ayar değişince kalan süre yeniden hesaplanır — 15 dk → 30 s değişikliği 15 dk gecikmez). İlk tik SetOnAcquire'dan gelir (entity syncer emsali: Run bir aralık bekler).

func (*Reconciler) SetKSMSource added in v0.10.212

func (r *Reconciler) SetKSMSource(s KSMSource)

SetKSMSource — Faz 5 (v0.10.212): Thanos KSM adaptörü (nil = ayak kapalı).

func (*Reconciler) SetLeaderCheck

func (r *Reconciler) SetLeaderCheck(f func() bool)

func (*Reconciler) Tick

func (r *Reconciler) Tick(ctx context.Context) bool

Tick — bir tur; örtüşen çağrı (onAcquire + ticker) atlanır. Döner: koştu mu.

type Resolved

type Resolved struct {
	Enabled        bool
	Interval       time.Duration
	Bucket         time.Duration
	Threshold      int64
	Hysteresis     int
	ExitHysteresis int
	OverlapMax     time.Duration
	Lookback       time.Duration
	WeakSignal     bool
	StalledMin     time.Duration
}

func (Resolved) Config

func (r Resolved) Config() Config

Config — saf çekirdeğin girdisi (reconcile.go).

type Rollout

type Rollout struct {
	ClusterID          string
	Namespace          string
	Workload           string
	Kind               string
	Revision           string
	StartedAt          time.Time
	Status             string
	PrevRevision       string
	Image              string
	ImageTag           string
	PrevImage          string
	PrevImageTag       string
	FirstSpanAt        time.Time
	TrafficConfirmedAt time.Time
	KSMStartedAt       time.Time
	PodsReadyAt        time.Time
	KSMNotReadySince   time.Time
	CompletedAt        time.Time
	DetectedBy         string
	SpanCount          int64
	Note               string
}

Rollout — workload_rollouts satırı (kimlik = ClusterID, Namespace, Workload, Revision, StartedAt). Yalnız TABLODAKİ alanlar: değişiklik tespiti (rolloutEqual) bunlarla yapılır. SpanCount = koşu boyunca görülen en büyük karar-penceresi toplamı (kayan pencere; olayın mutlak span sayısı değil).

func Reconcile

func Reconcile(cfg Config, in Input) []Rollout

Reconcile — SAF. Döner: değişen/yeni satırlar (upsert listesi).

type Run

type Run struct {
	StartedAt, FinishedAt time.Time
	Host                  string // yazan pod (ORDER BY ayırıcısı)
	Status                string // ok | partial | failed | skipped
	Clusters              int
	RolloutsWritten       int
	SpanMs, KSMMs         int
	Error                 string
}

Run — rollout_reconcile_runs satırı. JSON: camelCase + epoch-ms zamanlar (RolloutRow ile aynı sözleşme; /api/rollouts/runs v0.10.200).

func (Run) MarshalJSON

func (r Run) MarshalJSON() ([]byte, error)

type Scored added in v0.10.242

type Scored struct {
	Rollout   Rollout
	MatchedBy string
	AgeMin    int // rollout başlangıcı → problem başlangıcı, dakika (negatif = problemden sonra)
	Band      string
	Score     float64
	Reason    string
}

Scored — puanlanmış aday; Reason operatörün okuyacağı tek cümle.

func Rank added in v0.10.242

func Rank(onset time.Time, cands []Candidate) []Scored

Rank — adayları puanlar, (cluster,ns,workload,revision) ile tekilleştirir (pod eşlemesi servis eşlemesini yener: daha yüksek puan kalır), puana göre sıralar (eşitlikte problem başlangıcına yakın olan önce) ve MaxScored ile keser.

func Score added in v0.10.242

func Score(onset time.Time, c Candidate) (Scored, bool)

Score — tek adayı puanlar; ok=false → pencere dışı, aday değil.

type Settings

type Settings struct {
	Enabled    bool   `json:"enabled"`
	Interval   string `json:"interval,omitempty"`   // reconciler tiki (60s)
	Bucket     string `json:"bucket,omitempty"`     // karar kovası (5m; düşük trafikte 10m) — 1m/5m/10m/15m/30m
	Threshold  int64  `json:"threshold,omitempty"`  // kovada aktif sayılmak için span (10)
	Hysteresis int    `json:"hysteresis,omitempty"` // GİRİŞ: ardışık kova (2)
	// ExitHysteresis — ÇIKIŞ: "çekildi" için ardışık inaktif kova (6 = 30 dk):
	// gece dalması / pod restart olay değildir (inceleme 2. tur).
	ExitHysteresis int    `json:"exitHysteresis,omitempty"`
	OverlapMax     string `json:"overlapMax,omitempty"` // çok-revizyonlu notu eşiği (30m)
	Lookback       string `json:"lookback,omitempty"`   // etkinlik penceresi (6h)
	// WeakSignal — "yeni revizyon son kovada eşik altında kaldı" notu (audit §11 vidası; nil = açık).
	WeakSignal *bool `json:"weakSignal,omitempty"`
	// StalledMin — Faz 5 (KSM): ready < desired bu süreden uzun → stalled (10m). Bugün yalnız saklanır/kelepçelenir.
	StalledMin string `json:"stalledMin,omitempty"`
	UpdatedAt  int64  `json:"updatedAt,omitempty"`
}

func DefaultSettings

func DefaultSettings() Settings

func (Settings) Resolved

func (s Settings) Resolved() Resolved

Resolved — kelepçeler: interval 30s..15m, bucket {1,5,10,15,30}m, threshold 1..1e6, hysteresis 2..12 VE hysteresis×bucket ≥ 10 dk (1 dk kovada 2 kova = 2 dk'lık karar çok kırılgan), exitHysteresis hysteresis..36 VE ×bucket ≥ 30 dk, overlapMax 5m..6h ve ≤ lookback/2, lookback 1h..48h ve ≥ 4×exitHysteresis×bucket ve lookback/bucket ≤ 576 kova, stalledMin 2m..2h.

type SettingsService

type SettingsService struct {
	// contains filtered or unexported fields
}

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

func (*SettingsService) Resolved

func (s *SettingsService) Resolved() Resolved

func (*SettingsService) SavePersisted

func (s *SettingsService) SavePersisted(ctx context.Context, store settingsStore, cfg Settings) error

func (*SettingsService) StartConfigRefresh

func (s *SettingsService) StartConfigRefresh(ctx context.Context, store settingsStore, interval time.Duration)

type Store

type Store interface {
	RolloutActivity(ctx context.Context, since time.Time, bucket time.Duration) (rows []ActivityRow, cut string, err error)
	// RolloutFirstSeen — 6 g ufkunda (MV TTL 7 g − 1) (cluster değeri, ns,
	// workload, revision) ilk kovası: bilinen revizyonun dönüşü olay değildir.
	RolloutFirstSeen(ctx context.Context, since time.Time) ([]FirstSeenRow, error)
	RolloutRecentRows(ctx context.Context, since time.Time) ([]Rollout, error)
	RolloutUpsert(ctx context.Context, rows []Rollout) error
	RolloutRecordRun(ctx context.Context, run Run) error
}

Store — chstore kapısı (testte sahte). RolloutActivity: cut = tavanın kestiği (düşürülen) iş yükü anahtarı ("" = kesilmedi).

Jump to

Keyboard shortcuts

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