Skip to content

Add custom models,terms and cluster-name support - #29

Open
khansaad wants to merge 2 commits into
kruize:mvp_demofrom
khansaad:bulk-cluster-change
Open

Add custom models,terms and cluster-name support#29
khansaad wants to merge 2 commits into
kruize:mvp_demofrom
khansaad:bulk-cluster-change

Conversation

@khansaad

@khansaad khansaad commented Jun 19, 2026

Copy link
Copy Markdown

This PR adds support to allow custom models, terms and cluster_name as part of the payload construction for the Bulk API.
Sample JSON Structure:

{
    "filter": {
        "exclude": {
            "namespace": [],
            "workload": [],
            "containers": [],
            "labels": {
            }
        },
        "include": {
            "namespace": [],
            "workload": [],
            "containers": [],
            "labels": {
                
            }
        }
    },
    "time_range": {},
    "datasource": "thanos-1",
    "metadata_profile": "cluster-metadata-local-monitoring",
    "measurement_duration": "15min",
    "cluster_name": "default",
    "model_settings": {
        "models": ["performance"]
    },
    "term_settings": {
        "terms": ["short"]
    }
}

Summary by Sourcery

Add cluster name, model settings, and term settings to the Bulk API payload using configurable defaults and datasource metadata.

New Features:

  • Include cluster name in Bulk API payload, derived from the default datasource when available with a configurable fallback.
  • Add configurable default model and term settings to Bulk API payload construction, supporting comma-separated lists of models and terms.
  • Extend the Datasource model to track associated cluster names for use in bulk scheduling.

Enhancements:

  • Introduce configuration properties and environment variables to control default cluster name, models, and terms for bulk scheduling behavior.

Build:

  • Update application configuration and deployment manifests to wire new default cluster, model, and term settings via environment variables.

Signed-off-by: Saad Khan <saakhan@ibm.com>
@khansaad khansaad self-assigned this Jun 19, 2026
@khansaad khansaad added the enhancement New feature or request label Jun 19, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds support for propagating cluster name, configurable default models, and default terms into the Bulk API payload, sourced from datasource metadata and application configuration, plus wiring for deployment configuration and datasource model changes.

Sequence diagram for building Bulk API payload with cluster and model/term settings

sequenceDiagram
    participant BulkSchedulerService
    participant KruizeStateService
    participant Datasource

    BulkSchedulerService->>KruizeStateService: getClusterNameFromDatasource()
    KruizeStateService->>Datasource: getClusters()
    Datasource-->>KruizeStateService: clusters
    KruizeStateService-->>BulkSchedulerService: Optional<String>
    BulkSchedulerService->>BulkSchedulerService: buildBulkPayload(targetLabels, datasource, metadataProfile, metricProfile, clusterName)
    BulkSchedulerService->>BulkSchedulerService: parseCommaSeparatedList(defaultModels)
    BulkSchedulerService->>BulkSchedulerService: parseCommaSeparatedList(defaultTerms)
Loading

File-Level Changes

Change Details Files
Bulk scheduler now includes cluster name, model settings, and term settings in the constructed Bulk API payload, using configurable defaults.
  • Introduced new configuration properties for default cluster name, default models, and default terms in BulkSchedulerService.
  • Resolved cluster name at runtime via KruizeStateService (preferring datasource cluster, falling back to configured default) and passed it into buildBulkPayload.
  • Extended buildBulkPayload to add cluster_name, model_settings.models, and term_settings.terms fields to the payload using a reusable comma-separated-list parser helper.
src/main/java/com/kruize/optimizer/service/BulkSchedulerService.java
src/main/java/com/kruize/optimizer/utils/OptimizerConstants.java
Kruize state now exposes cluster-name information derived from datasources.
  • Extended Datasource model to carry a list of clusters with getters, setters, and updated toString.
  • Added KruizeStateService helper to derive a cluster name from the default (or first available) datasource by inspecting its clusters list.
src/main/java/com/kruize/optimizer/model/kruize/Datasource.java
src/main/java/com/kruize/optimizer/service/KruizeStateService.java
Configuration and deployment wiring added for new defaults used by the bulk scheduler.
  • Extended application.yml with new kruize.bulk cluster-name, model.defaults, and term.defaults properties, wired to environment variables with sensible fallbacks.
  • Updated deployment.yaml to define KRUIZE_DEFAULT_CLUSTER_NAME, KRUIZE_DEFAULT_MODELS, and KRUIZE_DEFAULT_TERMS env vars on the optimizer container, mirroring existing default profile configuration.
src/main/resources/application.yml
deployment/base/deployment.yaml

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

@khansaad khansaad moved this to Under Review in Monitoring Jun 19, 2026

@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 left some high level feedback:

  • The ConfigProperty key kruize.defaults.cluster-name in BulkSchedulerService does not match the application.yml path (kruize.bulk.cluster-name), so the configured value will never be picked up; align the property name with the YAML structure.
  • getClusterNameFromDatasource() calls defaultDatasource.equals(ds.getName()) without a null check on defaultDatasource, which can NPE if the default datasource name is unset; consider using Objects.equals(defaultDatasource, ds.getName()) or guarding against null.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The ConfigProperty key `kruize.defaults.cluster-name` in `BulkSchedulerService` does not match the `application.yml` path (`kruize.bulk.cluster-name`), so the configured value will never be picked up; align the property name with the YAML structure.
- `getClusterNameFromDatasource()` calls `defaultDatasource.equals(ds.getName())` without a null check on `defaultDatasource`, which can NPE if the default datasource name is unset; consider using `Objects.equals(defaultDatasource, ds.getName())` or guarding against null.

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.

Signed-off-by: Saad Khan <saakhan@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Under Review

Development

Successfully merging this pull request may close these issues.

1 participant