Skip to content

Remove unused APIs from Optimizer - #26

Open
gulati-aakriti wants to merge 4 commits into
kruize:mvp_demofrom
gulati-aakriti:KRUIZE-44
Open

Remove unused APIs from Optimizer#26
gulati-aakriti wants to merge 4 commits into
kruize:mvp_demofrom
gulati-aakriti:KRUIZE-44

Conversation

@gulati-aakriti

@gulati-aakriti gulati-aakriti commented Jun 4, 2026

Copy link
Copy Markdown

Description

Key Changes

  1. API Endpoint Cleanup
    Removed 5 unused REST resource classes, eliminating redundant API endpoints for:

Datasource management
Layer configuration
Metadata profiles
Metric profiles
Status reporting

  1. Service Layer Refactoring
    Removed StatusService.java entirely
    Cleaned up unused methods in DatasourceService, JobsService, and ProfileService
    Removed KruizeStatus model class

  2. Test Strategy Shift
    Removed: 4 resource-level test files (839 lines)
    Added: 2 service-level test files (502 lines)
    Result: More focused testing at the service layer with better coverage

  3. Constants Cleanup
    Removed 22 lines of unused constants from OptimizerConstants.java

Fixes # (issue)

Type of change

  • Bug fix
  • New feature
  • Docs update
  • Breaking change (What changes might users need to make in their application due to this PR?)
  • Requires DB changes

How has this been tested?

Please describe the tests that were run to verify your changes and steps to reproduce. Please specify any test configuration required.

  • Optimizer Demo test
  • Functional testsuite

Test Configuration

  • Kubernetes clusters tested on:

Checklist 🎯

  • Followed coding guidelines
  • Comments added
  • Dependent changes merged
  • Documentation updated
  • Tests added or updated

Summary by Sourcery

Remove unused optimizer REST resources and related status model while shifting tests from removed resource endpoints to the underlying service layer.

Bug Fixes:

  • Eliminate dead API endpoints and unused status functionality to reduce surface area and avoid confusion around unsupported operations.

Enhancements:

  • Streamline service layer by removing unused methods from JobsService and DatasourceService and deleting StatusService and KruizeStatus model.
  • Clean up obsolete API constants and messages related to removed endpoints in OptimizerConstants.

Tests:

  • Replace resource-level tests for datasource, layer, metadata profile, and metric profile endpoints with new unit tests for DatasourceService and ProfileService covering success, empty responses, and error scenarios.

@gulati-aakriti gulati-aakriti self-assigned this Jun 4, 2026
@gulati-aakriti gulati-aakriti added the bug Something isn't working label Jun 4, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR removes unused REST API resources and related status infrastructure, cleans up unused service methods and constants, and replaces resource-level tests with focused service-level tests for datasources and profiles.

File-Level Changes

Change Details Files
Remove unused REST resources and status model/service APIs.
  • Delete DatasourceResource, LayerResource, MetadataProfileResource, MetricProfileResource, and StatusResource classes that exposed unused REST endpoints.
  • Remove StatusService and its associated KruizeStatus model no longer used by the application.
  • Drop status- and profile-related API paths and messages that were only referenced by the removed resources.
src/main/java/com/kruize/optimizer/resource/DatasourceResource.java
src/main/java/com/kruize/optimizer/resource/LayerResource.java
src/main/java/com/kruize/optimizer/resource/MetadataProfileResource.java
src/main/java/com/kruize/optimizer/resource/MetricProfileResource.java
src/main/java/com/kruize/optimizer/resource/StatusResource.java
src/main/java/com/kruize/optimizer/service/StatusService.java
src/main/java/com/kruize/optimizer/model/kruize/KruizeStatus.java
src/main/java/com/kruize/optimizer/utils/OptimizerConstants.java
Tighten service layer APIs by removing unused methods and relying on internal state/behavior.
  • Remove getter methods for totalJobsTriggered/totalExperimentsCreated/totalExperimentsProcessed/totalExperimentsUnique from JobsService, leaving only getJobsOverview as the public aggregation API.
  • Remove getDatasourceCount from DatasourceService and keep callers using getDatasources() directly instead.
src/main/java/com/kruize/optimizer/service/JobsService.java
src/main/java/com/kruize/optimizer/service/DatasourceService.java
Shift testing from resource layer to service layer for profiles and datasources.
  • Delete resource-level tests for datasource, layer, metadata profile, and metric profile endpoints that were tied to removed resources.
  • Add DatasourceServiceTest to cover datasource fetching, empty results, error handling, and availability checks against KruizeClient.
  • Add ProfileServiceTest to cover metadata profiles, metric profiles, and layer fetching, including empty and error scenarios, and to stub BulkSchedulerService and KruizeStateService initialization.
  • Use MockResponseLoader-based JSON fixtures (e.g., datasource_list.json, metadata_profile_list.json, layer_list.json) to drive service tests.
