From efa28b8e53130f24443df3e22f6e30a0c3093782 Mon Sep 17 00:00:00 2001 From: Shekhar Saxena Date: Tue, 21 Jan 2025 01:53:12 +0530 Subject: [PATCH 1/4] adding min duration parameter in recommendation settings Signed-off-by: Shekhar Saxena --- .../analyzer/kruizeObject/KruizeObject.java | 36 ++++++++++++++----- .../kruizeObject/RecommendationSettings.java | 23 ++++++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java index d11be2c3d..26ffa0bf3 100644 --- a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java +++ b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java @@ -136,15 +136,33 @@ public KruizeObject() { public static void setDefaultTerms(Map terms, KruizeObject kruizeObject) { // TODO: define term names like daily, weekly, fortnightly etc // TODO: add CRD for terms - terms.put(KruizeConstants.JSONKeys.SHORT_TERM, new Terms(KruizeConstants.JSONKeys.SHORT_TERM, KruizeConstants.RecommendationEngineConstants - .DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS, KruizeConstants.RecommendationEngineConstants - .DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS_THRESHOLD, 4, 0.25)); - terms.put(KruizeConstants.JSONKeys.MEDIUM_TERM, new Terms(KruizeConstants.JSONKeys.MEDIUM_TERM, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS_THRESHOLD, 7, 1)); - terms.put(KruizeConstants.JSONKeys.LONG_TERM, new Terms(KruizeConstants.JSONKeys.LONG_TERM, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS, KruizeConstants - .RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS_THRESHOLD, 15, 1)); + HashMap minDuration = new HashMap<>(); + + if (null != kruizeObject.getRecommendation_settings().getMinDurationInMins()) { + minDuration = kruizeObject.getRecommendation_settings().getMinDurationInMins(); + } + + double shortTermThreshold = minDuration.containsKey(KruizeConstants.JSONKeys.SHORT_TERM) + ? kruizeObject.getRecommendation_settings().getThresholdForTerm(KruizeConstants.JSONKeys.SHORT_TERM) + : KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS_THRESHOLD; + + double mediumTermThreshold = minDuration.containsKey(KruizeConstants.JSONKeys.MEDIUM_TERM) + ? kruizeObject.getRecommendation_settings().getThresholdForTerm(KruizeConstants.JSONKeys.MEDIUM_TERM) + : KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS_THRESHOLD; + + double longTermThreshold = minDuration.containsKey(KruizeConstants.JSONKeys.LONG_TERM) + ? kruizeObject.getRecommendation_settings().getThresholdForTerm(KruizeConstants.JSONKeys.LONG_TERM) + : KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS_THRESHOLD; + + terms.put(KruizeConstants.JSONKeys.SHORT_TERM, new Terms(KruizeConstants.JSONKeys.SHORT_TERM, + KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS, + shortTermThreshold, 4, 0.25)); + terms.put(KruizeConstants.JSONKeys.MEDIUM_TERM, new Terms(KruizeConstants.JSONKeys.MEDIUM_TERM, + KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS, + mediumTermThreshold, 7, 1)); + terms.put(KruizeConstants.JSONKeys.LONG_TERM, new Terms(KruizeConstants.JSONKeys.LONG_TERM, + KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS, + longTermThreshold, 15, 1)); kruizeObject.setTerms(terms); } diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java b/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java index 9ced5be3b..f13617ec4 100644 --- a/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java +++ b/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java @@ -15,13 +15,36 @@ *******************************************************************************/ package com.autotune.analyzer.kruizeObject; +import com.autotune.utils.KruizeConstants; + +import java.util.HashMap; + public class RecommendationSettings { private Double threshold; + /** + * A map to store the custom minimum duration (in minutes) provided by user for recommendation terms + * The keys represent the recommendation terms (e.g., "short_term"), and the values are the corresponding minimum durations in minutes. + */ + private HashMap minDurationInMins; + public Double getThreshold() { return threshold; } + public HashMap getMinDurationInMins() { + return minDurationInMins; + } + + public void setMinDurationInMins(HashMap minDurationInMins) { + this.minDurationInMins = minDurationInMins; + } + + // converts minimum duration required for terms in minutes to days + public double getThresholdForTerm(String term) { + return minDurationInMins.get(term) / (KruizeConstants.TimeConv.NO_OF_HOURS_PER_DAY * KruizeConstants.TimeConv.NO_OF_MINUTES_PER_HOUR); + } + public void setThreshold(Double threshold) { this.threshold = threshold; } From 0226745bd62b41497aacb820005e45d3e0d6a783 Mon Sep 17 00:00:00 2001 From: Shekhar Saxena Date: Tue, 21 Jan 2025 17:57:16 +0530 Subject: [PATCH 2/4] updating threshold calculation logic Signed-off-by: Shekhar Saxena --- .../analyzer/kruizeObject/KruizeObject.java | 46 +++++++++++-------- .../com/autotune/utils/KruizeConstants.java | 8 ++++ 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java index 26ffa0bf3..6b13b23ef 100644 --- a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java +++ b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java @@ -29,6 +29,7 @@ import com.google.gson.annotations.JsonAdapter; import com.google.gson.annotations.SerializedName; import io.fabric8.kubernetes.api.model.ObjectReference; +import org.apache.logging.log4j.spi.LoggerRegistry; import java.util.HashMap; import java.util.List; @@ -136,33 +137,19 @@ public KruizeObject() { public static void setDefaultTerms(Map terms, KruizeObject kruizeObject) { // TODO: define term names like daily, weekly, fortnightly etc // TODO: add CRD for terms - HashMap minDuration = new HashMap<>(); - - if (null != kruizeObject.getRecommendation_settings().getMinDurationInMins()) { - minDuration = kruizeObject.getRecommendation_settings().getMinDurationInMins(); - } - - double shortTermThreshold = minDuration.containsKey(KruizeConstants.JSONKeys.SHORT_TERM) - ? kruizeObject.getRecommendation_settings().getThresholdForTerm(KruizeConstants.JSONKeys.SHORT_TERM) - : KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS_THRESHOLD; - - double mediumTermThreshold = minDuration.containsKey(KruizeConstants.JSONKeys.MEDIUM_TERM) - ? kruizeObject.getRecommendation_settings().getThresholdForTerm(KruizeConstants.JSONKeys.MEDIUM_TERM) - : KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS_THRESHOLD; - - double longTermThreshold = minDuration.containsKey(KruizeConstants.JSONKeys.LONG_TERM) - ? kruizeObject.getRecommendation_settings().getThresholdForTerm(KruizeConstants.JSONKeys.LONG_TERM) - : KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS_THRESHOLD; terms.put(KruizeConstants.JSONKeys.SHORT_TERM, new Terms(KruizeConstants.JSONKeys.SHORT_TERM, KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.SHORT_TERM_DURATION_DAYS, - shortTermThreshold, 4, 0.25)); + getTermThresholdInDays(KruizeConstants.JSONKeys.SHORT_TERM, kruizeObject.getTrial_settings().getMeasurement_durationMinutes_inDouble()), + 4, 0.25)); terms.put(KruizeConstants.JSONKeys.MEDIUM_TERM, new Terms(KruizeConstants.JSONKeys.MEDIUM_TERM, KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_DURATION_DAYS, - mediumTermThreshold, 7, 1)); + getTermThresholdInDays(KruizeConstants.JSONKeys.MEDIUM_TERM, kruizeObject.getTrial_settings().getMeasurement_durationMinutes_inDouble()), + 7, 1)); terms.put(KruizeConstants.JSONKeys.LONG_TERM, new Terms(KruizeConstants.JSONKeys.LONG_TERM, KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_DURATION_DAYS, - longTermThreshold, 15, 1)); + getTermThresholdInDays(KruizeConstants.JSONKeys.LONG_TERM, kruizeObject.getTrial_settings().getMeasurement_durationMinutes_inDouble()), + 15, 1)); kruizeObject.setTerms(terms); } @@ -377,4 +364,23 @@ public boolean isNamespaceExperiment() { public boolean isContainerExperiment() { return ExperimentTypeUtil.isContainerExperiment(experimentType); } + + private static double getTermThresholdInDays(String term, Double measurement_duration) { + double minDataPoints = 2; + + switch (term) { + case KruizeConstants.JSONKeys.SHORT_TERM: + minDataPoints = KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.SHORT_TERM_MIN_DATAPOINTS; + break; + case KruizeConstants.JSONKeys.MEDIUM_TERM: + minDataPoints = KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.MEDIUM_TERM_MIN_DATAPOINTS; + break; + case KruizeConstants.JSONKeys.LONG_TERM: + minDataPoints = KruizeConstants.RecommendationEngineConstants.DurationBasedEngine.DurationAmount.LONG_TERM_MIN_DATAPOINTS; + break; + } + + return ((double) measurement_duration * minDataPoints + / (KruizeConstants.TimeConv.NO_OF_HOURS_PER_DAY * KruizeConstants.TimeConv.NO_OF_MINUTES_PER_HOUR)); + } } diff --git a/src/main/java/com/autotune/utils/KruizeConstants.java b/src/main/java/com/autotune/utils/KruizeConstants.java index ff0b52592..5484526b8 100644 --- a/src/main/java/com/autotune/utils/KruizeConstants.java +++ b/src/main/java/com/autotune/utils/KruizeConstants.java @@ -730,6 +730,14 @@ public static final class DurationAmount { public static final int MEDIUM_TERM_DURATION_DAYS_THRESHOLD = 2; public static final int LONG_TERM_DURATION_DAYS = 15; public static final int LONG_TERM_DURATION_DAYS_THRESHOLD = 8; + // Represents the minimum number of data points required for different term thresholds. + // Minimum data points are calculated based on the above threshold in days and a 15-minute measurement duration. + // If the short-term threshold is 30 minutes and the measurement duration is 15 minutes + // then the minimum data points = 30 / 15 = 2 + public static final int SHORT_TERM_MIN_DATAPOINTS = 2; + public static final int MEDIUM_TERM_MIN_DATAPOINTS = 192; + public static final int LONG_TERM_MIN_DATAPOINTS = 768; + private DurationAmount() { From 29126b9af9d18c52f2747a5d47ba157fe6736be1 Mon Sep 17 00:00:00 2001 From: Shekhar Saxena Date: Tue, 21 Jan 2025 18:01:02 +0530 Subject: [PATCH 3/4] refactor old code Signed-off-by: Shekhar Saxena --- .../kruizeObject/RecommendationSettings.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java b/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java index f13617ec4..9ced5be3b 100644 --- a/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java +++ b/src/main/java/com/autotune/analyzer/kruizeObject/RecommendationSettings.java @@ -15,36 +15,13 @@ *******************************************************************************/ package com.autotune.analyzer.kruizeObject; -import com.autotune.utils.KruizeConstants; - -import java.util.HashMap; - public class RecommendationSettings { private Double threshold; - /** - * A map to store the custom minimum duration (in minutes) provided by user for recommendation terms - * The keys represent the recommendation terms (e.g., "short_term"), and the values are the corresponding minimum durations in minutes. - */ - private HashMap minDurationInMins; - public Double getThreshold() { return threshold; } - public HashMap getMinDurationInMins() { - return minDurationInMins; - } - - public void setMinDurationInMins(HashMap minDurationInMins) { - this.minDurationInMins = minDurationInMins; - } - - // converts minimum duration required for terms in minutes to days - public double getThresholdForTerm(String term) { - return minDurationInMins.get(term) / (KruizeConstants.TimeConv.NO_OF_HOURS_PER_DAY * KruizeConstants.TimeConv.NO_OF_MINUTES_PER_HOUR); - } - public void setThreshold(Double threshold) { this.threshold = threshold; } From 95bb9cc4fe0e7718f9a850b120eb99c3ce36d603 Mon Sep 17 00:00:00 2001 From: Shekhar Saxena Date: Tue, 21 Jan 2025 18:02:03 +0530 Subject: [PATCH 4/4] removing redundant imports Signed-off-by: Shekhar Saxena --- .../java/com/autotune/analyzer/kruizeObject/KruizeObject.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java index 6b13b23ef..990fb57d7 100644 --- a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java +++ b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java @@ -29,7 +29,6 @@ import com.google.gson.annotations.JsonAdapter; import com.google.gson.annotations.SerializedName; import io.fabric8.kubernetes.api.model.ObjectReference; -import org.apache.logging.log4j.spi.LoggerRegistry; import java.util.HashMap; import java.util.List;