refactor(streaming): optimize sync batch inserts#4523
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughBatchInsert now has separate async and sync execution paths (async uses Exec with WithAsync; sync uses PrepareBatch, Append, Send and respects Config.InsertTimeout). Tests, mocks, configuration, query column ordering, and tracing were updated to support and observe the sync path. ChangesAsync/Sync Insert Path Separation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR replaces the synchronous
Confidence Score: 5/5Safe to merge; the sync batch rewrite is well-guarded and the async path is untouched. The core BatchInsert rewrite is correct: the defer for Close is registered only after a successful PrepareBatch, the InsertTimeout fallback fires only when the context has no deadline, and the shared rawEventColumns slice keeps both insert paths in sync. The only inconsistency is that tracedBatch.Abort does not record its error on the span, unlike every other method in that wrapper — but this does not affect data correctness. pkg/framework/clickhouseotel/otel.go — the Abort method in tracedBatch omits span error recording. Important Files Changed
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openmeter/streaming/clickhouse/connector_test.go`:
- Around line 191-205: The SyncInsert subtest only verifies Append was called
once and misses validating the exact values/order and error branches; update the
test for connector.BatchInsert (using GetMockConnector and NewMockBatch) to
assert PrepareBatch is called with the expected SQL/column list, and assert that
mockBatch.Append is called ten times (or called with the exact slice/values
matching the explicit columns in connector.go) verifying each appended record's
fields and order, then also add separate subtests that exercise and assert
behavior when PrepareBatch, Append, and Send return errors (mock their returns
and require the corresponding error from BatchInsert). Ensure you use
mockCH.AssertExpectations and mockBatch.AssertExpectations to verify these
stricter expectations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 12929957-eaa7-42cc-8ef7-33b16646573d
📒 Files selected for processing (3)
openmeter/streaming/clickhouse/connector.goopenmeter/streaming/clickhouse/connector_test.goopenmeter/streaming/clickhouse/mock.go
Summary by CodeRabbit
New Features
Refactor
Configuration
Tests