helpers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package helpers provides performance assertion utilities for load testing.

Package helpers provides mock server implementations for load testing.

Package helpers provides Prometheus metrics collection for load testing.

Package helpers provides utility functions for load testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSLO

func CheckSLO(slo PerformanceSLO, value float64) (bool, string)

CheckSLO checks if a value meets the SLO requirement.

func ExtractRepoName

func ExtractRepoName(fullName string) string

ExtractRepoName extracts the repository name from owner/repo format.

func GenerateNamespaceName

func GenerateNamespaceName(prefix string) string

GenerateNamespaceName creates a unique namespace name for testing. Format: <prefix>-<timestamp>-<random>

func GetCRDPath

func GetCRDPath() string

GetCRDPath returns the path to the CRD directory for testing. Walks up the directory tree to find the project root.

func NewNamespace

func NewNamespace(name string) *corev1.Namespace

NewNamespace creates a Namespace object for testing.

func Percentile

func Percentile(durations []time.Duration, percentile int) time.Duration

Percentile calculates the nth percentile of a duration slice. Returns zero duration if slice is empty.

func SanitizeName

func SanitizeName(name string) string

SanitizeName converts a string to a valid Kubernetes name. Replaces invalid characters with hyphens and lowercases.

func WriteHTMLReport

func WriteHTMLReport(filename string, report PerformanceReport) error

WriteHTMLReport writes a performance report to an HTML file.

Types

type ArgoCDAppStatus

type ArgoCDAppStatus struct {
	Sync   ArgoCDSyncStatus
	Health ArgoCDHealthStatus
}

ArgoCDAppStatus represents ArgoCD application status.

type ArgoCDHealthStatus

type ArgoCDHealthStatus struct {
	Status string
}

ArgoCDHealthStatus represents health status.

type ArgoCDMockServer

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

ArgoCDMockServer is a high-performance mock ArgoCD API server for load testing.

func NewArgoCDMockServer

func NewArgoCDMockServer() *ArgoCDMockServer

NewArgoCDMockServer creates a new mock ArgoCD API server.

func (*ArgoCDMockServer) AddApplication

func (am *ArgoCDMockServer) AddApplication(cluster string, app *MockArgoCDApp)

AddApplication adds an application to a cluster.

func (*ArgoCDMockServer) CreateCluster

func (am *ArgoCDMockServer) CreateCluster(name string)

CreateCluster creates a mock cluster.

func (*ArgoCDMockServer) GetApplication

func (am *ArgoCDMockServer) GetApplication(cluster, appName string) *MockArgoCDApp

GetApplication retrieves an application from a cluster.

func (*ArgoCDMockServer) GetRateLimitStats

func (am *ArgoCDMockServer) GetRateLimitStats(cluster string) clusterStats

GetRateLimitStats returns rate limiting statistics for a cluster.

func (*ArgoCDMockServer) GetURL

func (am *ArgoCDMockServer) GetURL() string

GetURL returns the mock server URL.

func (*ArgoCDMockServer) Reset

func (am *ArgoCDMockServer) Reset()

Reset clears all data in the mock server.

func (*ArgoCDMockServer) SetLatency

func (am *ArgoCDMockServer) SetLatency(cluster string, latency time.Duration)

SetLatency configures simulated latency for a cluster.

func (*ArgoCDMockServer) SetRateLimit

func (am *ArgoCDMockServer) SetRateLimit(cluster string, tokensPerInterval int, interval time.Duration)

SetRateLimit configures rate limiting for a cluster.

func (*ArgoCDMockServer) Start

func (am *ArgoCDMockServer) Start() error

Start starts the mock ArgoCD API server.

func (*ArgoCDMockServer) Stop

func (am *ArgoCDMockServer) Stop()

Stop stops the mock ArgoCD API server.

func (*ArgoCDMockServer) UpdateApplication

func (am *ArgoCDMockServer) UpdateApplication(cluster string, app *MockArgoCDApp)

UpdateApplication updates an application in a cluster.

type ArgoCDSyncStatus

type ArgoCDSyncStatus struct {
	Status   string
	Revision string
}

ArgoCDSyncStatus represents sync status.

type GitHubMockServer

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

GitHubMockServer is a high-performance mock GitHub API server for load testing.

func NewGitHubMockServer

func NewGitHubMockServer() *GitHubMockServer

NewGitHubMockServer creates a new mock GitHub API server.

func (*GitHubMockServer) AddPR

func (gm *GitHubMockServer) AddPR(repo string, pr *MockPR)

AddPR adds a PR to a repository.

