timing

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package timing provides pure functions for computing derived timing fields in the EffectivenessAssessment lifecycle.

These functions are extracted from the EM reconciler to enable unit testing of timing logic independently from K8s API interactions.

Business Requirements: - BR-EM-009: Derived timing computation (ValidityDeadline, CheckAfter, AlertCheckAfter) - BR-EM-010.4: Stabilization anchored to HashComputeDelay for async targets (#253) - Issue #277: AlertCheckDelay additive semantics, Duration-based HashComputeDelay

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DerivedTiming

type DerivedTiming struct {
	// CheckAfter is when Prometheus metrics checks should begin.
	// For sync targets: creationTimestamp + StabilizationWindow.
	// For async targets (#253): creationTimestamp + HashComputeDelay + StabilizationWindow.
	CheckAfter metav1.Time

	// AlertCheckAfter is when AlertManager alert resolution checks should begin.
	// Equals CheckAfter when AlertCheckDelay is nil.
	// When AlertCheckDelay is set: CheckAfter + AlertCheckDelay (additive, #277).
	AlertCheckAfter metav1.Time

	// ValidityDeadline is when the assessment expires.
	// The runtime guard ensures the deadline extends to cover all checks:
	// if the latest check offset (stab + alertCheckDelay) >= ValidityWindow,
	// the effective validity is extended accordingly.
	ValidityDeadline metav1.Time

	// EffectiveValidity is the computed validity duration (may be extended).
	EffectiveValidity time.Duration

	// Extended is true when the runtime guard extended the validity window.
	Extended bool
}

DerivedTiming holds the computed timing fields for an EffectivenessAssessment. These are persisted in EA.Status on first reconciliation so operators can observe the assessment timeline immediately.

func ComputeDerivedTiming

func ComputeDerivedTiming(creationTimestamp metav1.Time, stabilizationWindow, validityWindow time.Duration, hashComputeDelay, alertCheckDelay *metav1.Duration) DerivedTiming

ComputeDerivedTiming calculates the derived timing fields for an EA.

For sync targets (hashComputeDelay nil or zero):

CheckAfter = creationTimestamp + StabilizationWindow
AlertCheckAfter = CheckAfter + AlertCheckDelay (or == CheckAfter if nil)
ValidityDeadline = creationTimestamp + effectiveValidity
Runtime guard extends validity when totalCheckOffset >= ValidityWindow.

For async targets (hashComputeDelay non-nil, non-zero — Issue #253, #277):

anchor = creationTimestamp + HashComputeDelay
CheckAfter = anchor + StabilizationWindow
AlertCheckAfter = CheckAfter + AlertCheckDelay (or == CheckAfter if nil)
effectiveValidity = stab + alertCheckDelay + validity (always extended from anchor)
ValidityDeadline = anchor + effectiveValidity

Parameters:

  • creationTimestamp: EA.metadata.creationTimestamp
  • stabilizationWindow: EA.Spec.Config.StabilizationWindow.Duration
  • validityWindow: ReconcilerConfig.ValidityWindow (EM-level config)
  • hashComputeDelay: EA.Spec.Config.HashComputeDelay (nil for sync targets)
  • alertCheckDelay: EA.Spec.Config.AlertCheckDelay (nil when not proactive)

Jump to

Keyboard shortcuts

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