Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run CATs with local CDK #23084

Merged
merged 14 commits into from
Feb 24, 2023
Merged

Run CATs with local CDK #23084

merged 14 commits into from
Feb 24, 2023

Conversation

clnoll
Copy link
Contributor

@clnoll clnoll commented Feb 15, 2023

What

Allow us to run all or a subset of CATs against the local CDK.

How

  • Modifies airbyte-integrations/connectors/<CONNECTOR>/acceptance-test-docker.sh to run airbyte-integrations/bases/connector-acceptance-test/acceptance-test-docker.sh, which will use the local CDK if the LOCAL_CDK environment variable is set. See the POC for information on how this is being done.
  • Breaks out the docker image-building component so we can build the connector image with the local CDK without running CATs.
  • Additionally modifies acceptance-test-docker.sh to fetch secrets if the FETCH_SECRETS environment variable is set. This requires the user to have a Google Service Account and the GCP_GSM_CREDENTIALS environment variable to be set, per the instructions here and here.
  • Includes a wrapper script that accepts a comma-separated list of connectors (using the -c flag) against which to run the CATs with the local CDK. If no connectors are supplied, defaults to running CATs for all connectors that use airbyte-cdk in their setup.py.

Recommended reading order

  1. airbyte-cdk/python/bin/run-cats-with-local-cdk.sh
  2. airbyte-integrations/bases/connector-acceptance-test/acceptance-test-docker.sh
  3. airbyte-integrations/bases/connectors/build-connector-image-with-local-cdk.sh
  4. airbyte-integrations/bases/connectors/utils.sh
  5. <CONNECTOR>/acceptance-test-docker.sh

Closes 22091 and 22695.

@clnoll clnoll requested a review from a team as a code owner February 15, 2023 16:02
@clnoll clnoll requested a review from a team February 15, 2023 16:02
@clnoll clnoll marked this pull request as draft February 15, 2023 16:02
@octavia-squidington-iii octavia-squidington-iii added area/connectors Connector related issues CDK Connector Development Kit labels Feb 15, 2023
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 16:04 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 16:04 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Feb 15, 2023

Airbyte Code Coverage

There is no coverage information present for the Files changed

Total Project Coverage 27.16% 🍏

@clnoll clnoll force-pushed the run-cats-with-local-cdk branch from ad65534 to 69478af Compare February 15, 2023 16:52
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 16:54 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 16:54 — with GitHub Actions Inactive
airbyte-cdk/python/bin/run-cats-with-local-cdk.sh Outdated Show resolved Hide resolved
# Clean up from previous test runs
rm -rf $OUTPUT_DIR && mkdir $OUTPUT_DIR

while getopts ":c:" opt; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be useful to give an example of how to run the script

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 added help text.

@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 19:54 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 19:54 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 20:34 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 20:34 — with GitHub Actions Inactive
@clnoll clnoll force-pushed the run-cats-with-local-cdk branch from 8af08bf to bfea1a1 Compare February 15, 2023 20:49
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 20:51 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 20:51 — with GitHub Actions Inactive
@clnoll clnoll force-pushed the run-cats-with-local-cdk branch from bfea1a1 to e9c9511 Compare February 15, 2023 20:57
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 20:59 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 20:59 — with GitHub Actions Inactive
@clnoll clnoll force-pushed the run-cats-with-local-cdk branch from e9c9511 to d9baa02 Compare February 15, 2023 21:01
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 21:03 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 15, 2023 21:04 — with GitHub Actions Inactive
@clnoll clnoll marked this pull request as ready for review February 16, 2023 16:06
@clnoll clnoll temporarily deployed to more-secrets February 16, 2023 16:07 — with GitHub Actions Inactive
@clnoll clnoll temporarily deployed to more-secrets February 16, 2023 16:07 — with GitHub Actions Inactive
@@ -1,16 +1,8 @@
#!/usr/bin/env sh

# Build latest connector image
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-)
set -e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to move this file to a top level (eg tools) and symlink it instead of copypasting the same file 250 times?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight hesitation with that - we'll have to update our documentation for creating a connector to tell people "create a symlink to <dir>/acceptance-test-docker.sh, but make sure it's a relative symlink not an absolute one". WDYT about keeping the file but reducing it even further so it just sources acceptance-test-docker.sh, and doesn't contain the readlink logic? An alternative would be to have a script that sets up a connector directory with the boilerplate files & relative symlink pre-populated. But that might be a project for another PR as I'm sure there are some other files/directories we'd want to create as part of the script, but am not totally sure yet what they are.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel too strongly about symlink vs removing even more cruft from the file, but we already have a script to generate connectors. We should update the template so it matches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing me to the template code! Turns out that the npm generate package does not copy over symlinks, so instead I've opted to clean things up a bit by having the connectors' acceptance-test-docker.sh just source the base acceptance-test-docker.sh, reducing it to just one line. LMK what you think.

airbyte-integrations/connectors/source-greenhouse/1 Outdated Show resolved Hide resolved
airbyte-integrations/connectors/source-posthog/testme.sh Outdated Show resolved Hide resolved
## Running the acceptance tests on multiple connectors:
If you are contributing to the python CDK, you may want to validate your changes by running acceptance tests against multiple connectors.

To do so, from the root of the `airbyte` repo, run `./airbyte-cdk/python/bin/run-cats-with-local-cdk.sh -c <connector1>,<connector2>,...`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting this error. Any idea what I'm doing wrong?

➜  airbyte git:(run-cats-with-local-cdk) ✗ ./airbyte-cdk/python/bin/run-cats-with-local-cdk.sh -c source-stripe,source-greenhouse
Running CATs for source-stripe source-greenhouse


source-greenhouse errors:

readlink: illegal option -- f
usage: readlink [-n] [file ...]

source-stripe errors:

readlink: illegal option -- f
usage: readlink [-n] [file ...]

Done.

edit: looks like readlink -f doesn't exist on macos :(

A potential suggestion might be to use raw readlink in a while loop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh weird, that run fine for me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and switched this to Alex's suggestion, so we don't have to require a non-builtin readlink.

Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that this is modularized in a way that enables the three use cases (testing a single connector, testing multiple connectors, only building the docker image). Nice work!

Left a few comments. Main request for change is that these scripts should be easily discoverable by the people who would benefit from them, so if we can sprinkle them in docs that would be great e.g:

  1. Add something in CDK README for a CDK dev
  2. Ideally we even add something in the connector README that says ... to run with a local version of the CDK use LOCAL_CDK=1 or something but it may be harder to finagle together the right sed command for that

But generally speaking these are all small comments. Overall it looks great.

airbyte-cdk/python/bin/run-cats-with-local-cdk.sh Outdated Show resolved Hide resolved
@@ -0,0 +1,75 @@
#!/usr/bin/env sh

USAGE="$(basename "$0") [-h] [-c connector1,connector2,...] -- Run connector acceptance tests (CATs) against the local CDK, if relevant.\n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which dir is this script expected to be run from? Should there be an assertion on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script can be run from anywhere in the airbyte repo. Added an assertion.