func (*GitHubMockServer) CreateRepository

func (gm *GitHubMockServer) CreateRepository(name string)

CreateRepository creates a mock repository.

func (*GitHubMockServer) GetURL

func (gm *GitHubMockServer) GetURL() string

GetURL returns the mock server URL.

func (*GitHubMockServer) Reset

func (gm *GitHubMockServer) Reset()

Reset clears all data in the mock server.

func (*GitHubMockServer) Start

func (gm *GitHubMockServer) Start() error

Start starts the mock GitHub API server.

func (*GitHubMockServer) Stop

func (gm *GitHubMockServer) Stop()

Stop stops the mock GitHub API server.

type LatencyHistogram

type LatencyHistogram struct {
	Buckets map[float64]float64
	Count   float64
	Sum     float64
}

LatencyHistogram represents a Prometheus histogram with calculated percentiles.

func ParseHTTPLatencyHistogram

func ParseHTTPLatencyHistogram(snapshot *MetricsSnapshot, metricPrefix string) LatencyHistogram

ParseHTTPLatencyHistogram parses a Prometheus histogram and returns percentiles.

func (LatencyHistogram) Average

func (lh LatencyHistogram) Average() time.Duration

Average returns the average latency from the histogram.

func (LatencyHistogram) Percentile

func (lh LatencyHistogram) Percentile(percentile float64) time.Duration

Percentile calculates the specified percentile from the histogram.

type MetricAnalysis

type MetricAnalysis struct {
	Name  string
	Count int
	Min   float64
	Max   float64
	Avg   float64
}

MetricAnalysis contains statistical analysis of a metric over time.

func (MetricAnalysis) String

func (ma MetricAnalysis) String() string

String returns a string representation of the analysis.

type MetricsCollector

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

MetricsCollector scrapes and analyzes Prometheus metrics during load tests.

func NewMetricsCollector

func NewMetricsCollector(registry *prometheus.Registry) *MetricsCollector

NewMetricsCollector creates a new metrics collector.

func (*MetricsCollector) AddEndpoint

func (mc *MetricsCollector) AddEndpoint(url string)

AddEndpoint adds a Prometheus metrics endpoint to scrape.

func (*MetricsCollector) AnalyzeMetric

func (mc *MetricsCollector) AnalyzeMetric(metricName string) MetricAnalysis

AnalyzeMetric analyzes a metric over time and returns statistics.

func (*MetricsCollector) ExtractOperatorMetrics

func (mc *MetricsCollector) ExtractOperatorMetrics(snapshot *MetricsSnapshot) OperatorMetrics

ExtractOperatorMetrics extracts cd-operator specific metrics from a snapshot.

func (*MetricsCollector) GetLatestSnapshot

func (mc *MetricsCollector) GetLatestSnapshot() *MetricsSnapshot

GetLatestSnapshot returns the most recent metrics snapshot.

func (*MetricsCollector) GetMetricHistory

func (mc *MetricsCollector) GetMetricHistory(metricName string) []float64

GetMetricHistory returns the history of a specific metric.

func (*MetricsCollector) ScrapeAll

func (mc *MetricsCollector) ScrapeAll() error

ScrapeAll scrapes all configured endpoints and stores a snapshot.

type MetricsSnapshot

type MetricsSnapshot struct {
	Timestamp time.Time
	Metrics   map[string]float64
}

MetricsSnapshot captures Prometheus metrics at a point in time.

type MockArgoCDApp

type MockArgoCDApp struct {
	Name   string
	Status ArgoCDAppStatus
}

MockArgoCDApp represents a mock ArgoCD application for load testing.

func GenerateMockArgoCDApp

func GenerateMockArgoCDApp(cluster, name, syncStatus, healthStatus string) *MockArgoCDApp

GenerateMockArgoCDApp creates a mock ArgoCD application.

type MockPR

type MockPR struct {
	Number    int
	State     string
	Mergeable bool
	HeadSHA   string
	Files     []string
}

MockPR represents a mock GitHub pull request for load testing.

func GenerateMockPR

func GenerateMockPR(repo string, number int, state string) *MockPR

GenerateMockPR creates a mock PR with realistic defaults.

type OperatorMetrics

type OperatorMetrics struct {
	PRDiscoveryTotal      float64
	PRQualificationTotal  float64
	PRMergeTotal          float64
	DriftDetectionTotal   float64
	GitHubAPICallsTotal   float64
	ArgoCDAPICallsTotal   float64
	WorkerPoolQueueDepth  float64
	ReconcileLoopDuration float64
}

OperatorMetrics contains key cd-operator metrics.

