-
Notifications
You must be signed in to change notification settings - Fork 0
Eliminate OOM during VCR recording: streaming, zero-copy body handling, and full test suite #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0131bac
Absorb ConfigSecretsSanitizer into DefaultSanitizer
matyas-jirat-keboola 96d1117
Stream cassette interactions to disk to avoid OOM on large jobs
matyas-jirat-keboola c37bdb4
freezetime update
matyas-jirat-keboola 995fb05
Eliminate deepcopy and reduce post-run memory pressure during recording
matyas-jirat-keboola 9d5769a
Eliminate VCR body copy overhead with zero-copy _VCRRecordingReader
matyas-jirat-keboola 4444801
Eliminate two more large allocations per response during recording
matyas-jirat-keboola 03a45f8
Apply code review fixes across all four source modules
matyas-jirat-keboola 941c8bc
Release _VCRRecordingReader._data after body is fully consumed
matyas-jirat-keboola 5e44d38
Extract nested functions, rename symbols, reorder by importance
matyas-jirat-keboola 00d1211
Fix _zero_copy_vcr_response_init not receiving self when monkey-patched
matyas-jirat-keboola 419a9b1
Fix issues 4-8 and add comprehensive unit tests
matyas-jirat-keboola 697bd91
Address code review: pin vcrpy, fix temp cleanup, sort keys, flag-bas…
matyas-jirat-keboola 5247f58
Tighten vcrpy pin to >=8.1.1,<9
matyas-jirat-keboola 5d2be49
Tighten freezegun pin to >=1.5.5,<2
matyas-jirat-keboola fab73f4
Add CI pipeline and uv lockfile
matyas-jirat-keboola f193713
Fix decode_compressed_response bypass in _append_interaction
matyas-jirat-keboola 84af9a6
Default scaffold freeze_time to now() instead of 2025-01-01
matyas-jirat-keboola fe8a236
Add PyPI/TestPyPI publishing pipeline
matyas-jirat-keboola 2933574
PyPi and Pipeline updates
matyas-jirat-keboola 4a44ff4
Updates for PyPi and Pipeline
matyas-jirat-keboola d54a94c
Published version
matyas-jirat-keboola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [flake8] | ||
| exclude = | ||
| .git, | ||
| __pycache__, | ||
| tests, | ||
| example | ||
| .venv | ||
| max-line-length = 120 | ||
| extend-ignore = E203 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Build & Deploy to PyPI | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| note: | ||
| description: 'This workflow publishes to TestPyPI only. For production, create a GitHub Release.' | ||
| required: false | ||
| default: "" | ||
|
|
||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout 🛒 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install uv 💜 | ||
| uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - name: Install and run ruff 🐶 | ||
| uses: astral-sh/ruff-action@v3 | ||
|
|
||
| - name: Set up Python 🐍 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.13" | ||
|
|
||
| - name: Install dependencies 📦 | ||
| run: uv sync --all-groups --frozen | ||
|
|
||
| - name: Lint with flake8 ❄️ | ||
| run: uv run flake8 | ||
|
|
||
| - name: Test with pytest ✅ | ||
| run: uv run pytest tests/ | ||
|
|
||
| - name: Version replacement based on tag ↔️ | ||
| if: github.ref_type == 'tag' | ||
| run: | | ||
| TAG_VERSION=${GITHUB_REF#refs/tags/} | ||
| echo "Tag version: $TAG_VERSION" | ||
| uv version $TAG_VERSION | ||
|
|
||
| - name: Build package 📦 | ||
| run: uv build | ||
|
|
||
| - name: Publish to TestPyPI 🧪 | ||
| env: | ||
| UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN_TEST_PYPI }} | ||
| run: uv publish --index testpypi | ||
|
|
||
| - name: Publish to PyPI 🚀 | ||
| if: github.event_name == 'release' | ||
| env: | ||
| UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN }} | ||
| run: uv publish |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| name: Build & Test | ||
|
|
||
| on: | ||
| push: | ||
| branches-ignore: | ||
| - main | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout 🛒 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install and run ruff 🐶 | ||
| uses: astral-sh/ruff-action@v3 | ||
|
|
||
| - name: Install uv 💜 | ||
| uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - name: Install dependencies 📦 | ||
| run: uv sync --all-groups --frozen | ||
|
|
||
| - name: Lint with flake8 ❄️ | ||
| run: uv run flake8 | ||
|
|
||
| test-310: | ||
| name: Test (Python 3.10) | ||
| runs-on: ubuntu-latest | ||
| needs: lint | ||
| steps: | ||
| - name: Checkout 🛒 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install uv 💜 | ||
| uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - name: Set up Python 3.10 🐍 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.10" | ||
|
|
||
| - name: Install dependencies 📦 | ||
| run: uv sync --all-groups --frozen | ||
|
|
||
| - name: Test with pytest ✅ | ||
| run: uv run pytest tests/ | ||
|
|
||
| test-313: | ||
| name: Test (Python 3.13) | ||
| runs-on: ubuntu-latest | ||
| needs: lint | ||
| steps: | ||
| - name: Checkout 🛒 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install uv 💜 | ||
| uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - name: Set up Python 3.13 🐍 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.13" | ||
|
|
||
| - name: Install dependencies 📦 | ||
| run: uv sync --all-groups --frozen | ||
|
|
||
| - name: Test with pytest ✅ | ||
| run: uv run pytest tests/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ venv/ | |
| .pytest_cache/ | ||
| .ruff_cache/ | ||
| *.lock | ||
| !uv.lock | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? 🤔
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will get rid of it. It is longer to explain then get rid of it. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # keboola.vcr | ||
|
|
||
| VCR recording, sanitization, and validation for Keboola component HTTP interactions. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install keboola.vcr | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```python | ||
| from keboola.vcr.recorder import VCRRecorder | ||
| from keboola.vcr.sanitizers import DefaultSanitizer | ||
|
|
||
| recorder = VCRRecorder( | ||
| cassette_dir="tests/cassettes/my_test", | ||
| secrets={"api_key": "secret"}, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Features | ||
|
|
||
| - **Recording**: Captures real HTTP interactions via vcrpy and stores them as JSON cassettes | ||
| - **Sanitization**: Redacts secrets, tokens, and sensitive fields before saving cassettes | ||
| - **Scaffolding**: Generates test directory structures from component config definitions | ||
| - **Validation**: Compares output snapshots to detect regressions | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| uv sync --all-groups | ||
| uv run pytest tests/ | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is inspired by another of our projects, but I think we can safely ditch flake8 in 2026, it was great while it lasted! 🫡 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that will be the next update where I test pipeline