Skip to content

Commit

Permalink
feat: add a cron job to test OSV API on test instance (#2540)
Browse files Browse the repository at this point in the history
Our test instance lacks real-life traffic, making it difficult to catch
API query errors.
Converting
[tools/api-performance-test](https://github.com/google/osv.dev/tree/master/tools/api-performance-test)
into a cron job that runs for one hour daily. This job will send traffic
to the test instance's API, helping us identify errors before deploying
changes to production.

The [tools/api-performance-test
](https://github.com/google/osv.dev/tree/master/tools/api-performance-test)script
will be deleted once the cron job is running stably.
  • Loading branch information
hogo6002 authored Sep 9, 2024
1 parent 4b9105d commit 9ed04e9
Show file tree
Hide file tree
Showing 8 changed files with 693 additions and 0 deletions.
12 changes: 12 additions & 0 deletions deployment/build-and-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ steps:
args: ['push', '--all-tags', 'gcr.io/oss-vdb/alias-computation']
waitFor: ['build-alias-computation', 'cloud-build-queue']

# Build/push staging-api-test images to gcr.io/oss-vdb-test.
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/oss-vdb-test/staging-api-test:latest', '-t', 'gcr.io/oss-vdb-test/staging-api-test:$COMMIT_SHA', '.']
dir: 'docker/staging_api_test'
id: 'build-staging-api-test'
waitFor: ['build-worker']
- name: gcr.io/cloud-builders/docker
args: ['push', '--all-tags', 'gcr.io/oss-vdb-test/staging-api-test']
waitFor: ['build-staging-api-test', 'cloud-build-queue']

# Build/push cron job images.
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/oss-vdb/cron:latest', '-t', 'gcr.io/oss-vdb/cron:$COMMIT_SHA', '.']
Expand Down Expand Up @@ -263,6 +273,7 @@ steps:
importer=gcr.io/oss-vdb/importer:$COMMIT_SHA,\
exporter=gcr.io/oss-vdb/exporter:$COMMIT_SHA,\
alias-computation=gcr.io/oss-vdb/alias-computation:$COMMIT_SHA,\
staging-api-test=gcr.io/oss-vdb-test/staging-api-test:$COMMIT_SHA,\
cron=gcr.io/oss-vdb/cron:$COMMIT_SHA,\
debian-convert=gcr.io/oss-vdb/debian-convert:$COMMIT_SHA,\
combine-to-osv=gcr.io/oss-vdb/combine-to-osv:$COMMIT_SHA,\
Expand Down Expand Up @@ -325,3 +336,4 @@ images:
- 'gcr.io/oss-vdb/cpe-repo-gen:$COMMIT_SHA'
- 'gcr.io/oss-vdb/nvd-cve-osv:$COMMIT_SHA'
- 'gcr.io/oss-vdb/nvd-mirror:$COMMIT_SHA'
- 'gcr.io/oss-vdb-test/staging-api-test:$COMMIT_SHA'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resources:
- ../../base
- staging-api-test.yaml
patches:
- path: workers.yaml
- path: scaler.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: staging-api-test
spec:
schedule: "50 9 * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: staging-api-test
image: staging-api-test
imagePullPolicy: Always
env:
- name: GOOGLE_CLOUD_PROJECT
value: "oss-vdb-test"
resources:
requests:
cpu: 1.5
memory: "4G"
limits:
cpu: 2
memory: "10G"
restartPolicy: Never
26 changes: 26 additions & 0 deletions docker/staging_api_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Google LLC
#
# 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.

FROM gcr.io/oss-vdb/worker

WORKDIR /staging_api_test

COPY retrieve_bugs_from_db.py perform_api_calls.py run.sh ./

# Add aiohttp lib
RUN cd /env/docker/worker && POETRY_VIRTUALENVS_CREATE=false poetry add aiohttp

RUN chmod 755 retrieve_bugs_from_db.py perform_api_calls.py run.sh

ENTRYPOINT ["./run.sh"]
19 changes: 19 additions & 0 deletions docker/staging_api_test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -x
# Copyright 2024 Google LLC
#
# 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.

docker build -t gcr.io/oss-vdb-test/staging-api-test:$1 . && \
docker build -t gcr.io/oss-vdb-test/staging-api-test:latest . && \
docker push gcr.io/oss-vdb-test/staging-api-test:$1 && \
docker push gcr.io/oss-vdb-test/staging-api-test:latest
Loading

0 comments on commit 9ed04e9

Please sign in to comment.