Skip to content

Add Bulk Profile service - #34

Open
bharathappali wants to merge 8 commits into
kruize:mvp_demofrom
bharathappali:feat-bulk-prof-4
Open

Add Bulk Profile service#34
bharathappali wants to merge 8 commits into
kruize:mvp_demofrom
bharathappali:feat-bulk-prof-4

Conversation

@bharathappali

@bharathappali bharathappali commented Jun 25, 2026

Copy link
Copy Markdown
Member

This PR is built on top of #33

#33 needs to be merged before this PR

This PR adds bulk profile service

Summary by Sourcery

Introduce a bulk profile capability that can be fetched from the Kruize backend and converted into bulk job requests.

New Features:

  • Add client API endpoints and constants for listing all bulk profiles and fetching a specific profile by name.
  • Define BulkProfile, ClusterConfig, and RecommendationSettings models to represent bulk profile configuration from Kruize.
  • Implement BulkProfileService to retrieve enabled bulk profiles and map their configuration into bulk job request payloads.

Signed-off-by: bharathappali <abharath@redhat.com>
@sourcery-ai

sourcery-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduce a bulk profile feature that retrieves bulk profiles from the Kruize backend, models them as Java POJOs, and converts enabled profiles into bulk job requests, including new REST client endpoints and supporting constants.

Sequence diagram for fetching enabled bulk profiles

sequenceDiagram
    participant BulkProfileService
    participant KruizeClient
    participant ObjectMapper

    BulkProfileService->>KruizeClient: getBulkProfiles()
    KruizeClient-->>BulkProfileService: JSON string
    BulkProfileService->>ObjectMapper: readValue(json, List<BulkProfile>)
    ObjectMapper-->>BulkProfileService: List<BulkProfile>
    BulkProfileService->>BulkProfileService: filter(p.getEnabled())
    BulkProfileService-->>BulkProfileService: List<BulkProfile> enabledProfiles
Loading

File-Level Changes

Change Details Files
Extend the REST client with bulk profile endpoints.
  • Add GET endpoint to fetch all bulk profiles as JSON.
  • Add GET endpoint to fetch a single bulk profile by profile name query parameter.
  • Wire endpoints to new bulk profile constants.
src/main/java/com/kruize/optimizer/client/KruizeClient.java
Add constants for bulk profile API paths and query parameters.
  • Define BULK_PROFILES_ENDPOINT for bulk profile REST calls.
  • Define PROFILE_NAME constant for querying a specific profile.
src/main/java/com/kruize/optimizer/utils/OptimizerConstants.java
Implement BulkProfileService to fetch, filter, and transform bulk profiles into bulk job requests.
  • Inject KruizeClient and ObjectMapper for remote calls and JSON handling.
  • Implement getEnabledProfiles to call bulkProfiles endpoint, deserialize response, and filter by enabled flag with logging and error handling.
  • Implement parseScheduling to convert human-readable scheduling strings to java.time.Duration using regex validation.
  • Implement convertProfileToBulkJob to map a BulkProfile and its ClusterConfig into the expected bulk job request structure, including filter, datasource, metadata_profile, measurement_duration, and webhook.
src/main/java/com/kruize/optimizer/service/BulkProfileService.java
Introduce BulkProfile domain model for deserializing bulk profile JSON.
  • Map JSON properties such as profile_name, clusters, recommendation_settings, webhook_url, enabled, created_at, updated_at to Java fields with getters/setters.
  • Provide constructors for initialization and use with Jackson.
src/main/java/com/kruize/optimizer/model/kruize/BulkProfile.java
Introduce ClusterConfig model to represent per-cluster profile configuration.
  • Model cluster_name, datasources, namespaces, labels, experiment_types, and metadata_profile fields with Jackson annotations.
  • Provide constructors and getters/setters to support JSON mapping and service logic.
src/main/java/com/kruize/optimizer/model/kruize/ClusterConfig.java
Introduce RecommendationSettings model to represent per-profile recommendation configuration.
  • Model scheduling, terms, models, and measurement_duration with Jackson annotations.
  • Provide constructors and getters/setters for use in BulkProfile and BulkProfileService.
src/main/java/com/kruize/optimizer/model/kruize/RecommendationSettings.java

Possibly linked issues

  • #Implement Bulk Profile API Integration for Dynamic Scheduling: PR delivers data models, client endpoints, and BulkProfileService, implementing core Bulk Profile API integration parts of issue.

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

@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:

  • In BulkProfileService.convertProfileToBulkJob, profile.getRecommendationSettings() is dereferenced without a null check, which can lead to NPEs if the field is omitted in the response; consider validating recommendationSettings before reading measurementDuration.
  • The bulk job conversion logic currently assumes a single cluster (profile.getClusters().get(0) and first datasource only); if multiple clusters/datasources are expected, it might be better to make this handling explicit or document/enforce the single-cluster constraint.
  • The REST client getBulkProfile(profileName) method is added but not yet used by BulkProfileService; if per-profile retrieval is part of the intended workflow, consider wiring it into the service or removing it until needed to avoid unused API surface.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `BulkProfileService.convertProfileToBulkJob`, `profile.getRecommendationSettings()` is dereferenced without a null check, which can lead to NPEs if the field is omitted in the response; consider validating `recommendationSettings` before reading `measurementDuration`.
- The bulk job conversion logic currently assumes a single cluster (`profile.getClusters().get(0)` and first datasource only); if multiple clusters/datasources are expected, it might be better to make this handling explicit or document/enforce the single-cluster constraint.
- The REST client `getBulkProfile(profileName)` method is added but not yet used by `BulkProfileService`; if per-profile retrieval is part of the intended workflow, consider wiring it into the service or removing it until needed to avoid unused API surface.

## Individual Comments

### Comment 1
<location path="src/main/java/com/kruize/optimizer/service/BulkProfileService.java" line_range="174" />
<code_context>
+        }
+
+        // Add measurement duration from recommendation settings
+        String measurementDuration = profile.getRecommendationSettings().getMeasurementDuration();
+        if (measurementDuration != null && !measurementDuration.isEmpty()) {
+            bulkJob.put("measurement_duration", measurementDuration);
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against null `recommendationSettings` to avoid a potential NPE.

If `profile.getRecommendationSettings()` is null, this line will throw a `NullPointerException`. Please add a null check (and optionally a default value) before calling `getMeasurementDuration()`.
</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.

}

// Add measurement duration from recommendation settings
String measurementDuration = profile.getRecommendationSettings().getMeasurementDuration();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Guard against null recommendationSettings to avoid a potential NPE.

If profile.getRecommendationSettings() is null, this line will throw a NullPointerException. Please add a null check (and optionally a default value) before calling getMeasurementDuration().

Signed-off-by: bharathappali <abharath@redhat.com>
Signed-off-by: bharathappali <abharath@redhat.com>
Signed-off-by: bharathappali <abharath@redhat.com>
Signed-off-by: bharathappali <abharath@redhat.com>
Signed-off-by: bharathappali <abharath@redhat.com>
Signed-off-by: bharathappali <abharath@redhat.com>
Signed-off-by: bharathappali <abharath@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Under Review

Development

Successfully merging this pull request may close these issues.

1 participant