Repository navigation
fix: allow larger import batches in BufferedConsumer - #210
rahul-mixpanel wants to merge 2 commits into
Conversation
BufferedConsumer caps every endpoint at 50 messages per request, but /import accepts up to 2000 events per request. Add an opt-in import_max_size argument (capped at 2000) for the imports buffer. It defaults to max_size, so existing callers send exactly what they send today. Related to #115 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #210 +/- ##
==========================================
+ Coverage 96.51% 96.54% +0.02%
==========================================
Files 15 15
Lines 2955 2980 +25
Branches 180 182 +2
==========================================
+ Hits 2852 2877 +25
Misses 66 66
Partials 37 37
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
[Medium impact] The change is limited to how import messages are batched. The previous oversized-request issue still needs a fix before merging. Findings
Fix with agent prompt### Issue 1
mixpanel/__init__.py:973-977
With `import_max_size=2000`, 2000 events of roughly 6 KB become one roughly 12 MB request. That exceeds the 10 MB import limit stated in the PR description, although the same events previously fit in 50-event batches. `_flush_endpoint` splits only by event count, so another `flush()` retries the same oversized batch.
Split import batches by encoded size as well as count, and add a test with large events.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (2) · Last reviewed commit: "fix(analytics): reject non-positive impo..." · Reviewed by Greptile |
| max_size = self._endpoint_max_size(endpoint) | ||
|
|
||
| while buf: | ||
| batch = buf[: self._max_size] | ||
| batch = buf[:max_size] | ||
| batch_json = "[{}]".format(",".join(batch)) |
There was a problem hiding this comment.
Larger batches exceed request limits
With import_max_size=2000, 2000 events of roughly 6 KB become one roughly 12 MB request. That exceeds the 10 MB import limit stated in the PR description, although the same events previously fit in 50-event batches. _flush_endpoint splits only by event count, so another flush() retries the same oversized batch.
Split import batches by encoded size as well as count, and add a test with large events.
Prompt To Fix With AI
This is a comment left during a code review.
Path: mixpanel/__init__.py
Line: 969-973
Comment:
**Larger batches exceed request limits**
With `import_max_size=2000`, 2000 events of roughly 6 KB become one roughly 12 MB request. That exceeds the 10 MB import limit stated in the PR description, although the same events previously fit in 50-event batches. `_flush_endpoint` splits only by event count, so another `flush()` retries the same oversized batch.
Split import batches by encoded size as well as count, and add a test with large events.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.import_max_size=0 or below made flush loop forever, because the batch slice was always empty. Raise ValueError for the new argument, and note that large import batches can exceed the 10 MB /import request limit. Related to #115 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No description provided.