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

🎉 Source Stripe: Implement StripePartition #31696

Conversation

yevhenii-ldv
Copy link
Contributor

What

Resolves airbytehq/airbyte-internal-issues#2147.

How

Describe the solution

Recommended reading order

  1. airbyte-integrations/connectors/source-stripe/source_stripe/partition.py
  2. airbyte-integrations/connectors/source-stripe/source_stripe/source.py

Pre-merge Actions

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Unit & integration tests added

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.

@vercel
Copy link

vercel bot commented Oct 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
airbyte-docs ⬜️ Ignored (Inspect) Visit Preview Nov 7, 2023 3:54pm

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2023

Before Merging a Connector Pull Request

Wow! What a great pull request you have here! 🎉

To merge this PR, ensure the following has been done/considered for each connector added or updated:

  • PR name follows PR naming conventions
  • Breaking changes are considered. If a Breaking Change is being introduced, ensure an Airbyte engineer has created a Breaking Change Plan.
  • Connector version has been incremented in the Dockerfile and metadata.yaml according to our Semantic Versioning for Connectors guidelines
  • You've updated the connector's metadata.yaml file any other relevant changes, including a breakingChanges entry for major version bumps. See metadata.yaml docs
  • Secrets in the connector's spec are annotated with airbyte_secret
  • All documentation files are up to date. (README.md, bootstrap.md, docs.md, etc...)
  • Changelog updated in docs/integrations/<source or destination>/<name>.md with an entry for the new version. See changelog example
  • Migration guide updated in docs/integrations/<source or destination>/<name>-migrations.md with an entry for the new version, if the version is a breaking change. See migration guide example
  • If set, you've ensured the icon is present in the platform-internal repo. (Docs)

If the checklist is complete, but the CI check is failing,

  1. Check for hidden checklists in your PR description

  2. Toggle the github label checklist-action-run on/off to re-run the checklist CI.

@octavia-squidington-iv octavia-squidington-iv requested a review from a team October 22, 2023 19:56
@airbyte-oss-build-runner
Copy link
Collaborator

source-stripe test report (commit e45c5aa66c) - ❌

⏲️ Total pipeline duration: 35.67s

Step Result
Build source-stripe docker image for platform(s) linux/amd64
Unit tests
Acceptance tests
Check our base image is used
Code format checks
Validate metadata for source-stripe
Connector version semver check
Connector version increment check
QA checks

🔗 View the logs here

☁️ View runs for commit in Dagger Cloud

Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command

airbyte-ci connectors --name=source-stripe test

@octavia-squidington-iii octavia-squidington-iii added the area/documentation Improvements or additions to documentation label Oct 22, 2023
@yevhenii-ldv yevhenii-ldv removed the request for review from a team October 22, 2023 20:06
@octavia-squidington-iv octavia-squidington-iv requested a review from a team October 22, 2023 20:07
@airbyte-oss-build-runner
Copy link
Collaborator

source-stripe test report (commit 1c091df4cc) - ❌

⏲️ Total pipeline duration: 33.69s

Step Result
Build source-stripe docker image for platform(s) linux/amd64
Unit tests
Acceptance tests
Check our base image is used
Code format checks
Validate metadata for source-stripe
Connector version semver check
Connector version increment check
QA checks

🔗 View the logs here

☁️ View runs for commit in Dagger Cloud

Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command

airbyte-ci connectors --name=source-stripe test

@yevhenii-ldv yevhenii-ldv requested a review from a team as a code owner October 22, 2023 21:04
@octavia-squidington-iii octavia-squidington-iii added the CDK Connector Development Kit label Oct 22, 2023
@airbyte-oss-build-runner
Copy link
Collaborator

source-stripe test report (commit 56ed09963c) - ❌

⏲️ Total pipeline duration: 28.05s

Step Result
Build source-stripe docker image for platform(s) linux/amd64
Unit tests
Acceptance tests
Check our base image is used
Code format checks
Validate metadata for source-stripe
Connector version semver check
Connector version increment check
QA checks

🔗 View the logs here

☁️ View runs for commit in Dagger Cloud

Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command

airbyte-ci connectors --name=source-stripe test

@yevhenii-ldv yevhenii-ldv force-pushed the ykurochkin/source-stripe/implement-partition branch from 56ed099 to 64b5167 Compare October 22, 2023 21:08
@airbyte-oss-build-runner
Copy link
Collaborator

source-stripe test report (commit 64b5167388) - ❌

