Skip to content

add required layer option to conditionally run runtimes queries#1866

Open
khansaad wants to merge 1 commit intokruize:mvp_demofrom
khansaad:runtime-conditional-run
Open

add required layer option to conditionally run runtimes queries#1866
khansaad wants to merge 1 commit intokruize:mvp_demofrom
khansaad:runtime-conditional-run

Conversation

@khansaad
Copy link
Copy Markdown
Contributor

@khansaad khansaad commented Apr 4, 2026

Description

This PR adds a new required_layer attribute in the aggregation_functions alongside the query to conditionally run the runtime queries based on the corresponding layer detection.

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.

  • New Test X
  • Functional testsuite

Test Configuration

  • Kubernetes clusters tested on:

Checklist 🎯

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

Additional information

Include any additional information such as links, test results, screenshots here

Summary by Sourcery

Add support for conditionally executing runtime aggregation queries based on detected container layers via a new required layer attribute on aggregation functions.

New Features:

  • Introduce a requiredLayer attribute on aggregation functions to gate metric queries on specific detected runtime layers.

Enhancements:

  • Update recommendation engine logic to skip runtime metrics whose required layers are not present on the target container.
  • Annotate JVM-related aggregation functions in performance profile manifests with required runtime layers to align with conditional query execution.

Signed-off-by: Saad Khan <saakhan@ibm.com>
@khansaad khansaad added this to the Kruize 0.11.0 Release milestone Apr 4, 2026
@khansaad khansaad requested a review from kusumachalasani April 4, 2026 08:19
@khansaad khansaad self-assigned this Apr 4, 2026
@khansaad khansaad added the enhancement New feature or request label Apr 4, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 4, 2026

Reviewer's Guide

Adds a new optional required_layer attribute to aggregation functions and uses it in the recommendation engine to conditionally execute runtime metrics queries only when matching container layers are detected, updating JVM-related performance profiles to specify applicable runtimes.

Sequence diagram for conditional metric query execution based on required_layer

sequenceDiagram
    participant RecommendationEngine
    participant KruizeObject
    participant ContainerData
    participant AggregationFunctions

    RecommendationEngine->>KruizeObject: getContainerData(containerName)
    KruizeObject-->>RecommendationEngine: ContainerData
    RecommendationEngine->>ContainerData: getLayerMap()
    ContainerData-->>RecommendationEngine: layerMap

    loop for each metricEntry
        RecommendationEngine->>metricEntry: getAggregationFunctionsMap()
        metricEntry-->>RecommendationEngine: aggregationFunctions
        loop for each aggregationFunctionsEntry
            RecommendationEngine->>AggregationFunctions: getRequiredLayer()
            AggregationFunctions-->>RecommendationEngine: requiredLayer
            alt requiredLayer is null or empty
                RecommendationEngine->>AggregationFunctions: getQuery()
                AggregationFunctions-->>RecommendationEngine: promQL
                RecommendationEngine->>RecommendationEngine: executePromQuery(promQL)
            else requiredLayer is set
                RecommendationEngine->>RecommendationEngine: split requiredLayer into requiredLayers
                RecommendationEngine->>ContainerData: getLayerMap()
                ContainerData-->>RecommendationEngine: layerMap
                alt any requiredLayers in layerMap
                    RecommendationEngine->>AggregationFunctions: getQuery()
                    AggregationFunctions-->>RecommendationEngine: promQL
                    RecommendationEngine->>RecommendationEngine: executePromQuery(promQL)
                else no requiredLayers detected
                    RecommendationEngine->>RecommendationEngine: skip metric (no query executed)
                end
            end
        end
    end
Loading

Class diagram for updated AggregationFunctions with required_layer

classDiagram
    class AggregationFunctions {
        - String function
        - String query
        - String version
        - String requiredLayer
        + AggregationFunctions(String function, String query, String version)
        + String getFunction()
        + void setFunction(String function)
        + String getQuery()
        + void setQuery(String query)
        + String getVersion()
        + void setVersion(String version)
        + String getRequiredLayer()
        + void setRequiredLayer(String requiredLayer)
        + String toString()
    }
Loading

File-Level Changes

Change Details Files
Introduce requiredLayer field on aggregation functions and expose accessors for it.
  • Add requiredLayer property to the AggregationFunctions model alongside function, query, and version.
  • Implement getter and setter for requiredLayer to support configuration-driven usage.
  • Extend toString to include requiredLayer for easier debugging and logging.
src/main/java/com/autotune/common/data/metrics/AggregationFunctions.java
Conditionally execute runtime metric queries based on detected container layers.
  • Before building the PromQL query, read requiredLayer from the aggregation function entry.
  • Parse comma-separated requiredLayer values into individual layers and check presence in containerData.layerMap.
  • Skip executing the metric (with debug log) when none of the required layers are detected for the container, otherwise proceed as before.
src/main/java/com/autotune/analyzer/recommendations/engine/RecommendationEngine.java
Wire required_layer configuration into JVM-related performance profile definitions.
  • Annotate jvmInfo metric aggregation_functions with required_layer set to "hotspot,semeru" in local monitoring profile.
  • Annotate jvmInfoTotal metric aggregation_functions with required_layer set to "hotspot,semeru" in local monitoring profile.
  • Mirror the same required_layer annotations in the no-recording-rules local monitoring profile and associated JSON profile, ensuring runtime metrics only run for supported JVM layers.
manifests/autotune/performance-profiles/resource_optimization_local_monitoring.yaml
manifests/autotune/performance-profiles/resource_optimization_local_monitoring_norecordingrules.yaml
manifests/autotune/performance-profiles/resource_optimization_local_monitoring.json

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 In Progress in Monitoring Apr 4, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

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:

  • In fetchContainerMetricsBasedOnDataSourceAndProfile, you repeatedly call containerData.getLayerMap() and null-check it inside the inner loop; consider pulling the map into a local variable and short-circuiting when it's null to simplify the logic and avoid repeated lookups.
  • The AggregationFunctions class now has a requiredLayer field but no constructor path to set it explicitly; if this type is ever instantiated programmatically (not just via deserialization), you may want to add an overloaded constructor or builder method that accepts requiredLayer to avoid partially initialized instances.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `fetchContainerMetricsBasedOnDataSourceAndProfile`, you repeatedly call `containerData.getLayerMap()` and null-check it inside the inner loop; consider pulling the map into a local variable and short-circuiting when it's null to simplify the logic and avoid repeated lookups.
- The `AggregationFunctions` class now has a `requiredLayer` field but no constructor path to set it explicitly; if this type is ever instantiated programmatically (not just via deserialization), you may want to add an overloaded constructor or builder method that accepts `requiredLayer` to avoid partially initialized instances.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant