Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Make user simulator a CronJob #29

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 23 additions & 37 deletions k8s-manifests/base/user-simulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
apiVersion: batch/v1
kind: CronJob
metadata:
name: unguard-user-simulator
labels:
app.kubernetes.io/name: user-simulator
app.kubernetes.io/part-of: unguard
spec:
selector:
matchLabels:
app.kubernetes.io/name: user-simulator
app.kubernetes.io/part-of: unguard
replicas: 3
strategy:
type: Recreate
template:
metadata:
labels:
app.kubernetes.io/name: user-simulator
app.kubernetes.io/part-of: unguard
schedule: "*/3 * * * *"
startingDeadlineSeconds: 180
jobTemplate:
spec:
terminationGracePeriodSeconds: 5
restartPolicy: Always
containers:
- name: main
image: unguard-user-simulator
env:
- name: FRONTEND_ADDR
value: "unguard-envoy-proxy:8080/ui"
- name: SIMULATE_PRIVATE_RANGES
value: "false"
resources:
requests:
cpu: 10m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
initContainers:
- name: wait-for-frontend
image: curlimages/curl
command: [ "/bin/sh", "-c" ]
# TODO: #22 Replace this endpoint with a proper health check endpoint
args: [ 'while [ $(curl -ksw "%{http_code}" "http://unguard-envoy-proxy:8081/healthz?path=unguard-frontend" -o /dev/null) -ne 200 ]; do sleep 5; echo "health check failed . Waiting for the service..."; done' ]
template:
spec:
restartPolicy: OnFailure
containers:
- name: unguard-user-simulator-job
image: unguard-user-simulator
env:
- name: FRONTEND_ADDR
value: "unguard-envoy-proxy:8080/ui"
- name: SIMULATE_PRIVATE_RANGES
value: "false"
resources:
requests:
cpu: 10m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
2 changes: 1 addition & 1 deletion src/user-simulator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# based on snippet from https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
FROM node:14.20.0
FROM node:18.11.0

# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer installs, work.
Expand Down
22 changes: 12 additions & 10 deletions src/user-simulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,38 @@ Executes following tasks:
* post text posts
* post URL posts
* post image posts
* upgrades membership status
* log out

> Note: Currently it only executes all the tasks 10 times, as the 11th run fails.
> To apply load continually, simply wrap this user-simulator in a loop, or let it be auto restarted by Kubernetes
> Note: Currently it only executes all the tasks once.
> To apply load continually, a cronjob is used that starts the user-simulator periodically

## Prerequesites
## Prerequisites

