Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
raghu0891 committed Nov 18, 2024
0 parents commit 2b133bb
Show file tree
Hide file tree
Showing 6,175 changed files with 1,893,154 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export LOKI_TOKEN=
export LOKI_URL=http://localhost:3030/loki/api/v1/push
export GRAFANA_URL=http://localhost:3000
export GRAFANA_TOKEN=
export DATA_SOURCE_NAME=Loki
export DASHBOARD_FOLDER=LoadTests
export DASHBOARD_NAME=Wasp
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
23 changes: 23 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Bench
on: [push]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu20.04-8cores-32GB
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
cache: true
- name: Download Go vendor packages
run: go mod download
- name: Install cob
run: curl -sfL https://raw.githubusercontent.com/knqyf263/cob/master/install.sh | sudo sh -s -- -b /usr/local/bin
- name: Run Benchmark
run: cob --bench-cmd make --bench-args test_bench
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint
on:
push:
permissions:
contents: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: true
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
23 changes: 23 additions & 0 deletions .github/workflows/test-external-load-gha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: E2E tests
on: [push]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
env:
LOKI_TENANT_ID: ${{ secrets.LOKI_TENANT_ID }}
LOKI_BASIC_AUTH: ${{ secrets.LOKI_BASIC_AUTH }}
LOKI_URL: ${{ secrets.LOKI_URL }}
runs-on: ubuntu20.04-8cores-32GB
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
cache: true
- name: Download Go vendor packages
run: go mod download
- name: Run external load test
run: make test_loki
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Go Tests
on: [push]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu20.04-8cores-32GB
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
cache: true
- name: Download Go vendor packages
run: go mod download
- name: Run tests
run: make test_race
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bin/
.vscode/
.idea/
.direnv/

k3dvolume/
.private.env
15 changes: 15 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
run:
timeout: 5m
skip-dirs:
- bin
- imports
issues:
exclude-use-default: false
linters-settings:
revive:
rules:
- name: exported
severity: warning
- name: dot-imports
disabled: true
linters:
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang 1.21.3
golangci-lint 1.55.2
112 changes: 112 additions & 0 deletions CLUSTER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Cluster mode

## Motivation

When it comes to load testing, using multiple nodes is essential for a few reasons:

**Increased accuracy**: Running a load test on a single node may not be able to replicate the actual user behavior accurately. In real-world scenarios, multiple users access the application from different locations and devices, resulting in varied network and device performance. Running the load test on a single node would not be able to take into account these variations, leading to inaccurate results. Using multiple nodes allows you to simulate more realistic conditions and produce more accurate load testing results.

**Higher throughput**: A single node has a limited capacity to generate load. When the load increases beyond this capacity, the results may become unreliable. By using multiple nodes, you can generate a higher level of load and stress the system more effectively, providing a better picture of the system's behavior under high load conditions.

## How it works
- You separate your code into 2 parts: `cluster_test.go` ( client ) and `node_*_test.go` ( test )
- `cluster_test.go` only controls the deployment and tracks `k8s jobs`
- You can share your `cluster_test.go` for a group of tests and use env vars to set `test.name` or other settings
- Run client code, if `k8s` will fail to allocate resources test will end in `Timeout` and jobs will be deleted with pods
- When each `job` got allocated your pod code will start to wait until all `pods` spun by client ( with unique `sync` id generated on start ) will have status `Running` if that won't happen until timeout client will remove all the pods
- When `N pods with unique test label are in status Running` the test will start, lag between pods start is 1sec max
- In case of any fatal error client will remove all the `jobs`
- When all `jobs` are complete test will end

## Workflow
- Create namespace `wasp` and apply default permissions
```
cd charts/wasp
kubectl create ns wasp
kubectl -n wasp apply -f setup.yaml
```
- Build your `Docker` container with tests, you can use this [example](Dockerfile.test)
```
docker build -f Dockerfile.test --build-arg BUILD_ROOT=/go/src/examples/cluster -t wasp_test .
docker tag wasp_test:latest ${registry}/wasp_test:latest
docker push ${registry}/wasp_test:latest
```

