Skip to content

Commit

Permalink
vdk-heartbeat: cover requirements.txt automatic installs (#2393)
Browse files Browse the repository at this point in the history
Upon `vdk deploy` the Control Service is responsible for installing all
external dependecies defined in requirements.txt of the data job so they
can be used during a cloud run.

A recent outage in one of our customers caused data jobs to ignore their
requirements.txt and not install any external libraries. It was trace to
be due to a release of [data job base

image](https://hub.docker.com/layers/versatiledatakit/data-job-base-python-3.11)

CICD of the open source VDK did not catch this. 

I am extending VDK heartbeat to test for the issue so we can catch it in
the future.
 
See also #2391
  • Loading branch information
antoniivanov authored Jul 25, 2023
1 parent 343f182 commit ffdee8b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 1 deletion.
22 changes: 22 additions & 0 deletions projects/vdk-heartbeat/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ vdk-heartbeat-test:
junit: tests.xml


vdk-heartbeat-release-acceptance-test:
stage: pre_release
before_script:
- cd projects/vdk-heartbeat
script:
- set -x
- python setup.py sdist --formats=gztar
- pip install vdk-heartbeat --extra-index-url $PIP_EXTRA_INDEX_URL
- export VDK_HEARTBEAT_API_TOKEN=$VDK_API_TOKEN
- export VDK_HEARTBEAT_OP_ID="vdk-heartbeat-$CI_PIPELINE_ID"
- export JOB_NAME=vdk-heartbeat-release-test-job-$(date +%s)
- vdk-heartbeat -f cicd/cicd_heartbeat_config.ini
artifacts:
when: always
reports:
junit: tests.xml
only:
refs: # TODO switch to "main" so it is used as a pre-release test not pre-merge test
- external_pull_requests
changes: *vdk_heartbeat_changes_locations


vdk-heartbeat-release:
before_script:
- cd projects/vdk-heartbeat
Expand Down
10 changes: 10 additions & 0 deletions projects/vdk-heartbeat/cicd/cicd_heartbeat_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[DEFAULT]
# Genereate with https://console-stg.cloud.vmware.com/csp/gateway/portal/#/user/tokens
# VDKCLI_OAUTH2_REFRESH_TOKEN= passed as environment variable
VDKCLI_OAUTH2_URI=https://console-stg.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize
CONTROL_API_URL=http://cicd-control-service-svc:8092
# https://iaclqhm5xk.execute-api.us-west-1.amazonaws.com/data-jobs

JOB_RUN_TEST_MODULE_NAME=vdk.internal.heartbeat.simple_run_test
JOB_RUN_TEST_CLASS_NAME=SimpleRunTest
DATAJOB_DIRECTORY_NAME=simple
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# SPDX-License-Identifier: Apache-2.0
import logging

from faker import Faker
from vdk.api.job_input import IJobInput

log = logging.getLogger(__name__)


def run(job_input: IJobInput):
# this is just added to test that external libraries are installed and imported correctly from requirements.txt
fake = Faker()
log.info(f"Fake name: {fake.name()}")

log.info(f"Empty job that just logs and exits")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Faker
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
# SPDX-License-Identifier: Apache-2.0
import logging

from faker import Faker
from vacloud.api.job_input import IJobInput

log = logging.getLogger(__name__)


def run(job_input: IJobInput):
# this is just added to test that external libraries are installed and imported correctly from requirements.txt
fake = Faker()
log.info(f"Fake name: {fake.name()}")

# Test creates dynamically file 06_override_properties.py
# which will override properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
# SPDX-License-Identifier: Apache-2.0
import logging

from faker import Faker
from vdk.api.job_input import IJobInput

log = logging.getLogger(__name__)


def run(job_input: IJobInput):
# this is just added to test that external libraries are installed and imported correctly from requirements.txt
fake = Faker()
log.info(f"Fake name: {fake.name()}")

log.info(f"Get current properties ")
props = job_input.get_all_properties()
props["succeeded"] = "true"
log.info(f"Save new properties ")
log.info(f"Save new properties {props}")
job_input.set_all_properties(props)
log.info(f"Updated property now to {props['succeeded']}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Faker
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
# SPDX-License-Identifier: Apache-2.0
import logging

from faker import Faker
from vdk.api.job_input import IJobInput


log = logging.getLogger(__name__)


def run(job_input: IJobInput):
# this is just added to test that external libraries are installed and imported correctly from requirements.txt
fake = Faker()
log.info(f"Fake name: {fake.name()}")

# Test creates dynamically file 06_override_properties.py
# which will override properties

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Faker
vdk-trino

0 comments on commit ffdee8b

Please sign in to comment.