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

Introduce the AirbyteStreamNamespaceNamePair to the DefaultReplicationWorker. #19360

Merged
merged 17 commits into from
Nov 16, 2022

Conversation

davinchia
Copy link
Contributor

@davinchia davinchia commented Nov 12, 2022

What

#19191 made me realise the DefaultReplicationWorker's metric tracking today has a bug where we aren't accounting for namespace when tracking metrics today. i.e. Streams with the same name and duplicate namespace will merge metrics.

While reading the code to figure out a fix, I realised we don't have a good conceptual representation of stream namespace <> name pairs within the platform today. We use a concatenated string. Though this works, it will become harder and harder to read/track as we do more operations that involve namespace i.e. progress bars and column selection.

This PR introduces the AirbyteStreamNameNamespacePair object into the platform code to make it more convenient to work with Streams in the future. (Especially if we proceed with the project to make streams a first-class citizen!)

The AirbyteStreamNameNamespacePair object was written to deal with the same issue of namespace <> name pair manipulation within the Java destination code. It implements the Comparable interface, which makes it convenient to use for Collections operations.

For an example of how this is consumed, see #19361.

How

  • Move the AirbyteStreamNameNamespacePair object from the base-java module to the protocol_models module. This location already contains models that make it easier to interact with pure Airbyte protocol-defined models, so moving it here is appropriate. All consumer modules already have dependencies on this, so there are build.gradle changes.
  • Update SchemaValidation to use the Pair instead of a string. Update all tests to use the Pair instead of a string.

No logic changes here - all modifications are to use the AirbyteStreamNameNamespacePair object.

Recommended reading order

  1. AirbyteStreamNameNamespacePair.java - the main file being moved.
  2. DefaultReplicatonWorker.java and RecordSchemaValidator.java - the main consumers being changed.
  3. RecordSchemaValidatorTest.Java, WorkerUtilsTest.java and DefaultReplicationWorkerTest.java - for the test modifications.
  4. Everything is package changes in the Java connector code.

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

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
    • Connector's bootstrap.md. See description and examples
    • 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

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
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as 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
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

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
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub and connector version bumped 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

Tests

Unit

Put your unit tests output here.

Integration

Put your integration tests output here.

Acceptance

Put your acceptance tests output here.

@davinchia davinchia temporarily deployed to more-secrets November 14, 2022 22:28 Inactive
…ocol/models/AirbyteStreamNameNamespacePair.java

Co-authored-by: Jimmy Ma <gosusnp@users.noreply.github.com>
@davinchia davinchia temporarily deployed to more-secrets November 14, 2022 22:48 Inactive
@davinchia
Copy link
Contributor Author

/test connector=source-postgres

@davinchia
Copy link
Contributor Author

/test connector=destination-snowflake

