Skip to content

Commit 88169d4

Browse files
Tofelgithub-actions[bot]
authored andcommitted
[Bot] Add automatically generated go documentation
1 parent 827b282 commit 88169d4

File tree

7 files changed

+142
-0
lines changed

7 files changed

+142
-0
lines changed

wasp/benchspy/basic.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type BasicData struct {
2222
GeneratorConfigs map[string]*wasp.Config `json:"generator_configs"`
2323
}
2424

25+
// MustNewBasicData creates a new BasicData instance from a commit or tag.
26+
// It panics if the creation fails, ensuring that the caller receives a valid instance.
2527
func MustNewBasicData(commitOrTag string, generators ...*wasp.Generator) BasicData {
2628
b, err := NewBasicData(commitOrTag, generators...)
2729
if err != nil {
@@ -31,6 +33,9 @@ func MustNewBasicData(commitOrTag string, generators ...*wasp.Generator) BasicDa
3133
return *b
3234
}
3335

36+
// NewBasicData creates a new BasicData instance using the provided commit or tag and a list of generators.
37+
// It ensures that at least one generator is supplied and that it is associated with a testing.T instance.
38+
// This function is essential for initializing data required for generating reports or executing tests.
3439
func NewBasicData(commitOrTag string, generators ...*wasp.Generator) (*BasicData, error) {
3540
if len(generators) == 0 {
3641
return nil, errors.New("at least one generator is required")
@@ -58,6 +63,10 @@ func NewBasicData(commitOrTag string, generators ...*wasp.Generator) (*BasicData
5863
return b, nil
5964
}
6065

66+
// FillStartEndTimes calculates and sets the earliest start time and latest end time
67+
// from the generator configurations. It ensures that all segments have valid start and
68+
// end times, returning an error if any are missing. This function is essential for
69+
// establishing the time range for tests based on generator schedules.
6170
func (b *BasicData) FillStartEndTimes() error {
6271
earliestTime := time.Now()
6372
var latestTime time.Time
@@ -89,6 +98,9 @@ func (b *BasicData) FillStartEndTimes() error {
8998
return nil
9099
}
91100

101+
// Validate checks the integrity of BasicData by ensuring that the test start and end times are set,
102+
// and that at least one generator configuration is provided. It returns an error if any of these
103+
// conditions are not met, guiding users to correct their input.
92104
func (b *BasicData) Validate() error {
93105
if b.TestStart.IsZero() {
94106
return errors.New("test start time is missing. We cannot query Loki without a time range. Please set it and try again")
@@ -104,6 +116,10 @@ func (b *BasicData) Validate() error {
104116
return nil
105117
}
106118

119+
// IsComparable checks if two BasicData instances have the same configuration settings.
120+
// It validates the count, presence, and equivalence of generator configurations,
121+
// returning an error if any discrepancies are found. This function is useful for ensuring
122+
// consistency between data reports before processing or comparison.
107123
func (b *BasicData) IsComparable(otherData BasicData) error {
108124
// are all configs present? do they have the same schedule type? do they have the same segments? is call timeout the same? is rate limit timeout the same?
109125
if len(b.GeneratorConfigs) != len(otherData.GeneratorConfigs) {

wasp/benchspy/generator.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type GeneratorQueryExecutor struct {
2020
QueryResults map[string]interface{} `json:"query_results"`
2121
}
2222

23+
// NewGeneratorQueryExecutor creates a new GeneratorQueryExecutor instance using the provided generator.
24+
// It initializes standard queries and prepares the executor for handling query results, returning any errors encountered.
2325
func NewGeneratorQueryExecutor(generator *wasp.Generator) (*GeneratorQueryExecutor, error) {
2426
g := &GeneratorQueryExecutor{
2527
KindName: string(StandardQueryExecutor_Generator),
@@ -37,14 +39,20 @@ func NewGeneratorQueryExecutor(generator *wasp.Generator) (*GeneratorQueryExecut
3739
return g, nil
3840
}
3941

42+
// Results returns the query results as a map of string keys to interface{} values.
43+
// It is useful for retrieving the output of executed queries in a structured format.
4044
func (g *GeneratorQueryExecutor) Results() map[string]interface{} {
4145
return g.QueryResults
4246
}
4347

48+
// Kind returns the type of the query executor as a string.
49+
// It is useful for identifying the specific kind of executor being used in various operations.
4450
func (l *GeneratorQueryExecutor) Kind() string {
4551
return l.KindName
4652
}
4753

54+
// IsComparable checks if the current GeneratorQueryExecutor is comparable to another QueryExecutor.
55+
// It validates the type and configuration of both executors, returning an error if they are not compatible.
4856
func (g *GeneratorQueryExecutor) IsComparable(otherQueryExecutor QueryExecutor) error {
4957
otherType := reflect.TypeOf(otherQueryExecutor)
5058

@@ -76,6 +84,8 @@ func (l *GeneratorQueryExecutor) compareQueries(other map[string]GeneratorQueryF
7684
return nil
7785
}
7886

87+
// Validate checks if the generator is set and if at least one query is provided.
88+
// It returns an error if either condition is not met, ensuring that the query executor is properly configured before execution.
7989
func (g *GeneratorQueryExecutor) Validate() error {
8090
if g.Generator == nil {
8191
return errors.New("generator is not set")
@@ -88,6 +98,9 @@ func (g *GeneratorQueryExecutor) Validate() error {
8898
return nil
8999
}
90100

101+
// Execute runs the defined queries on the generator's data, aggregating results for each query.
102+
// It returns an error if the generator is not set, lacks data, or if any query execution fails.
103+
// This function is essential for processing and retrieving results from multiple queries concurrently.
91104
func (g *GeneratorQueryExecutor) Execute(_ context.Context) error {
92105
if g.Generator == nil {
93106
return errors.New("generator is not set")
@@ -123,6 +136,9 @@ func (g *GeneratorQueryExecutor) Execute(_ context.Context) error {
123136
return nil
124137
}
125138

139+
// TimeRange sets the time range for the query executor.
140+
// It ensures that all responses are within the specified time range,
141+
// although no action is needed if the generator already contains the correct data.
126142
func (g *GeneratorQueryExecutor) TimeRange(_, _ time.Time) {
127143
// nothing to do here, since all responses stored in the generator are already in the right time range
128144
}
@@ -183,6 +199,9 @@ func (g *GeneratorQueryExecutor) standardQuery(standardMetric StandardLoadMetric
183199
}
184200
}
185201

202+
// MarshalJSON customizes the JSON encoding of the GeneratorQueryExecutor.
203+
// It serializes only the relevant fields, including query names and results,
204+
// making it suitable for efficient data transmission and storage in JSON format.
186205
func (g *GeneratorQueryExecutor) MarshalJSON() ([]byte, error) {
187206
// we need custom marshalling to only include query names, since the functions are not serializable
188207
type QueryExecutor struct {
@@ -211,6 +230,9 @@ func (g *GeneratorQueryExecutor) MarshalJSON() ([]byte, error) {
211230
})
212231
}
213232

233+
// UnmarshalJSON parses the JSON-encoded data and populates the GeneratorQueryExecutor fields.
234+
// It extracts generator configuration, queries, and query results, converting them to appropriate types.
235+
// This function is essential for initializing the GeneratorQueryExecutor from JSON data.
214236
func (g *GeneratorQueryExecutor) UnmarshalJSON(data []byte) error {
215237
// helper struct with QueryExecutors as json.RawMessage and QueryResults as map[string]interface{}
216238
// and as actual types

wasp/benchspy/loki.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"golang.org/x/sync/errgroup"
1616
)
1717

18+
// NewLokiQueryExecutor initializes a LokiQueryExecutor with specified queries and configuration.
19+
// It prepares the executor to handle queries against a Loki instance, facilitating efficient log retrieval.
1820
func NewLokiQueryExecutor(queries map[string]string, lokiConfig *wasp.LokiConfig) *LokiQueryExecutor {
1921
return &LokiQueryExecutor{
2022
KindName: string(StandardQueryExecutor_Loki),
@@ -40,14 +42,21 @@ type LokiQueryExecutor struct {
4042
Config *wasp.LokiConfig `json:"-"`
4143
}
4244

45+
// Results returns the query results as a map of string to interface{}.
46+
// It allows users to access the results of executed queries, facilitating further processing or type assertions.
4347
func (l *LokiQueryExecutor) Results() map[string]interface{} {
4448
return l.QueryResults
4549
}
4650

51+
// Kind returns the type of the query executor as a string.
52+
// It is used to identify the specific kind of query executor in various contexts.
4753
func (l *LokiQueryExecutor) Kind() string {
4854
return l.KindName
4955
}
5056

57+
// IsComparable checks if the current LokiQueryExecutor is of the same type as another QueryExecutor.
58+
// It validates the queries for equivalence, ensuring they match in count and content.
59+
// This function is useful for comparing query executors in reporting scenarios.
5160
func (l *LokiQueryExecutor) IsComparable(otherQueryExecutor QueryExecutor) error {
5261
otherType := reflect.TypeOf(otherQueryExecutor)
5362

@@ -58,6 +67,9 @@ func (l *LokiQueryExecutor) IsComparable(otherQueryExecutor QueryExecutor) error
5867
return l.compareQueries(otherQueryExecutor.(*LokiQueryExecutor).Queries)
5968
}
6069

70+
// Validate checks if the LokiQueryExecutor has valid queries and configuration.
71+
// It returns an error if no queries are set or if the configuration is missing,
72+
// ensuring that the executor is ready for execution.
6173
func (l *LokiQueryExecutor) Validate() error {
6274
if len(l.Queries) == 0 {
6375
return errors.New("there are no Loki queries, there's nothing to fetch. Please set them and try again")
@@ -69,6 +81,9 @@ func (l *LokiQueryExecutor) Validate() error {
6981
return nil
7082
}
7183

84+
// Execute runs multiple Loki queries concurrently and collects their results.
85+
// It validates the configuration, handles authentication, and manages errors.
86+
// This function is essential for retrieving logs from Loki based on specified queries and time ranges.
7287
func (l *LokiQueryExecutor) Execute(ctx context.Context) error {
7388
var basicAuth client.LokiBasicAuth
7489

@@ -159,11 +174,16 @@ func (l *LokiQueryExecutor) compareQueries(other map[string]string) error {
159174
return nil
160175
}
161176

177+
// TimeRange sets the start and end time for the Loki query execution.
178+
// This function is essential for defining the time window of the data to be queried.
162179
func (l *LokiQueryExecutor) TimeRange(start, end time.Time) {
163180
l.StartTime = start
164181
l.EndTime = end
165182
}
166183

184+
// UnmarshalJSON decodes JSON data into a LokiQueryExecutor instance.
185+
// It populates the QueryResults field with a typed map from the raw JSON input,
186+
// enabling structured access to query results for further processing.
167187
func (l *LokiQueryExecutor) UnmarshalJSON(data []byte) error {
168188
// helper struct with QueryResults map[string]interface{}
169189
type Alias LokiQueryExecutor
@@ -188,6 +208,9 @@ func (l *LokiQueryExecutor) UnmarshalJSON(data []byte) error {
188208
return nil
189209
}
190210

211+
// NewStandardMetricsLokiExecutor creates a LokiQueryExecutor configured with standard queries
212+
// based on the provided test and generator details. It facilitates querying metrics from Loki
213+
// for performance analysis and monitoring during tests.
191214
func NewStandardMetricsLokiExecutor(lokiConfig *wasp.LokiConfig, testName, generatorName, branch, commit string, startTime, endTime time.Time) (*LokiQueryExecutor, error) {
192215
lq := &LokiQueryExecutor{
193216
KindName: string(StandardQueryExecutor_Loki),

wasp/benchspy/metrics.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"strconv"
77
)
88

9+
// CalculatePercentile computes the value at a specified percentile from a slice of numbers.
10+
// It is useful for statistical analysis, allowing users to determine thresholds or benchmarks in data sets.
911
func CalculatePercentile(numbers []float64, percentile float64) float64 {
1012
// Sort the slice
1113
sort.Float64s(numbers)
@@ -31,6 +33,9 @@ func CalculatePercentile(numbers []float64, percentile float64) float64 {
3133
return numbers[lowerIndex]*(1-weight) + numbers[upperIndex]*weight
3234
}
3335

36+
// StringSliceToFloat64Slice converts a slice of strings to a slice of float64 values.
37+
// It returns an error if any string cannot be parsed as a float64. This function is useful
38+
// for data processing where numeric values are represented as strings.
3439
func StringSliceToFloat64Slice(s []string) ([]float64, error) {
3540
numbers := make([]float64, len(s))
3641
for i, str := range s {

wasp/benchspy/prometheus.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type PrometheusConfig struct {
2222

2323
const PrometheusUrlEnvVar = "PROMETHEUS_URL"
2424

25+
// NewPrometheusConfig creates a new PrometheusConfig instance with the specified name regex patterns.
26+
// It retrieves the Prometheus URL from the environment and is useful for configuring Prometheus query executors.
2527
func NewPrometheusConfig(nameRegexPatterns ...string) *PrometheusConfig {
2628
return &PrometheusConfig{
2729
Url: os.Getenv(PrometheusUrlEnvVar),
@@ -56,6 +58,8 @@ func NewPrometheusQueryExecutor(queries map[string]string, config PrometheusConf
5658
}, nil
5759
}
5860

61+
// NewStandardPrometheusQueryExecutor creates a PrometheusQueryExecutor with standard queries based on the provided time range and configuration.
62+
// It simplifies the setup of query execution for Prometheus by generating queries that match specified name patterns.
5963
func NewStandardPrometheusQueryExecutor(startTime, endTime time.Time, config PrometheusConfig) (*PrometheusQueryExecutor, error) {
6064
p := &PrometheusQueryExecutor{}
6165

@@ -74,6 +78,8 @@ func NewStandardPrometheusQueryExecutor(startTime, endTime time.Time, config Pro
7478
return NewPrometheusQueryExecutor(standardQueries, config)
7579
}
7680

81+
// Execute runs the defined Prometheus queries concurrently, collecting results and warnings.
82+
// It returns an error if any query fails, allowing for efficient data retrieval and error handling.
7783
func (r *PrometheusQueryExecutor) Execute(ctx context.Context) error {
7884
for name, query := range r.Queries {
7985
result, warnings, queryErr := r.client.Query(ctx, query, r.EndTime)
@@ -91,14 +97,20 @@ func (r *PrometheusQueryExecutor) Execute(ctx context.Context) error {
9197
return nil
9298
}
9399

100+
// Results returns the query results as a map of string to interface{}.
101+
// It allows users to access the outcomes of executed queries, facilitating further processing or analysis of the data.
94102
func (r *PrometheusQueryExecutor) Results() map[string]interface{} {
95103
return r.QueryResults
96104
}
97105

106+
// Kind returns the type of the query executor as a string.
107+
// It is used to identify the specific kind of query executor in a collection.
98108
func (l *PrometheusQueryExecutor) Kind() string {
99109
return l.KindName
100110
}
101111

112+
// Validate checks the Prometheus client and the provided queries for correctness.
113+
// It returns an error if the client is nil or if no queries are specified, ensuring that the executor is properly configured before execution.
102114
func (r *PrometheusQueryExecutor) Validate() error {
103115
if r.client == nil {
104116
return errors.New("prometheus client is nil")
@@ -111,6 +123,8 @@ func (r *PrometheusQueryExecutor) Validate() error {
111123
return nil
112124
}
113125

126+
// IsComparable checks if the provided QueryExecutor is of the same type as the receiver.
127+
// It returns an error if the types do not match, ensuring type safety for query comparisons.
114128
func (r *PrometheusQueryExecutor) IsComparable(other QueryExecutor) error {
115129
otherType := reflect.TypeOf(other)
116130
if otherType != reflect.TypeOf(r) {
@@ -141,10 +155,15 @@ func (r *PrometheusQueryExecutor) compareQueries(other map[string]string) error
141155
return nil
142156
}
143157

158+
// Warnings returns a map of warnings encountered during query execution.
159+
// This function is useful for retrieving any issues that may have arisen,
160+
// allowing users to address potential problems in their queries.
144161
func (r *PrometheusQueryExecutor) Warnings() map[string]v1.Warnings {
145162
return r.warnings
146163
}
147164

165+
// MustResultsAsValue retrieves the query results as a map of metric names to their corresponding values.
166+
// It ensures that all results are converted to a common value type, facilitating further processing or serialization.
148167
func (r *PrometheusQueryExecutor) MustResultsAsValue() map[string]model.Value {
149168
results := make(map[string]model.Value)
150169
for name, result := range r.QueryResults {
@@ -180,6 +199,8 @@ func (r *PrometheusQueryExecutor) MustResultsAsValue() map[string]model.Value {
180199
return results
181200
}
182201

202+
// TimeRange sets the start and end time for the Prometheus query execution.
203+
// This function is essential for defining the time window for data retrieval, ensuring accurate and relevant results.
183204
func (r *PrometheusQueryExecutor) TimeRange(startTime, endTime time.Time) {
184205
r.StartTime = startTime
185206
r.EndTime = endTime
@@ -222,6 +243,9 @@ type TypedMetric struct {
222243
MetricType string `json:"metric_type"`
223244
}
224245

246+
// MarshalJSON customizes the JSON representation of the PrometheusQueryExecutor.
247+
// It includes only essential fields: Kind, Queries, and simplified QueryResults.
248+
// This function is useful for serializing the executor's state in a concise format.
225249
func (g *PrometheusQueryExecutor) MarshalJSON() ([]byte, error) {
226250
// we need custom marshalling to only include some parts of the metrics
227251
type QueryExecutor struct {
@@ -248,6 +272,9 @@ func (g *PrometheusQueryExecutor) MarshalJSON() ([]byte, error) {
248272
return json.Marshal(q)
249273
}
250274

275+
// UnmarshalJSON decodes JSON data into a PrometheusQueryExecutor instance.
276+
// It populates the QueryResults field with the appropriate metric types,
277+
// enabling structured access to the query results for further processing.
251278
func (r *PrometheusQueryExecutor) UnmarshalJSON(data []byte) error {
252279
// helper struct with QueryResults map[string]interface{}
253280
type Alias PrometheusQueryExecutor

0 commit comments

Comments
 (0)