Skip to content

Commit

Permalink
fixup! cloud, plz: add public detail and abort to events
Browse files Browse the repository at this point in the history
  • Loading branch information
yorugac committed Nov 6, 2023
1 parent 030ddf2 commit d48f8cf
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
11 changes: 11 additions & 0 deletions api/v1alpha1/testruni.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ type TestRunI interface {
GetSpec() *TestRunSpec
NamespacedName() types.NamespacedName
}

// TestRunID is a tiny helper to get k6 Cloud test run ID.
// PLZ test run will have test run ID as part of spec
// while cloud output test run as part of status.
func TestRunID(k6 TestRunI) string {
specId := k6.GetSpec().TestRunID
if len(specId) > 0 {
return specId
}
return k6.GetStatus().TestRunID
}
2 changes: 1 addition & 1 deletion controllers/k6_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func CreateJobs(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI, r *T
events := cloud.ErrorEvent(cloud.K6OperatorStartError).
WithDetail(fmt.Sprintf("Failed to create runner jobs: %v", err)).
WithAbort()
cloud.SendTestRunEvents(r.k6CloudClient, k6.GetSpec().TestRunID, log, events)
cloud.SendTestRunEvents(r.k6CloudClient, v1alpha1.TestRunID(k6), log, events)
}

return res, err
Expand Down
2 changes: 1 addition & 1 deletion controllers/k6_finish.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func FinishJobs(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI, r *T
events := cloud.ErrorEvent(cloud.K6OperatorRunnerError).
WithDetail(msg).
WithAbort()
cloud.SendTestRunEvents(r.k6CloudClient, k6.GetSpec().TestRunID, log, events)
cloud.SendTestRunEvents(r.k6CloudClient, v1alpha1.TestRunID(k6), log, events)
}

if finished < k6.GetSpec().Parallelism {
Expand Down
2 changes: 1 addition & 1 deletion controllers/k6_initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func RunValidations(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
events := cloud.ErrorEvent(cloud.K6OperatorStartError).
WithDetail(fmt.Sprintf("Failed to inspect the test script: %v", err)).
WithAbort()
cloud.SendTestRunEvents(r.k6CloudClient, k6.GetSpec().TestRunID, log, events)
cloud.SendTestRunEvents(r.k6CloudClient, v1alpha1.TestRunID(k6), log, events)
}

// inspectTestRun made a log message already so just return without requeue
Expand Down
2 changes: 1 addition & 1 deletion controllers/k6_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func StartJobs(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI, r *Te
events := cloud.ErrorEvent(cloud.K6OperatorStartError).
WithDetail("Creation of runner pods takes too long: your configuration might be off. Check if runner jobs and pods were created successfully.").
WithAbort()
cloud.SendTestRunEvents(r.k6CloudClient, k6.GetSpec().TestRunID, log, events)
cloud.SendTestRunEvents(r.k6CloudClient, v1alpha1.TestRunID(k6), log, events)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/test_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func GetTestRunData(client *cloudapi.Client, refID string) (*TestRunData, error)
return getTestRun(client, url)
}

// called by K6 controller
// called by TestRun controller
func GetTestRunState(client *cloudapi.Client, refID string, log logr.Logger) (TestRunStatus, error) {
url := fmt.Sprintf("%s/loadtests/v4/test_runs(%s)?$select=id,run_status", ApiURL(client.BaseURL()), refID)
trData, err := getTestRun(client, url)
Expand All @@ -121,7 +121,7 @@ func GetTestRunState(client *cloudapi.Client, refID string, log logr.Logger) (Te
return TestRunStatus(trData.RunStatus), nil
}

// called by K6 controller
// called by TestRun controller
// If there's an error, it'll be logged.
func SendTestRunEvents(client *cloudapi.Client, refID string, log logr.Logger, events *Events) {
if len(*events) == 0 {
Expand Down

0 comments on commit d48f8cf

Please sign in to comment.