jonathansudhakar1 opened a new pull request, #41881:
URL: https://github.com/apache/beam/pull/41881

   Fixes #20319.
   
   `SpannerIO.write()` counts batches and mutation groups (received, succeeded, 
failed), plus latency, timeouts and retries, but nothing about bytes. So a 
running write job's metrics don't show how much data it has written, which is 
what the issue asks for. This follows the plan on the issue (agreed there on 
2026-12-02).
   
   ## Change
   
   - `WriteToSpannerFn` gets one new counter, `spanner_write_bytes`, in the 
same `WriteGrouped` namespace as the other write counters.
   - It's incremented by `MutationSizeEstimator.sizeOf` for each mutation 
group, **only after the group commits**:
     - on the batch path, by the whole batch once `writeMutations` returns;
     - when a failed batch is retried group by group (`REPORT_FAILURES`), by 
each group that succeeds. Groups that fail again aren't counted.
     - Under `FAIL_FAST` a failed batch counts nothing. A write that succeeds 
after `DEADLINE_EXCEEDED` retries is counted once.
   - The value is the same estimate that `withBatchSizeBytes` uses for 
batching, not bytes on the wire. The class Javadoc's "Monitoring" list says so.
   - Cost: one more `sizeOf` pass per committed group. The batching steps 
already compute the size, but passing it along would change the batch element 
type, so it's recomputed here.
   - While adding the counter to the Javadoc list, I fixed two names there that 
didn't match the code: `mutation_group_batches_write_failed` → 
`mutation_group_batches_write_fail`, and `spanner_write_total_latency_ms` → 
`spanner_write_latency_ms` (it's a distribution of each write attempt's 
latency).
   - CHANGES.md bullet under 2.79.0 New Feature.
   
   ## Testing
   
   Run locally with JDK 21 (CI's `--release 11` bytecode level), on 3b166fba7eb:
   
   ```
   ./gradlew :sdks:java:io:google-cloud-platform:spotlessCheck \
     :sdks:java:io:google-cloud-platform:compileJava 
:sdks:java:io:google-cloud-platform:compileTestJava \
     :sdks:java:io:google-cloud-platform:checkstyleMain 
:sdks:java:io:google-cloud-platform:checkstyleTest \
     :sdks:java:io:google-cloud-platform:javadoc
   ./gradlew :sdks:java:io:google-cloud-platform:test \
     --tests 'org.apache.beam.sdk.io.gcp.spanner.SpannerIOWriteTest' \
     --tests 
'org.apache.beam.sdk.io.gcp.spanner.SpannerSchemaTransformProviderTest' \
     --tests 'org.apache.beam.sdk.io.gcp.spanner.SpannerTransformRegistrarTest' 
\
     --tests 'org.apache.beam.sdk.io.gcp.spanner.MutationSizeEstimatorTest' 
--rerun
   ```
   
   - spotless, compile (Checker Framework on), checkstyle and javadoc: clean.
   - `SpannerIOWriteTest` 49/49 (3 new), `SpannerSchemaTransformProviderTest` 
7/7, `SpannerTransformRegistrarTest` 22/22, `MutationSizeEstimatorTest` 13/13.
   
   New tests in `SpannerIOWriteTest`, using the existing `FakeServiceFactory`:
   - `writeBytesCounterCountsCommittedMutationGroups`: a `grouped()` pipeline 
on the DirectRunner; the counter, queried from `PipelineResult.metrics()`, 
equals the summed size of the groups.
   - `writeBytesCounterSkipsFailedMutationGroupsWhenReportingFailures`: 
`WriteToSpannerFn` with `REPORT_FAILURES` on one batch of three groups, where 
any write containing one group's mutation fails. Only the two committed groups 
are counted, and the failed group goes to the failed output.
   - `writeBytesCounterSkipsFailedBatchInFailFastMode`: with `FAIL_FAST`, a 
committed batch is counted and a later failed batch (which throws) adds nothing.
   
   The three tests fail without the change (counter 0). A mutant that 
increments the counter before the write makes both `WriteToSpannerFn` tests 
fail (they read 32 instead of 16, and 96 instead of 32).
   
   No ITs were run (they need Spanner).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to