Skip to content

Commit babb831

Browse files
committed
better godocs
1 parent af82790 commit babb831

22 files changed

+275
-347
lines changed

wasp/alert.go

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

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.
26+
// NewAlertChecker creates a new AlertChecker using Grafana configurations from environment variables.
27+
// It retrieves GRAFANA_URL and GRAFANA_TOKEN, ensuring they are set.
28+
// Use this function to set up alert checking in tests.
2929
func NewAlertChecker(t *testing.T) *AlertChecker {
3030
url := os.Getenv("GRAFANA_URL")
3131
if url == "" {
@@ -46,9 +46,8 @@ func NewAlertChecker(t *testing.T) *AlertChecker {
4646
}
4747
}
4848

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.
49+
// AnyAlerts retrieves alert groups from Grafana and checks for alerts matching the specified dashboard UUID and requirement label value.
50+
// It returns the matching alert groups, enabling users to identify and respond to specific alert conditions.
5251
func (m *AlertChecker) AnyAlerts(dashboardUUID, requirementLabelValue string) ([]grafana.AlertGroupsResponse, error) {
5352
raised := false
5453
defer func() {
@@ -80,8 +79,9 @@ func (m *AlertChecker) AnyAlerts(dashboardUUID, requirementLabelValue string) ([
8079
return alertGroups, nil
8180
}
8281

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.
82+
// CheckDashboardAlerts retrieves alert annotations from a Grafana dashboard within the specified time range.
83+
// It returns the sorted alerts and an error if any alert is in the alerting state.
84+
// Use it to verify the status of dashboard alerts after a run.
8585
func CheckDashboardAlerts(grafanaClient *grafana.Client, from, to time.Time, dashboardUID string) ([]grafana.Annotation, error) {
8686
annotationType := "alert"
8787
alerts, _, err := grafanaClient.GetAnnotations(grafana.AnnotationsQueryParams{

wasp/buffer.go

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

10-
// NewSliceBuffer creates and returns a new SliceBuffer for elements of type T with the specified capacity.
10+
// NewSliceBuffer creates a new SliceBuffer with the specified capacity.
11+
// It provides an efficient way to store and manage a fixed number of elements,
12+
// enabling optimized access and manipulation in concurrent and decentralized applications.
1113
func NewSliceBuffer[T any](cap int) *SliceBuffer[T] {
1214
return &SliceBuffer[T]{Capacity: cap, Data: make([]T, 0)}
1315
}
1416

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.
17+
// Append adds an element to the SliceBuffer. When the buffer reaches its capacity, it overwrites the oldest item.
18+
// This function is useful for maintaining a fixed-size, circular collection of elements.
1619
func (m *SliceBuffer[T]) Append(s T) {
1720
if m.Idx >= m.Capacity {
1821
m.Idx = 0

wasp/cluster.go

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

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.
71+
// Defaults initializes ClusterConfig with default values for any unset fields.
72+
// It ensures all necessary configuration parameters are provided for proper cluster deployment.
7573
func (m *ClusterConfig) Defaults(a int) error {
7674
// TODO: will it be more clear if we move Helm values to a struct
7775
// TODO: or should it be like that for extensibility of a chart without reflection?
@@ -136,8 +134,8 @@ func (m *ClusterConfig) Defaults(a int) error {
136134
return nil
137135
}
138136

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.
137+
// Validate checks that the ClusterConfig has all required fields set.
138+
// It returns an error if any mandatory configuration is missing.
141139
func (m *ClusterConfig) Validate() (err error) {
142140
if m.Namespace == "" {
143141
err = errors.Join(err, ErrNoNamespace)
@@ -148,9 +146,9 @@ func (m *ClusterConfig) Validate() (err error) {
148146
return
149147
}
150148

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.
149+
// parseECRImageURI parses an ECR image URI into registry, repository, and tag.
150+
// It returns an error if the URI format is invalid.
151+
// Use it to extract components for building and deploying Docker images.
154152
func parseECRImageURI(uri string) (registry, repo, tag string, err error) {
155153
re := regexp.MustCompile(`^([^/]+)/([^:]+):(.+)$`)
156154
matches := re.FindStringSubmatch(uri)
@@ -168,11 +166,10 @@ type ClusterProfile struct {
168166
Cancel context.CancelFunc
169167
}
170168

171-
// NewClusterProfile creates a new ClusterProfile using the provided ClusterConfig.
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.
169+
// NewClusterProfile creates a new ClusterProfile from the provided ClusterConfig.
170+
// It validates the configuration, sets default values, and initializes necessary components.
171+
// Optionally, it builds and pushes images based on the configuration.
172+
// Use this function to initialize cluster management.
176173
func NewClusterProfile(cfg *ClusterConfig) (*ClusterProfile, error) {
177174
if err := cfg.Validate(); err != nil {
178175
return nil, err
@@ -198,9 +195,8 @@ func NewClusterProfile(cfg *ClusterConfig) (*ClusterProfile, error) {
198195
return cp, nil
199196
}
200197

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.
198+
// buildAndPushImage builds a Docker image using the cluster's configuration and pushes it to the specified registry.
199+
// It returns an error if the build or push operation fails.
204200
func (m *ClusterProfile) buildAndPushImage() error {
205201
registry, repo, tag, err := parseECRImageURI(m.cfg.HelmValues["image"])
206202
if err != nil {
@@ -219,10 +215,8 @@ func (m *ClusterProfile) buildAndPushImage() error {
219215
return ExecCmd(cmd)
220216
}
221217

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.
218+
// deployHelm installs a Helm chart using the provided test name and the ClusterProfile's configuration.
219+
// It constructs the Helm install command with specified values, namespace, and timeout, then executes it.
226220
func (m *ClusterProfile) deployHelm(testName string) error {
227221
//nolint
228222
defer os.Remove(m.cfg.tmpHelmFilePath)
@@ -237,9 +231,9 @@ func (m *ClusterProfile) deployHelm(testName string) error {
237231
return ExecCmd(cmd.String())
238232
}
239233

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.
234+
// Run deploys the Helm chart and tracks job execution for the ClusterProfile.
235+
// It generates a unique ID, deploys via Helm, and monitors jobs in the namespace.
236+
// Returns an error if deployment or tracking fails.
243237
func (m *ClusterProfile) Run() error {
244238
testName := uuid.NewString()[0:8]
245239
tn := []rune(testName)

wasp/cmd.go

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

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.
12+
// ExecCmd executes the provided command string and logs its output.
13+
// It returns an error if the command fails to run or exits with a non-zero status.
1414
func ExecCmd(command string) error {
1515
return ExecCmdWithStreamFunc(command, func(m string) {
1616
log.Info().Str("Text", m).Msg("Command output")
1717
})
1818
}
1919

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.
20+
// readStdPipe reads lines from the provided pipe and sends each line to streamFunc.
21+
// It is used to handle streaming output from command execution, such as stdout and stderr.
2322
func readStdPipe(pipe io.ReadCloser, streamFunc func(string)) {
2423
scanner := bufio.NewScanner(pipe)
2524
scanner.Split(bufio.ScanLines)
@@ -31,9 +30,8 @@ func readStdPipe(pipe io.ReadCloser, streamFunc func(string)) {
3130
}
3231
}
3332

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.
33+
// ExecCmdWithStreamFunc runs the specified command and streams its output and error lines
34+
// to the provided outputFunction. It enables real-time handling of command execution output.
3735
func ExecCmdWithStreamFunc(command string, outputFunction func(string)) error {
3836
c := strings.Split(command, " ")
3937
cmd := exec.Command(c[0], c[1:]...)

wasp/dashboard/cmd/main.go

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

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.
7+
// main creates and deploys a default dashboard using environment variables for configuration.
8+
// It sets up the dashboard without extensions or non-functional requirements, enabling straightforward deployment.
109
func main() {
1110
// just default dashboard, no NFRs, no dashboard extensions
1211
// see examples/alerts.go for an example extension

0 commit comments

Comments
 (0)