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

Enable client-side rate limiting on source-stripe #31512 #32284

Merged
merged 22 commits into from
Nov 16, 2023

Conversation

keu
Copy link
Contributor

@keu keu commented Nov 8, 2023

What

This adds client-side rate limiting that helps increase the number of workers and not hit the call rate limit when it is too big.

How

Describe the solution

Recommended reading order

  1. spec.yaml
  2. source.py

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user?

For connector PRs, use this section to explain which type of semantic versioning bump occurs as a result of the changes. Refer to our Semantic Versioning for Connectors guidelines for more information. Breaking changes to connectors must be documented by an Airbyte engineer (PR author, or reviewer for community PRs) by using the Breaking Change Release Playbook.

If there are breaking changes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

Pre-merge Actions

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • 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.
  • Connector version is set to 0.0.1
    • Dockerfile has version 0.0.1
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/integrations/<source or destination>/<name>.md including changelog with an entry for the initial version. See changelog example
    • docs/integrations/README.md

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.
Updating a connector

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.
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:generateScaffolds then checking in your changes
  • Documentation which references the generator is updated as needed
Updating the Python CDK

Airbyter

Before merging:

  • Pull Request description explains what problem it is solving
  • Code change is unit tested
  • Build and my-py check pass
  • Smoke test the change on at least one affected connector
    • On Github: Run this workflow, passing --use-local-cdk --name=source-<connector> as options
    • Locally: airbyte-ci connectors --use-local-cdk --name=source-<connector> test
  • PR is reviewed and approved

After merging:

  • Publish the CDK
    • The CDK does not follow proper semantic versioning. Choose minor if this the change has significant user impact or is a breaking change. Choose patch otherwise.
    • Write a thoughtful changelog message so we know what was updated.
  • Merge the platform PR that was auto-created for updating the Connector Builder's CDK version
    • This step is optional if the change does not affect the connector builder or declarative connectors.

Copy link

vercel bot commented Nov 8, 2023

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

Name Status Preview Comments Updated (UTC)
airbyte-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 16, 2023 1:50am

@CLAassistant
Copy link

CLAassistant commented Nov 8, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ keu
❌ eugene-kulak
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

github-actions bot commented Nov 8, 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 November 8, 2023 00:34
@keu keu linked an issue Nov 8, 2023 that may be closed by this pull request
4 tasks
@keu keu requested review from yevhenii-ldv and removed request for a team November 8, 2023 00:50
@girarda girarda requested a review from maxi297 November 8, 2023 19:31
Copy link
Contributor

@maxi297 maxi297 left a comment

Choose a reason for hiding this comment

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

Can we add some test to ensure that we get the behavior we want?

@keu
Copy link
Contributor Author

keu commented Nov 8, 2023

blocked by this https://github.com/airbytehq/airbyte/pull/31696/files?diff=unified&w=0
I'm waiting for it to update this PR with logic for concurrent streams.

it showed better performance and almost never hit the API limit in local testing
Copy link
Contributor

@maxi297 maxi297 left a comment

Choose a reason for hiding this comment

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

Thanks for adding the tests! We just need to do the items from the connector checklist and we should be good to go. There is this blocked situation with the other PR that I don't fully get though so if you can expand on that just to be sure we're aligned

@@ -76,3 +76,9 @@ connectionSpecification:
The number of API calls per second that you allow connector to make. This value can not be bigger than real
API call rate limit (https://stripe.com/docs/rate-limits). If not specified the default maximum is 25 and 100
calls per second for test and production tokens respectively.
call_rate_policy:
Copy link
Contributor

Choose a reason for hiding this comment

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

is this field only for testing purposes? This looks like an implementation detail to me. a simpler option for the user would be to configure the rate limit in terms of requests per seconds

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 added this just for your convenience to test with different policies :)

@keu
Copy link
Contributor Author

keu commented Nov 14, 2023

Thanks for adding the tests! We just need to do the items from the connector checklist and we should be good to go. There is this blocked situation with the other PR that I don't fully get though so if you can expand on that just to be sure we're aligned

Got it, I want to run a few more tests to make sure which policy to enable by default. Also @girarda will help me to run tests with live account to make sure we don't miss anything. And I'm done.

Copy link
Contributor

@girarda girarda left a comment

Choose a reason for hiding this comment

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

I ran a test locally with a live account and 15 workers and the moving window strategy.

The acquire_call CPU usage was ~2% which isn't outrageous to me

Screenshot 2023-11-14 at 10 54 43 AM

@@ -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.53.2", "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.

note: we'll need to bump this to the latest version with the higher retry count

),
]
else:
policies = []
Copy link
Contributor

Choose a reason for hiding this comment

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

the default should use a policy

_MAX_CONCURRENCY = 3
logger = logging.getLogger("airbyte")

_MAX_CONCURRENCY = 20
Copy link
Contributor

Choose a reason for hiding this comment

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

the limit in the spec should be aligned with this limit

@@ -62,9 +62,17 @@ connectionSpecification:
title: Number of concurrent workers
minimum: 1
maximum: 3
Copy link
Contributor

Choose a reason for hiding this comment

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

maximum should be 20

@@ -62,9 +62,17 @@ connectionSpecification:
title: Number of concurrent workers
minimum: 1
maximum: 3
default: 2
default: 20
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 set the default to 10 and go from there

@@ -62,9 +62,17 @@ connectionSpecification:
title: Number of concurrent workers
minimum: 1
maximum: 3
default: 2
default: 20
examples: [1, 2, 3]
description: >-
The number of worker thread to use for the sync. The bigger the value is, the faster the sync will be.
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
The number of worker thread to use for the sync. The bigger the value is, the faster the sync will be.
The number of worker thread to use for the sync.

Copy link
Contributor

Choose a reason for hiding this comment

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

this statement isn't true

else:
call_limit = max_call_rate

if config.get("call_rate_policy") == "fixed_window":
Copy link
Contributor

Choose a reason for hiding this comment

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

call_rate_policy isn't in the pec so this will never be true

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 think something went wrong with merge, so this was an old code, updated

Copy link
Contributor

@girarda girarda left a comment

Choose a reason for hiding this comment

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

:shipit: !

@@ -216,6 +216,7 @@ Each record is marked with `is_deleted` flag when the appropriate event happens

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:----------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
| 4.5.4 | 2023-11-15 | [32284](https://github.com/airbytehq/airbyte/pull/32284/) | Enable client-side rate limiting |
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's update the date before merging

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

@keu
Copy link
Contributor Author

keu commented Nov 16, 2023

@maxi297 😇
Screenshot 2023-11-16 at 03 51 26

Copy link
Contributor

@maxi297 maxi297 left a comment

Choose a reason for hiding this comment

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

Check list has been updated. I'm good with the implementation

@keu keu merged commit a38eca1 into master Nov 16, 2023
24 of 26 checks passed
@keu keu deleted the keu/source-stripe/call_rate branch November 16, 2023 15:02
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.

Enable client-side rate limiting on source-stripe
6 participants