⏲️ Total pipeline duration: 24.10s

Step Result
Build source-stripe docker image for platform(s) linux/amd64
Unit tests
Acceptance tests
Check our base image is used
Code format checks
Validate metadata for source-stripe
Connector version semver check
Connector version increment check
QA checks

🔗 View the logs here

☁️ View runs for commit in Dagger Cloud

Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command

airbyte-ci connectors --name=source-stripe test

@yevhenii-ldv yevhenii-ldv force-pushed the ykurochkin/source-stripe/implement-partition branch from 64b5167 to 1c091df Compare October 22, 2023 21:13
@octavia-squidington-iii octavia-squidington-iii removed the CDK Connector Development Kit label Oct 22, 2023
@airbyte-oss-build-runner
Copy link
Collaborator

source-stripe test report (commit 1c091df4cc) - ❌

⏲️ Total pipeline duration: 01mn04s

Step Result
Build source-stripe docker image for platform(s) linux/amd64
Unit tests
Acceptance tests
Check our base image is used
Code format checks
Validate metadata for source-stripe
Connector version semver check
Connector version increment check
QA checks

🔗 View the logs here

☁️ View runs for commit in Dagger Cloud

Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command

airbyte-ci connectors --name=source-stripe test

@octavia-squidington-iii octavia-squidington-iii added the CDK Connector Development Kit label Oct 22, 2023
@airbyte-oss-build-runner
Copy link
Collaborator

source-stripe test report (commit f568b03dfb) - ❌

⏲️ Total pipeline duration: 30.76s

Step Result
Build source-stripe docker image for platform(s) linux/amd64
Unit tests
Acceptance tests
Check our base image is used
Code format checks
Validate metadata for source-stripe
Connector version semver check
Connector version increment check
QA checks

🔗 View the logs here

☁️ View runs for commit in Dagger Cloud

Please note that tests are only run on PR ready for review. Please set your PR to draft mode to not flood the CI engine and upstream service on following commits.
You can run the same pipeline locally on this branch with the airbyte-ci tool with the following command

airbyte-ci connectors --name=source-stripe test

@yevhenii-ldv yevhenii-ldv requested review from girarda and removed request for a team October 22, 2023 23:54
@@ -168,7 +168,10 @@ def as_airbyte_stream(self) -> AirbyteStream:

keys = self._primary_key
if keys and len(keys) > 0:
stream.source_defined_primary_key = [keys]
if isinstance(keys, str):
Copy link
Contributor

Choose a reason for hiding this comment

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

did you encounter a case where keys was a string and not a list? This wouldn't respect the interface

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, agree, will fix

@@ -0,0 +1,130 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

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

can you unit test these classes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -158,10 +220,203 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
],
**args,
)
return [

concurrent_streams = [
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 only create concurrent streams when running in full refresh. You can tell the source will run in full refresh mode by checking that there's no input state file. Here's an example

cursor_value="{{ last_records[-1]['id'] if last_records else None }}",
config={},
parameters={},
page_size=1000,
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make this a constant

concurrent_stream = StreamFacade(
ThreadBasedConcurrentStream(
partition_generator=StripePartitionGenerator(base_stream, self.message_repository, paginated_requester),
max_workers=1,
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make this a constant

self._requester = requester

@property
def request_parameters(self) -> Optional[Mapping[str, Any]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't expose these properties publicly for arbitrary source because not all sources are HTTP API sources

@property
def request_parameters(self) -> Mapping[str, Any]:
params = {
"limit": 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

this parameter should be set by the paginator

class SourcePartition(Partition):
def __init__(self, _slice: Mapping[str, Any], message_repository: MessageRepository, requester: PaginatedRequester):
self._slice = _slice
self._message_repository = message_repository
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the message repository needed? it doesn't seem used

def __init__(self, requester: Requester, record_selector: RecordSelector, paginator: DefaultPaginator):
self._requester = requester
self._record_selector = record_selector
self._page_token_option = paginator.page_token_option
Copy link
Contributor

Choose a reason for hiding this comment

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

why create a new field instead of always referring to paginator.page_token_option?

@octavia-squidington-iv octavia-squidington-iv requested a review from a team October 23, 2023 21:41
@girarda girarda requested a review from brianjlai October 27, 2023 05:38
SessionTokenAuthenticator,
LegacySessionTokenAuthenticator,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@girarda It seems that when was changed the SessionTokenAuthenticator to LegacySessionTokenAuthenticator, wasn't changed this file, so mypy complained about this one. Let me know if this is not the case

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting. would you mind fixing this in a separate PR? no reason to delay this fix with the stripe partition work

Copy link
Contributor Author

@yevhenii-ldv yevhenii-ldv Nov 1, 2023

Choose a reason for hiding this comment

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

sure, I've created separate PR for this

@@ -56,7 +56,7 @@
"""
CLASS_TYPES_REGISTRY contains a mapping of developer-friendly string -> class to abstract the specific class referred to
"""
CLASS_TYPES_REGISTRY: Mapping[str, Type] = {
CLASS_TYPES_REGISTRY: Mapping[str, type] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I make changes to this file, mypy finds the following error:

airbyte_cdk/sources/declarative/parsers/class_types_registry.py:59: error: Missing type parameters for generic type "Type"  [type-arg]

I've created a separate PR to fix the SessionTokenAuthorization, and you can see there that mypy is failing with this error: https://github.com/airbytehq/airbyte/actions/runs/6719622494/job/18261600772?pr=32040

It seems that when using a Type (imported from the typing), we also need to specify a parameter in the annotation (Type[<param>]).

Ours doesn't specify a parameter, so I replaced it with a generic type to get around the mypy error.

from airbyte_cdk.sources.declarative.types import Config
from airbyte_cdk.sources.declarative.types import Config, Record

DECODED_RESPONSE_TYPE = Union[Mapping[str, Any], List[dict[str, Any]]]
Copy link
Contributor

Choose a reason for hiding this comment

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

this is needed because the decoder can return either a mapping or a list, is this correct? If so, can you update the decoder to return a value of this type to document why this is needed

return token if token else None

def reset(self):
@abstractmethod
def stop(self, response: DECODED_RESPONSE_TYPE, headers: Mapping[str, Any], last_records: List[Record]) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need both a stop_condition and a stop method? Maybe we can remove the stop_condition property and only keep the private field in the LowCodeCursorPaginationStrategy

…package' of github.com:airbytehq/airbyte into ykurochkin/source-stripe/implement-partition

# Conflicts:
#	airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/paginators/strategies/__init__.py
#	airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/paginators/strategies/cursor_pagination_strategy.py
@yevhenii-ldv yevhenii-ldv force-pushed the ykurochkin/source-stripe/implement-partition branch from 1ff33ee to 1872989 Compare November 2, 2023 11:40
@yevhenii-ldv yevhenii-ldv changed the base branch from master to ykurochkin/cdk/decoupling-the-objects-from-declarative-package November 2, 2023 11:41
…package' of github.com:airbytehq/airbyte into ykurochkin/source-stripe/implement-partition

# Conflicts:
#	airbyte-integrations/connectors/source-stripe/source_stripe/source.py
#	docs/integrations/sources/stripe.md
@octavia-squidington-iii octavia-squidington-iii removed the CDK Connector Development Kit label Nov 2, 2023
…package' of github.com:airbytehq/airbyte into ykurochkin/source-stripe/implement-partition
…package' of github.com:airbytehq/airbyte into ykurochkin/source-stripe/implement-partition
@@ -5,7 +5,7 @@

from setuptools import find_packages, setup

MAIN_REQUIREMENTS = ["airbyte-cdk==0.52.8", "stripe==2.56.0", "pendulum==2.1.2"]
MAIN_REQUIREMENTS = ["airbyte-cdk>=0.52.8", "stripe==2.56.0", "pendulum==2.1.2"]
Copy link
Contributor

Choose a reason for hiding this comment

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

let's pin the version before releasing to avoid the connector accidentally breaking if we make a breaking change

return None


class StripePaginationStrategy(CursorPaginationStrategy):
Copy link
Contributor

Choose a reason for hiding this comment

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

let's write unit tests for this class



class StripePaginator(DefaultPaginator):
def path(self) -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

let's write unit tests for this method

@octavia-squidington-iv octavia-squidington-iv requested a review from a team November 5, 2023 18:44
…package' of github.com:airbytehq/airbyte into ykurochkin/source-stripe/implement-partition
@lazebnyi lazebnyi requested a review from davydov-d November 10, 2023 09:30
@katmarkham katmarkham requested review from lazebnyi and removed request for a team November 27, 2023 15:20
@lazebnyi
Copy link
Collaborator

lazebnyi commented Feb 8, 2024

Hey @yevhenii-ldv
Are you still in work on this pull request?

@girarda girarda closed this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation connectors/source/stripe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants