Skip to content

Refactor: Modularize ApiResponseHelper#createUsageResponse (4.22 Backport)#13695

Open
PrashantBhanage wants to merge 2 commits into
apache:4.22from
PrashantBhanage:fix-11635-refactor-usage-4.22
Open

Refactor: Modularize ApiResponseHelper#createUsageResponse (4.22 Backport)#13695
PrashantBhanage wants to merge 2 commits into
apache:4.22from
PrashantBhanage:fix-11635-refactor-usage-4.22

Conversation

@PrashantBhanage

@PrashantBhanage PrashantBhanage commented Jul 24, 2026

Copy link
Copy Markdown

Note: This is the 4.22 LTS backport of PR #13490 as requested by @DaanHoogland.

Fixes #11635

Description

This PR addresses the technical debt in ApiResponseHelper#createUsageResponse(Usage) by modularizing the 530-line method.

  • Extracted the 500+ line switch/if-else block into a main dispatcher method populateUsageTypeSpecificDetails.
  • Created 18 individual private helper methods for each specific UsageType to improve maintainability and readability.
  • Introduced a UsageResourceDetails container class to safely manage and return resourceId and resourceType state for tag lookups.
  • Verified zero business logic changes; strictly structural refactoring.
  • Note: The JUnit 5 test migration from the original main PR has been intentionally excluded from this backport to avoid framework conflicts with the stable 4.22 LTS testing architecture.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

N/A (Pure backend refactoring)

How Has This Been Tested?

  • Verified structural integrity locally.
  • Fixed .toString() type mismatch in usage entity lookups to ensure Simulator CI passes cleanly on the LTS branch.

How did you try to break this feature and the system with this change?

This is a pure structural refactor. Carefully verified that no business logic, string formatting, or calculations were altered.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.69%. Comparing base (0339f31) to head (f474c58).

❗ There is a different number of reports uploaded between BASE (0339f31) and HEAD (f474c58). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (0339f31) HEAD (f474c58)
unittests 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##               4.22   #13695       +/-   ##
=============================================
- Coverage     17.69%    3.69%   -14.01%     
=============================================
  Files          5925      449     -5476     
  Lines        533534    38176   -495358     
  Branches      65273     7072    -58201     
=============================================
- Hits          94421     1409    -93012     
+ Misses       428434    36580   -391854     
+ Partials      10679      187    -10492     
Flag Coverage Δ
uitests 3.69% <ø> (ø)
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ApiResponseHelper#createUsageResponse(Usage) needs to be modularised (530 lines).

2 participants