src/test/java/com/kruize/optimizer/resource/DatasourceResourceTest.java
src/test/java/com/kruize/optimizer/resource/LayerResourceTest.java
src/test/java/com/kruize/optimizer/resource/MetadataProfileResourceTest.java
src/test/java/com/kruize/optimizer/resource/MetricProfileResourceTest.java
src/test/java/com/kruize/optimizer/service/DatasourceServiceTest.java
src/test/java/com/kruize/optimizer/service/ProfileServiceTest.java
Remove unused API path and message constants.
  • Delete list/install path suffix constants and datasources/metadataProfiles/metricProfiles/layers/status path constants that are no longer referenced after resource removal.
  • Remove success message constants related to profiles and datasources that are no longer used by any code paths.
  • Keep only jobs-related paths and messages that are still in use.
src/main/java/com/kruize/optimizer/utils/OptimizerConstants.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gulati-aakriti
gulati-aakriti requested a review from shekhar316 June 4, 2026 07:28

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The repeated mocking of bulkSchedulerService.initialize() and kruizeStateService.refreshStateAndInstallProfiles() in both DatasourceServiceTest and ProfileServiceTest could be extracted into a shared test utility or base class to reduce duplication and keep future changes to initialization behavior centralized.
  • The // Made with Bob footer comments in the new test classes are non-standard and may not align with the project's style; consider removing them to keep test files focused on their purpose.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The repeated mocking of `bulkSchedulerService.initialize()` and `kruizeStateService.refreshStateAndInstallProfiles()` in both `DatasourceServiceTest` and `ProfileServiceTest` could be extracted into a shared test utility or base class to reduce duplication and keep future changes to initialization behavior centralized.
- The `// Made with Bob` footer comments in the new test classes are non-standard and may not align with the project's style; consider removing them to keep test files focused on their purpose.

## Individual Comments

### Comment 1
<location path="src/test/java/com/kruize/optimizer/service/ProfileServiceTest.java" line_range="117" />
<code_context>
+     * - Returns empty list
+     */
+    @Test
+    void testGetMetadataProfiles_EmptyList() {
+        // Arrange
+        Response mockResponse = Response.status(400)
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test for non-400 `ClientWebApplicationException` to ensure they are handled as true errors

`testGetMetadataProfiles_EmptyList` covers the 400 "no profiles" case. Please also add a test where `kruizeClient.getMetadataProfiles(true)` throws a `ClientWebApplicationException` with a non-400 status (e.g., 500 or 503) and assert that a `KruizeServiceException` is thrown. This will verify and document the generic error-handling behavior for Kruize API HTTP errors.

Suggested implementation:

```java
        // Assert
        assertNotNull(profiles);

```

Please add the following test method to `ProfileServiceTest` (at class scope, alongside the existing `testGetMetadataProfiles_EmptyList`), and ensure the necessary imports are present:

```java
    /**
     * Test getMetadataProfiles when Kruize returns a non-400 HTTP error
     *
     * Test Description: Verifies that when Kruize returns a 5xx error,
     * the service treats it as a true error and throws KruizeServiceException.
     *
     * Expected Output:
     * - KruizeServiceException is thrown
     */
    @Test
    void testGetMetadataProfiles_Non400ClientWebApplicationException() {
        // Arrange
        Response mockResponse = Response.status(500)
                .entity("Internal Server Error from Kruize")
                .build();
        ClientWebApplicationException exception = new ClientWebApplicationException(mockResponse);
        when(kruizeClient.getMetadataProfiles(true)).thenThrow(exception);

        // Act & Assert
        assertThrows(KruizeServiceException.class, () -> profileService.getMetadataProfiles());
    }
```

You may need to ensure the following imports exist (or equivalent, depending on your project conventions):

```java
import javax.ws.rs.core.Response;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.ClientWebApplicationException;

import static org.junit.jupiter.api.Assertions.assertThrows;
```

Adjust the imports to match whatever is already in `ProfileServiceTest` (e.g., if `ClientWebApplicationException` or `assertThrows` is already imported, do not duplicate them). This new test will ensure that non-400 `ClientWebApplicationException`s are surfaced as `KruizeServiceException` and will document the generic error-handling behavior for Kruize API HTTP errors.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/test/java/com/kruize/optimizer/service/ProfileServiceTest.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant