Filter results at term level and process the calc for pod count#1802
Open
bharathappali wants to merge 3 commits intokruize:mvp_demofrom
Open
Filter results at term level and process the calc for pod count#1802bharathappali wants to merge 3 commits intokruize:mvp_demofrom
bharathappali wants to merge 3 commits intokruize:mvp_demofrom
Conversation
Contributor
Reviewer's GuideImplements term-level replica statistics in the recommendation engine by filtering interval results to the monitoring window, computing pod count aggregates, wiring them into term recommendations, and refactoring model-level recommendation generation to reuse the filtered results. Introduces JSON/constant support for term replica data. Sequence diagram for term-level replica statistics computation and usagesequenceDiagram
participant RecommendationEngine
participant ContainerData
participant TermRecommendations
participant RecommendationModel
participant IntervalResults
participant MetricResults
participant MetricAggregationInfoResults
RecommendationEngine->>ContainerData: getResults()
ContainerData-->>RecommendationEngine: Map_Timestamp_IntervalResults_
RecommendationEngine->>RecommendationEngine: filter results by monitoringStartTime and monitoringEndTime
Note over RecommendationEngine: filteredResultsMap created
RecommendationEngine->>RecommendationEngine: getPodStats(filteredResultsMap)
loop for each IntervalResults in filteredResultsMap
RecommendationEngine->>IntervalResults: getMetricResultsMap()
IntervalResults-->>RecommendationEngine: Map_MetricName_MetricResults_
alt cpuUsage present
RecommendationEngine->>RecommendationEngine: extractPods(metrics, cpuUsage)
else memoryUsage present
RecommendationEngine->>RecommendationEngine: extractPods(metrics, memoryUsage)
end
RecommendationEngine->>MetricResults: getAggregationInfoResult()
MetricResults-->>RecommendationEngine: MetricAggregationInfoResults
RecommendationEngine->>MetricAggregationInfoResults: getSum(), getAvg()
MetricAggregationInfoResults-->>RecommendationEngine: sum, avg
RecommendationEngine->>RecommendationEngine: compute pods = round(sum / avg)
RecommendationEngine->>RecommendationEngine: update min, max, total, count
end
RecommendationEngine->>RecommendationEngine: build Map_Aggregates_Integer_ podStats
alt podStats not null
RecommendationEngine->>TermRecommendations: setTermReplicas(podStats)
end
loop for each RecommendationModel
RecommendationEngine->>RecommendationEngine: generateRecommendationBasedOnModel(monitoringStartTime, model, filteredResultsMap, monitoringEndTime, ...)
Note over RecommendationEngine: reuse filteredResultsMap
end
Class diagram for term-level replica stats and related typesclassDiagram
class RecommendationEngine {
- static int getNumPods(Map_Timestamp_IntervalResults_ filteredResultsMap)
- static Map_AnalyzerConstants_Aggregates_Integer_ getPodStats(Map_Timestamp_IntervalResults_ filteredResultsMap)
- static Double extractPods(Map_AnalyzerConstants_MetricName_MetricResults_ metrics, AnalyzerConstants_MetricName metricName)
+ boolean generateRecommendationsBasedOnTerms(ContainerData containerData, KruizeObject kruizeObject)
+ MappedRecommendationForModel generateRecommendationBasedOnModel(Timestamp monitoringStartTime, RecommendationModel model, Map_Timestamp_IntervalResults_ filteredResultsMap, Timestamp monitoringEndTime, KruizeObject kruizeObject, MappedRecommendationForTerm mappedRecommendationForTerm)
}
class TermRecommendations {
- Timestamp monitoringStartTime
- Map_AnalyzerConstants_Aggregates_Integer_ termReplicas
- HashMap_String_MappedRecommendationForModel_ recommendationForModelHashMap
- PlotData_PlotsData_ plots
+ Map_AnalyzerConstants_Aggregates_Integer_ getTermReplicas()
+ void setTermReplicas(Map_AnalyzerConstants_Aggregates_Integer_ termReplicas)
}
class AnalyzerConstants {
}
class Aggregates {
<<enumeration>>
max
min
avg
}
class KruizeConstants_JSONKeys {
<<static>> String TERM_REPLICAS
}
class MappedRecommendationForModel {
}
class MappedRecommendationForTerm {
}
class ContainerData {
+ Map_Timestamp_IntervalResults_ getResults()
}
class IntervalResults {
+ Map_AnalyzerConstants_MetricName_MetricResults_ getMetricResultsMap()
}
class MetricResults {
+ MetricAggregationInfoResults getAggregationInfoResult()
}
class MetricAggregationInfoResults {
+ Double getSum()
+ Double getAvg()
}
RecommendationEngine --> ContainerData : uses
RecommendationEngine --> TermRecommendations : populates
RecommendationEngine --> IntervalResults : uses
RecommendationEngine --> MetricResults : uses
RecommendationEngine --> MetricAggregationInfoResults : uses
RecommendationEngine --> Aggregates : uses
TermRecommendations ..|> MappedRecommendationForTerm
TermRecommendations --> MappedRecommendationForModel : contains
TermRecommendations --> Aggregates : termReplicas
AnalyzerConstants --> Aggregates : defines
KruizeConstants_JSONKeys --> TermRecommendations : TERM_REPLICAS key
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
getPodStats, consider initializingmaxPodswithDouble.NEGATIVE_INFINITYinstead ofDouble.MIN_VALUEto better reflect an empty maximum and avoid relying on the subtle semantics ofDouble.MIN_VALUE(smallest positive value). - Both
getPodStatsandextractPodsheavily use boxedDoubleand returnnullto signal no data; you could simplify this by using primitives where possible and returning an empty map (or Optional) instead ofnullto reduce null-handling branches for callers. - If
termReplicasis expected to always be present in the serialized output, consider initializing it to an empty map rather than leaving itnullso consumers don’t have to handle bothnulland empty cases.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `getPodStats`, consider initializing `maxPods` with `Double.NEGATIVE_INFINITY` instead of `Double.MIN_VALUE` to better reflect an empty maximum and avoid relying on the subtle semantics of `Double.MIN_VALUE` (smallest positive value).
- Both `getPodStats` and `extractPods` heavily use boxed `Double` and return `null` to signal no data; you could simplify this by using primitives where possible and returning an empty map (or Optional) instead of `null` to reduce null-handling branches for callers.
- If `termReplicas` is expected to always be present in the serialized output, consider initializing it to an empty map rather than leaving it `null` so consumers don’t have to handle both `null` and empty cases.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
eaae492 to
37828af
Compare
| return null; | ||
| } | ||
|
|
||
| double minPods = Double.MAX_VALUE; |
Contributor
There was a problem hiding this comment.
Looks like minPods and maxPods values are interchanged.
Member
Author
There was a problem hiding this comment.
Thanks for the review @kusumachalasani
Fixed it
Signed-off-by: bharathappali <abharath@redhat.com>
Signed-off-by: bharathappali <abharath@redhat.com>
37828af to
b8f8faa
Compare
Signed-off-by: bharathappali <abharath@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the replica information at term level
Fixes #1801
Type of change
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.
Test Configuration
Checklist 🎯
Additional information
Include any additional information such as links, test results, screenshots here
Summary by Sourcery
Add term-level replica statistics to recommendation outputs and reuse the time-window-filtered metrics map across recommendation generation.
New Features:
Enhancements: