refactor(computing-unit-managing-service): share CU listing helpers and batch k8s calls#6853
refactor(computing-unit-managing-service): share CU listing helpers and batch k8s calls#6853kunwp1 wants to merge 3 commits into
Conversation
…nd batch k8s calls Centralize the computing-unit listing logic in ComputingUnitHelpers so the per-user listing endpoint routes through a single, reusable implementation (also reused by a follow-up admin endpoint): - Add resolveOwnerInfo, partitionLiveUnits, reconcileVanishedKubernetesUnits, buildDashboardUnit, and the isKubernetes / podPhasesFor / podMetricsFor guards. - Remove the duplicated private getComputingUnitStatus / getComputingUnitMetrics from ComputingUnitManagingResource; callers use the shared helpers. - Add bulk KubernetesClient.getAllPodPhases / getAllPodMetrics (one namespace-wide list()/top() each) plus a shared containerUsage helper and a fetchPodMetricsItems extraction; listComputingUnits now resolves pod status/metrics in bulk instead of probing podExists twice per unit and re-fetching top() per unit. - Add a package-private KubernetesClient test seam (setClientForTesting) so the fabric8 client can be stubbed in tests; not used in production. API response behavior is unchanged; per-user reconciliation now runs over cuid-deduplicated units, reducing redundant DB updates. Tests: ComputingUnitHelpersSpec (embedded Postgres via MockTexeraDB), KubernetesClientSpec (stubbed fabric8 client), and a new ComputingUnitManagingResourceSpec driving the per-user endpoints over the embedded DB. build.sbt gains DAO/Auth test artifacts and serial test execution. Generated-by: Claude Code, Claude Opus 4.8
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6853 +/- ##
============================================
+ Coverage 69.77% 70.61% +0.83%
- Complexity 3379 3505 +126
============================================
Files 1142 1145 +3
Lines 44828 44976 +148
Branches 4948 4963 +15
============================================
+ Hits 31277 31758 +481
+ Misses 11895 11518 -377
- Partials 1656 1700 +44
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/request-review @mengw15 |
|
| config | throughput | MB/s | latency | max Δ latest / 7d | |
|---|---|---|---|---|---|
| 🔴 | bs=10 sw=10 sl=64 | 422 | 0.258 | 23,112/31,380/31,380 us | 🔴 +11.2% / 🔴 +96.0% |
| 🔴 | bs=100 sw=10 sl=64 | 928 | 0.567 | 106,952/127,744/127,744 us | 🔴 +5.9% / 🔴 +20.1% |
| 🔴 | bs=1000 sw=10 sl=64 | 1,080 | 0.659 | 927,233/1,081,678/1,081,678 us | 🔴 +13.6% / 🔴 +6.1% |
Baseline details
Latest main 17cdba4 from same runner
| config | metric | PR | latest main | 7d avg | Δ latest | Δ 7d |
|---|---|---|---|---|---|---|
| bs=10 sw=10 sl=64 | throughput | 422 tuples/sec | 473 tuples/sec | 767.66 tuples/sec | -10.8% | -45.0% |
| bs=10 sw=10 sl=64 | MB/s | 0.258 MB/s | 0.289 MB/s | 0.469 MB/s | -10.7% | -44.9% |
| bs=10 sw=10 sl=64 | p50 | 23,112 us | 20,791 us | 12,623 us | +11.2% | +83.1% |
| bs=10 sw=10 sl=64 | p95 | 31,380 us | 30,254 us | 16,011 us | +3.7% | +96.0% |
| bs=10 sw=10 sl=64 | p99 | 31,380 us | 30,254 us | 18,856 us | +3.7% | +66.4% |
| bs=100 sw=10 sl=64 | throughput | 928 tuples/sec | 953 tuples/sec | 998.44 tuples/sec | -2.6% | -7.1% |
| bs=100 sw=10 sl=64 | MB/s | 0.567 MB/s | 0.582 MB/s | 0.609 MB/s | -2.6% | -7.0% |
| bs=100 sw=10 sl=64 | p50 | 106,952 us | 103,979 us | 100,463 us | +2.9% | +6.5% |
| bs=100 sw=10 sl=64 | p95 | 127,744 us | 120,625 us | 106,400 us | +5.9% | +20.1% |
| bs=100 sw=10 sl=64 | p99 | 127,744 us | 120,625 us | 117,712 us | +5.9% | +8.5% |
| bs=1000 sw=10 sl=64 | throughput | 1,080 tuples/sec | 1,110 tuples/sec | 1,034 tuples/sec | -2.7% | +4.4% |
| bs=1000 sw=10 sl=64 | MB/s | 0.659 MB/s | 0.678 MB/s | 0.631 MB/s | -2.8% | +4.4% |
| bs=1000 sw=10 sl=64 | p50 | 927,233 us | 899,406 us | 973,294 us | +3.1% | -4.7% |
| bs=1000 sw=10 sl=64 | p95 | 1,081,678 us | 952,431 us | 1,019,213 us | +13.6% | +6.1% |
| bs=1000 sw=10 sl=64 | p99 | 1,081,678 us | 952,431 us | 1,049,896 us | +13.6% | +3.0% |
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,473.42,200,128000,422,0.258,23112.27,31380.36,31380.36
1,100,10,64,20,2154.48,2000,1280000,928,0.567,106952.04,127744.37,127744.37
2,1000,10,64,20,18517.16,20000,12800000,1080,0.659,927232.83,1081677.77,1081677.77There was a problem hiding this comment.
Pull request overview
Refactors the computing-unit managing service’s per-user CU listing to reuse shared helper logic and reduce Kubernetes API round-trips by fetching pod phase/metrics in bulk, while keeping the API response shape unchanged. This lays groundwork for the upcoming admin computing-unit listing endpoint.
Changes:
- Centralized CU dashboard-row construction and owner/status/metrics resolution in
ComputingUnitHelpers, including bulk-friendly variants and vanished-pod reconciliation. - Added bulk Kubernetes queries in
KubernetesClient(getAllPodPhases,getAllPodMetrics) plus a test seam (setClientForTesting) to enable stubbing fabric8 without a cluster. - Added/expanded unit tests for the new helper and bulk K8s paths, and introduced a resource-level spec for per-user endpoints using embedded Postgres.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| computing-unit-managing-service/src/main/scala/org/apache/texera/service/util/KubernetesClient.scala | Adds bulk namespace-wide pod phase/metrics fetchers and a package-private test seam for the fabric8 client. |
| computing-unit-managing-service/src/main/scala/org/apache/texera/service/util/ComputingUnitHelpers.scala | Introduces shared CU listing helpers: owner info resolution, bulk status/metrics, live/vanished partitioning, reconciliation, and dashboard-row builder. |
| computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitManagingResource.scala | Refactors per-user listing to dedupe by cuid and use bulk pod phase/metrics maps plus shared helper methods. |
| computing-unit-managing-service/src/test/scala/org/apache/texera/service/util/KubernetesClientSpec.scala | Adds Mockito-based fabric8 stubs and tests covering bulk K8s wrappers and helper guard behavior. |
| computing-unit-managing-service/src/test/scala/org/apache/texera/service/util/ComputingUnitHelpersSpec.scala | Expands helper coverage for bulk variants, reconciliation behavior, and DB-backed owner-info resolution. |
| computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitManagingResourceSpec.scala | Adds embedded-DB resource-level tests for per-user endpoints using local units (no K8s calls). |
| build.sbt | Wires test-scope dependencies for embedded DB reuse and forces serial test execution for this module due to JVM-wide singletons. |
Comments suppressed due to low confidence (2)
computing-unit-managing-service/src/test/scala/org/apache/texera/service/util/KubernetesClientSpec.scala:124
- afterAll() should call super.afterAll(), ideally in a finally block, to ensure other traits' teardown runs even if resetting the KubernetesClient fails.
override protected def afterAll(): Unit = {
// Restore a real client so subsequent suites don't reuse the mock.
KubernetesClient.setClientForTesting(new KubernetesClientBuilder().build())
}
computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitManagingResourceSpec.scala:73
- afterAll() should call super.afterAll(), preferably in a finally block, to ensure proper teardown if additional traits are mixed in later.
override protected def afterAll(): Unit = shutdownDB()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Kunwoo (Chris) <143021053+kunwp1@users.noreply.github.com>
…cle hooks Complete and correct the Copilot-suggested fix on apache#6853. The auto-pushed commit only touched KubernetesClientSpec.beforeAll (dedenting the override so it fails scalafmtCheck) and left the other sites unaddressed. - Restore correct indentation in KubernetesClientSpec.beforeAll. - Call super.afterAll() (via try/finally) in KubernetesClientSpec.afterAll. - Call super.beforeAll()/super.afterAll() in ComputingUnitHelpersSpec and ComputingUnitManagingResourceSpec. So lifecycle code from other mixed-in traits is not skipped if the trait stack changes; matches the majority convention across the repo's suites. No behavior change (MockTexeraDB defines no lifecycle hooks). scalafmtCheck clean; the three specs pass. Generated-by: Claude Code, Claude Opus 4.8
…cle hooks Mirror the apache#6853 review fix onto the stacked admin PR so the whole contribution is uniform: beforeAll/afterAll overrides call super.beforeAll()/super.afterAll() (teardown via try/finally) in the shared specs and in AdminComputingUnitResourceSpec. No behavior change. Generated-by: Claude Code, Claude Opus 4.8
What changes were proposed in this PR?
Refactor the per-user computing-unit listing so its status/metrics logic lives in one reusable place and hits Kubernetes in bulk. No API response changes; this is groundwork for the admin listing endpoint (stacked follow-up PR).
ComputingUnitHelpers(resolveOwnerInfo,partitionLiveUnits,reconcileVanishedKubernetesUnits,buildDashboardUnit, plus theisKubernetes/podPhasesFor/podMetricsForguards), and remove the duplicated private status/metrics helpers fromComputingUnitManagingResource.KubernetesClient.getAllPodPhases/getAllPodMetrics(one namespace-widelist()/top()each) and a sharedcontainerUsagehelper;listComputingUnitsnow resolves pod status/metrics in bulk instead of probing pod existence twice per unit and re-fetchingtop()per unit.KubernetesClienttest seam (setClientForTesting) so the fabric8 client can be stubbed in tests; unused in production.Any related issues, documentation, discussions?
Part of #6476 (Admin Computing Units Dashboard); prepares the shared listing helpers reused by the admin endpoint in the stacked follow-up. Originates from discussion #6322.
How was this PR tested?
Added
ComputingUnitManagingResourceSpecand extendedComputingUnitHelpersSpec/KubernetesClientSpec(embedded Postgres viaMockTexeraDB; stubbed fabric8 client for the bulk k8s paths).Ran
sbt 'ComputingUnitManagingService/testOnly org.apache.texera.service.util.ComputingUnitHelpersSpec org.apache.texera.service.util.KubernetesClientSpec org.apache.texera.service.resource.ComputingUnitManagingResourceSpec'(34 tests, all green) andsbt 'ComputingUnitManagingService/scalafmtCheck; ComputingUnitManagingService/Test/scalafmtCheck'(clean).Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code, Claude Opus 4.8