Skip to content

Commit

Permalink
add sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kane8n committed Mar 1, 2024
1 parent 3c7ae90 commit 9db5543
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
134 changes: 134 additions & 0 deletions config/samples/gatling-operator_v1alpha1_gatling03.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
apiVersion: gatling-operator.tech.zozo.com/v1alpha1
kind: Gatling
metadata:
name: gatling-sample03
spec:
generateReport: false # The flag of generating gatling report
generateLocalReport: false # The flag of generating gatling report for each pod
notifyReport: false # The flag of notifying gatling report
cleanupAfterJobDone: true # The flag of cleaning up gatling jobs resources after the job done
podSpec:
serviceAccountName: "gatling-operator-worker"
gatlingImage: ghcr.io/st-tech/gatling:latest # Optional. Default: ghcr.io/st-tech/gatling:latest. The image that will be used for Gatling container.
rcloneImage: rclone/rclone # Optional. Default: rclone/rclone:latest. The image that will be used for rclone conatiner.
resources: # Optional. Resources specifies the resource limits of the container.
limits:
cpu: "500m"
memory: "500Mi"
volumes:
- name: resource-vol
persistentVolumeClaim:
claimName: resource-pvc
affinity: # Optional. Affinity specification
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
#########################################################################################
# PersistentVolume
#########################################################################################
# To try this scenario with kind, add the extraMounts setting to config/kind/cluster.yaml
# ---------------------------------------------------------------------------------------
# kind: Cluster
# apiVersion: kind.x-k8s.io/v1alpha4
# nodes:
# - role: control-plane
# - role: worker
# + extraMounts:
# + - hostPath: /Users
# + containerPath: /Users
#########################################################################################
persistentVolume:
name: resource-pv
spec:
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
storageClassName: ""
capacity:
storage: 1Gi
local:
path: /Users/xxxxxx/github/st-tech/gatling-operator/gatling/sample/resources # path of the local environment you want to mount as a persistent volume
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
persistentVolumeClaim:
name: resource-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: ""
volumeName: resource-pv
resources:
requests:
storage: 1Gi
cloudStorageSpec:
#############################################################
# Storage Provider - aws (AMAZON S3)
#############################################################
provider: "aws" # Provider specifies the cloud provider that will be used. Supported providers: "aws", "gcp", "azure"
bucket: "gatling-operator-reports" # S3 Bucket name on which Gatlilng report files are stored
region: "ap-northeast-1" # Optional. Default: "ap-northeast-1" for aws provider. Region name
#env: # Optional. Environment variables to be used for connecting to the cloud providers
# # For S3 see also the env variables for auth: https://rclone.org/s3/#authentication
# - name: AWS_ACCESS_KEY_ID
# value: xxxxxxxxxxxxxxx
# - name: AWS_SECRET_ACCESS_KEY
# valueFrom:
# secretKeyRef:
# name: aws-credentail-secrets
# key: AWS_SECRET_ACCESS_KEY
#
#############################################################
# Storage Provider - gcp (Google Cloud Storage)
#############################################################
# provider: "gcp"
# bucket: "gatling-operator-reports" # GCS bucket name on which Gatlilng report files are stored
#
#############################################################
# Storage Provider - azure (Azure Blob Storage)
#############################################################
#provider: "azure"
#bucket: "gatling-operator-reports" # Azure Blob Storage container name on which Gatlilng report files are stored
#env: # Optional. Environment variables to be used for connecting to the cloud providers
# - name: AZUREBLOB_ACCOUNT # Azure Blob Storage Account Name
# value: xxxxxxxxxxxxxxx
# - name: AZUREBLOB_KEY # Azure Blob Access Key. Leave blank to use SAS URL
# valueFrom:
# secretKeyRef:
# name: azure-credentail-secrets
# key: AZUREBLOB_KEY
# - name: AZUREBLOB_SAS_URL # SAS URL. "Read, Write, List" permissions are required
# valueFrom:
# secretKeyRef:
# name: azure-credentail-secrets
# key: AZUREBLOB_SAS_URL
notificationServiceSpec:
provider: "slack" # Notification provider name. Supported provider: "slack"
secretName: "gatling-notification-slack-secrets" # The name of secret in which all key/value sets needed for the notification are stored
testScenarioSpec:
# startTime: 2021-09-10 08:45:31 # Optional. Start time of running test scenario in UTC. Format: %Y-%m-%d %H:%M:%S
parallelism: 3 # Optional. Default: 1. Number of pods running at any instant
# simulationsDirectoryPath: "/dir-path-to-simulation" # Optional. Default: /opt/gatling/user-files/simulations
# resourcesDirectoryPath: "dir-path-to-resources" # Optional. Default: /opt/gatling/user-files/resources
# resultsDirectoryPath: "dir-path-to-results" # Optional. Default: /opt/gatling/results.
simulationClass: "PersistentVolumeSampleSimulation" # Gatling simulation class name
env:
- name: ENV
value: "dev"
- name: CONCURRENCY
value: "2"
- name: DURATION
value: "10"
volumeMounts:
- name: resource-vol
mountPath: /opt/gatling/user-files/resources/pv
6 changes: 6 additions & 0 deletions gatling/sample/resources/goods_ids.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
goods_id,goods_name
1,hoge
2,fuga
3,sample
4,test
5,goods
6 changes: 6 additions & 0 deletions gatling/sample/resources/user_ids.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
user_id
1
2
3
4
5
1 change: 1 addition & 0 deletions gatling/user-files/resources/myresources.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
alphabet
"a"
"b"
"c"
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Sample originally from https://github.com/gatling/gatling/blob/400a125d7995d1b895c4cc4847ff15059d252948/gatling-bundle/src/main/scala/computerdatabase/BasicSimulation.scala
/*
* Copyright 2011-2021 GatlingCorp (https://gatling.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class PersistentVolumeSampleSimulation extends Simulation {

val usersPerSec = sys.env.getOrElse("CONCURRENCY", "1").toInt
val durationSec = sys.env.getOrElse("DURATION", "10").toInt

val feeder_user_ids = csv("pv/user_ids.csv")
val feeder_goods_ids = csv("pv/goods_ids.csv")
val feeder_myresources = csv("myresources.csv")

// A scenario is a chain of requests and pauses
val scn = scenario("Scenario Name")
.feed(feeder_user_ids.circular)
.feed(feeder_goods_ids.circular)
.feed(feeder_myresources.circular)
.exec { session =>
println(s"User ${session("user_id").as[String]} is buying goods ${session("goods_id").as[String]} ${session("goods_name").as[String]}")
println(s"myresource: ${session("alphabet").as[String]}")
session
}
// Note that Gatling has recorded real time pauses
.pause(1)

setUp(
scn.inject(
constantUsersPerSec(usersPerSec) during(durationSec seconds)
)
)
}

0 comments on commit 9db5543

Please sign in to comment.