Repository navigation
[Python] Add with_exception_handling to RequestResponseIO and Enrichment (#41356) - #41451
shikhabhadoria wants to merge 6 commits into
Conversation
Give Enrichment explicit miss policy and column prefixing, and thread dead-letter outputs through RequestResponseIO so misses and RPC failures can be quarantined.
|
Assigning reviewers: R: @damccorm for label python. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
…apache#41356) Drop the unused json import flagged in review. Import FileEnrichmentHandler separately so a missing module does not disable Enrichment, and skip the file-handler tests until apache#41451 and apache#41452 are available.
…pache#41356) Stop learning null enriched fields from prior hits. Without a static handler schema, unmatched rows keep only their input fields so miss output does not depend on processing order.
|
@JunaidAhamed-7777 Good catch. Without a static handler schema, I removed that learning path. For
Added |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41451 +/- ##
============================================
+ Coverage 58.89% 59.49% +0.60%
- Complexity 2315 5156 +2841
============================================
Files 1135 1470 +335
Lines 170578 187893 +17315
Branches 1499 3828 +2329
============================================
+ Hits 100454 111782 +11328
- Misses 67580 72709 +5129
- Partials 2544 3402 +858
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:
|
…ling Address review feedback by keeping this change focused on with_exception_handling. Forward *args/**kwargs to DoFn.with_exception_handling, document that API, and keep FlattenBatchErrors for batched DLQ shape. Move on_miss/prefix work to feat-enrichment-on-miss-prefix-followup-41356.
|
@damccorm thanks for the review. Addressed all three comments:
Also merged latest |
Refresh the branch onto latest master per review. Update skip/error messages so on_miss/prefix point at the follow-up to apache#41451, while error_handling continues to use with_exception_handling from that PR.
…with_exception_handling
| input_count_view = input_pcoll | 'CountTotal' >> ( | ||
| _MaybeWindow() | beam.Map(lambda _: 1) | ||
| | beam.CombineGlobally(sum).as_singleton_view()) | ||
| bad_count_pcoll = error_pcoll | 'CountBad' >> ( | ||
| _MaybeWindow() | beam.Map(lambda _: 1) | ||
| | beam.CombineGlobally(sum).without_defaults()) | ||
|
|
||
| def _check_threshold(bad, total, threshold_val, window=beam.DoFn.WindowParam): | ||
| if bad > total * threshold_val: | ||
| raise ValueError( | ||
| 'The number of failing elements within the window %r ' | ||
| 'exceeded threshold: %s / %s = %s > %s' % | ||
| (window, bad, total, bad / total, threshold_val)) | ||
|
|
||
| _ = bad_count_pcoll | 'CheckThreshold' >> beam.Map( | ||
| _check_threshold, input_count_view, threshold) |
There was a problem hiding this comment.
Two notes on _check_exception_threshold:
- Batched callers +
threshold_windowingmismatch /ZeroDivisionError:BatchElementsemits batches atwindow.max_timestamp()(_GlobalWindowsBatchingDoFnusesGlobalWindow().max_timestamp(),_WindowAwareBatchingDoFnuseswindow.max_timestamp()). BecauseCountTotalre-windows the pre-batchrequests/input_rowusing original event timestamps whileCountBadre-windows the post-batcherrors/all_errorsatwindow.max_timestamp(),CountTotalandCountBadland in differentthreshold_windowingwindows when batching is enabled.input_count_viewthen defaults tototal = 0, which both falsely triggersbad > total * threshold_valand raisesZeroDivisionErroronbad / totalat line 806.- Could we raise a clear
ValueErrorinRequestResponseIO.expand(whenself._batching_kwargs) andEnrichment.expand(whenself._source_handler.batch_elements_kwargs()) ifthreshold_windowing is not None and threshold is not None and threshold < 1.0(advising users to window inputs before the transform instead), and also guardratio = bad / total if total else float('inf')here?
- Could we raise a clear
- Nit (update-compat): Please give the two
beam.Map(lambda _: 1)steps explicit static labels (e.g.,'ToOne' >> beam.Map(lambda _: 1)) so line numbers aren't baked into the transform names (see the comment atcore.py:2425-2428).
|
|
||
| def _build_do_outputs_tuple( | ||
| pipeline, | ||
| main_tag: str, |
There was a problem hiding this comment.
Nit: main_tag: Optional[str] matches pvalue.DoOutputsTuple.__init__ since ParDo.with_exception_handling(main_tag=None) allows None.
| join_errors = ( | ||
| join_result[dead_letter_tag] | ||
| | "NormalizeJoinErrors" >> beam.Map(lambda x: (x[0][0], x[1]))) |
There was a problem hiding this comment.
Nit: if a misbehaving handler returns None or (), _join_element fails to unpack and x[0][0] here would raise an unhandled TypeError/IndexError. Guarding with lambda x: (x[0][0], x[1]) if isinstance(x[0], tuple) and len(x[0]) == 2 else x handles that safely while still working for use_custom_types=True tuple requests (since valid fetched_data entries are always (request, response) 2-tuples).
Purpose
Add
with_exception_handlingtoRequestResponseIOandEnrichment, forwarding toDoFn.with_exception_handlingso RPC and join failures can be routed to a dead-letter output.This PR is intentionally scoped to exception handling only.
on_miss/prefixsemantics are deferred to a follow-up branch (feat-enrichment-on-miss-prefix-followup-41356) per review feedback.Related issue
Fixes part of #41356
Changes
RequestResponseIO.with_exception_handling(*args, **kwargs)and_Call.with_exception_handling(*args, **kwargs)forward toDoFn.with_exception_handling(batch, error)records to per-element(request, error)for a consistent DLQ shapeEnrichment.with_exception_handlingwires RRIO and join through the same API and flattens error outputsTesting
enrichment_test.py: RPC timeout DLQ routing, join failure DLQ routing, cross_join