From 9db5543fb48c772e2a8da88663f7f404367fcbb9 Mon Sep 17 00:00:00 2001 From: kane8n Date: Fri, 1 Mar 2024 18:13:50 +0900 Subject: [PATCH] add sample --- .../gatling-operator_v1alpha1_gatling03.yaml | 134 ++++++++++++++++++ gatling/sample/resources/goods_ids.csv | 6 + gatling/sample/resources/user_ids.csv | 6 + gatling/user-files/resources/myresources.csv | 1 + .../PersistentVolumeSampleSimulation.scala | 49 +++++++ 5 files changed, 196 insertions(+) create mode 100644 config/samples/gatling-operator_v1alpha1_gatling03.yaml create mode 100644 gatling/sample/resources/goods_ids.csv create mode 100644 gatling/sample/resources/user_ids.csv create mode 100644 gatling/user-files/simulations/PersistentVolumeSampleSimulation.scala diff --git a/config/samples/gatling-operator_v1alpha1_gatling03.yaml b/config/samples/gatling-operator_v1alpha1_gatling03.yaml new file mode 100644 index 0000000..11c844f --- /dev/null +++ b/config/samples/gatling-operator_v1alpha1_gatling03.yaml @@ -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 diff --git a/gatling/sample/resources/goods_ids.csv b/gatling/sample/resources/goods_ids.csv new file mode 100644 index 0000000..0b1029c --- /dev/null +++ b/gatling/sample/resources/goods_ids.csv @@ -0,0 +1,6 @@ +goods_id,goods_name +1,hoge +2,fuga +3,sample +4,test +5,goods diff --git a/gatling/sample/resources/user_ids.csv b/gatling/sample/resources/user_ids.csv new file mode 100644 index 0000000..d05828d --- /dev/null +++ b/gatling/sample/resources/user_ids.csv @@ -0,0 +1,6 @@ +user_id +1 +2 +3 +4 +5 diff --git a/gatling/user-files/resources/myresources.csv b/gatling/user-files/resources/myresources.csv index 9df02fe..3b634ff 100644 --- a/gatling/user-files/resources/myresources.csv +++ b/gatling/user-files/resources/myresources.csv @@ -1,3 +1,4 @@ +alphabet "a" "b" "c" diff --git a/gatling/user-files/simulations/PersistentVolumeSampleSimulation.scala b/gatling/user-files/simulations/PersistentVolumeSampleSimulation.scala new file mode 100644 index 0000000..e1fa24a --- /dev/null +++ b/gatling/user-files/simulations/PersistentVolumeSampleSimulation.scala @@ -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) + ) + ) +}