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

4776: Python CDK: Validate input config.py against spec #5457

Merged
merged 12 commits into from
Aug 19, 2021

Conversation

avida
Copy link
Contributor

@avida avida commented Aug 17, 2021

What

Resolves #4776

How

Describe the solution

Recommended reading order

  1. x.java
  2. y.python

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions
  • Connector added to connector index like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions
  • Connector version bumped like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.

@github-actions github-actions bot added the CDK Connector Development Kit label Aug 17, 2021
@avida avida force-pushed the drezchykov/4776-cdk-validate-spec branch from bcc4dc6 to 257c9bb Compare August 17, 2021 08:38
@avida
Copy link
Contributor Author

avida commented Aug 17, 2021

/publish-cdk dry-run=true

🕑 https://github.com/airbytehq/airbyte/actions/runs/1138577784
https://github.com/airbytehq/airbyte/actions/runs/1138577784

@avida avida force-pushed the drezchykov/4776-cdk-validate-spec branch from 257c9bb to c019bce Compare August 17, 2021 08:46
@avida avida requested a review from sherifnada August 17, 2021 12:04
@@ -1,5 +1,11 @@
# Changelog

## 0.1.10
Add checking specified config againt spec for read, write, check and ddiscover commands
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
Add checking specified config againt spec for read, write, check and ddiscover commands
Add checking specified config againt spec for read, write, check and discover commands

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

Add checking specified config againt spec for read, write, check and ddiscover commands

##0.1.9
remove this line after rebase
Copy link
Contributor

Choose a reason for hiding this comment

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

rudiment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, its cause Artur has his MR with 0.1.9 version published so my is 0.1.10 https://pypi.org/project/airbyte-cdk/

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'm waiting when he will be ready, rebase my changes onto his and update this file

spec_schema = spec.connectionSpecification
try:
validate(instance=config, schema=spec_schema)
return None
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
return None
return

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

Copy link
Contributor

@yevhenii-ldv yevhenii-ldv left a comment

Choose a reason for hiding this comment

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

Small changes

@avida avida force-pushed the drezchykov/4776-cdk-validate-spec branch from e4bdf9a to e3d5279 Compare August 17, 2021 12:30
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.

couple of changes needed:

  1. exit code should be > 0 if config is invalid
  2. we should have unit tests for checkin catalogs #1


@abstractmethod
def write(
self, config: Mapping[str, Any], configured_catalog: ConfiguredAirbyteCatalog, input_messages: Iterable[AirbyteMessage]
) -> Iterable[AirbyteMessage]:
"""Implement to define how the connector writes data to the destination"""

def _run_spec(self) -> AirbyteMessage:
return AirbyteMessage(type=Type.SPEC, spec=self.spec(self.logger))
def _run_spec(self, spec: ConnectorSpecification) -> AirbyteMessage:
Copy link
Contributor

Choose a reason for hiding this comment

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

we should delete this method, calling it _run_spec when it just wraps an object is misleading

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -35,7 +35,7 @@

setup(
name="airbyte-cdk",
version="0.1.8",
version="0.1.10",
Copy link
Contributor

Choose a reason for hiding this comment

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

you'll need to either merge this with arthur's changes or release separately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ive merged Arthur's branch into mine so now this PR looks dirty before his branch will be merged on master.

return
config = self.read_config(config_path=parsed_args.config)
check_error_msg = check_config_against_spec(config, spec)
if check_error_msg:
Copy link
Contributor

Choose a reason for hiding this comment

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

an invalid config should cause the exit code to be >0, it's invalid input. An exit code of 0 means the connector succeeded

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

@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Aug 18, 2021
@avida
Copy link
Contributor Author

avida commented Aug 18, 2021

@sherifnada

we should have unit tests for checkin catalogs #1

Didnt get about this. Looks like an old PR with json files and bash scripts. How can I add unit tests on it?

@avida avida requested a review from sherifnada August 18, 2021 08:07
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.

Couple of comments, feel free to merge once they are addressed and the other PR is merged

@@ -180,6 +180,7 @@ def test_run_check(self, mocker, destination: Destination, tmp_path):
parsed_args = argparse.Namespace(**args)
destination.run_cmd(parsed_args)

mocker.patch.object(destination, "spec", return_value=ConnectorSpecification(connectionSpecification={}))
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add a test case here too to verify the config is validated.

It may help to look at test coverage by running ./type_check_and_test.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is already detailed test case that covers validation function here: https://github.com/airbytehq/airbyte/pull/5457/files#diff-0d9087e19f5bdabe137529bb861aaaa261b39d5344e79041602a2a94c7530301R150 So Ive just added checks if this validation function is called with correct args for destination.

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, done


def check_config_against_spec_or_exit(config: Mapping[str, Any], spec: ConnectorSpecification, logger: Logger):
"""
Check config object against spec. In case of spec is invalid, throws
Copy link
Contributor

Choose a reason for hiding this comment

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

nice docstring

@github-actions github-actions bot removed the area/documentation Improvements or additions to documentation label Aug 19, 2021
@avida avida force-pushed the drezchykov/4776-cdk-validate-spec branch from ebaa6aa to e29552e Compare August 19, 2021 09:58
@avida
Copy link
Contributor Author

avida commented Aug 19, 2021

/publish-cdk dry-run=false

🕑 https://github.com/airbytehq/airbyte/actions/runs/1146507705
https://github.com/airbytehq/airbyte/actions/runs/1146507705

@avida avida merged commit b1f2bf5 into master Aug 19, 2021
@avida avida deleted the drezchykov/4776-cdk-validate-spec branch August 19, 2021 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CDK Connector Development Kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CDK Destinations: Validate input config.py against spec
5 participants