@@ -77,7 +77,7 @@ private static <T> Map<AirbyteStreamNameNamespacePair, StreamCopier> createWrite
final String stagingFolder = UUID.randomUUID().toString();
for (final var configuredStream : catalog.getStreams()) {
final var stream = configuredStream.getStream();
final var pair = AirbyteStreamNameNamespacePair.fromAirbyteSteam(stream);
final var pair = AirbyteStreamNameNamespacePair.fromAirbyteStream(stream);
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: since we're being more explicit with AirbyteStreamNameNamespacePair, should this var be AirbyteStreamNameNamespacePair instead?

Copy link
Contributor

@ryankfu ryankfu left a comment

Choose a reason for hiding this comment

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

LGTM

@davinchia
Copy link
Contributor Author

/test connector=source-postgres

@davinchia
Copy link
Contributor Author

davinchia commented Nov 15, 2022

/test connector=destination-snowflake

🕑 destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/3466473063
✅ destination-snowflake https://github.com/airbytehq/airbyte/actions/runs/3466473063
Python tests coverage:

Name                                                              Stmts   Miss  Cover
-------------------------------------------------------------------------------------
normalization/transform_config/__init__.py                            2      0   100%
normalization/transform_catalog/reserved_keywords.py                 14      0   100%
normalization/transform_catalog/__init__.py                           2      0   100%
normalization/destination_type.py                                    14      0   100%
normalization/__init__.py                                             4      0   100%
normalization/transform_catalog/destination_name_transformer.py     166      8    95%
normalization/transform_catalog/table_name_registry.py              174     34    80%
normalization/transform_config/transform.py                         189     48    75%
normalization/transform_catalog/utils.py                             51     14    73%
normalization/transform_catalog/dbt_macro.py                         22      7    68%
normalization/transform_catalog/catalog_processor.py                147     80    46%
normalization/transform_catalog/transform.py                         61     38    38%
normalization/transform_catalog/stream_processor.py                 595    400    33%
-------------------------------------------------------------------------------------
TOTAL                                                              1441    629    56%

Build Passed

Test summary info:

All Passed

@davinchia
Copy link
Contributor Author

davinchia commented Nov 15, 2022

/test connector=source-postgres

🕑 source-postgres https://github.com/airbytehq/airbyte/actions/runs/3467497373
❌ source-postgres https://github.com/airbytehq/airbyte/actions/runs/3467497373
🐛 https://gradle.com/s/jo6bjqwnkcbca

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_core.py::TestSpec::test_enum_usage[inputs0] - TypeError: list ind...
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:63: Skipping TestConnection.test_check: not found in the config.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:63: Skipping TestDiscovery.test_discover: not found in the config.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:63: Skipping TestBasicRead.test_read: not found in the config.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:63: Skipping TestFullRefresh.test_sequential_reads: not found in the config.
SKIPPED [1] ../usr/local/lib/python3.9/site-packages/source_acceptance_test/plugin.py:63: Skipping TestIncremental.test_two_sequential_reads: not found in the config.
============ 1 failed, 13 passed, 5 skipped, 21 warnings in 22.02s =============

@davinchia
Copy link
Contributor Author

@grishick @ryankfu the source-postgres build has been failing for the last 5 days for reasons unrelated to this PR.

From the connector-health dash, looks like this has been failing for a few days now:
Screenshot 2022-11-14 at 10 01 57 PM

Since this is a package change, I think this change set should be fine to merge. I want to check in with both of you first. I would prefer to merge in sooner rather than later due to the freeze next week & this blocking other feature work.

@davinchia davinchia merged commit 0d4a2bb into master Nov 16, 2022
@davinchia davinchia deleted the davinchia/message-tracker-refactor branch November 16, 2022 19:50
davinchia added a commit that referenced this pull request Nov 17, 2022
Follow up to #19360.

This PR adjusts the MessageTracker interface to use the new Pair object.
akashkulk pushed a commit that referenced this pull request Dec 2, 2022
…nWorker. (#19360)

#19191 made me realise the DefaultReplicationWorker's metric tracking today has a bug where we aren't accounting for namespace when tracking metrics today. i.e. Streams with the same name and duplicate namespace will merge metrics.

While reading the code to figure out a fix, I realised we don't have a good conceptual representation of stream namespace <> name pairs within the platform today. We use a concatenated string. Though this works, it will become harder and harder to read/track as we do more operations that involve namespace i.e. progress bars and column selection.

This PR introduces the AirbyteStreamNameNamespacePair object into the platform code to make it more convenient to work with Streams in the future. (Especially if we proceed with the project to make streams a first-class citizen!)

The AirbyteStreamNameNamespacePair object was written to deal with the same issue of namespace <> name pair manipulation within the Java destination code. It implements the Comparable interface, which makes it convenient to use for Collections operations.

For an example of how this is consumed, see #19361.
akashkulk pushed a commit that referenced this pull request Dec 2, 2022
Follow up to #19360.

This PR adjusts the MessageTracker interface to use the new Pair object.
@Eusebiotrigo
Copy link

Now that there is the v0 version of the protocol models, will there be an updated version of AirbyteStreamNameNamespacePair that accepts the v0 or v1 models?

@edgao
Copy link
Contributor

edgao commented Jan 17, 2023

Now that there is the v0 version of the protocol models, will there be an updated version of AirbyteStreamNameNamespacePair that accepts the v0 or v1 models?

Eventually I think we'll want to get something similar (possibly extracting an interface from the protocol models a la #20905). De facto, v0 and v1 don't have any structural changes (since the only diff is in the JSON blob fields, i.e. record data / stream schemas) so we can get away with using v0 everywhere for now.

cc @gosusnp to fact-check me on that though

@gosusnp
Copy link
Contributor

gosusnp commented Jan 17, 2023

@Eusebiotrigo, AirbyteStreamNameNamespacePair may be removed (https://github.com/airbytehq/airbyte-internal-issues/issues/1187), it is currently redundant with StreamDescriptor from the protocol.
The current duplication of objects is far from ideal, it is something we have identified but there is no clear timeline on it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment