You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "corgy-w (via GitHub)" <gi...@apache.org> on 2026/08/22 19:48:18 UTC

[PR] [Fix][Client] Avoid division by zero on first job metrics print [seatunnel]

corgy-w opened a new pull request, #11942:
URL: https://github.com/apache/seatunnel/pull/11942

   ### What problem does this PR solve?
   
   `JobMetricsRunner` is scheduled by `ClientExecuteCommand` with an initial delay of `0`, so its **first run executes in the same second** the runner is constructed. `Duration.between(lastRunTime, now).getSeconds()` then returns `0`, and the average-rate calculation divides by zero:
   
   ```java
   long averageRead = (jobMetricsSummary.getSourceReadCount() - lastReadCount) / seconds;
   ```
   
   The `ArithmeticException` is swallowed by the catch-all handler, so:
   - every job start logs a misleading warning (`Failed to get job metrics summary, it maybe first-run`), and
   - the first "Job Progress Information" print is **always silently dropped**.
   
   A system clock rollback can also produce a negative elapsed value and break the same calculation.
   
   ### What does this PR change?
   
   Clamp the elapsed seconds to at least `1` before computing the average rates (`Math.max(1L, ...)`), so the first run completes and prints progress info like any later run.
   
   ### How was it verified?
   
   - Added `testJobMetricsRunnerFirstRunDoesNotDivideByZero` and `testJobMetricsRunnerWhenMetricsNotReadyDoesNotThrow` to the existing `JobClientTest` (no new test class).
   - `JobClientTest`: 12/12 tests pass.
   - Confirmed the new regression test **fails against the pre-fix code** (`expected: <100> but was: <0>`, counters untouched after the swallowed exception) and passes with the fix.
   - `spotless:apply` clean.


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Client] Avoid division by zero on first job metrics print [seatunnel]

Posted by "DanielLeens (via GitHub)" <gi...@apache.org>.
DanielLeens commented on PR #11942:
URL: https://github.com/apache/seatunnel/pull/11942#issuecomment-5459168647

   Quick CI-status correction on my own review: I wrote "the CI build check should be watched to green before merge (it was still pending at last check)" while the run was in flight. That run (fork `corgy-w/seatunnel`, run `32636335738`, head `fbf1fad5`) has since finished, and the apache-side `Build` pointer is now showing `FAILURE` rather than pending, so I want to correct the record.
   
   I pulled the actual job matrix rather than trusting the top-level rollup: every job that ran is `success`, and the sole reason the overall run is red is one job, `kafka-connector-it (8, ubuntu-latest)`, which shows `conclusion: cancelled` after running from 13:35 to 17:05 (about 3.5 hours) before being cut off. `kafka-connector-it` has no relationship to this PR's diff (`JobMetricsRunner`/`ClientExecuteCommand` in the CLI client module), so this reads as a stuck/timed-out job on an unrelated connector-IT lane, not a real test failure caused by this change.
   
   Net: there is no new code-level finding here, and my "Ready to merge after fixes" conclusion (no blockers on the crash fix itself) stands. The actionable next step is simply a job-level rerun of `kafka-connector-it (8, ubuntu-latest)` to clear the stuck/cancelled job; once that comes back green (or non-red), CI should no longer be a factor here.
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Client] Avoid division by zero on first job metrics print [seatunnel]

Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on PR #11942:
URL: https://github.com/apache/seatunnel/pull/11942#issuecomment-6393977663

   Refreshed this PR against current dev in c6965831a28f487d80819b813f6769389e6b13cc while preserving its existing monotonic-clock/millisecond rate calculation and counter-baseline regression assertions. The source already contains the earlier requested metrics fixes; the additional source change only clarifies the clock contract in Javadoc. Scoped Spotless and target-relative file/whitespace checks passed. The current-head Build is queued. The earlier Pulsar classloader and Couchbase readiness failures are not claimed fixed by the base sync; only execution on this new head can settle those CI gates.


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Client] Avoid division by zero on first job metrics print [seatunnel]

Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w commented on PR #11942:
URL: https://github.com/apache/seatunnel/pull/11942#issuecomment-5385731863

   Thanks for the detailed review! Pushed `fbf1fad53c` addressing all 5 points:
   
   - **Issue 1 + 2**: `JobMetricsRunner` now computes the average rates over **milliseconds** (clamped to 1 ms) instead of whole seconds, and measures the elapsed time with the **monotonic `System.nanoTime()`** clock. The first run's rate is now the real per-second rate (`delta * 1000 / elapsedMillis`), and a wall-clock rollback can no longer produce a wrong/negative rate.
   - **Issue 3**: the first-run test now overwrites the private `lastRunTimeNanos` base right before `run()` via `ReflectionUtils.setField`, so the zero-elapsed path is exercised deterministically regardless of test speed.
   - **Issue 4**: the metrics-not-ready test now asserts all three `last*Count` fields stay `0L` and adds `verify(seaTunnelClient).getJobMetricsSummary(1L)`.
   - **Issue 5**: `orElse(-1L)` replaced with `orElseThrow(AssertionError)` naming the missing field.
   
   `JobClientTest`: 12/12 pass, spotless clean.


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Client] Avoid division by zero on first job metrics print [seatunnel]

Posted by "corgy-w (via GitHub) via commits" <co...@seatunnel.apache.org>.
corgy-w commented on PR #11942:
URL: https://github.com/apache/seatunnel/pull/11942#issuecomment-6788882050

   The only failure on the current head (`c6965831a2`) is the unrelated `SeaTunnelClientTest.testSetJobIdDuplicate` in `unit-test (11, ubuntu-latest)`: the changed `JobClientTest` reports 12 tests, 0 failures in the same run. I reran only that failed job instead of touching the duplicate-ID test in this PR:
   
   - rerun: https://github.com/corgy-w/seatunnel/actions/runs/40165553992 (currently queued)
   
   The branch is mergeable and the metrics fix itself has no open review threads. Once the rerun is green, this needs the committer approval to merge.
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org