type PerformanceAssertion

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

PerformanceAssertion provides fluent API for asserting performance metrics.

func AssertErrorRate

func AssertErrorRate(name string, errors, total int) *PerformanceAssertion

AssertErrorRate creates an error rate assertion.

func AssertGoroutines

func AssertGoroutines(name string, count int) *PerformanceAssertion

AssertGoroutines creates a goroutine count assertion.

func AssertLatency

func AssertLatency(name string, latency time.Duration) *PerformanceAssertion

AssertLatency creates a latency assertion.

func AssertMemory

func AssertMemory(name string, bytes uint64) *PerformanceAssertion

AssertMemory creates a memory usage assertion.

func AssertThroughput

func AssertThroughput(name string, itemsProcessed int, duration time.Duration) *PerformanceAssertion

AssertThroughput creates a throughput assertion.

func (*PerformanceAssertion) Failed

func (pa *PerformanceAssertion) Failed() bool

Failed returns true if the assertion failed.

func (*PerformanceAssertion) Reason

func (pa *PerformanceAssertion) Reason() string

Reason returns the failure reason.

func (*PerformanceAssertion) ShouldBeAtLeast

func (pa *PerformanceAssertion) ShouldBeAtLeast(min float64) *PerformanceAssertion

ShouldBeAtLeast asserts the value is at least the minimum.

func (*PerformanceAssertion) ShouldBeAtMost

func (pa *PerformanceAssertion) ShouldBeAtMost(max float64) *PerformanceAssertion

ShouldBeAtMost asserts the value is at most the maximum.

func (*PerformanceAssertion) ShouldBeBetween

func (pa *PerformanceAssertion) ShouldBeBetween(min, max float64) *PerformanceAssertion

ShouldBeBetween asserts the value is between min and max.

type PerformanceReport

type PerformanceReport struct {
	TestName      string
	TotalItems    int
	Duration      time.Duration
	StartSnapshot ResourceSnapshot
	EndSnapshot   ResourceSnapshot
	SuccessCount  int
	ErrorCount    int
	LatencyP50    time.Duration
	LatencyP95    time.Duration
	LatencyP99    time.Duration
}

PerformanceReport captures performance metrics for a load test.

type PerformanceSLO

type PerformanceSLO struct {
	Name        string
	Description string
	Threshold   float64
	Unit        string
	Comparator  string // "<=", ">=", "<", ">"
}

PerformanceSLO defines a Service Level Objective for load tests.

func DriftPipelineSLOs

func DriftPipelineSLOs() []PerformanceSLO

DriftPipelineSLOs returns the default SLOs for drift pipeline load tests.

func PRPipelineSLOs

func PRPipelineSLOs() []PerformanceSLO

PRPipelineSLOs returns the default SLOs for PR pipeline load tests.

type ResourceMonitor

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

ResourceMonitor tracks resource usage over time during load tests.

func NewResourceMonitor

func NewResourceMonitor(ctx context.Context) *ResourceMonitor

NewResourceMonitor creates a new resource monitor.

func (*ResourceMonitor) GenerateReport

func (rm *ResourceMonitor) GenerateReport() PerformanceReport

GenerateReport generates a performance report from collected data.

func (*ResourceMonitor) Snapshot

func (rm *ResourceMonitor) Snapshot() ResourceSnapshot

Snapshot returns the current resource usage snapshot.

func (*ResourceMonitor) Start

func (rm *ResourceMonitor) Start() error

Start begins collecting resource metrics at regular intervals.

func (*ResourceMonitor) Stop

func (rm *ResourceMonitor) Stop()

Stop stops the resource monitor.

type ResourceSnapshot

type ResourceSnapshot struct {
	Timestamp        time.Time
	CPUUsagePercent  float64
	MemoryUsageBytes uint64
	GoroutineCount   int
}

ResourceSnapshot captures system resource usage at a point in time.

type SLOReport

type SLOReport struct {
	TotalSLOs int
	MetSLOs   int
	Results   []SLOResult
}

SLOReport summarizes SLO compliance for a load test.

func CheckAllSLOs

func CheckAllSLOs(slos []PerformanceSLO, measurements map[string]float64) SLOReport

CheckAllSLOs checks all SLOs against measured values.

func (SLOReport) String

func (sr SLOReport) String() string

String returns a formatted string representation of the SLO report.

type SLOResult

type SLOResult struct {
	SLO     PerformanceSLO
	Value   float64
	Met     bool
	Message string
}

SLOResult represents the result of checking a single SLO.

Jump to

Keyboard shortcuts

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