* Node 14.*
* Node 18.* (recommended)
* [Yarn](https://yarnpkg.com/)


* Install all the dependencies by running:

```
yarn
yarn install
```

Adjust the following environment variables to fit your environment:

| Name | Example Value | Description |
|-------------------------|-------------------|----------------------------------------------------------------------------------|
| FRONTEND_ADDR | `unguard.kube/ui` | The base address for the Unguard frontend, contains no protocol or trailing slash
| SIMULATE_PRIVATE_RANGES | 'true' | Set to 'true' if you want the user simulator to generate traffic from private IP ranges
| Name | Example Value | Description |
|-------------------------|-------------------------------|----------------------------------------------------------------------------------------------|
| FRONTEND_ADDR | `unguard-envoy-proxy:8080/ui` | The base address for the Unguard frontend, contains no protocol or trailing slash |
| SIMULATE_PRIVATE_RANGES | `true` | Set to `true` if you want the user simulator to generate traffic from private IP ranges only |

## Running the user simulator

1. Start Unguard
2. Run the user simulator, pointing it to the Unguard frontend

```
export FRONTEND_ADDR="unguard.kube/ui"
export FRONTEND_ADDR="unguard-envoy-proxy:8080/ui"
yarn start
```

4 changes: 1 addition & 3 deletions src/user-simulator/default-user-sim.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ const ip = privateRanges ? random_ips_priv[getRandomInt(random_ips_priv.length)]
// noinspection JSUnusedGlobalSymbols
export const settings: TestSettings = {
userAgent: 'simulated-browser-user',
// Currently only 10 loops instead of Infinite, as the 11th run stalls forever
// But as K8s will restart the pod, this will still run indefinitely
loopCount: 10,
loopCount: 1,
screenshotOnFailure: false,
// Automatically wait for elements before trying to interact with them
waitUntil: 'visible',
Expand Down
12 changes: 4 additions & 8 deletions src/user-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@
"arrowParens": "avoid"
},
"dependencies": {
"@flood/element": "2.0.4",
"@flood/element-cli": "2.0.4",
"assert": "*",
"faker": "*",
"prettier": "*"
"@flood/element": "^2.0.4",
"@flood/element-cli": "^2.0.4",
"prettier": "^2.8.3"
},
"devDependencies": {
"@types/faker": "*",
"@types/assert": "*",
"@types/node": "*"
"@types/node": "18.11.18"
},
"element": {
"testMatch": [
Expand Down
50 changes: 20 additions & 30 deletions src/user-simulator/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@flood/element-core" "2.0.4"
"@flood/element-report" "2.0.0"

"@flood/element-cli@2.0.4":
"@flood/element-cli@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@flood/element-cli/-/element-cli-2.0.4.tgz#5c8db37cf227b710daf97b0a46e8ccf1065e873f"
integrity sha512-dZs1hpT/9SMqlrgd9riXMmdv4bZusc/DOtTKrWusj8EeFgFHtRMkY4wXjzmcuyV7UBT66DLXcsGwW0P8ahvZqA==
Expand Down Expand Up @@ -159,7 +159,7 @@
parse-duration "^0.1.2"
winston "^3.0.0"

"@flood/element@2.0.4":
"@flood/element@2.0.4", "@flood/element@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@flood/element/-/element-2.0.4.tgz#65c789f8abd8e591ecd4151f3c8995db586f02f5"
integrity sha512-/zFaby021P7+lIxrgDYDCcssHY9e9FkMvzNas4+fck8YQSbJaig0X4bvZKn9KiKiGXKKVXk59DQObNRPJesWLw==
Expand All @@ -184,16 +184,6 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==

"@types/assert@*":
version "1.5.6"
resolved "https://registry.yarnpkg.com/@types/assert/-/assert-1.5.6.tgz#a8b5a94ce5fb8f4ba65fdc37fc9507609114189e"
integrity sha512-Y7gDJiIqb9qKUHfBQYOWGngUpLORtirAVPuj/CWJrU2C6ZM4/y3XLwuwfGMF8s7QzW746LQZx23m0+1FSgjfug==

"@types/faker@*":
version "5.5.9"
resolved "https://registry.yarnpkg.com/@types/faker/-/faker-5.5.9.tgz#588ede92186dc557bff8341d294335d50d255f0c"
integrity sha512-uCx6mP3UY5SIO14XlspxsGjgaemrxpssJI0Ol+GfhxtcKpv9pgRZYsS4eeKeHVLje6Qtc8lGszuBI461+gVZBA==

"@types/faker@^4.1.9":
version "4.1.12"
resolved "https://registry.yarnpkg.com/@types/faker/-/faker-4.1.12.tgz#065d37343677df1aa757c622650bd14666c42602"
Expand Down Expand Up @@ -237,6 +227,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.4.tgz#64db61e0359eb5a8d99b55e05c729f130a678b04"
integrity sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ==

"@types/node@18.12.1":
version "18.11.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.18.tgz#8dfb97f0da23c2293e554c5a50d61ef134d7697f"
integrity sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==

"@types/normalize-package-data@^2.4.0":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
Expand Down Expand Up @@ -592,7 +587,15 @@ asn1.js@^5.2.0:
minimalistic-assert "^1.0.0"
safer-buffer "^2.1.0"

assert@*, assert@^2.0.0:
assert@^1.1.1, assert@^1.4.1:
version "1.5.0"
resolved "https://registry.yarnpkg.com/assert/-/assert-1.5.0.tgz#55c109aaf6e0aefdb3dc4b71240c70bf574b18eb"
integrity sha512-EDsgawzwoun2CZkCgtxJbv392v4nbk9XDD06zI+kQYoBM/3RBWLlEyJARDOmhAAosBjWACEkKL6S+lIZtcAubA==
dependencies:
object-assign "^4.1.1"
util "0.10.3"

assert@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/assert/-/assert-2.0.0.tgz#95fc1c616d48713510680f2eaf2d10dd22e02d32"
integrity sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==
Expand All @@ -602,14 +605,6 @@ assert@*, assert@^2.0.0:
object-is "^1.0.1"
util "^0.12.0"

assert@^1.1.1, assert@^1.4.1:
version "1.5.0"
resolved "https://registry.yarnpkg.com/assert/-/assert-1.5.0.tgz#55c109aaf6e0aefdb3dc4b71240c70bf574b18eb"
integrity sha512-EDsgawzwoun2CZkCgtxJbv392v4nbk9XDD06zI+kQYoBM/3RBWLlEyJARDOmhAAosBjWACEkKL6S+lIZtcAubA==
dependencies:
object-assign "^4.1.1"
util "0.10.3"

assign-symbols@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
Expand Down Expand Up @@ -1948,11 +1943,6 @@ extract-zip@^2.0.1:
optionalDependencies:
"@types/yauzl" "^2.9.1"

faker@*:
version "5.5.3"
resolved "https://registry.yarnpkg.com/faker/-/faker-5.5.3.tgz#c57974ee484431b25205c2c8dc09fda861e51e0e"
integrity sha512-wLTv2a28wjUyWkbnX7u/ABZBkUkIF2fCd73V6P2oFqEGEktDfzWx4UxrSqtPRw0xPRAcjeAOIiJWqZm3pP4u3g==

faker@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f"
Expand Down Expand Up @@ -4112,10 +4102,10 @@ prepend-http@^1.0.1:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=

prettier@*:
version "2.4.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.4.1.tgz#671e11c89c14a4cfc876ce564106c4a6726c9f5c"
integrity sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==
prettier@^2.8.3:
version "2.8.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.3.tgz#ab697b1d3dd46fb4626fbe2f543afe0cc98d8632"
integrity sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==

pretty-bytes@^5.1.0, pretty-bytes@^5.2.0:
version "5.6.0"
Expand Down