Skip to content

Commit 497a704

Browse files
Tofelgithub-actions[bot]
authored andcommitted
[Bot] Add automatically generated go documentation
1 parent 305088e commit 497a704

File tree

7 files changed

+135
-0
lines changed

7 files changed

+135
-0
lines changed

wasp/benchspy/basic.go

Lines changed: 15 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 provided and that it is associated with a testing.T instance.
38+
// This function is essential for initializing test data configurations in a structured manner.
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,9 @@ func NewBasicData(commitOrTag string, generators ...*wasp.Generator) (*BasicData
5863
return b, nil
5964
}
6065

66+
// FillStartEndTimes calculates the earliest start time and latest end time from generator schedules.
67+
// It updates the BasicData instance with these times, ensuring all segments have valid start and end times.
68+
// This function is essential for managing and analyzing generator execution timelines.
6169
func (b *BasicData) FillStartEndTimes() error {
6270
earliestTime := time.Now()
6371
var latestTime time.Time
@@ -89,6 +97,9 @@ func (b *BasicData) FillStartEndTimes() error {
8997
return nil
9098
}
9199

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

118+
// IsComparable checks if two BasicData instances have the same configuration settings.
119+
// It validates the count, presence, and equivalence of generator configurations,
120+
// returning an error if any discrepancies are found. This function is useful for ensuring
121+
// consistency between different data reports.
107122
func (b *BasicData) IsComparable(otherData BasicData) error {
108123
// 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?
109124
if len(b.GeneratorConfigs) != len(otherData.GeneratorConfigs) {

wasp/benchspy/generator.go

Lines changed: 20 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 instance of GeneratorQueryExecutor 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 to interface{}.
43+
// It allows users to access the outcomes of executed queries, facilitating further processing or type assertions.
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 used to identify the specific kind of query executor 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 the generators, 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,8 @@ func (g *GeneratorQueryExecutor) Validate() error {
8898
return nil
8999
}
90100

101+
// Execute runs the defined queries using 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.
91103
func (g *GeneratorQueryExecutor) Execute(_ context.Context) error {
92104
if g.Generator == nil {
93105
return errors.New("generator is not set")
@@ -123,6 +135,8 @@ func (g *GeneratorQueryExecutor) Execute(_ context.Context) error {
123135
return nil
124136
}
125137

138+
// TimeRange ensures that the data responses stored in the generator are within the specified time range.
139+
// It is a no-op function, as the generator already maintains the correct time range for its responses.
126140
func (g *GeneratorQueryExecutor) TimeRange(_, _ time.Time) {
127141
// nothing to do here, since all responses stored in the generator are already in the right time range
128142
}
@@ -185,6 +199,9 @@ func (g *GeneratorQueryExecutor) standardQuery(standardMetric StandardLoadMetric
185199
}
186200
}
187201

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.
188205
func (g *GeneratorQueryExecutor) MarshalJSON() ([]byte, error) {
189206
// we need custom marshalling to only include query names, since the functions are not serializable
190207
type QueryExecutor struct {
@@ -213,6 +230,9 @@ func (g *GeneratorQueryExecutor) MarshalJSON() ([]byte, error) {
213230
})
214231
}
215232

233+
// UnmarshalJSON decodes JSON data into a GeneratorQueryExecutor instance.
234+
// It populates the Queries and QueryResults fields, converting types as necessary.
235+
// This function is essential for initializing the executor with data from JSON sources.
216236
func (g *GeneratorQueryExecutor) UnmarshalJSON(data []byte) error {
217237
// helper struct with QueryExecutors as json.RawMessage and QueryResults as map[string]interface{}
218238
// and as actual types

wasp/benchspy/loki.go

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

18+
// NewLokiQueryExecutor creates a new LokiQueryExecutor instance.
19+
// It initializes the executor with provided queries and Loki configuration,
20+
// enabling efficient querying of logs from a Loki data source.
1821
func NewLokiQueryExecutor(queries map[string]string, lokiConfig *wasp.LokiConfig) *LokiQueryExecutor {
1922
return &LokiQueryExecutor{
2023
KindName: string(StandardQueryExecutor_Loki),
@@ -40,14 +43,20 @@ type LokiQueryExecutor struct {
4043
Config *wasp.LokiConfig `json:"-"`
4144
}
4245

46+
// Results returns the query results as a map of string keys to interface{} values.
47+
// It allows users to access the outcomes of executed queries, facilitating further processing or type assertions.
4348
func (l *LokiQueryExecutor) Results() map[string]interface{} {
4449
return l.QueryResults
4550
}
4651

52+
// Kind returns the type of the query executor as a string.
53+
// It is used to identify the specific kind of query executor in various contexts.
4754
func (l *LokiQueryExecutor) Kind() string {
4855
return l.KindName
4956
}
5057

58+
// IsComparable checks if the current LokiQueryExecutor is of the same type as another QueryExecutor.
59+
// It validates the queries for equivalence, returning an error if they differ in count or content.
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 properly initialized before 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, collecting their results.
85+
// It requires a valid configuration and handles basic authentication if provided.
86+
// This function is useful for fetching logs from Loki in a structured manner.
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 fetched.
162179
func (l *LokiQueryExecutor) TimeRange(start, end time.Time) {
163180
l.StartTime = start
164181
l.EndTime = end
165182
}
166183

184+
// UnmarshalJSON parses the JSON-encoded data and populates the LokiQueryExecutor fields.
185+
// It converts the query results from a generic map to a specific type map, ensuring type safety.
186+
// This function is essential for handling JSON data in a structured manner.
167187
func (l *LokiQueryExecutor) UnmarshalJSON(data []byte) error {
168188
// helper struct with QueryResults map[string]interface{}
169189
type Alias LokiQueryExecutor
@@ -188,6 +208,8 @@ func (l *LokiQueryExecutor) UnmarshalJSON(data []byte) error {
188208
return nil
189209
}
190210

211+
// NewStandardMetricsLokiExecutor creates a LokiQueryExecutor configured with standard metrics queries.
212+
// It generates queries based on provided test parameters and time range, returning the executor or an error if query generation fails.
191213
func NewStandardMetricsLokiExecutor(lokiConfig *wasp.LokiConfig, testName, generatorName, branch, commit string, startTime, endTime time.Time) (*LokiQueryExecutor, error) {
192214
lq := &LokiQueryExecutor{
193215
KindName: string(StandardQueryExecutor_Loki),

wasp/benchspy/metrics.go

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

9+
// CalculatePercentile computes the specified percentile of a slice of numbers.
10+
// It is useful for statistical analysis, allowing users to understand data distributions
11+
// by retrieving values at specific percentiles, such as median or 95th percentile.
912
func CalculatePercentile(numbers []float64, percentile float64) float64 {
1013
// Sort the slice
1114
sort.Float64s(numbers)
@@ -31,6 +34,9 @@ func CalculatePercentile(numbers []float64, percentile float64) float64 {
3134
return numbers[lowerIndex]*(1-weight) + numbers[upperIndex]*weight
3235
}
3336

37+
// StringSliceToFloat64Slice converts a slice of strings to a slice of float64 values.
38+
// It returns an error if any string cannot be parsed as a float64, making it useful for
39+
// data transformation in numerical computations.
3440
func StringSliceToFloat64Slice(s []string) ([]float64, error) {
3541
numbers := make([]float64, len(s))
3642
for i, str := range s {

wasp/benchspy/prometheus.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func NewPrometheusQueryExecutor(url string, startTime, endTime time.Time, querie
4747
}, nil
4848
}
4949

50+
// NewStandardPrometheusQueryExecutor creates a PrometheusQueryExecutor with standard queries based on the provided time range and name regex pattern.
51+
// It simplifies the setup of query execution against a Prometheus instance for monitoring and reporting purposes.
5052
func NewStandardPrometheusQueryExecutor(url string, startTime, endTime time.Time, nameRegexPattern string) (*PrometheusQueryExecutor, error) {
5153
p := &PrometheusQueryExecutor{}
5254

@@ -58,6 +60,8 @@ func NewStandardPrometheusQueryExecutor(url string, startTime, endTime time.Time
5860
return NewPrometheusQueryExecutor(url, startTime, endTime, standardQueries)
5961
}
6062

63+
// Execute runs a series of Prometheus queries concurrently, collecting results and warnings for each query.
64+
// It returns an error if any query fails, allowing for efficient data retrieval in reporting scenarios.
6165
func (r *PrometheusQueryExecutor) Execute(ctx context.Context) error {
6266
for name, query := range r.Queries {
6367
result, warnings, queryErr := r.client.Query(ctx, query, r.endTime)
@@ -75,14 +79,22 @@ func (r *PrometheusQueryExecutor) Execute(ctx context.Context) error {
7579
return nil
7680
}
7781

82+
// Results returns the query results as a map of string to interface{}.
83+
// It allows users to access the outcomes of executed queries, facilitating further processing or analysis of the data.
7884
func (r *PrometheusQueryExecutor) Results() map[string]interface{} {
7985
return r.QueryResults
8086
}
8187

88+
// Kind returns the type of the query executor as a string.
89+
// It is used to identify the specific kind of executor in a collection,
90+
// enabling filtering and type-specific operations.
8291
func (l *PrometheusQueryExecutor) Kind() string {
8392
return l.KindName
8493
}
8594

95+
// Validate checks the PrometheusQueryExecutor's configuration for correctness.
96+
// It ensures that the client is set, queries are provided, and both start and end times are defined.
97+
// This function is essential for preventing execution errors due to misconfiguration.
8698
func (r *PrometheusQueryExecutor) Validate() error {
8799
if r.client == nil {
88100
return errors.New("prometheus client is nil")
@@ -103,6 +115,8 @@ func (r *PrometheusQueryExecutor) Validate() error {
103115
return nil
104116
}
105117

118+
// IsComparable checks if the provided QueryExecutor is of the same type as the receiver.
119+
// It returns an error if the types do not match, ensuring type safety for query comparisons.
106120
func (r *PrometheusQueryExecutor) IsComparable(other QueryExecutor) error {
107121
otherType := reflect.TypeOf(other)
108122
if otherType != reflect.TypeOf(r) {
@@ -133,10 +147,16 @@ func (r *PrometheusQueryExecutor) compareQueries(other map[string]string) error
133147
return nil
134148
}
135149

150+
// Warnings returns a map of warnings encountered during Prometheus queries.
151+
// This function is useful for retrieving any issues that may have occurred,
152+
// allowing users to handle or log them appropriately.
136153
func (r *PrometheusQueryExecutor) Warnings() map[string]v1.Warnings {
137154
return r.warnings
138155
}
139156

157+
// MustResultsAsValue returns a map of query results as model.Values.
158+
// It is used to simplify the retrieval of metric values from the query results,
159+
// enabling easier processing and serialization of metrics in various formats.
140160
func (r *PrometheusQueryExecutor) MustResultsAsValue() map[string]model.Value {
141161
results := make(map[string]model.Value)
142162
for name, result := range r.QueryResults {
@@ -145,6 +165,8 @@ func (r *PrometheusQueryExecutor) MustResultsAsValue() map[string]model.Value {
145165
return results
146166
}
147167

168+
// TimeRange sets the start and end time for the Prometheus query execution.
169+
// This function is essential for defining the time window in which data will be fetched and analyzed.
148170
func (r *PrometheusQueryExecutor) TimeRange(startTime, endTime time.Time) {
149171
r.startTime = startTime
150172
r.endTime = endTime
@@ -188,6 +210,9 @@ type TypedMetric struct {
188210
MetricType string `json:"metric_type"`
189211
}
190212

213+
// MarshalJSON customizes the JSON representation of the PrometheusQueryExecutor.
214+
// It includes only essential fields: Kind, Queries, and simplified QueryResults,
215+
// making it suitable for efficient serialization and data transfer.
191216
func (g *PrometheusQueryExecutor) MarshalJSON() ([]byte, error) {
192217
// we need custom marshalling to only include some parts of the metrics
193218
type QueryExecutor struct {
@@ -214,6 +239,9 @@ func (g *PrometheusQueryExecutor) MarshalJSON() ([]byte, error) {
214239
return json.Marshal(q)
215240
}
216241

242+
// UnmarshalJSON decodes JSON data into a PrometheusQueryExecutor instance.
243+
// It populates the QueryResults field with appropriately typed metrics,
244+
// enabling easy access to the results of Prometheus queries.
217245
func (r *PrometheusQueryExecutor) UnmarshalJSON(data []byte) error {
218246
// helper struct with QueryResults map[string]interface{}
219247
type Alias PrometheusQueryExecutor

0 commit comments

Comments
 (0)