Skip to content

Commit af82790

Browse files
committed
docs with o1-mini
1 parent 915f0ac commit af82790

22 files changed

+344
-393
lines changed

wasp/alert.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ type AlertChecker struct {
2323
grafanaClient *grafana.Client
2424
}
2525

26-
// NewAlertChecker initializes and returns a new AlertChecker instance.
27-
// It retrieves the Grafana URL and API token from environment variables
28-
// GRAFANA_URL and GRAFANA_TOKEN, respectively. If either is not set, it
29-
// panics. The function creates a Grafana client using these credentials
30-
// and sets up the AlertChecker with a logger and a requirement label key.
26+
// NewAlertChecker creates and initializes a new AlertChecker.
27+
// It retrieves GRAFANA_URL and GRAFANA_TOKEN from environment variables, panicking if they are not set.
28+
// The AlertChecker is configured with the provided testing.T, a Grafana client, and a logger.
3129
func NewAlertChecker(t *testing.T) *AlertChecker {
3230
url := os.Getenv("GRAFANA_URL")
3331
if url == "" {
@@ -48,9 +46,9 @@ func NewAlertChecker(t *testing.T) *AlertChecker {
4846
}
4947
}
5048

51-
// AnyAlerts checks for alerts in Grafana that match the specified dashboard UUID and requirement label value.
52-
// It returns a slice of AlertGroupsResponse and any error encountered during the retrieval of alert groups.
53-
// If an alert is found, it logs the alert details and marks the test as failed if a testing object is present.
49+
// AnyAlerts retrieves alert groups from Grafana and scans for alerts matching the specified dashboardUUID and requirementLabelValue.
50+
// If matching alerts are found, it logs their details and marks the test as failed.
51+
// It returns all alert groups and any error encountered during retrieval.
5452
func (m *AlertChecker) AnyAlerts(dashboardUUID, requirementLabelValue string) ([]grafana.AlertGroupsResponse, error) {
5553
raised := false
5654
defer func() {
@@ -82,9 +80,8 @@ func (m *AlertChecker) AnyAlerts(dashboardUUID, requirementLabelValue string) ([
8280
return alertGroups, nil
8381
}
8482

85-
// CheckDashboardAlerts retrieves and checks alerts from a Grafana dashboard within a specified time range.
86-
// It returns a slice of annotations representing the alerts and an error if any alert is in the "alerting" state
87-
// or if there is an issue retrieving the annotations. The alerts are sorted by time from oldest to newest.
83+
// CheckDashboardAlerts retrieves alert annotations from a Grafana dashboard identified by dashboardUID within the specified time range.
84+
// It returns a sorted slice of annotations and an error if the retrieval fails or any alert is in a firing state.
8885
func CheckDashboardAlerts(grafanaClient *grafana.Client, from, to time.Time, dashboardUID string) ([]grafana.Annotation, error) {
8986
annotationType := "alert"
9087
alerts, _, err := grafanaClient.GetAnnotations(grafana.AnnotationsQueryParams{

wasp/buffer.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ type SliceBuffer[T any] struct {
77
Data []T
88
}
99

10-
// NewSliceBuffer creates a new SliceBuffer with the specified capacity.
11-
// It initializes the buffer to hold elements of any type T, starting with an empty slice.
12-
// The function returns a pointer to the newly created SliceBuffer.
10+
// NewSliceBuffer creates and returns a new SliceBuffer for elements of type T with the specified capacity.
1311
func NewSliceBuffer[T any](cap int) *SliceBuffer[T] {
1412
return &SliceBuffer[T]{Capacity: cap, Data: make([]T, 0)}
1513
}
1614

17-
// Append adds an element of type T to the SliceBuffer. If the buffer's capacity is reached,
18-
// it overwrites the oldest element, maintaining a circular buffer. The index is incremented
19-
// after each append operation, wrapping around to the start if necessary.
15+
// Append adds the element s to the SliceBuffer. If the buffer has not reached its capacity, s is appended to the data slice. Once the capacity is exceeded, Append overwrites the oldest element in the buffer. The internal index is incremented to track the next insertion point.
2016
func (m *SliceBuffer[T]) Append(s T) {
2117
if m.Idx >= m.Capacity {
2218
m.Idx = 0

wasp/cluster.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ type ClusterConfig struct {
6868
tmpHelmFilePath string
6969
}
7070

71-
// Defaults sets default values for the ClusterConfig fields if they are not already set.
72-
// It initializes Helm values, file paths, and resource requests and limits with default values.
73-
// It returns an error if any file operations fail during the setup process.
71+
// Defaults initializes default settings for the ClusterConfig.
72+
// It populates HelmValues and sets necessary file paths if they are not already configured.
73+
// The parameter a allows for customization during the defaulting process.
74+
// Returns an error if any defaulting operation fails.
7475
func (m *ClusterConfig) Defaults(a int) error {
7576
// TODO: will it be more clear if we move Helm values to a struct
7677
// TODO: or should it be like that for extensibility of a chart without reflection?
@@ -135,8 +136,8 @@ func (m *ClusterConfig) Defaults(a int) error {
135136
return nil
136137
}
137138

138-
// Validate checks the ClusterConfig for required fields and returns an error if any are missing.
139-
// Specifically, it ensures that the Namespace and HelmValues["jobs"] fields are not empty.
139+
// Validate checks that ClusterConfig has all required fields set.
140+
// It returns an error if Namespace is empty or if the "jobs" entry in HelmValues is missing.
140141
func (m *ClusterConfig) Validate() (err error) {
141142
if m.Namespace == "" {
142143
err = errors.Join(err, ErrNoNamespace)
@@ -147,8 +148,9 @@ func (m *ClusterConfig) Validate() (err error) {
147148
return
148149
}
149150

150-
// parseECRImageURI parses an Amazon ECR image URI into its constituent parts: registry, repository, and tag.
151-
// It returns an error if the URI does not match the expected format `${registry}/${repo}:${tag}`.
151+
// parseECRImageURI parses an ECR image URI and returns the registry, repository, and tag.
152+
// It expects the URI to follow the format ${registry}/${repo}:${tag}.
153+
// If the URI does not match this format, an error is returned.
152154
func parseECRImageURI(uri string) (registry, repo, tag string, err error) {
153155
re := regexp.MustCompile(`^([^/]+)/([^:]+):(.+)$`)
154156
matches := re.FindStringSubmatch(uri)
@@ -167,10 +169,10 @@ type ClusterProfile struct {
167169
}
168170

169171
// NewClusterProfile creates a new ClusterProfile using the provided ClusterConfig.
170-
// It validates and applies default settings to the configuration. It logs the configuration
171-
// and sets a context with a timeout based on the test timeout duration specified in the config.
172-
// If UpdateImage is true, it builds and pushes the image. It returns the ClusterProfile and
173-
// any error encountered during the process.
172+
// It validates the configuration, sets default values, and initializes the Kubernetes client.
173+
// The function parses the test timeout duration and sets up a context with the specified timeout.
174+
// If UpdateImage is enabled in the configuration, it builds and pushes the image.
175+
// It returns the initialized ClusterProfile or an error if any step fails.
174176
func NewClusterProfile(cfg *ClusterConfig) (*ClusterProfile, error) {
175177
if err := cfg.Validate(); err != nil {
176178
return nil, err
@@ -196,7 +198,9 @@ func NewClusterProfile(cfg *ClusterConfig) (*ClusterProfile, error) {
196198
return cp, nil
197199
}
198200

199-
// buildAndPushImage parses the ECR image URI from the configuration and constructs a command to build and push a Docker image. It returns an error if the URI parsing or command execution fails.
201+
// buildAndPushImage builds and pushes a Docker image based on the ClusterProfile configuration.
202+
// It parses the ECR image URI, constructs the Docker build and push command,
203+
// executes the command, and returns any encountered error.
200204
func (m *ClusterProfile) buildAndPushImage() error {
201205
registry, repo, tag, err := parseECRImageURI(m.cfg.HelmValues["image"])
202206
if err != nil {
@@ -215,10 +219,10 @@ func (m *ClusterProfile) buildAndPushImage() error {
215219
return ExecCmd(cmd)
216220
}
217221

218-
// deployHelm installs a Helm chart using the specified testName as the release name.
219-
// It constructs the Helm command with the chart path, values, namespace, and timeout
220-
// from the ClusterProfile configuration. It returns any error encountered during the
221-
// execution of the Helm command.
222+
// deployHelm installs the Helm chart using the provided testName and the ClusterProfile's configuration.
223+
// It sets the necessary Helm values, namespace, and deployment timeout based on the configuration.
224+
// The function constructs the Helm install command, logs the execution, and runs the command.
225+
// Returns an error if the Helm deployment fails.
222226
func (m *ClusterProfile) deployHelm(testName string) error {
223227
//nolint
224228
defer os.Remove(m.cfg.tmpHelmFilePath)
@@ -233,10 +237,9 @@ func (m *ClusterProfile) deployHelm(testName string) error {
233237
return ExecCmd(cmd.String())
234238
}
235239

236-
// Run generates a unique test name, modifies it to comply with Helm naming rules,
237-
// and deploys a Helm chart using this name. It retrieves the number of jobs from
238-
// the Helm values and tracks these jobs within the specified namespace. It returns
239-
// an error if any step in the process fails.
240+
// Run deploys the Helm chart using a generated test name and tracks the specified number of jobs.
241+
// It modifies the test name to ensure it starts with a letter and retrieves job configurations
242+
// from the cluster profile. Returns an error if deployment or job tracking fails.
240243
func (m *ClusterProfile) Run() error {
241244
testName := uuid.NewString()[0:8]
242245
tn := []rune(testName)

wasp/cmd.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import (
99
"github.com/rs/zerolog/log"
1010
)
1111

12-
// ExecCmd executes the given command string in a shell environment.
13-
// It logs the command's output using the default logging mechanism.
14-
// It returns any error encountered during the execution of the command.
12+
// ExecCmd executes the specified shell command and logs its standard output.
13+
// It returns an error if the command fails to start or exits with a non-zero status.
1514
func ExecCmd(command string) error {
1615
return ExecCmdWithStreamFunc(command, func(m string) {
1716
log.Info().Str("Text", m).Msg("Command output")
1817
})
1918
}
2019

21-
// readStdPipe reads lines from the provided io.ReadCloser pipe and passes each line to the streamFunc callback.
22-
// If streamFunc is nil, the lines are not processed. This function is typically used to handle output streams
23-
// from executed commands, allowing real-time processing of command output.
20+
// readStdPipe reads from the provided io.ReadCloser line by line and passes each line to streamFunc.
21+
// It continuously scans the pipe for newline-delimited input.
22+
// If streamFunc is nil, the input lines are ignored.
2423
func readStdPipe(pipe io.ReadCloser, streamFunc func(string)) {
2524
scanner := bufio.NewScanner(pipe)
2625
scanner.Split(bufio.ScanLines)
@@ -32,9 +31,9 @@ func readStdPipe(pipe io.ReadCloser, streamFunc func(string)) {
3231
}
3332
}
3433

35-
// ExecCmdWithStreamFunc executes a shell command and streams its output to the provided outputFunction.
36-
// The command's standard output and standard error are captured and passed to outputFunction line by line.
37-
// It returns any error encountered during the execution of the command.
34+
// ExecCmdWithStreamFunc executes the specified command and streams its output.
35+
// It splits the command string, starts the command, and sends each line from stdout and stderr to outputFunction.
36+
// Returns an error if the command fails to start or encounters an execution error.
3837
func ExecCmdWithStreamFunc(command string, outputFunction func(string)) error {
3938
c := strings.Split(command, " ")
4039
cmd := exec.Command(c[0], c[1:]...)

wasp/dashboard/cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"github.com/smartcontractkit/chainlink-testing-framework/wasp/dashboard"
55
)
66

7-
// main initializes a default dashboard without non-functional requirements (NFRs) or extensions.
8-
// It creates a new dashboard instance and deploys it, using environment variables for configuration.
9-
// If an error occurs during dashboard creation or deployment, the function panics.
7+
// main initializes and deploys the default dashboard without NFRs or extensions.
8+
// It sets required environment variables and deploys the dashboard.
9+
// The function panics if dashboard creation or deployment fails.
1010
func main() {
1111
// just default dashboard, no NFRs, no dashboard extensions
1212
// see examples/alerts.go for an example extension

0 commit comments

Comments
 (0)