@@ -35,6 +35,15 @@ _Note: this way will also build docker image for the connector_
```
_Note: this will use the latest docker image for connector-acceptance-test and will also build docker image for the connector_

You can also use the following environment variables with the Gradle and Bash commands:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these instructions should probably also be in the CDK README? or it should point to these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 updated.

airbyte-cdk/python/bin/run-cats-with-local-cdk.sh Outdated Show resolved Hide resolved
## Running the acceptance tests on multiple connectors:
If you are contributing to the python CDK, you may want to validate your changes by running acceptance tests against multiple connectors.

To do so, from the root of the `airbyte` repo, run `./airbyte-cdk/python/bin/run-cats-with-local-cdk.sh -c <connector1>,<connector2>,...`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh weird, that run fine for me

sed -iE 's,"airbyte-cdk[^"]*","airbyte-cdk @ file://localhost/airbyte-cdk",' setup.py

# Build the connector image
docker_build_quiet "$CONNECTOR_TAG"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a little thrown off that this built quietly. I am sort of used to seeing Docker build output in our current scripts otherwise I assumed something was going wrong. Any reason you wanted it quiet instead of normal verbosity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker build sends its output to stderr by default, so when this script is called from the run-cats-with-local-cdk.sh wrapper, the build output gets printed out along with any other CAT errors. I think it makes sense to use -q in that situation (lmk if you disagree), but now that the image-building happens in its own script, I agree that the build output should be visible. I've updated this script to only use -q if called from run-cats-with-local-cdk.sh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine, can we at least add a log message that says building docker image $NAME or something? it would help the human at the keyboard know that things are moving along rather than stalled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, makes sense to me - added.

esac
done

if [ -z "$connectors" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ -z "$connectors" ]; then
if [ -z "$connectors" ]; then
echo "You did not specify any connectors using the -c flag which means this script will run for ALL connectors"
echo "You almost certainly did not mean to do this. Exit now would be my advice. But what do I know? I'm just a script."
echo "Hope you have 128 cores on this machine!"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about I exit with an error, instead of defaulting to all? It feels like running all should work in theory since the tests are network-bound but Docker doesn't seem to want to handle the load.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could also just fail if $connectors is not defined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit with error makes more sense :P

@@ -0,0 +1,75 @@
#!/usr/bin/env sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CDK readme should contain something about this file, maybe replacing the existing guidance saying how to fiddle with gradle etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 updated.

@@ -1,16 +1,8 @@
#!/usr/bin/env sh

# Build latest connector image
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-)
set -e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2023

Affected Connector Report

The latest commit has removed all connector-related changes. There are no more dependent connectors for this PR.

@clnoll clnoll force-pushed the run-cats-with-local-cdk branch from f0678c2 to 8243697 Compare February 23, 2023 22:01
@clnoll clnoll force-pushed the run-cats-with-local-cdk branch from 8243697 to 47e6b2a Compare February 23, 2023 22:41
@clnoll
Copy link
Contributor Author

clnoll commented Feb 24, 2023

/test connector=connectors/source-gnews

🕑 connectors/source-gnews https://github.com/airbytehq/airbyte/actions/runs/4263090629
❌ connectors/source-gnews https://github.com/airbytehq/airbyte/actions/runs/4263090629
🐛 https://gradle.com/s/5sdvqq5f2px4i

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_core.py::TestConnection::test_check[inputs0] - docker.errors.Cont...
FAILED test_core.py::TestConnection::test_check[inputs1] - docker.errors.Cont...
FAILED test_core.py::TestDiscovery::test_discover[inputs0] - docker.errors.Co...
FAILED test_core.py::TestBasicRead::test_airbyte_trace_message_on_failure[inputs0]
ERROR test_core.py::TestSpec::test_config_match_spec[inputs0] - docker.errors...
ERROR test_core.py::TestSpec::test_match_expected[inputs0] - docker.errors.Co...
ERROR test_core.py::TestSpec::test_docker_env[inputs0] - docker.errors.Contai...
ERROR test_core.py::TestSpec::test_enum_usage[inputs0] - docker.errors.Contai...
ERROR test_core.py::TestSpec::test_oneof_usage[inputs0] - docker.errors.Conta...
ERROR test_core.py::TestSpec::test_secret_is_properly_marked[inputs0] - docke...
ERROR test_core.py::TestSpec::test_defined_refs_exist_in_json_spec_file[inputs0]
ERROR test_core.py::TestSpec::test_oauth_flow_parameters[inputs0] - docker.er...
ERROR test_core.py::TestSpec::test_backward_compatibility[inputs0] - docker.e...
ERROR test_core.py::TestSpec::test_additional_properties_is_true[inputs0] - d...
ERROR test_core.py::TestDiscovery::test_defined_cursors_exist_in_schema[inputs0]
ERROR test_core.py::TestDiscovery::test_defined_refs_exist_in_schema[inputs0]
ERROR test_core.py::TestDiscovery::test_defined_keyword_exist_in_schema[inputs0-allOf]
ERROR test_core.py::TestDiscovery::test_defined_keyword_exist_in_schema[inputs0-not]
ERROR test_core.py::TestDiscovery::test_primary_keys_exist_in_schema[inputs0]
ERROR test_core.py::TestDiscovery::test_streams_has_sync_modes[inputs0] - doc...
ERROR test_core.py::TestDiscovery::test_additional_properties_is_true[inputs0]
ERROR test_core.py::TestDiscovery::test_backward_compatibility[inputs0] - doc...
ERROR test_core.py::TestBasicRead::test_read[inputs0] - docker.errors.Contain...
ERROR test_full_refresh.py::TestFullRefresh::test_sequential_reads[inputs0]
ERROR test_incremental.py::TestIncremental::test_two_sequential_reads[inputs0]
ERROR test_incremental.py::TestIncremental::test_read_sequential_slices[inputs0]
ERROR test_incremental.py::TestIncremental::test_state_with_abnormally_large_values[inputs0]
============ 4 failed, 10 passed, 37 warnings, 23 errors in 38.59s =============

@clnoll
Copy link
Contributor Author

clnoll commented Feb 24, 2023

/test connector=connectors/source-facebook-pages

🕑 connectors/source-facebook-pages https://github.com/airbytehq/airbyte/actions/runs/4263755202
❌ connectors/source-facebook-pages https://github.com/airbytehq/airbyte/actions/runs/4263755202
🐛 https://gradle.com/s/shg6gkio6uv5s

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_full_refresh.py::TestFullRefresh::test_sequential_reads[inputs0]
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/plugin.py:63: Skipping TestIncremental.test_two_sequential_reads: not found in the config.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/tests/test_core.py:98: The previous and actual specifications are identical.
============= 1 failed, 32 passed, 2 skipped in 238.17s (0:03:58) ==============

@clnoll
Copy link
Contributor Author

clnoll commented Feb 24, 2023

/test connector=connectors/source-courier

🕑 connectors/source-courier https://github.com/airbytehq/airbyte/actions/runs/4264926521
❌ connectors/source-courier https://github.com/airbytehq/airbyte/actions/runs/4264926521
🐛 https://gradle.com/s/kytuwgixzy5gy

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_core.py::TestBasicRead::test_read[inputs0] - AssertionError: At l...
FAILED test_full_refresh.py::TestFullRefresh::test_sequential_reads[inputs0]
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/plugin.py:63: Skipping TestIncremental.test_two_sequential_reads: not found in the config.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/tests/test_core.py:98: The previous and actual specifications are identical.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/tests/test_core.py:507: The previous and actual discovered catalogs are identical.
============ 2 failed, 30 passed, 3 skipped, 35 warnings in 33.57s =============

@clnoll
Copy link
Contributor Author

clnoll commented Feb 24, 2023

/test connector=connectors/source-zoom

🕑 connectors/source-zoom https://github.com/airbytehq/airbyte/actions/runs/4265485306
✅ connectors/source-zoom https://github.com/airbytehq/airbyte/actions/runs/4265485306
No Python unittests run

Build Passed

Test summary info:

=========================== short test summary info ============================
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/plugin.py:63: Skipping TestIncremental.test_two_sequential_reads: not found in the config.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/tests/test_core.py:98: The previous and actual specifications are identical.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/connector_acceptance_test/tests/test_core.py:507: The previous and actual discovered catalogs are identical.
============ 32 passed, 3 skipped, 35 warnings in 718.33s (0:11:58) ============

@clnoll clnoll merged commit 7da6a3b into master Feb 24, 2023
@clnoll clnoll deleted the run-cats-with-local-cdk branch February 24, 2023 21:13
@clnoll clnoll restored the run-cats-with-local-cdk branch February 24, 2023 23:49
@clnoll clnoll deleted the run-cats-with-local-cdk branch February 25, 2023 00:04
@clnoll clnoll restored the run-cats-with-local-cdk branch February 27, 2023 14:59
@clnoll clnoll deleted the run-cats-with-local-cdk branch February 27, 2023 15:03
@clnoll clnoll restored the run-cats-with-local-cdk branch February 27, 2023 16:35
@clnoll clnoll deleted the run-cats-with-local-cdk branch February 27, 2023 16:40
danielduckworth pushed a commit to danielduckworth/airbyte that referenced this pull request Mar 13, 2023
Scripts to 

* Run CATs against the local CDK for one connector

* Run CATs against the local CDK for multiple connectors

* Create a connecter image with the local CDK

---------

Co-authored-by: Alexandre Girard <alexandre@airbyte.io>
Co-authored-by: Sherif A. Nada <snadalive@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues CDK Connector Development Kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants