Skip to content

Commit 656b2e6

Browse files
authored
Add load-test-api CI job (#2358)
* Add `load-test-api` CI job Signed-off-by: wslulciuc <willy@datakin.com> * Fix path to load script Signed-off-by: wslulciuc <willy@datakin.com> * Add `get-k6.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Add get-k6.sh Signed-off-by: wslulciuc <willy@datakin.com> * Move load-testing/ under api/ Signed-off-by: wslulciuc <willy@datakin.com> * Create `/root/.gnupg/` Signed-off-by: wslulciuc <willy@datakin.com> * Add load test plan to `.circleci/api-load-test.sh` Signed-off-by: wslulciuc <willy@datakin.com> * continued: Add load test plan to `.circleci/api-load-test.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Run http server in detach mode Signed-off-by: wslulciuc <willy@datakin.com> * Log steps in `.circleci/api-load-test.sh` Signed-off-by: wslulciuc <willy@datakin.com> * continued: Log steps in `.circleci/api-load-test.sh` Signed-off-by: wslulciuc <willy@datakin.com> * Fix persist workspace path Signed-off-by: wslulciuc <willy@datakin.com> * Use db container only Signed-off-by: wslulciuc <willy@datakin.com> * Install jdk17 Signed-off-by: wslulciuc <willy@datakin.com> * Fix paths Signed-off-by: wslulciuc <willy@datakin.com> * Debug Signed-off-by: wslulciuc <willy@datakin.com> * continued: Debug Signed-off-by: wslulciuc <willy@datakin.com> * continued: Debug Signed-off-by: wslulciuc <willy@datakin.com> * Add postgres host override in marquez.dev.yml Signed-off-by: wslulciuc <willy@datakin.com> * continued: Add postgres host override in marquez.dev.yml Signed-off-by: wslulciuc <willy@datakin.com> * continued: Add postgres host override in marquez.dev.yml Signed-off-by: wslulciuc <willy@datakin.com> * continued: Add postgres host override in marquez.dev.yml Signed-off-by: wslulciuc <willy@datakin.com> * continued: Add postgres host override in marquez.dev.yml Signed-off-by: wslulciuc <willy@datakin.com> * WIP Signed-off-by: wslulciuc <willy@datakin.com> * Wait for http API server Signed-off-by: wslulciuc <willy@datakin.com> * Fix mqz host in load test Signed-off-by: wslulciuc <willy@datakin.com> * Use mqz dev port Signed-off-by: wslulciuc <willy@datakin.com> * Set mqz admin port Signed-off-by: wslulciuc <willy@datakin.com> * Use default dev admin port Signed-off-by: wslulciuc <willy@datakin.com> * Save http logs Signed-off-by: wslulciuc <willy@datakin.com> * continued: Save http logs Signed-off-by: wslulciuc <willy@datakin.com> * continued: Save http logs Signed-off-by: wslulciuc <willy@datakin.com> * Display CPU/MEM info Signed-off-by: wslulciuc <willy@datakin.com> * Require `build-api` on `load-test-api` Signed-off-by: wslulciuc <willy@datakin.com> * Display OL events stats Signed-off-by: wslulciuc <willy@datakin.com> * Use `METADATA_STATS_QUERY` Signed-off-by: wslulciuc <willy@datakin.com> * Remove unused method Signed-off-by: wslulciuc <willy@datakin.com> Signed-off-by: wslulciuc <willy@datakin.com>
1 parent 3ca46c1 commit 656b2e6

10 files changed

Lines changed: 170 additions & 19 deletions

File tree

.circleci/api-load-test.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2018-2023 contributors to the Marquez project
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# A script used in CI to load test HTTP API server by:
7+
# (1) Starting HTTP API server
8+
# (2) Generating random dataset, job, and run metadata
9+
# (3) Running load test using k6
10+
# (4) Writing load test results to 'k6/results' for analysis
11+
#
12+
# Usage: $ ./api-load-test.sh
13+
14+
set -e
15+
16+
# Build version of Marquez
17+
readonly MARQUEZ_VERSION="0.30.0-SNAPSHOT"
18+
# Fully qualified path to marquez.jar
19+
readonly MARQUEZ_JAR="api/build/libs/marquez-api-${MARQUEZ_VERSION}.jar"
20+
21+
readonly MARQUEZ_HOST="localhost"
22+
readonly MARQUEZ_ADMIN_PORT=5001 # Use default 'dev' admin port
23+
readonly MARQUEZ_URL="http://${MARQUEZ_HOST}:${MARQUEZ_ADMIN_PORT}"
24+
readonly MARQUEZ_DB="marquez-db"
25+
26+
readonly METADATA_FILE="api/load-testing/metadata.json"
27+
readonly METADATA_STATS_QUERY=$(cat <<-END
28+
SELECT run_uuid,COUNT(*)
29+
FROM lineage_events
30+
GROUP BY run_uuid;
31+
END
32+
)
33+
34+
log() {
35+
echo -e "\033[1m>>\033[0m ${1}"
36+
}
37+
38+
cpu_and_mem_info() {
39+
log "CPU info:"
40+
cat /proc/cpuinfo
41+
log "MEM info:"
42+
cat /proc/meminfo
43+
}
44+
45+
ol_events_stats() {
46+
# Query db for OL events stats
47+
log "load test metadata stats:"
48+
docker exec "${MARQUEZ_DB}" \
49+
psql -U marquez -c "${METADATA_STATS_QUERY}"
50+
}
51+
52+
# Change working directory to project root
53+
project_root=$(git rev-parse --show-toplevel)
54+
cd "${project_root}"
55+
56+
# (1) Start db
57+
log "start db:"
58+
docker-compose -f docker-compose.db.yml up --detach
59+
60+
# (2) Build HTTP API server
61+
log "build http API server..."
62+
./gradlew --no-daemon :api:build -x test > /dev/null 2>&1
63+
64+
# (3) Start HTTP API server
65+
log "start http API server..."
66+
mkdir marquez && \
67+
java -jar "${MARQUEZ_JAR}" server marquez.dev.yml > marquez/http.log 2>&1 &
68+
69+
# (4) Wait for HTTP API server
70+
log "waiting for http API server (${MARQUEZ_URL})..."
71+
until curl --output /dev/null --silent --head --fail "${MARQUEZ_URL}/ping"; do
72+
sleep 5
73+
done
74+
# When available, print status
75+
log "http API server is ready!"
76+
77+
# (5) Use metadata command to generate random dataset, job, and run metadata
78+
log "generate load test metadata (${METADATA_FILE}):"
79+
java -jar "${MARQUEZ_JAR}" metadata --runs 10 --bytes-per-event 16384 --output "${METADATA_FILE}"
80+
81+
# Display CPU/MEM
82+
cpu_and_mem_info
83+
84+
# (6) Run load test
85+
log "start load test:"
86+
mkdir -p k6/results && \
87+
k6 run --vus 25 --duration 30s api/load-testing/http.js \
88+
--out json=k6/results/full.json --summary-export=k6/results/summary.json
89+
90+
# Display OL event stats
91+
ol_events_stats
92+
93+
echo "DONE!"

.circleci/config.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ only-on-release: &only-on-release
1515
ignore: /.*/
1616

1717
orbs:
18-
# https://circleci.com/orbs/registry/orb/codecov/codecov
1918
codecov: codecov/codecov@3.2.3
2019

2120
jobs:
@@ -148,6 +147,21 @@ jobs:
148147
- run: npm install --prefix=${HOME}/.local --global redoc-cli
149148
- run: redoc-cli bundle spec/openapi.yml
150149

150+
load-test-api:
151+
working_directory: ~/marquez
152+
machine:
153+
image: ubuntu-2004:current
154+
steps:
155+
- checkout
156+
- run: ./.circleci/get-docker-compose.sh
157+
- run: ./.circleci/get-jdk17.sh
158+
- run: ./.circleci/get-k6.sh
159+
- run: ./.circleci/api-load-test.sh
160+
- store_artifacts:
161+
path: marquez
162+
- store_artifacts:
163+
path: k6
164+
151165
migrate-db:
152166
working_directory: ~/marquez
153167
machine:
@@ -204,6 +218,9 @@ workflows:
204218
- unit-test-web
205219
- unit-test-client-python
206220
- lint-spec-api
221+
- load-test-api:
222+
requires:
223+
- build-api
207224
- migrate-db:
208225
requires:
209226
- build-api

.circleci/db-migration.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22
#
3-
# Copyright 2018-2022 contributors to the Marquez project
3+
# Copyright 2018-2023 contributors to the Marquez project
44
# SPDX-License-Identifier: Apache-2.0
55
#
66
# A script used in CI to test database migrations by:
77
# (1) Applying db migrations on latest Marquez release
8-
# (2) Take a backup of db from Step 1
8+
# (2) Taking a backup of db from Step 1
99
# (3) Applying db migrations on latest Marquez build using backup
1010
#
1111
# Usage: $ ./db-migration.sh

.circleci/get-jdk17.sh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
#!/bin/bash
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
3+
# Copyright 2018-2023 contributors to the Marquez project
4+
# SPDX-License-Identifier: Apache-2.0
145
#
156
# Usage: $ ./get-jdk17.sh
167

8+
set -e
9+
1710
wget -qO - https://adoptium.jfrog.io/adoptium/api/gpg/key/public | sudo apt-key add -
1811
sudo add-apt-repository --yes https://adoptium.jfrog.io/adoptium/deb
1912
sudo apt-get update --allow-releaseinfo-change && sudo apt-get install --yes temurin-17-jdk

.circleci/get-k6.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2018-2023 contributors to the Marquez project
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Usage: $ ./get-k6.sh
7+
8+
set -e
9+
10+
# Delete existing key (if present)
11+
sudo apt-key del k6
12+
13+
# Add k6 key and update the repository
14+
sudo gpg -k && \
15+
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
16+
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
17+
18+
# Install k6, then verify
19+
sudo snap install k6 && k6 version
20+
21+
echo "DONE!"

api/load-testing/http.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { SharedArray } from 'k6/data';
2+
import http from 'k6/http';
3+
import { check, sleep } from 'k6';
4+
import { Rate } from 'k6/metrics';
5+
6+
export const errorRate = new Rate('errors');
7+
8+
const metadata = new SharedArray('metadata', function () {
9+
return JSON.parse(open('./metadata.json'));
10+
});
11+
12+
export default function () {
13+
const url = 'http://localhost:5000/api/v1/lineage';
14+
const params = {
15+
headers: {
16+
'Content-Type': 'application/json',
17+
},
18+
};
19+
20+
var ol_event = metadata[__VU-1]
21+
22+
check(http.post(url, JSON.stringify(ol_event), params), {
23+
'status is 201': (r) => r.status == 201,
24+
}) || errorRate.add(1);
25+
26+
sleep(1);
27+
}
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ export default function () {
9090
> **Note:** To learn how to run tests locally with `k6`, see [_Running k6_](https://k6.io/docs/getting-started/running-k6).
9191
9292
----
93-
SPDX-License-Identifier: Apache-2.0
94-
Copyright 2018-2023 contributors to the Marquez project.
93+
SPDX-License-Identifier: Apache-2.0
94+
Copyright 2018-2023 contributors to the Marquez project.

docker-compose.db.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- POSTGRES_USER=postgres
1010
- POSTGRES_PASSWORD=password
1111
- MARQUEZ_DB=marquez
12-
- MARQUEZ_USER=buendia
13-
- MARQUEZ_PASSWORD=macondo
12+
- MARQUEZ_USER=marquez
13+
- MARQUEZ_PASSWORD=marquez
1414
volumes:
1515
- ./docker/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh

marquez.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ server:
99

1010
db:
1111
driverClass: org.postgresql.Driver
12-
url: jdbc:postgresql://postgres:5432/marquez
12+
url: jdbc:postgresql://${POSTGRES_HOST:-localhost}:5432/marquez
1313
user: marquez
1414
password: marquez
1515

0 commit comments

Comments
 (0)