Documentation
¶
Overview ¶
Package simulate provides utilities for running stress tests via the simulate command.
Index ¶
- Variables
- type Alert
- type InjectionResult
- type Injector
- type ScenarioBuilder
- func (s *ScenarioBuilder) AddAlert(alert Alert) *ScenarioBuilder
- func (s *ScenarioBuilder) AddStressAlerts(count int, prefix, namespace string, startTime, endTime int) *ScenarioBuilder
- func (s *ScenarioBuilder) AddWatchdog(start, end int) *ScenarioBuilder
- func (s *ScenarioBuilder) WriteCSV(path string) (retErr error)
Constants ¶
This section is empty.
Variables ¶
var DefaultPrometheusPods = []string{"prometheus-k8s-0", "prometheus-k8s-1"}
DefaultPrometheusPods are the default Prometheus pods to try (in order).
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
Start int
End int
Name string
Namespace string
Severity string
Silenced bool
ExtraLabels map[string]string
}
Alert represents one alert in a scenario.
type InjectionResult ¶
type InjectionResult struct {
// QueryTime is the time to use when querying for the injected alerts.
// Alerts with maxEnd exist at approximately this time.
QueryTime time.Time
// UsedPod is the Prometheus pod that was successfully used for injection.
UsedPod string
}
InjectionResult contains information about the injection for querying.
type Injector ¶
type Injector struct {
// contains filtered or unexported fields
}
Injector injects simulated alerts into Prometheus.
func NewInjector ¶
NewInjector creates an injector for the given Prometheus instance. Uses DefaultPrometheusPods for fallback if one pod is unavailable.
func NewInjectorWithPods ¶
NewInjectorWithPods creates an injector with specific Prometheus pods. Pods are tried in order - if copying to the first pod fails, the next is tried.
func (*Injector) Inject ¶
func (i *Injector) Inject(ctx context.Context, scenario *ScenarioBuilder) (*InjectionResult, error)
Inject takes a scenario and injects only ALERTS into Prometheus. It handles the full workflow: CSV -> simulate (alerts-only) -> TSDB blocks -> copy to Prometheus. The cluster_health_components_map metrics are NOT injected - they should be computed by the cluster-health-analyzer being tested. Returns InjectionResult with the query time to use for finding the alerts.
func (*Injector) InjectFull ¶
func (i *Injector) InjectFull(ctx context.Context, scenario *ScenarioBuilder) (*InjectionResult, error)
InjectFull takes a scenario and injects ALL metrics into Prometheus. This includes ALERTS, cluster_health_components, and cluster_health_components_map. Use this when you want pre-computed metrics (e.g., for testing queries).
func (*Injector) WipePrometheusData ¶
WipePrometheusData deletes all Prometheus data and restarts the pods. This guarantees a clean slate before running tests. WARNING: This destroys ALL metrics data. Only use on dedicated test clusters.
type ScenarioBuilder ¶
type ScenarioBuilder struct {
// contains filtered or unexported fields
}
ScenarioBuilder creates scenario CSV files for the simulate command.
func NewScenarioBuilder ¶
func NewScenarioBuilder() *ScenarioBuilder
NewScenarioBuilder creates a new scenario builder.
func (*ScenarioBuilder) AddAlert ¶
func (s *ScenarioBuilder) AddAlert(alert Alert) *ScenarioBuilder
AddAlert adds a single alert to the scenario.
func (*ScenarioBuilder) AddStressAlerts ¶
func (s *ScenarioBuilder) AddStressAlerts(count int, prefix, namespace string, startTime, endTime int) *ScenarioBuilder
AddStressAlerts adds multiple alerts with sequential names. The unique prefix (e.g., "StressSim1234567890") prevents grouping with other test runs.
func (*ScenarioBuilder) AddWatchdog ¶
func (s *ScenarioBuilder) AddWatchdog(start, end int) *ScenarioBuilder
AddWatchdog adds a background Watchdog alert (commonly needed).
func (*ScenarioBuilder) WriteCSV ¶
func (s *ScenarioBuilder) WriteCSV(path string) (retErr error)
WriteCSV writes the scenario to a CSV file.