Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go docs for PR#1424 #1486

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wasp/benchspy/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func NewDirectQueryExecutor(generator *wasp.Generator, queries map[string]Direct
return g, nil
}

// GeneratorName returns the name of the generator associated with the query executor.
// It is useful for identifying and categorizing results based on their generator type.
func (g *DirectQueryExecutor) GeneratorName() string {
return g.Generator.Cfg.GenName
}
Expand Down
5 changes: 5 additions & 0 deletions wasp/benchspy/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var (
Loki_ErrorRate = `sum(max_over_time({branch=~"%s", commit=~"%s", go_test_name=~"%s", test_data_type=~"stats", gen_name=~"%s"} | json| unwrap failed [%s]) by (node_id, go_test_name, gen_name)) by (__stream_shard__)`
)

// NewLokiQueryExecutor creates a new LokiQueryExecutor instance.
// It initializes the executor with the specified generator name, queries, and Loki configuration.
// This function is useful for setting up a query executor to interact with Loki for log data retrieval.
func NewLokiQueryExecutor(generatorName string, queries map[string]string, lokiConfig *wasp.LokiConfig) *LokiQueryExecutor {
return &LokiQueryExecutor{
KindName: string(StandardQueryExecutor_Loki),
Expand All @@ -49,6 +52,8 @@ type LokiQueryExecutor struct {
Config *wasp.LokiConfig `json:"-"`
}

// GeneratorName returns the name of the generator associated with the LokiQueryExecutor.
// It is useful for identifying the source of results in reports or logs.
func (l *LokiQueryExecutor) GeneratorName() string {
return l.GeneratorNameString
}
Expand Down
11 changes: 11 additions & 0 deletions wasp/benchspy/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (b *StandardReport) LoadLatest(testName string) error {
return b.LocalStorage.Load(testName, "", b)
}

// ResultsAs retrieves and casts results from a query executor to a specified type.
// It returns a map of query names to their corresponding results, or an error if casting fails.
func ResultsAs[Type any](newType Type, queryExecutor QueryExecutor, queryNames ...string) (map[string]Type, error) {
results := make(map[string]Type)

Expand Down Expand Up @@ -74,6 +76,8 @@ func ResultsAs[Type any](newType Type, queryExecutor QueryExecutor, queryNames .

type LokiResultsByGenerator map[string]map[string][]string

// MustAllLokiResults retrieves and aggregates results from all Loki query executors in a StandardReport.
// It panics if any query execution fails, ensuring that only successful results are returned.
func MustAllLokiResults(sr *StandardReport) LokiResultsByGenerator {
results := make(LokiResultsByGenerator)

Expand All @@ -94,6 +98,8 @@ func MustAllLokiResults(sr *StandardReport) LokiResultsByGenerator {

type DirectResultsByGenerator map[string]map[string]float64

// MustAllDirectResults extracts and returns all direct results from a given StandardReport.
// It panics if any result extraction fails, ensuring that only valid results are processed.
func MustAllDirectResults(sr *StandardReport) DirectResultsByGenerator {
results := make(DirectResultsByGenerator)

Expand Down Expand Up @@ -144,6 +150,8 @@ func calculateDiffPercentage(current, previous float64) float64 {
return diffPrecentage
}

// CompareDirectWithThresholds evaluates the current and previous reports against specified thresholds.
// It checks for significant differences in metrics and returns any discrepancies found, aiding in performance analysis.
func CompareDirectWithThresholds(medianThreshold, p95Threshold, maxThreshold, errorRateThreshold float64, currentReport, previousReport *StandardReport) (bool, map[string][]error) {
allCurrentResults := MustAllDirectResults(currentReport)
allPreviousResults := MustAllDirectResults(previousReport)
Expand Down Expand Up @@ -207,6 +215,9 @@ func CompareDirectWithThresholds(medianThreshold, p95Threshold, maxThreshold, er
return len(errors) > 0, errors
}

// PrintStandardDirectMetrics outputs a comparison of direct metrics between two reports.
// It displays the current and previous values along with the percentage difference for each metric,
// helping users to quickly assess performance changes across different generator configurations.
func PrintStandardDirectMetrics(currentReport, previousReport *StandardReport) {
currentResults := MustAllDirectResults(currentReport)
previousResults := MustAllDirectResults(previousReport)
Expand Down
Loading