- Set [wasp chart](charts/wasp) in test params
```
ChartPath: "../../charts/wasp"
or
ChartPath: "oci://public.ecr.aws/plugin/wasp"
```
- Set `HelmValues` test params
```
"env.loki.url": os.Getenv("LOKI_URL"),
"env.loki.token": os.Getenv("LOKI_TOKEN"),
// put any test name from node_*_test.go here
"test.name": "TestNodeRPS",
"test.timeout": "24h",
// put your image here
"image": "public.ecr.aws/plugin/wasp-test:latest",
"jobs": "40",
"resources.requests.cpu": "2000m",
"resources.requests.memory": "512Mi",
"resources.limits.cpu": "2000m",
"resources.limits.memory": "512Mi",
"env.wasp.log_level": "debug",
```
- If you need to share some static data, you can use `go:embed` as described [here](http://www.inanzzz.com/index.php/post/1rwm/including-and-reading-static-files-with-embed-directive-at-compile-time-in-golang)
- Each test `pod` have some cluster env vars set on start:
```
LOKI_URL
LOKI_TOKEN
WASP_LOG_LEVEL - wasp log level
WASP_NODE_ID - pod unique ID (int, 1.."jobs")
WASP_NAMESPACE - namespace for wasp jobs
WASP_SYNC - label of a test group, used to select pods for a start check
WASP_JOBS - amount of jobs in test group
```

[Code](examples/cluster) examples

Example cluster component diagram:
```mermaid
---
title: Workload execution. P - Profile, G - Generator, VU - VirtualUser
---
flowchart TB
ClusterProfile-- generate k8s manifests/deploy/await jobs completion -->P1
ClusterProfile-->PN
ClusterProfile-- check NFRs -->Grafana
subgraph Pod1
P1-->P1-G1
P1-->P1-GN
P1-G1-->P1-G1-VU1
P1-G1-->P1-G1-VUN
P1-GN-->P1-GN-VU1
P1-GN--->P1-GN-VUN
P1-G1-VU1-->P1-Batch
P1-G1-VUN-->P1-Batch
P1-GN-VU1-->P1-Batch
P1-GN-VUN-->P1-Batch
end
subgraph PodN
PN-->PN-G1
PN-->PN-GN
PN-G1-->PN-G1-VU1
PN-G1-->PN-G1-VUN
PN-GN-->PN-GN-VU1
PN-GN--->PN-GN-VUN
PN-G1-VU1-->PN-Batch
PN-G1-VUN-->PN-Batch
PN-GN-VU1-->PN-Batch
PN-GN-VUN-->PN-Batch
end
P1-Batch-->Loki
PN-Batch-->Loki
Loki-->Grafana
```
14 changes: 14 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Example Dockerfile for k8s run
FROM golang:1.20 as build
ARG BUILD_ROOT

WORKDIR /go/src
COPY . .

RUN CGO_ENABLED=0 cd ${BUILD_ROOT} && go test -c -o wasp_test

FROM debian
ARG BUILD_ROOT

COPY --from=build ${BUILD_ROOT} /
ENTRYPOINT /bin/bash
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 SmartContract Plugin, Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.PHONY: test
test:
go test -v -count 1 `go list ./... | grep -v examples` -run TestSmoke

.PHONY: test_race
test_race:
go test -v -race -count 1 `go list ./... | grep -v examples` -run TestSmoke

.PHONY: test_bench
test_bench:
go test -bench=. -benchmem -count 1 -run=^#

.PHONY: test+cover
test_cover:
go test -v -coverprofile cover.out -count 1 `go list ./... | grep -v examples` -run TestSmoke
go tool cover -html cover.out

.PHONY: test
test_loki:
go test -v -count 1 `go list ./... | grep -v examples` -run TestPerfRenderLoki

.PHONY: test
test_pyro_rps:
go test -v -run TestPyroscopeLocalTraceRPSCalls -trace trace.out

.PHONY: test
test_pyro_vu:
go test -v -run TestPyroscopeLocalTraceVUCalls -trace trace.out

.PHONY: dashboard
dashboard:
go run dashboard/dashboard.go

.PHONY: start
start:
docker compose -f compose/docker-compose.yaml up -d
sleep 5 && curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "role": "Admin"}' http://localhost:3000/api/auth/keys | jq .key

.PHONY: stop
stop:
docker compose -f compose/docker-compose.yaml down -v

.PHONY: pyro_start
pyro_start:
docker compose -f compose/pyroscope-compose.yaml up -d

.PHONY: pyro_stop
pyro_stop:
docker compose -f compose/pyroscope-compose.yaml down -v

.PHONY: lint
lint:
golangci-lint --color=always run -v
Loading

0 comments on commit 2b133bb

Please sign in to comment.