Skip to content

[WIP] Write failed JSON to Document parsing to DLQ and catch NPE exceptions#3749

Open
le-michael wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
le-michael:better-parse-error
Open

[WIP] Write failed JSON to Document parsing to DLQ and catch NPE exceptions#3749
le-michael wants to merge 4 commits intoGoogleCloudPlatform:mainfrom
le-michael:better-parse-error

Conversation

@le-michael
Copy link
Copy Markdown
Contributor

No description provided.

@le-michael le-michael requested a review from a team as a code owner April 30, 2026 16:02
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the reliability of the MongoDB to Firestore data pipeline by introducing a more resilient error handling mechanism. By decoupling the parsing logic from the bulk write operation, the system can now identify and isolate malformed records, routing them to a DLQ rather than allowing them to cause pipeline failures or runtime exceptions.

Highlights

  • DLQ Integration: Implemented logic to capture failed JSON parsing events and route them to a Dead Letter Queue (DLQ) instead of failing the entire batch.
  • Exception Handling: Added robust handling for parsing errors and null document fields, preventing NullPointerExceptions during the data transformation process.
  • Validation Improvements: Updated the utility layer to explicitly validate the presence of required data fields, with corresponding unit tests to ensure stability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces error handling for MongoDB document parsing by capturing failures and routing them to a Dead Letter Queue (DLQ). It refactors processBatch and processBatchFinish to use a new lazy-parsing mechanism in MongoDbChangeEventContext and adds validation to Utils.jsonToDocument. Review feedback points out that FailsafeElement lacks a setException method, suggests a standard approach for stack trace formatting, and recommends refactoring duplicated logic into a shared helper method.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 5.17241% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.07%. Comparing base (0af55a0) to head (edb5446).

Files with missing lines Patch % Lines
...ort/v2/templates/DataStreamMongoDBToFirestore.java 0.00% 45 Missing ⚠️
...emplates/datastream/MongoDbChangeEventContext.java 0.00% 10 Missing ⚠️

❌ Your patch check has failed because the patch coverage (5.17%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##               main    #3749    +/-   ##
==========================================
  Coverage     53.06%   53.07%            
- Complexity     6026     6439   +413     
==========================================
  Files          1072     1072            
  Lines         64967    64979    +12     
  Branches       7198     7199     +1     
==========================================
+ Hits          34477    34489    +12     
- Misses        28172    28176     +4     
+ Partials       2318     2314     -4     
Components Coverage Δ
spanner-templates 72.86% <ø> (+0.05%) ⬆️
spanner-import-export 68.63% <ø> (+0.17%) ⬆️
spanner-live-forward-migration 81.00% <ø> (ø)
spanner-live-reverse-replication 77.20% <ø> (ø)
spanner-bulk-migration 91.14% <ø> (ø)
gcs-spanner-dv 85.83% <ø> (ø)
Files with missing lines Coverage Δ
...com/google/cloud/teleport/v2/transforms/Utils.java 95.45% <100.00%> (+0.71%) ⬆️
...emplates/datastream/MongoDbChangeEventContext.java 65.90% <0.00%> (-5.41%) ⬇️
...ort/v2/templates/DataStreamMongoDBToFirestore.java 16.35% <0.00%> (+0.03%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants