Skip to content

Commit 8f1e109

Browse files
authored
Merge pull request #66 from st-tech/add-print-columns
Support Additional printer columns for Gatling CR
2 parents 417fa51 + 0e5598a commit 8f1e109

File tree

4 files changed

+57
-23
lines changed

4 files changed

+57
-23
lines changed

api/v1alpha1/gatling_types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
)
2323

24-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26-
2724
// GatlingSpec defines the desired state of Gatling
2825
type GatlingSpec struct {
2926
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
@@ -200,6 +197,10 @@ type GatlingStatus struct {
200197
// +optional
201198
RunnerCompleted bool `json:"runnerCompleted,omitempty"`
202199

200+
// The number of successfully completed runner pods. The format is (completed#/parallelism#)
201+
// +optional
202+
RunnerCompletions string `json:"runnerCompletions,omitempty"`
203+
203204
// Reporter job name
204205
// +optional
205206
ReporterJobName string `json:"reporterJobName,omitempty"`
@@ -231,6 +232,11 @@ type GatlingStatus struct {
231232

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

235241
// Gatling is the Schema for the gatlings API
236242
type Gatling struct {

config/crd/bases/gatling-operator.tech.zozo.com_gatlings.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ spec:
1616
singular: gatling
1717
scope: Namespaced
1818
versions:
19-
- name: v1alpha1
19+
- additionalPrinterColumns:
20+
- jsonPath: .status.runnerCompletions
21+
name: Runned
22+
type: string
23+
- jsonPath: .status.reportCompleted
24+
name: Reported
25+
type: boolean
26+
- jsonPath: .status.notificationCompleted
27+
name: Notified
28+
type: boolean
29+
- jsonPath: .status.reportUrl
30+
name: ReportURL
31+
type: string
32+
- jsonPath: .metadata.creationTimestamp
33+
name: Age
34+
type: date
35+
name: v1alpha1
2036
schema:
2137
openAPIV3Schema:
2238
description: Gatling is the Schema for the gatlings API
@@ -1339,6 +1355,10 @@ spec:
13391355
runnerCompleted:
13401356
description: Is runner job completed (default false)
13411357
type: boolean
1358+
runnerCompletions:
1359+
description: The number of successfully completed runner pods. The
1360+
format is (completed#/parallelism#)
1361+
type: string
13421362
runnerJobName:
13431363
description: Runner job name
13441364
type: string

controllers/gatling_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
205205
gatling.Status.Active = runnerJob.Status.Active
206206
gatling.Status.Failed = runnerJob.Status.Failed
207207
gatling.Status.Succeeded = runnerJob.Status.Succeeded
208+
gatling.Status.RunnerCompletions = r.getRunnerCompletionsStatus(gatling)
208209
gatling.Status.RunnerCompleted = false
209210
gatling.Status.ReportCompleted = false
210211
gatling.Status.NotificationCompleted = false
@@ -235,6 +236,7 @@ func (r *GatlingReconciler) gatlingRunnerReconcile(ctx context.Context, req ctrl
235236
gatling.Status.Active = foundJob.Status.Active
236237
gatling.Status.Failed = foundJob.Status.Failed
237238
gatling.Status.Succeeded = foundJob.Status.Succeeded
239+
gatling.Status.RunnerCompletions = r.getRunnerCompletionsStatus(gatling)
238240

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

840842
func (r *GatlingReconciler) dumpGatlingStatus(gatling *gatlingv1alpha1.Gatling, log logr.Logger) {
841-
log.Info(fmt.Sprintf("GatlingStatus: Active %d Succeeded %d Failed %d ReportCompleted %t NotificationCompleted %t ReportUrl %s Error %v",
843+
log.Info(fmt.Sprintf("GatlingStatus: Active %d Succeeded %d Failed %d RunnerCompletions %s ReportCompleted %t NotificationCompleted %t ReportUrl %s Error %v",
842844
gatling.Status.Active,
843845
gatling.Status.Succeeded,
844846
gatling.Status.Failed,
847+
gatling.Status.RunnerCompletions,
845848
gatling.Status.ReportCompleted,
846849
gatling.Status.NotificationCompleted,
847850
gatling.Status.ReportUrl,
@@ -1004,6 +1007,10 @@ func (r *GatlingReconciler) getGenerateLocalReport(gatling *gatlingv1alpha1.Gatl
10041007
return gatling.Spec.GenerateLocalReport
10051008
}
10061009

1010+
func (r *GatlingReconciler) getRunnerCompletionsStatus(gatling *gatlingv1alpha1.Gatling) string {
1011+
return fmt.Sprintf("%d/%d", gatling.Status.Succeeded, *(r.getGatlingRunnerJobParallelism(gatling)))
1012+
}
1013+
10071014
// SetupWithManager sets up the controller with the Manager.
10081015
func (r *GatlingReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
10091016
return ctrl.NewControllerManagedBy(mgr).

docs/quickstart-guide.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ kind create cluster
3131
## Install Gatling Operator
3232

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

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

5050
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.
5151

52-
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).
52+
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).
5353

5454
## Run your first load testing by deploying Gatling CR
5555

@@ -78,16 +78,16 @@ $ kubectl get gatling,job,pod
7878
Expected output would be like this:
7979

8080
```
81-
NAME AGE
82-
gatling.gatling-operator.tech.zozo.com/gatling-sample01 10s
81+
NAME RUNNED REPORTED NOTIFIED REPORTURL AGE
82+
gatling.gatling-operator.tech.zozo.com/gatling-sample01 0/3 https://gatling-operator-reports.s3.amazonaws.com/gatling-sample01/318807881/index.html 24s
8383
8484
NAME COMPLETIONS DURATION AGE
85-
job.batch/gatling-sample01-runner 0/3 9s 9s
85+
job.batch/gatling-sample01-runner 0/3 24s 24s
8686
8787
NAME READY STATUS RESTARTS AGE
88-
pod/gatling-sample01-runner-8rhl4 1/1 Running 0 9s
89-
pod/gatling-sample01-runner-cg8rt 1/1 Running 0 9s
90-
pod/gatling-sample01-runner-tkplh 1/1 Running 0 9s
88+
pod/gatling-sample01-runner-8rhl4 2/2 Running 0 24s
89+
pod/gatling-sample01-runner-cg8rt 2/2 Running 0 24s
90+
pod/gatling-sample01-runner-tkplh 2/2 Running 0 24s
9191
```
9292

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

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

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

118118

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

132132

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

149-
Simulation MyBasicSimulation completed in 14 seconds
149+
Simulation MyBasicSimulation completed in 15 seconds
150150
```
151151
152152
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.
@@ -206,11 +206,12 @@ kubectl get gatling gatling-sample01 -o jsonpath='{@.status}' |jq
206206
"reportStoragePath": "s3:gatling-operator-reports/gatling-sample01/318807881"
207207
"reportUrl": "https://gatling-operator-reports.s3.amazonaws.com/gatling-sample01/318807881/index.html"
208208
"reporterJobName": gatling-sample01-reporter
209-
"reporterStartTime": 1631415671
210-
"runnerCompleted": true
211-
"runnerJobName": gatling-sample01-runner
212-
"runnerStartTime": 1631415570
213-
"succeeded": 5
209+
"reporterStartTime": 1669595852,
210+
"runnerCompleted": true,
211+
"runnerCompletions": "3/3",
212+
"runnerJobName": "gatling-sample01-runner",
213+
"runnerStartTime": 1669595687,
214+
"succeeded": 3
214215
}
215216
```
216217

0 commit comments

Comments
 (0)