Skip to content

Commit 05bdeeb

Browse files
authored
feat: timescaledb and grafana setup for loadtests (#367)
* feat: enable timescaledb through patroni chart * feat: run all flows under 2 mins for testing * feat: tags for test runs * feat: convert datetime string for tags * feat: updated documentation * feat: updated github workflow on conditions
1 parent 78a01c7 commit 05bdeeb

File tree

9 files changed

+359
-137
lines changed

9 files changed

+359
-137
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Create and publish K6 Runner Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
paths:
9+
- 'k6/**'
10+
- '.github/workflows/publish-image-k6-runner.yml'
11+
12+
env:
13+
GITHUB_REGISTRY: ghcr.io
14+
REDHAT_REGISTRY: registry.redhat.io
15+
IMAGE_NAME: bcgov/sso-k6-runner
16+
17+
jobs:
18+
build-and-push-image:
19+
runs-on: ubuntu-20.04
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
28+
- name: Log in to the GitHub Container registry
29+
uses: docker/login-action@v2
30+
with:
31+
registry: ${{ env.GITHUB_REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v1
37+
38+
- name: Cache Docker layers
39+
uses: actions/cache@v2
40+
with:
41+
path: /tmp/.buildx-cache
42+
key: ${{ runner.os }}-buildx-${{ github.sha }}
43+
restore-keys: |
44+
${{ runner.os }}-buildx-
45+
46+
- name: Build and push Docker image
47+
uses: docker/build-push-action@v3
48+
with:
49+
context: k6/k6-runner
50+
push: true
51+
tags: ${{ env.GITHUB_REGISTRY }}/${{env.IMAGE_NAME}}:dev
52+
file: k6/k6-runner/Dockerfile
53+
cache-from: type=local,src=/tmp/.buildx-cache
54+
cache-to: type=local,dest=/tmp/.buildx-cache-new
55+
56+
# Temp fix
57+
# https://github.com/docker/build-push-action/issues/252
58+
# https://github.com/moby/buildkit/issues/1896
59+
- name: Move cache
60+
run: |
61+
rm -rf /tmp/.buildx-cache
62+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

helm/timescaledb/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Installing TimescaleDB
2+
3+
## Setup
4+
5+
- Run below to install the patroni managed postgres instance
6+
7+
```sh
8+
export NAMESPACE=
9+
10+
helm repo add sso-charts https://bcgov.github.io/sso-helm-charts
11+
12+
helm upgrade --install k6-patroni sso-charts/patroni -n ${NAMESPACE} --version 1.6.0 -f ${NAMESPACE}-values.yaml
13+
```
14+
15+
- Create a database and enable the timescaleDB extension
16+
17+
```sql
18+
CREATE DATABASE k6loadtests;
19+
20+
\c k6loadtests;
21+
22+
CREATE EXTENSION IF NOT EXISTS timescaledb;
23+
```
24+
25+
### Grafana
26+
27+
- Existing [grafana](https://sso-grafana-sandbox.apps.gold.devops.gov.bc.ca/) instance is being used to host the dashboards.
28+
- Ensure a data source exists with below config.
29+
30+
```yaml
31+
name: 'K6 Load Tests TimeScaleDB'
32+
type: postgres
33+
url: k6-patroni.xxx.svc.cluster.local:5432
34+
database: k6loadtests
35+
user: xxx
36+
isDefault: false
37+
secureJsonData:
38+
password: xxx
39+
jsonData:
40+
sslmode: 'disable' # disable/require/verify-ca/verify-full
41+
maxOpenConns: 0 # Grafana v5.4+
42+
maxIdleConns: 2 # Grafana v5.4+
43+
connMaxLifetime: 14400 # Grafana v5.4+
44+
postgresVersion: 15
45+
timescaledb: true
46+
```
47+
48+
- Pre-built dashboards can be found [here](https://github.com/grafana/xk6-output-timescaledb/tree/main/grafana/dashboards)](https://github.com/grafana/xk6-output-timescaledb/tree/main/grafana/dashboards)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
nameOverride: k6-patroni
2+
3+
fullnameOverride: k6-patroni
4+
5+
image:
6+
# see https://github.com/zalando/spilo/releases
7+
repository: ghcr.io/zalando/spilo-15
8+
pullPolicy: Always
9+
tag: 3.2-p1
10+
11+
replicaCount: 2
12+
13+
postgresMajorVersion: 15
14+
15+
resources:
16+
requests:
17+
cpu: 50m
18+
memory: 128Mi
19+
limits:
20+
cpu: 200m
21+
memory: 256Mi
22+
23+
podDisruptionBudget:
24+
enabled: false
25+
26+
persistentVolume:
27+
size: 500Mi

k6/k6-runner/Dockerfile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
FROM loadimpact/k6:latest
1+
FROM golang:1.20-alpine3.17 as builder
2+
WORKDIR $GOPATH/src/go.k6.io/k6
3+
ADD . .
4+
RUN apk --no-cache add git
5+
RUN CGO_ENABLED=0 go install go.k6.io/xk6/cmd/xk6@latest
6+
RUN CGO_ENABLED=0 xk6 build --with github.com/grafana/xk6-output-timescaledb --output /tmp/k6
27

3-
WORKDIR /var/opt
8+
FROM alpine:3.17
9+
RUN apk add --no-cache ca-certificates && \
10+
adduser -D -u 12345 -g 12345 k6
11+
COPY --from=builder /tmp/k6 /usr/bin/k6
412

5-
COPY /src/tests /var/opt/scripts
6-
COPY /openshift/k6/start.sh /var/opt
13+
USER 12345
14+
WORKDIR /home/k6
715

8-
ENTRYPOINT [ "sh", "/var/opt/start.sh" ]
16+
COPY /src/tests /home/k6/scripts
17+
18+
ENTRYPOINT ["k6"]

k6/k6-runner/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ config:
88

99
.PHONY: run_job
1010
run_job:
11-
oc -n $(NAMESPACE) process -f ./openshift/k6/dc.yaml | oc -n $(NAMESPACE) apply -f -
11+
oc -n $(NAMESPACE) process -f ./openshift/k6/dc.yaml -p DB_PASSWORD=$(DB_PASSWORD) -p DB_USER=$(DB_USER) | oc -n $(NAMESPACE) apply -f -
1212

13-
.PHONY: delete
14-
delete:
13+
.PHONY: cleanup
14+
cleanup:
1515
oc -n $(NAMESPACE) delete job sso-k6
1616
oc -n $(NAMESPACE) delete configmap k6-config

k6/k6-runner/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# K6 Runner for Load Tests
2+
3+
## Requirements
4+
5+
- `k6-patroni` timescaleDB built on top of postgreSQL managed by patroni
6+
- `grafana` is the open source analytics & monitoring solution
7+
8+
## Setup
9+
10+
- Ensure `k6-patroni` is running in `c6af30-dev` namespace as a statefulset
11+
- Copy `sso-keycloak/k6/k6-runner/src/config/config.example.json` to `sso-keycloak/k6/k6-runner/src/config/config.json` and update values accordingly
12+
13+
```sh
14+
# initialize env vars
15+
export NAMESPACE=
16+
export DB_USER=
17+
export DB_PASSWORD=
18+
19+
# create configmap with all the configurations
20+
make config
21+
22+
# create a job to run load tests
23+
make run_job
24+
25+
# clean up job and config map
26+
make cleanup
27+
```

k6/k6-runner/openshift/k6/dc.yaml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ objects:
1616
containers:
1717
- image: ${IMAGE_REPOSITORY}:${IMAGE_TAG}
1818
name: ${NAME}
19+
args:
20+
- 'run'
21+
- '-e'
22+
- 'CONFIG=/var/opt/config/config.json'
23+
- '/home/k6/scripts/constantRateAllFlows.js'
24+
env:
25+
- name: K6_OUT
26+
value: 'timescaledb=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}'
1927
resources:
2028
limits:
2129
cpu: 2
@@ -36,9 +44,18 @@ parameters:
3644
- name: NAME
3745
value: sso-k6
3846
- name: IMAGE_TAG
39-
value: latest
47+
value: dev
4048
- name: IMAGE_REPOSITORY
41-
value: ghcr.io/bcgov/sso-k6
42-
- name: HTTP_DEBUG
43-
description: enable http debug logging in the k6 pod
44-
value: "false"
49+
value: ghcr.io/bcgov/sso-k6-runner
50+
- name: DB_USER
51+
value: ''
52+
required: true
53+
- name: DB_PASSWORD
54+
value: ''
55+
required: true
56+
- name: DB_NAME
57+
value: 'k6loadtests'
58+
- name: DB_HOST
59+
value: 'k6-patroni'
60+
- name: DB_PORT
61+
value: '5432'

0 commit comments

Comments
 (0)