Skip to content

Commit

Permalink
Merge pull request #66 from st-tech/add-print-columns
Browse files Browse the repository at this point in the history
Support Additional printer columns for Gatling CR
  • Loading branch information
yokawasa authored Nov 29, 2022
2 parents 417fa51 + 0e5598a commit 8f1e109
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 23 deletions.
12 changes: 9 additions & 3 deletions api/v1alpha1/gatling_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// GatlingSpec defines the desired state of Gatling
type GatlingSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
Expand Down Expand Up @@ -200,6 +197,10 @@ type GatlingStatus struct {
// +optional
RunnerCompleted bool `json:"runnerCompleted,omitempty"`

// The number of successfully completed runner pods. The format is (completed#/parallelism#)
// +optional
RunnerCompletions string `json:"runnerCompletions,omitempty"`

// Reporter job name
// +optional
ReporterJobName string `json:"reporterJobName,omitempty"`
Expand Down Expand Up @@ -231,6 +232,11 @@ type GatlingStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Runned",type=string,JSONPath=`.status.runnerCompletions`
//+kubebuilder:printcolumn:name="Reported",type=boolean,JSONPath=`.status.reportCompleted`
//+kubebuilder:printcolumn:name="Notified",type=boolean,JSONPath=`.status.notificationCompleted`
//+kubebuilder:printcolumn:name="ReportURL",type=string,JSONPath=`.status.reportUrl`
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// Gatling is the Schema for the gatlings API
type Gatling struct {
Expand Down
22 changes: 21 additions & 1 deletion config/crd/bases/gatling-operator.tech.zozo.com_gatlings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@ spec:
singular: gatling
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .status.runnerCompletions
name: Runned
type: string
- jsonPath: .status.reportCompleted
name: Reported
type: boolean
- jsonPath: .status.notificationCompleted
name: Notified
type: boolean
- jsonPath: .status.reportUrl
name: ReportURL
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: Gatling is the Schema for the gatlings API
Expand Down Expand Up @@ -1339,6 +1355,10 @@ spec:
runnerCompleted:
description: Is runner job completed (default false)
type: boolean
runnerCompletions:
description: The number of successfully completed runner pods. The
format is (completed#/parallelism#)
type: string
runnerJobName:
description: Runner job name
type: string
Expand Down
9 changes: 8 additions & 1 deletion controllers/gatling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
gatling.Status.Active = runnerJob.Status.Active
gatling.Status.Failed = runnerJob.Status.Failed
gatling.Status.Succeeded = runnerJob.Status.Succeeded
gatling.Status.RunnerCompletions = r.getRunnerCompletionsStatus(gatling)
gatling.Status.RunnerCompleted = false
gatling.Status.ReportCompleted = false
gatling.Status.NotificationCompleted = false
Expand Down Expand Up @@ -235,6 +236,7 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
gatling.Status.Active = foundJob.Status.Active
gatling.Status.Failed = foundJob.Status.Failed
gatling.Status.Succeeded = foundJob.Status.Succeeded
gatling.Status.RunnerCompletions = r.getRunnerCompletionsStatus(gatling)

// Check if the job runs out of time in running the job
duration := utils.GetEpocTime() - gatling.Status.RunnerStartTime
Expand Down Expand Up @@ -838,10 +840,11 @@ func (r *GatlingReconciler) updateGatlingStatus(ctx context.Context, gatling *ga
}

func (r *GatlingReconciler) dumpGatlingStatus(gatling *gatlingv1alpha1.Gatling, log logr.Logger) {
log.Info(fmt.Sprintf("GatlingStatus: Active %d Succeeded %d Failed %d ReportCompleted %t NotificationCompleted %t ReportUrl %s Error %v",
log.Info(fmt.Sprintf("GatlingStatus: Active %d Succeeded %d Failed %d RunnerCompletions %s ReportCompleted %t NotificationCompleted %t ReportUrl %s Error %v",
gatling.Status.Active,
gatling.Status.Succeeded,
gatling.Status.Failed,
gatling.Status.RunnerCompletions,
gatling.Status.ReportCompleted,
gatling.Status.NotificationCompleted,
gatling.Status.ReportUrl,
Expand Down Expand Up @@ -1004,6 +1007,10 @@ func (r *GatlingReconciler) getGenerateLocalReport(gatling *gatlingv1alpha1.Gatl
return gatling.Spec.GenerateLocalReport
}

func (r *GatlingReconciler) getRunnerCompletionsStatus(gatling *gatlingv1alpha1.Gatling) string {
return fmt.Sprintf("%d/%d", gatling.Status.Succeeded, *(r.getGatlingRunnerJobParallelism(gatling)))
}

// SetupWithManager sets up the controller with the Manager.
func (r *GatlingReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down
37 changes: 19 additions & 18 deletions docs/quickstart-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ kind create cluster
## Install Gatling Operator

```bash
kubectl apply -f https://github.com/st-tech/gatling-operator/releases/download/v0.5.0/gatling-operator.yaml
kubectl apply -f https://github.com/st-tech/gatling-operator/releases/download/v0.9.0/gatling-operator.yaml
```

Expected output would be like this:
Expand All @@ -49,7 +49,7 @@ deployment.apps/gatling-operator-controller-manager created

All resources required for the Gatling operator, such as CRD and controller manager, are deployed using the command above. Now you're ready to deploy Gatling CR to run Gatling load testing.

The command above applies a Gatling Operator manifest of v0.5.0. Please change the version if necessary. You can check the version from the [Release page](https://github.com/st-tech/gatling-operator/releases).
The command above applies a Gatling Operator manifest of v0.9.0. Please change the version if necessary. You can check the version from the [Release page](https://github.com/st-tech/gatling-operator/releases).

## Run your first load testing by deploying Gatling CR

Expand Down Expand Up @@ -78,16 +78,16 @@ $ kubectl get gatling,job,pod
Expected output would be like this:

```
NAME AGE
gatling.gatling-operator.tech.zozo.com/gatling-sample01 10s
NAME RUNNED REPORTED NOTIFIED REPORTURL AGE
gatling.gatling-operator.tech.zozo.com/gatling-sample01 0/3 https://gatling-operator-reports.s3.amazonaws.com/gatling-sample01/318807881/index.html 24s
NAME COMPLETIONS DURATION AGE
job.batch/gatling-sample01-runner 0/3 9s 9s
job.batch/gatling-sample01-runner 0/3 24s 24s
NAME READY STATUS RESTARTS AGE
pod/gatling-sample01-runner-8rhl4 1/1 Running 0 9s
pod/gatling-sample01-runner-cg8rt 1/1 Running 0 9s
pod/gatling-sample01-runner-tkplh 1/1 Running 0 9s
pod/gatling-sample01-runner-8rhl4 2/2 Running 0 24s
pod/gatling-sample01-runner-cg8rt 2/2 Running 0 24s
pod/gatling-sample01-runner-tkplh 2/2 Running 0 24s
```

You can also see from the Pod logs that Gatling is running.
Expand All @@ -99,12 +99,12 @@ kubectl logs gatling-sample01-runner-tkplh -c gatling-runner -f
Expected output would be like this:

```bash
Wait until 2022-02-25 06:07:25
Wait until 2022-11-28 00:34:56
GATLING_HOME is set to /opt/gatling
Simulation MyBasicSimulation started...

================================================================================
2022-02-25 06:08:31 5s elapsed
2022-11-28 00:37:17 5s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=2 KO=0 )
> request_1 (OK=1 KO=0 )
Expand All @@ -117,7 +117,7 @@ Simulation MyBasicSimulation started...


================================================================================
2022-02-25 06:08:36 10s elapsed
2022-11-28 00:37:22 10s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=3 KO=0 )
> request_1 (OK=1 KO=0 )
Expand All @@ -131,7 +131,7 @@ Simulation MyBasicSimulation started...


================================================================================
2022-02-25 06:08:40 14s elapsed
2022-11-28 00:37:27 14s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=6 KO=0 )
> request_1 (OK=1 KO=0 )
Expand All @@ -146,7 +146,7 @@ Simulation MyBasicSimulation started...
waiting: 0 / active: 0 / done: 1
================================================================================

Simulation MyBasicSimulation completed in 14 seconds
Simulation MyBasicSimulation completed in 15 seconds
```
As configured in [the sample manifest](https://github.com/st-tech/gatling-operator/blob/85e69840274214c47e63f65a5c807dd541dff245/config/samples/gatling-operator_v1alpha1_gatling01.yaml#L6-L8), an aggregated Gatling HTML report is not created, nor a notification message is posted.
Expand Down Expand Up @@ -206,11 +206,12 @@ kubectl get gatling gatling-sample01 -o jsonpath='{@.status}' |jq
"reportStoragePath": "s3:gatling-operator-reports/gatling-sample01/318807881"
"reportUrl": "https://gatling-operator-reports.s3.amazonaws.com/gatling-sample01/318807881/index.html"
"reporterJobName": gatling-sample01-reporter
"reporterStartTime": 1631415671
"runnerCompleted": true
"runnerJobName": gatling-sample01-runner
"runnerStartTime": 1631415570
"succeeded": 5
"reporterStartTime": 1669595852,
"runnerCompleted": true,
"runnerCompletions": "3/3",
"runnerJobName": "gatling-sample01-runner",
"runnerStartTime": 1669595687,
"succeeded": 3
}
```
Expand Down

0 comments on commit 8f1e109

Please sign in to comment.