diff --git a/src/main/java/com/autotune/analyzer/Analyzer.java b/src/main/java/com/autotune/analyzer/Analyzer.java index 675e7cb54..8285409c6 100644 --- a/src/main/java/com/autotune/analyzer/Analyzer.java +++ b/src/main/java/com/autotune/analyzer/Analyzer.java @@ -16,7 +16,7 @@ package com.autotune.analyzer; import com.autotune.analyzer.experiment.Experimentator; -import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment; +import com.autotune.analyzer.metricProfiles.MetricProfilesDeployment; import com.autotune.analyzer.services.*; import com.autotune.operator.KruizeDeploymentInfo; import com.autotune.operator.KruizeOperator; @@ -31,7 +31,7 @@ public static void start(ServletContextHandler contextHandler) { try { addServlets(contextHandler); - PerformanceProfilesDeployment.getPerformanceProfiles(); // Performance profile should be called first + MetricProfilesDeployment.getMetricProfiles(); // Performance profile should be called first KruizeOperator.getKruizeObjects(kruizeOperator); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/autotune/analyzer/experiment/ExperimentValidation.java b/src/main/java/com/autotune/analyzer/experiment/ExperimentValidation.java index a3ad10ea5..e01cb3594 100644 --- a/src/main/java/com/autotune/analyzer/experiment/ExperimentValidation.java +++ b/src/main/java/com/autotune/analyzer/experiment/ExperimentValidation.java @@ -16,8 +16,7 @@ package com.autotune.analyzer.experiment; import com.autotune.analyzer.kruizeObject.KruizeObject; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment; +import com.autotune.analyzer.metricProfiles.MetricProfile; import com.autotune.analyzer.recommendations.ContainerRecommendations; import com.autotune.analyzer.utils.AnalyzerConstants; import com.autotune.analyzer.utils.AnalyzerErrorConstants; @@ -47,7 +46,7 @@ public class ExperimentValidation { private boolean success; private String errorMessage; private Map mainKruizeExperimentMAP; - private Map performanceProfilesMap = new HashMap<>(); + private Map metricProfilesMap = new HashMap<>(); //Mandatory fields private List mandatoryFields = new ArrayList<>(Arrays.asList( AnalyzerConstants.NAME, @@ -99,20 +98,20 @@ public void validate(List kruizeExptList) { boolean proceed = false; String errorMsg = ""; if (null == this.mainKruizeExperimentMAP.get(expName)) { - // check for slo and performance profile - if (null != kruizeObject.getPerformanceProfile()) { + // check for slo and metric profile + if (null != kruizeObject.getMetricProfile()) { if (null != kruizeObject.getSloInfo()) { errorMsg = AnalyzerErrorConstants.AutotuneObjectErrors.SLO_REDUNDANCY_ERROR; validationOutputData.setErrorCode(HttpServletResponse.SC_BAD_REQUEST); } else { // fetch the Performance Profile from the DB try { - new ExperimentDBService().loadPerformanceProfileFromDBByName(performanceProfilesMap, kruizeObject.getPerformanceProfile()); + new ExperimentDBService().loadPerformanceProfileFromDBByName(metricProfilesMap, kruizeObject.getMetricProfile()); } catch (Exception e) { LOGGER.error("Loading saved Performance Profile {} failed: {} ", expName, e.getMessage()); } - if (null == performanceProfilesMap.get(kruizeObject.getPerformanceProfile())) { - errorMsg = AnalyzerErrorConstants.AutotuneObjectErrors.MISSING_PERF_PROFILE + kruizeObject.getPerformanceProfile(); + if (null == metricProfilesMap.get(kruizeObject.getMetricProfile())) { + errorMsg = AnalyzerErrorConstants.AutotuneObjectErrors.MISSING_PERF_PROFILE + kruizeObject.getMetricProfile(); validationOutputData.setErrorCode(HttpServletResponse.SC_BAD_REQUEST); } else proceed = true; @@ -122,8 +121,8 @@ public void validate(List kruizeExptList) { errorMsg = AnalyzerErrorConstants.AutotuneObjectErrors.MISSING_SLO_DATA; validationOutputData.setErrorCode(HttpServletResponse.SC_BAD_REQUEST); } else { - String perfProfileName = KruizeOperator.setDefaultPerformanceProfile(kruizeObject.getSloInfo(), mode, target_cluster); - kruizeObject.setPerformanceProfile(perfProfileName); + String metricProfileName = KruizeOperator.setDefaultPerformanceProfile(kruizeObject.getSloInfo(), mode, target_cluster); + kruizeObject.setMetricProfile(metricProfileName); proceed = true; } } @@ -144,11 +143,11 @@ public void validate(List kruizeExptList) { markFailed(validationOutputData.getMessage()); break; } - // set Performance Profile metrics in the Kruize Object - PerformanceProfile performanceProfile = performanceProfilesMap.get(kruizeObject.getPerformanceProfile()); + // set Metric Profile metrics in the Kruize Object + MetricProfile metricProfile = metricProfilesMap.get(kruizeObject.getMetricProfile()); try { HashMap metricsMap = new HashMap<>(); - for (Metric metric : performanceProfile.getSloInfo().getFunctionVariables()) { + for (Metric metric : metricProfile.getSloInfo().getFunctionVariables()) { if (metric.getKubernetesObject().equals(KruizeConstants.JSONKeys.CONTAINER)) metricsMap.put(AnalyzerConstants.MetricName.valueOf(metric.getName()), metric); } @@ -164,7 +163,7 @@ public void validate(List kruizeExptList) { } kruizeObject.setKubernetes_objects(k8sObjectList); } catch (Exception e) { - LOGGER.error("Failed to set Performance Profile Metrics to the Kruize Object: {}", e.getMessage()); + LOGGER.error("Failed to set Metric Profile Metrics to the Kruize Object: {}", e.getMessage()); } } } diff --git a/src/main/java/com/autotune/analyzer/experiment/Experimentator.java b/src/main/java/com/autotune/analyzer/experiment/Experimentator.java index 526469d09..e2f97655d 100644 --- a/src/main/java/com/autotune/analyzer/experiment/Experimentator.java +++ b/src/main/java/com/autotune/analyzer/experiment/Experimentator.java @@ -9,8 +9,8 @@ import com.autotune.analyzer.kruizeLayer.KruizeLayer; import com.autotune.analyzer.kruizeObject.KruizeObject; import com.autotune.analyzer.kruizeObject.ObjectiveFunction; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.MetricProfilesDeployment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,11 +105,11 @@ private static ApplicationSearchSpace updateSearchSpace(KruizeExperiment kruizeE KruizeObject kruizeObject = kruizeExperiment.getAutotuneObject(); String experimentName = kruizeExperiment.getExperimentName(); String experimentId = kruizeObject.getExperiment_id(); - PerformanceProfile performanceProfile = PerformanceProfilesDeployment.performanceProfilesMap - .get(kruizeObject.getPerformanceProfile()); - ObjectiveFunction objectiveFunction = performanceProfile.getSloInfo().getObjectiveFunction(); + MetricProfile metricProfile = MetricProfilesDeployment.metricProfilesMap + .get(kruizeObject.getMetricProfile()); + ObjectiveFunction objectiveFunction = metricProfile.getSloInfo().getObjectiveFunction(); String hpoAlgoImpl = kruizeObject.getHpoAlgoImpl(); - String direction = performanceProfile.getSloInfo().getDirection(); + String direction = metricProfile.getSloInfo().getDirection(); // TODO: Need to add valueType to the ObjectiveFunction! String valueType = "double"; diff --git a/src/main/java/com/autotune/analyzer/experiment/KruizeExperiment.java b/src/main/java/com/autotune/analyzer/experiment/KruizeExperiment.java index 203989cd7..7bc62a002 100644 --- a/src/main/java/com/autotune/analyzer/experiment/KruizeExperiment.java +++ b/src/main/java/com/autotune/analyzer/experiment/KruizeExperiment.java @@ -6,8 +6,8 @@ import com.autotune.common.trials.ExperimentSummary; import com.autotune.common.trials.ExperimentTrial; import com.autotune.common.trials.TrialDetails; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.MetricProfilesDeployment; import java.util.TreeMap; @@ -140,9 +140,9 @@ public void summarizeTrial(TrialDetails trialDetails) { ExperimentTrial bestExperimentTrial = getExperimentTrials().get(bestTrial); TrialDetails bestTrialDetails = bestExperimentTrial.getTrialDetails().get(TRAINING); double bestResult = Double.parseDouble(bestTrialDetails.getResult()); - PerformanceProfile performanceProfile = PerformanceProfilesDeployment.performanceProfilesMap - .get(kruizeObject.getPerformanceProfile()); - String direction = performanceProfile.getSloInfo().getDirection(); + MetricProfile metricProfile = MetricProfilesDeployment.metricProfilesMap + .get(kruizeObject.getMetricProfile()); + String direction = metricProfile.getSloInfo().getDirection(); if ((direction.equals(MINIMIZE) && currentResult < bestResult) || (direction.equals(MAXIMIZE) && currentResult > bestResult)) { experimentSummary.setBestTrial(currentTrial); diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java index 41670ac8f..c6a75ded0 100644 --- a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java +++ b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java @@ -58,8 +58,8 @@ public final class KruizeObject { private SelectorInfo selectorInfo; private ObjectReference objectReference; private AnalyzerConstants.ExperimentStatus status; - @SerializedName("performance_profile") - private String performanceProfile; + @SerializedName("metric_profile") + private String metricProfile; private TrialSettings trial_settings; private RecommendationSettings recommendation_settings; private ExperimentUseCaseType experiment_usecase_type; @@ -75,7 +75,7 @@ public KruizeObject(String experimentName, String targetCluster, String hpoAlgoImpl, SelectorInfo selectorInfo, - String performanceProfile, + String metricProfile, String datasource, ObjectReference objectReference ) throws InvalidValueException { @@ -102,7 +102,7 @@ public KruizeObject(String experimentName, } else { throw new InvalidValueException(error.toString()); } - this.performanceProfile = performanceProfile; + this.metricProfile = metricProfile; if (KruizeSupportedTypes.HPO_ALGOS_SUPPORTED.contains(hpoAlgoImpl)) this.hpoAlgoImpl = hpoAlgoImpl; else @@ -205,12 +205,12 @@ public void setStatus(AnalyzerConstants.ExperimentStatus status) { this.status = status; } - public String getPerformanceProfile() { - return performanceProfile; + public String getMetricProfile() { + return metricProfile; } - public void setPerformanceProfile(String performanceProfile) { - this.performanceProfile = performanceProfile; + public void setMetricProfile(String metricProfile) { + this.metricProfile = metricProfile; } public TrialSettings getTrial_settings() { @@ -315,7 +315,7 @@ public String toString() { ", selectorInfo=" + selectorInfo + ", objectReference=" + objectReference + ", status=" + status + - ", performanceProfile='" + performanceProfile + '\'' + + ", metricProfile='" + metricProfile + '\'' + ", trial_settings=" + trial_settings + ", recommendation_settings=" + recommendation_settings + ", experimentUseCaseType=" + experiment_usecase_type + diff --git a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfile.java b/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfile.java similarity index 86% rename from src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfile.java rename to src/main/java/com/autotune/analyzer/metricProfiles/MetricProfile.java index 5f5705867..563d33f90 100644 --- a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfile.java +++ b/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2022 Red Hat, IBM Corporation and others. + * Copyright (c) 2020, 2024 Red Hat, IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.autotune.analyzer.performanceProfiles; +package com.autotune.analyzer.metricProfiles; import com.autotune.analyzer.kruizeObject.SloInfo; import com.autotune.analyzer.recommendations.term.Terms; @@ -22,12 +22,12 @@ import java.util.Map; /** - * Container class for the PerformanceProfile kubernetes kind, which is used to define + * Container class for the MetricProfile kubernetes kind, which is used to define * a profile * */ -public class PerformanceProfile { +public class MetricProfile { private String name; @@ -61,7 +61,7 @@ public void setSloInfo(SloInfo sloInfo) { this.sloInfo = sloInfo; } - public PerformanceProfile(String name, double profile_version, String k8s_type, SloInfo sloInfo) { + public MetricProfile(String name, double profile_version, String k8s_type, SloInfo sloInfo) { this.name = name; this.profile_version = profile_version; this.k8s_type = k8s_type; @@ -94,7 +94,7 @@ public void setTerms(Map terms) { @Override public String toString() { - return "PerformanceProfile{" + + return "MetricProfile{" + "name='" + name + '\'' + ", profile_version=" + profile_version + ", k8s_type='" + k8s_type + '\'' + diff --git a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileInterface/ResourceOptimizationOpenshiftImpl.java b/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfileInterface/ResourceOptimizationOpenshiftImpl.java similarity index 100% rename from src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileInterface/ResourceOptimizationOpenshiftImpl.java rename to src/main/java/com/autotune/analyzer/metricProfiles/MetricProfileInterface/ResourceOptimizationOpenshiftImpl.java diff --git a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileValidation.java b/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfileValidation.java similarity index 86% rename from src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileValidation.java rename to src/main/java/com/autotune/analyzer/metricProfiles/MetricProfileValidation.java index 0f99f8890..7af67b8a9 100644 --- a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileValidation.java +++ b/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfileValidation.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.autotune.analyzer.performanceProfiles; +package com.autotune.analyzer.metricProfiles; import com.autotune.analyzer.exceptions.InvalidValueException; import com.autotune.analyzer.utils.EvalExParser; @@ -40,11 +40,11 @@ /** * create Experiment input validation */ -public class PerformanceProfileValidation { - private static final Logger LOGGER = LoggerFactory.getLogger(PerformanceProfileValidation.class); +public class MetricProfileValidation { + private static final Logger LOGGER = LoggerFactory.getLogger(MetricProfileValidation.class); private boolean success; private String errorMessage; - private final Map performanceProfilesMap; + private final Map metricProfilesMap; //Mandatory fields private final List mandatoryFields = new ArrayList<>(Arrays.asList( @@ -64,52 +64,52 @@ public class PerformanceProfileValidation { AnalyzerConstants.PerformanceProfileConstants.VALUE_TYPE )); - public PerformanceProfileValidation(Map performanceProfilesMap) { - this.performanceProfilesMap = performanceProfilesMap; + public MetricProfileValidation(Map metricProfilesMap) { + this.metricProfilesMap = metricProfilesMap; } /** * Validates function variables * - * @param performanceProfile Performance Profile Object to be validated + * @param metricProfile Metric Profile Object to be validated * @return Returns the ValidationOutputData containing the response based on the validation */ - public ValidationOutputData validate(PerformanceProfile performanceProfile) { + public ValidationOutputData validate(MetricProfile metricProfile) { - return validatePerformanceProfileData(performanceProfile); + return validateMetricProfileData(metricProfile); } /** - * Validates the data present in the performance profile object before adding it to the map - * @param performanceProfile + * Validates the data present in the metric profile object before adding it to the map + * @param metricProfile * @return */ - private ValidationOutputData validatePerformanceProfileData(PerformanceProfile performanceProfile) { + private ValidationOutputData validateMetricProfileData(MetricProfile metricProfile) { // validate the mandatory values first - ValidationOutputData validationOutputData = validateMandatoryFieldsAndData(performanceProfile); + ValidationOutputData validationOutputData = validateMandatoryFieldsAndData(metricProfile); // If the mandatory values are present,proceed for further validation else return the validation object directly if (validationOutputData.isSuccess()) { try { - new ExperimentDBService().loadAllPerformanceProfiles(performanceProfilesMap); + new ExperimentDBService().loadAllPerformanceProfiles(metricProfilesMap); } catch (Exception e) { - LOGGER.error("Loading saved performance profiles failed: {} ", e.getMessage()); + LOGGER.error("Loading saved metric profiles failed: {} ", e.getMessage()); } StringBuilder errorString = new StringBuilder(); - // check if the performance profile already exists - if (performanceProfilesMap.get(performanceProfile.getName()) != null) { - errorString.append(AnalyzerErrorConstants.AutotuneObjectErrors.DUPLICATE_PERF_PROFILE).append(performanceProfile.getName()); + // check if the metric profile already exists + if (metricProfilesMap.get(metricProfile.getName()) != null) { + errorString.append(AnalyzerErrorConstants.AutotuneObjectErrors.DUPLICATE_PERF_PROFILE).append(metricProfile.getName()); return new ValidationOutputData(false, errorString.toString(), HttpServletResponse.SC_CONFLICT); } // Check if k8s type is supported - String k8sType = performanceProfile.getK8S_TYPE(); + String k8sType = metricProfile.getK8S_TYPE(); if (!KruizeSupportedTypes.K8S_TYPES_SUPPORTED.contains(k8sType)) { errorString.append(AnalyzerConstants.PerformanceProfileConstants.K8S_TYPE).append(k8sType) .append(AnalyzerErrorConstants.AutotuneObjectErrors.UNSUPPORTED); } - SloInfo sloInfo = performanceProfile.getSloInfo(); + SloInfo sloInfo = metricProfile.getSloInfo(); // Check if direction is supported if (!KruizeSupportedTypes.DIRECTIONS_SUPPORTED.contains(sloInfo.getDirection())) errorString.append(AnalyzerErrorConstants.AutotuneObjectErrors.DIRECTION_NOT_SUPPORTED); @@ -221,10 +221,10 @@ private ValidationOutputData validatePerformanceProfileData(PerformanceProfile p /** * Check if all mandatory values are present. * - * @param perfObj Mandatory fields of this Performance Profile Object will be validated + * @param metricObj Mandatory fields of this Metric Profile Object will be validated * @return ValidationOutputData object containing status of the validations */ - public ValidationOutputData validateMandatoryFieldsAndData(PerformanceProfile perfObj) { + public ValidationOutputData validateMandatoryFieldsAndData(MetricProfile metricObj) { List missingMandatoryFields = new ArrayList<>(); ValidationOutputData validationOutputData = new ValidationOutputData(false, null, null); String errorMsg; @@ -234,8 +234,8 @@ public ValidationOutputData validateMandatoryFieldsAndData(PerformanceProfile pe String methodName = "get" + mField.substring(0, 1).toUpperCase() + mField.substring(1); try { LOGGER.debug("MethodName = {}",methodName); - Method getNameMethod = perfObj.getClass().getMethod(methodName); - if (getNameMethod.invoke(perfObj) == null) + Method getNameMethod = metricObj.getClass().getMethod(methodName); + if (getNameMethod.invoke(metricObj) == null) missingMandatoryFields.add(mField); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOGGER.error("Method name {} doesn't exist!", mField); @@ -249,8 +249,8 @@ public ValidationOutputData validateMandatoryFieldsAndData(PerformanceProfile pe String methodName = "get" + mField.substring(0, 1).toUpperCase() + mField.substring(1); try { LOGGER.debug("MethodName = {}",methodName); - Method getNameMethod = perfObj.getSloInfo().getClass().getMethod(methodName); - if (getNameMethod.invoke(perfObj.getSloInfo()) == null) + Method getNameMethod = metricObj.getSloInfo().getClass().getMethod(methodName); + if (getNameMethod.invoke(metricObj.getSloInfo()) == null) missingMandatoryFields.add(mField); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOGGER.error("Method name {} doesn't exist!", mField); @@ -263,9 +263,9 @@ public ValidationOutputData validateMandatoryFieldsAndData(PerformanceProfile pe String methodName = "get" + mField.substring(0, 1).toUpperCase() + mField.substring(1); try { LOGGER.debug("MethodName = {}",methodName); - Method getNameMethod = perfObj.getSloInfo().getFunctionVariables().get(0) + Method getNameMethod = metricObj.getSloInfo().getFunctionVariables().get(0) .getClass().getMethod(methodName); - if (getNameMethod.invoke(perfObj.getSloInfo().getFunctionVariables().get(0)) == null) + if (getNameMethod.invoke(metricObj.getSloInfo().getFunctionVariables().get(0)) == null) missingMandatoryFields.add(mField); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOGGER.error("Method name {} doesn't exist!", mField); @@ -277,9 +277,9 @@ public ValidationOutputData validateMandatoryFieldsAndData(PerformanceProfile pe mandatoryObjFuncData.substring(1); try { LOGGER.debug("MethodName = {}",methodName); - Method getNameMethod = perfObj.getSloInfo().getObjectiveFunction() + Method getNameMethod = metricObj.getSloInfo().getObjectiveFunction() .getClass().getMethod(methodName); - if (getNameMethod.invoke(perfObj.getSloInfo().getObjectiveFunction()) == null) + if (getNameMethod.invoke(metricObj.getSloInfo().getObjectiveFunction()) == null) missingMandatoryFields.add(mandatoryObjFuncData); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOGGER.error("Method name {} doesn't exist!", mandatoryObjFuncData); @@ -311,7 +311,7 @@ public void setSuccess(boolean success) { } @Override public String toString() { - return "PerformanceProfileValidation{" + + return "MetricProfileValidation{" + "success=" + success + ", errorMessage='" + errorMessage + '\'' + '}'; diff --git a/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfilesDeployment.java b/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfilesDeployment.java new file mode 100644 index 000000000..12562668c --- /dev/null +++ b/src/main/java/com/autotune/analyzer/metricProfiles/MetricProfilesDeployment.java @@ -0,0 +1,125 @@ +package com.autotune.analyzer.metricProfiles; + +import com.autotune.analyzer.metricProfiles.utils.MetricProfileUtil; +import com.autotune.common.data.ValidationOutputData; +import com.autotune.common.k8sObjects.*; +import com.autotune.common.target.kubernetes.service.KubernetesServices; +import com.autotune.common.target.kubernetes.service.impl.KubernetesServicesImpl; +import com.autotune.analyzer.utils.AnalyzerConstants; +import com.autotune.utils.EventLogger; +import com.autotune.utils.KubeEventLogger; +import com.google.gson.Gson; +import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.Watcher; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.Clock; +import java.util.HashMap; +import java.util.Map; + +/** + * Maintains information about the Metric Profile objects deployed in the cluster + */ +public class MetricProfilesDeployment { + public static Map metricProfilesMap = new HashMap<>(); + private static final Logger LOGGER = LoggerFactory.getLogger(MetricProfile.class); + + /** + * Get Metric Profile objects from kubernetes, and watch for any additions, modifications or deletions. + * + */ + public static void getMetricProfiles() { + /* Watch for events (additions, modifications or deletions) of metric profile objects */ + Watcher metricProfileObjectWatcher = new Watcher<>() { + @Override + public void eventReceived(Action action, String resource) { + MetricProfile metricProfile = null; + + switch (action.toString().toUpperCase()) { + case "ADDED": + metricProfile = getMetricProfile(resource); + if ( validateMetricProfile(metricProfile)) + MetricProfileUtil.addMetricProfile(metricProfilesMap, metricProfile); + break; + case "MODIFIED": + metricProfile = getMetricProfile(resource); + if (metricProfile != null) { + // Check if any of the values have changed from the existing object in the map + if (!metricProfilesMap.get(metricProfile.getName()) + .equals(metricProfile)) { + if (validateMetricProfile(metricProfile)) { + deleteExistingMetricProfile(resource); + MetricProfileUtil.addMetricProfile(metricProfilesMap, metricProfile); + } + } + } + break; + case "DELETED": + deleteExistingMetricProfile(resource); + default: + break; + } + } + + @Override + public void onClose(KubernetesClientException e) { } + }; + + KubernetesServices kubernetesServices = new KubernetesServicesImpl(); + kubernetesServices.addWatcher(KubernetesContexts.getPerformanceProfileCrdContext(), metricProfileObjectWatcher); + } + + private static boolean validateMetricProfile(MetricProfile metricProfile) { + boolean validationStatus = false; + try { + if (null != metricProfile) { + ValidationOutputData validationOutputData = new MetricProfileValidation(metricProfilesMap).validate(metricProfile); + if (validationOutputData.isSuccess()) + validationStatus = true; + else + new KubeEventLogger(Clock.systemUTC()).log("Failed", validationOutputData.getMessage(), EventLogger.Type.Warning, null, null, null, null); + } else + new KubeEventLogger(Clock.systemUTC()).log("Failed", "Validation of metric profile failed! ", EventLogger.Type.Warning, null, null, null, null); + } catch (Exception e) { + new KubeEventLogger(Clock.systemUTC()).log("Failed", e.getMessage(), EventLogger.Type.Warning, null, null, null, null); + } + return validationStatus; + } + + public static MetricProfile getMetricProfile(String metricProfileObjectJsonStr) { + try { + JSONObject metricProfileProfileObjectJson = new JSONObject(metricProfileObjectJsonStr); + JSONObject metadataJson = metricProfileProfileObjectJson + .getJSONObject(AnalyzerConstants.AutotuneObjectConstants.METADATA); + metricProfileProfileObjectJson.remove("apiversion"); + metricProfileProfileObjectJson.remove("kind"); + metricProfileProfileObjectJson.remove("metadata"); + + metricProfileProfileObjectJson.put("name",metadataJson.optString(AnalyzerConstants.PerformanceProfileConstants.PERF_PROFILE_NAME)); + MetricProfile metricProfile = new Gson().fromJson(metricProfileProfileObjectJson.toString(), MetricProfile.class); + + return metricProfile; + + } catch (NullPointerException | JSONException e) { + LOGGER.error("Exception occurred while parsing the data: {}",e.getMessage()); + return null; + } + } + + /** + * Delete the metric Profile object corresponding to the passed parameter + * + * @param metricProfileObject - removes the Metric Profile object from the map + */ + private static void deleteExistingMetricProfile(String metricProfileObject) { + JSONObject metricProfileObjectJson = new JSONObject(metricProfileObject); + String name = metricProfileObjectJson.getJSONObject(AnalyzerConstants.AutotuneObjectConstants.METADATA) + .optString(AnalyzerConstants.AutotuneObjectConstants.NAME); + + metricProfilesMap.remove(name); + LOGGER.info("Deleted metric profile object {}", name); + } +} diff --git a/src/main/java/com/autotune/analyzer/performanceProfiles/utils/PerformanceProfileUtil.java b/src/main/java/com/autotune/analyzer/metricProfiles/utils/MetricProfileUtil.java similarity index 82% rename from src/main/java/com/autotune/analyzer/performanceProfiles/utils/PerformanceProfileUtil.java rename to src/main/java/com/autotune/analyzer/metricProfiles/utils/MetricProfileUtil.java index b37dffb3f..0fe79672e 100644 --- a/src/main/java/com/autotune/analyzer/performanceProfiles/utils/PerformanceProfileUtil.java +++ b/src/main/java/com/autotune/analyzer/metricProfiles/utils/MetricProfileUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023 Red Hat, IBM Corporation and others. + * Copyright (c) 2023, 2024 Red Hat, IBM Corporation and others. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.autotune.analyzer.performanceProfiles.utils; +package com.autotune.analyzer.metricProfiles.utils; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.PerformanceProfileValidation; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.MetricProfileValidation; import com.autotune.analyzer.serviceObjects.ContainerAPIObject; import com.autotune.analyzer.serviceObjects.KubernetesAPIObject; import com.autotune.analyzer.serviceObjects.UpdateResultsAPIObject; @@ -34,23 +34,23 @@ import java.lang.reflect.Method; import java.util.*; -public class PerformanceProfileUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(PerformanceProfileUtil.class); - private PerformanceProfileUtil() { +public class MetricProfileUtil { + private static final Logger LOGGER = LoggerFactory.getLogger(MetricProfileUtil.class); + private MetricProfileUtil() { } /** - * validates the performance profile fields and the data and then adds it to the map - * @param performanceProfile + * validates the metric profile fields and the data and then adds it to the map + * @param metricProfile * @return */ - public static ValidationOutputData validateAndAddProfile(Map performanceProfilesMap, PerformanceProfile performanceProfile) { + public static ValidationOutputData validateAndAddProfile(Map metricProfilesMap, MetricProfile metricProfile) { ValidationOutputData validationOutputData; try { - validationOutputData = new PerformanceProfileValidation(performanceProfilesMap).validate(performanceProfile); + validationOutputData = new MetricProfileValidation(metricProfilesMap).validate(metricProfile); if (validationOutputData.isSuccess()) { - addPerformanceProfile(performanceProfilesMap, performanceProfile); + addMetricProfile(metricProfilesMap, metricProfile); } else { validationOutputData.setMessage("Validation failed: " + validationOutputData.getMessage()); } @@ -62,11 +62,11 @@ public static ValidationOutputData validateAndAddProfile(Map validateResults(PerformanceProfile performanceProfile, UpdateResultsAPIObject updateResultsAPIObject) { + public static List validateResults(MetricProfile metricProfile, UpdateResultsAPIObject updateResultsAPIObject) { List errorReasons = new ArrayList<>(); String errorMsg = ""; @@ -74,15 +74,15 @@ public static List validateResults(PerformanceProfile performanceProfile AnalyzerConstants.MetricName.cpuUsage, AnalyzerConstants.MetricName.memoryUsage, AnalyzerConstants.MetricName.memoryRSS); - // Get the metrics data from the Performance Profile - List perfProfileAggrFunctions = new ArrayList<>(); + // Get the metrics data from the Metric Profile + List metricProfileAggrFunctions = new ArrayList<>(); List queryList = new ArrayList<>(); - List perfProfileFunctionVariablesList = new ArrayList<>(); - for (Metric metric : performanceProfile.getSloInfo().getFunctionVariables()) { - perfProfileFunctionVariablesList.add(metric.getName()); + List metricProfileFunctionVariablesList = new ArrayList<>(); + for (Metric metric : metricProfile.getSloInfo().getFunctionVariables()) { + metricProfileFunctionVariablesList.add(metric.getName()); if (null != metric.getAggregationFunctionsMap()) { metric.getAggregationFunctionsMap().values().forEach(aggregationFunctions -> - perfProfileAggrFunctions.add(aggregationFunctions.getFunction())); + metricProfileAggrFunctions.add(aggregationFunctions.getFunction())); } if (null != metric.getQuery()) queryList.add(metric.getQuery()); @@ -105,7 +105,7 @@ public static List validateResults(PerformanceProfile performanceProfile for (Metric metric : metrics) { try { // validate the metric values - errorMsg = PerformanceProfileUtil.validateMetricsValues(metric.getName(), metric.getMetricResult()); + errorMsg = MetricProfileUtil.validateMetricsValues(metric.getName(), metric.getMetricResult()); if (!errorMsg.isBlank()) { errorReasons.add(errorMsg.concat(String.format( AnalyzerErrorConstants.AutotuneObjectErrors.CONTAINER_AND_EXPERIMENT, @@ -117,10 +117,10 @@ public static List validateResults(PerformanceProfile performanceProfile kruizeFunctionVariablesList.add(metricName); MetricResults metricResults = metric.getMetricResult(); Map aggrInfoClassAsMap; - if (!perfProfileAggrFunctions.isEmpty()) { + if (!metricProfileAggrFunctions.isEmpty()) { try { aggrInfoClassAsMap = convertObjectToMap(metricResults.getAggregationInfoResult()); - errorMsg = validateAggFunction(aggrInfoClassAsMap, perfProfileAggrFunctions); + errorMsg = validateAggFunction(aggrInfoClassAsMap, metricProfileAggrFunctions); if (!errorMsg.isBlank()) { errorReasons.add(errorMsg.concat(String.format( AnalyzerErrorConstants.AutotuneObjectErrors.CONTAINER_AND_EXPERIMENT, @@ -145,7 +145,7 @@ public static List validateResults(PerformanceProfile performanceProfile if (!errorReasons.isEmpty()) break; - LOGGER.debug("perfProfileFunctionVariablesList: {}", perfProfileFunctionVariablesList); + LOGGER.debug("metricProfileFunctionVariablesList: {}", metricProfileFunctionVariablesList); LOGGER.debug("kruizeFunctionVariablesList: {}", kruizeFunctionVariablesList); if (!new HashSet<>(kruizeFunctionVariablesList).containsAll(mandatoryFields)) { errorReasons.add(errorMsg.concat(String.format("Missing one of the following mandatory parameters for experiment - %s : %s", @@ -157,28 +157,28 @@ public static List validateResults(PerformanceProfile performanceProfile return errorReasons; } - public static void addPerformanceProfile(Map performanceProfileMap, PerformanceProfile performanceProfile) { - performanceProfileMap.put(performanceProfile.getName(), performanceProfile); - LOGGER.debug("Added PerformanceProfile: {} ",performanceProfile.getName()); + public static void addMetricProfile(Map metricProfileMapProfileMap, MetricProfile metricProfile) { + metricProfileMapProfileMap.put(metricProfile.getName(), metricProfile); + LOGGER.debug("Added MetricProfile: {} ", metricProfile.getName()); } /** * Validates the aggregation function objects against the aggregationInfoResult metrics * * @param aggrInfoClassAsMap - * @param perfProfileAggrFunctions + * @param metricProfileAggrFunctions * @return */ - public static String validateAggFunction(Map aggrInfoClassAsMap, List perfProfileAggrFunctions) { + public static String validateAggFunction(Map aggrInfoClassAsMap, List metricProfileAggrFunctions) { List resultDataAggrFuncObjects = aggrInfoClassAsMap.keySet().stream().toList(); String errorMsg = ""; // check if none of the aggrfunctions are present in the aggrInfoObjects List - if (resultDataAggrFuncObjects.stream().noneMatch(perfProfileAggrFunctions::contains)) { + if (resultDataAggrFuncObjects.stream().noneMatch(metricProfileAggrFunctions::contains)) { LOGGER.error(AnalyzerErrorConstants.AutotuneObjectErrors.MISSING_AGG_FUNCTION); errorMsg = errorMsg.concat(AnalyzerErrorConstants.AutotuneObjectErrors.MISSING_AGG_FUNCTION); - } else if (!resultDataAggrFuncObjects.containsAll(perfProfileAggrFunctions)) { - List missingObjects = new ArrayList<>(perfProfileAggrFunctions); + } else if (!resultDataAggrFuncObjects.containsAll(metricProfileAggrFunctions)) { + List missingObjects = new ArrayList<>(metricProfileAggrFunctions); missingObjects.removeAll(resultDataAggrFuncObjects); LOGGER.error(AnalyzerErrorConstants.AutotuneObjectErrors.AGG_FUNCTION_MISMATCH.concat(missingObjects.toString())); errorMsg = errorMsg.concat(AnalyzerErrorConstants.AutotuneObjectErrors.AGG_FUNCTION_MISMATCH).concat(": ") diff --git a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfilesDeployment.java b/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfilesDeployment.java deleted file mode 100644 index a8aebcb2c..000000000 --- a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfilesDeployment.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.autotune.analyzer.performanceProfiles; - -import com.autotune.analyzer.performanceProfiles.utils.PerformanceProfileUtil; -import com.autotune.common.data.ValidationOutputData; -import com.autotune.common.k8sObjects.*; -import com.autotune.common.target.kubernetes.service.KubernetesServices; -import com.autotune.common.target.kubernetes.service.impl.KubernetesServicesImpl; -import com.autotune.analyzer.utils.AnalyzerConstants; -import com.autotune.utils.EventLogger; -import com.autotune.utils.KubeEventLogger; -import com.google.gson.Gson; -import io.fabric8.kubernetes.client.KubernetesClientException; -import io.fabric8.kubernetes.client.Watcher; -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.Clock; -import java.util.HashMap; -import java.util.Map; - -/** - * Maintains information about the Performance Profile objects deployed in the cluster - */ -public class PerformanceProfilesDeployment { - public static Map performanceProfilesMap = new HashMap<>(); - private static final Logger LOGGER = LoggerFactory.getLogger(PerformanceProfile.class); - - /** - * Get Performance Profile objects from kubernetes, and watch for any additions, modifications or deletions. - * - */ - public static void getPerformanceProfiles() { - /* Watch for events (additions, modifications or deletions) of performance profile objects */ - Watcher performanceProfileObjectWatcher = new Watcher<>() { - @Override - public void eventReceived(Action action, String resource) { - PerformanceProfile performanceProfile = null; - - switch (action.toString().toUpperCase()) { - case "ADDED": - performanceProfile = getPerformanceProfile(resource); - if ( validatePerformanceProfile(performanceProfile)) - PerformanceProfileUtil.addPerformanceProfile(performanceProfilesMap, performanceProfile); - break; - case "MODIFIED": - performanceProfile = getPerformanceProfile(resource); - if (performanceProfile != null) { - // Check if any of the values have changed from the existing object in the map - if (!performanceProfilesMap.get(performanceProfile.getName()) - .equals(performanceProfile)) { - if (validatePerformanceProfile(performanceProfile)) { - deleteExistingPerformanceProfile(resource); - PerformanceProfileUtil.addPerformanceProfile(performanceProfilesMap, performanceProfile); - } - } - } - break; - case "DELETED": - deleteExistingPerformanceProfile(resource); - default: - break; - } - } - - @Override - public void onClose(KubernetesClientException e) { } - }; - - KubernetesServices kubernetesServices = new KubernetesServicesImpl(); - kubernetesServices.addWatcher(KubernetesContexts.getPerformanceProfileCrdContext(), performanceProfileObjectWatcher); - } - - private static boolean validatePerformanceProfile(PerformanceProfile performanceProfile) { - boolean validationStatus = false; - try { - if (null != performanceProfile) { - ValidationOutputData validationOutputData = new PerformanceProfileValidation(performanceProfilesMap).validate(performanceProfile); - if (validationOutputData.isSuccess()) - validationStatus = true; - else - new KubeEventLogger(Clock.systemUTC()).log("Failed", validationOutputData.getMessage(), EventLogger.Type.Warning, null, null, null, null); - } else - new KubeEventLogger(Clock.systemUTC()).log("Failed", "Validation of performance profile failed! ", EventLogger.Type.Warning, null, null, null, null); - } catch (Exception e) { - new KubeEventLogger(Clock.systemUTC()).log("Failed", e.getMessage(), EventLogger.Type.Warning, null, null, null, null); - } - return validationStatus; - } - - public static PerformanceProfile getPerformanceProfile(String performanceProfileObjectJsonStr) { - try { - JSONObject performanceProfileObjectJson = new JSONObject(performanceProfileObjectJsonStr); - JSONObject metadataJson = performanceProfileObjectJson - .getJSONObject(AnalyzerConstants.AutotuneObjectConstants.METADATA); - performanceProfileObjectJson.remove("apiversion"); - performanceProfileObjectJson.remove("kind"); - performanceProfileObjectJson.remove("metadata"); - - performanceProfileObjectJson.put("name",metadataJson.optString(AnalyzerConstants.PerformanceProfileConstants.PERF_PROFILE_NAME)); - PerformanceProfile performanceProfile = new Gson().fromJson(performanceProfileObjectJson.toString(), PerformanceProfile.class); - - return performanceProfile; - - } catch (NullPointerException | JSONException e) { - LOGGER.error("Exception occurred while parsing the data: {}",e.getMessage()); - return null; - } - } - - /** - * Delete the performance Profile object corresponding to the passed parameter - * - * @param performanceProfileObject - removes the Performance Profile object from the map - */ - private static void deleteExistingPerformanceProfile(String performanceProfileObject) { - JSONObject performanceProfileObjectJson = new JSONObject(performanceProfileObject); - String name = performanceProfileObjectJson.getJSONObject(AnalyzerConstants.AutotuneObjectConstants.METADATA) - .optString(AnalyzerConstants.AutotuneObjectConstants.NAME); - - performanceProfilesMap.remove(name); - LOGGER.info("Deleted performance profile object {}", name); - } -} diff --git a/src/main/java/com/autotune/analyzer/recommendations/engine/RecommendationEngine.java b/src/main/java/com/autotune/analyzer/recommendations/engine/RecommendationEngine.java index ad06a3d69..407dd60a0 100644 --- a/src/main/java/com/autotune/analyzer/recommendations/engine/RecommendationEngine.java +++ b/src/main/java/com/autotune/analyzer/recommendations/engine/RecommendationEngine.java @@ -61,7 +61,7 @@ public class RecommendationEngine { private final String intervalEndTimeStr; private final String intervalStartTimeStr; // TODO: to be used in future List recommendationModels; - private String performanceProfile; + private String metricProfile; private String experimentName; private Map terms; private KruizeObject kruizeObject; @@ -139,12 +139,12 @@ public List getModels() { return this.recommendationModels; } - public String getPerformanceProfile() { - return performanceProfile; + public String getMetricProfile() { + return metricProfile; } - public void setPerformanceProfile(String performanceProfile) { - this.performanceProfile = performanceProfile; + public void setMetricProfile(String metricProfile) { + this.metricProfile = metricProfile; } public String getExperimentName() { @@ -266,8 +266,8 @@ public KruizeObject prepareRecommendations(int calCount) { // set the default terms if the terms aren't provided by the user if (kruizeObject.getTerms() == null) KruizeObject.setDefaultTerms(terms, kruizeObject); - // set the performance profile - setPerformanceProfile(kruizeObject.getPerformanceProfile()); + // set the metric profile + setMetricProfile(kruizeObject.getMetricProfile()); // get the datasource // TODO: If no data source given use KruizeDeploymentInfo.monitoring_agent / default datasource String dataSource = kruizeObject.getDataSource(); diff --git a/src/main/java/com/autotune/analyzer/serviceObjects/Converters.java b/src/main/java/com/autotune/analyzer/serviceObjects/Converters.java index 489ac1b7e..3c1f0a0a0 100644 --- a/src/main/java/com/autotune/analyzer/serviceObjects/Converters.java +++ b/src/main/java/com/autotune/analyzer/serviceObjects/Converters.java @@ -5,7 +5,7 @@ import com.autotune.analyzer.kruizeObject.KruizeObject; import com.autotune.analyzer.kruizeObject.ObjectiveFunction; import com.autotune.analyzer.kruizeObject.SloInfo; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; +import com.autotune.analyzer.metricProfiles.MetricProfile; import com.autotune.analyzer.recommendations.ContainerRecommendations; import com.autotune.analyzer.recommendations.objects.MappedRecommendationForTimestamp; import com.autotune.analyzer.utils.AnalyzerConstants; @@ -27,7 +27,6 @@ import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -72,7 +71,7 @@ public static KruizeObject convertCreateExperimentAPIObjToKruizeObject(CreateExp kruizeObject.setTarget_cluster(createExperimentAPIObject.getTargetCluster()); kruizeObject.setClusterName(createExperimentAPIObject.getClusterName()); kruizeObject.setMode(createExperimentAPIObject.getMode()); - kruizeObject.setPerformanceProfile(createExperimentAPIObject.getPerformanceProfile()); + kruizeObject.setMetricProfile(createExperimentAPIObject.getPerformanceProfile()); kruizeObject.setDataSource(createExperimentAPIObject.getDatasource()); kruizeObject.setSloInfo(createExperimentAPIObject.getSloInfo()); kruizeObject.setTrial_settings(createExperimentAPIObject.getTrialSettings()); @@ -250,11 +249,11 @@ public static ExperimentResultData convertUpdateResultsAPIObjToExperimentResultD return experimentResultData; } - public static PerformanceProfile convertInputJSONToCreatePerfProfile(String inputData) throws InvalidValueException { - PerformanceProfile performanceProfile = null; + public static MetricProfile convertInputJSONToCreatePerfProfile(String inputData) throws InvalidValueException { + MetricProfile metricProfile = null; if (inputData != null) { JSONObject jsonObject = new JSONObject(inputData); - String perfProfileName = jsonObject.getString(AnalyzerConstants.AutotuneObjectConstants.NAME); + String metricProfileName = jsonObject.getString(AnalyzerConstants.AutotuneObjectConstants.NAME); Double profileVersion = jsonObject.has(AnalyzerConstants.PROFILE_VERSION) ? jsonObject.getDouble(AnalyzerConstants.PROFILE_VERSION) : null; String k8sType = jsonObject.has(AnalyzerConstants.PerformanceProfileConstants.K8S_TYPE) ? jsonObject.getString(AnalyzerConstants.PerformanceProfileConstants.K8S_TYPE) : null; JSONObject sloJsonObject = jsonObject.getJSONObject(AnalyzerConstants.AutotuneObjectConstants.SLO); @@ -285,9 +284,9 @@ public static PerformanceProfile convertInputJSONToCreatePerfProfile(String inpu String direction = sloJsonObject.has(AnalyzerConstants.AutotuneObjectConstants.DIRECTION) ? sloJsonObject.get(AnalyzerConstants.AutotuneObjectConstants.DIRECTION).toString() : null; ObjectiveFunction objectiveFunction = new Gson().fromJson(sloJsonObject.getJSONObject(AnalyzerConstants.AutotuneObjectConstants.OBJECTIVE_FUNCTION).toString(), ObjectiveFunction.class); SloInfo sloInfo = new SloInfo(sloClass, objectiveFunction, direction, functionVariablesList); - performanceProfile = new PerformanceProfile(perfProfileName, profileVersion, k8sType, sloInfo); + metricProfile = new MetricProfile(metricProfileName, profileVersion, k8sType, sloInfo); } - return performanceProfile; + return metricProfile; } public static ConcurrentHashMap ConvertUpdateResultDataToAPIResponse(ConcurrentHashMap mainKruizeExperimentMap) { diff --git a/src/main/java/com/autotune/analyzer/serviceObjects/UpdateResultsAPIObject.java b/src/main/java/com/autotune/analyzer/serviceObjects/UpdateResultsAPIObject.java index bfc646b48..103f2baad 100644 --- a/src/main/java/com/autotune/analyzer/serviceObjects/UpdateResultsAPIObject.java +++ b/src/main/java/com/autotune/analyzer/serviceObjects/UpdateResultsAPIObject.java @@ -19,7 +19,7 @@ import com.autotune.analyzer.kruizeObject.KruizeObject; import com.autotune.analyzer.serviceObjects.verification.annotators.CompareDate; import com.autotune.analyzer.serviceObjects.verification.annotators.KubernetesElementsCheck; -import com.autotune.analyzer.serviceObjects.verification.annotators.PerformanceProfileCheck; +import com.autotune.analyzer.serviceObjects.verification.annotators.MetricProfileCheck; import com.autotune.analyzer.serviceObjects.verification.annotators.TimeDifferenceCheck; import com.autotune.analyzer.utils.AnalyzerErrorConstants; import com.autotune.utils.KruizeConstants; @@ -33,7 +33,7 @@ @CompareDate(groups = BaseSO.InitialValidation.class, message = AnalyzerErrorConstants.AutotuneObjectErrors.WRONG_TIMESTAMP) @TimeDifferenceCheck(groups = UpdateResultsAPIObject.EvaluateRemainingConstraints.class, message = AnalyzerErrorConstants.AutotuneObjectErrors.MEASUREMENT_DURATION_ERROR) -@PerformanceProfileCheck(groups = UpdateResultsAPIObject.EvaluatePerformanceProfileConstraints.class) +@MetricProfileCheck(groups = UpdateResultsAPIObject.EvaluatePerformanceProfileConstraints.class) @KubernetesElementsCheck(groups = UpdateResultsAPIObject.EvaluateRemainingConstraints.class) public class UpdateResultsAPIObject extends BaseSO { diff --git a/src/main/java/com/autotune/analyzer/serviceObjects/verification/annotators/PerformanceProfileCheck.java b/src/main/java/com/autotune/analyzer/serviceObjects/verification/annotators/MetricProfileCheck.java similarity index 89% rename from src/main/java/com/autotune/analyzer/serviceObjects/verification/annotators/PerformanceProfileCheck.java rename to src/main/java/com/autotune/analyzer/serviceObjects/verification/annotators/MetricProfileCheck.java index be562fd09..342f17655 100644 --- a/src/main/java/com/autotune/analyzer/serviceObjects/verification/annotators/PerformanceProfileCheck.java +++ b/src/main/java/com/autotune/analyzer/serviceObjects/verification/annotators/MetricProfileCheck.java @@ -15,7 +15,7 @@ *******************************************************************************/ package com.autotune.analyzer.serviceObjects.verification.annotators; -import com.autotune.analyzer.serviceObjects.verification.validators.PerformanceProfileValidator; +import com.autotune.analyzer.serviceObjects.verification.validators.MetricProfileValidator; import jakarta.validation.Constraint; import jakarta.validation.Payload; @@ -23,9 +23,9 @@ @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = PerformanceProfileValidator.class) +@Constraint(validatedBy = MetricProfileValidator.class) @Documented -public @interface PerformanceProfileCheck { +public @interface MetricProfileCheck { String message() default ""; Class[] groups() default {}; diff --git a/src/main/java/com/autotune/analyzer/serviceObjects/verification/validators/PerformanceProfileValidator.java b/src/main/java/com/autotune/analyzer/serviceObjects/verification/validators/MetricProfileValidator.java similarity index 70% rename from src/main/java/com/autotune/analyzer/serviceObjects/verification/validators/PerformanceProfileValidator.java rename to src/main/java/com/autotune/analyzer/serviceObjects/verification/validators/MetricProfileValidator.java index abb80e1ae..19f4ba19d 100644 --- a/src/main/java/com/autotune/analyzer/serviceObjects/verification/validators/PerformanceProfileValidator.java +++ b/src/main/java/com/autotune/analyzer/serviceObjects/verification/validators/MetricProfileValidator.java @@ -16,10 +16,10 @@ package com.autotune.analyzer.serviceObjects.verification.validators; import com.autotune.analyzer.kruizeObject.KruizeObject; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.utils.PerformanceProfileUtil; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.utils.MetricProfileUtil; import com.autotune.analyzer.serviceObjects.UpdateResultsAPIObject; -import com.autotune.analyzer.serviceObjects.verification.annotators.PerformanceProfileCheck; +import com.autotune.analyzer.serviceObjects.verification.annotators.MetricProfileCheck; import com.autotune.analyzer.services.UpdateResults; import com.autotune.database.service.ExperimentDBService; import jakarta.validation.ConstraintValidator; @@ -34,11 +34,11 @@ import static com.autotune.analyzer.utils.AnalyzerErrorConstants.AutotuneObjectErrors.MISSING_PERF_PROFILE; -public class PerformanceProfileValidator implements ConstraintValidator { - private static final Logger LOGGER = LoggerFactory.getLogger(PerformanceProfileValidator.class); +public class MetricProfileValidator implements ConstraintValidator { + private static final Logger LOGGER = LoggerFactory.getLogger(MetricProfileValidator.class); @Override - public void initialize(PerformanceProfileCheck constraintAnnotation) { + public void initialize(MetricProfileCheck constraintAnnotation) { } @Override @@ -46,31 +46,31 @@ public boolean isValid(UpdateResultsAPIObject updateResultsAPIObject, Constraint LOGGER.debug("PerformanceProfileValidator expName - {} - {} - {}", updateResultsAPIObject.getExperimentName(), updateResultsAPIObject.getStartTimestamp(), updateResultsAPIObject.getEndTimestamp()); boolean success = false; /* - Fetch the performance profile from the Map corresponding to the name in the kruize object, - and then validate the Performance Profile data + Fetch the metric profile from the Map corresponding to the name in the kruize object, + and then validate the Metric Profile data */ try { KruizeObject kruizeObject = updateResultsAPIObject.getKruizeObject(); - if (UpdateResults.performanceProfilesMap.isEmpty() || !UpdateResults.performanceProfilesMap.containsKey(kruizeObject.getPerformanceProfile())) { - ConcurrentHashMap tempPerformanceProfilesMap = new ConcurrentHashMap<>(); - new ExperimentDBService().loadAllPerformanceProfiles(tempPerformanceProfilesMap); - UpdateResults.performanceProfilesMap.putAll(tempPerformanceProfilesMap); + if (UpdateResults.metricProfilesMap.isEmpty() || !UpdateResults.metricProfilesMap.containsKey(kruizeObject.getMetricProfile())) { + ConcurrentHashMap tempMetricProfilesMap = new ConcurrentHashMap<>(); + new ExperimentDBService().loadAllPerformanceProfiles(tempMetricProfilesMap); + UpdateResults.metricProfilesMap.putAll(tempMetricProfilesMap); } - PerformanceProfile performanceProfile = null; - if (UpdateResults.performanceProfilesMap.containsKey(kruizeObject.getPerformanceProfile())) { - performanceProfile = UpdateResults.performanceProfilesMap.get(kruizeObject.getPerformanceProfile()); + MetricProfile metricProfile = null; + if (UpdateResults.metricProfilesMap.containsKey(kruizeObject.getMetricProfile())) { + metricProfile = UpdateResults.metricProfilesMap.get(kruizeObject.getMetricProfile()); } else { - throw new Exception(String.format("%s%s", MISSING_PERF_PROFILE, kruizeObject.getPerformanceProfile())); + throw new Exception(String.format("%s%s", MISSING_PERF_PROFILE, kruizeObject.getMetricProfile())); } // validate the results value present in the updateResultsAPIObject - List errorMsg = PerformanceProfileUtil.validateResults(performanceProfile, updateResultsAPIObject); + List errorMsg = MetricProfileUtil.validateResults(metricProfile, updateResultsAPIObject); if (errorMsg.isEmpty()) { success = true; } else { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(errorMsg.toString()) - .addPropertyNode("Performance profile") + .addPropertyNode("Metric profile") .addConstraintViolation(); } diff --git a/src/main/java/com/autotune/analyzer/services/PerformanceProfileService.java b/src/main/java/com/autotune/analyzer/services/PerformanceProfileService.java index 71be6267e..3161f1d9c 100644 --- a/src/main/java/com/autotune/analyzer/services/PerformanceProfileService.java +++ b/src/main/java/com/autotune/analyzer/services/PerformanceProfileService.java @@ -18,8 +18,8 @@ import com.autotune.analyzer.exceptions.InvalidValueException; import com.autotune.analyzer.exceptions.PerformanceProfileResponse; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.utils.PerformanceProfileUtil; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.utils.MetricProfileUtil; import com.autotune.analyzer.serviceObjects.Converters; import com.autotune.analyzer.utils.AnalyzerConstants; import com.autotune.analyzer.utils.AnalyzerErrorConstants; @@ -60,12 +60,12 @@ public class PerformanceProfileService extends HttpServlet { @Serial private static final long serialVersionUID = 1L; private static final Logger LOGGER = LoggerFactory.getLogger(PerformanceProfileService.class); - private ConcurrentHashMap performanceProfilesMap; + private ConcurrentHashMap performanceProfilesMap; @Override public void init(ServletConfig config) throws ServletException { super.init(config); - performanceProfilesMap = (ConcurrentHashMap) getServletContext() + performanceProfilesMap = (ConcurrentHashMap) getServletContext() .getAttribute(AnalyzerConstants.PerformanceProfileConstants.PERF_PROFILE_MAP); } @@ -79,10 +79,10 @@ public void init(ServletConfig config) throws ServletException { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { try { - Map performanceProfilesMap = new ConcurrentHashMap<>(); + Map performanceProfilesMap = new ConcurrentHashMap<>(); String inputData = request.getReader().lines().collect(Collectors.joining()); - PerformanceProfile performanceProfile = Converters.KruizeObjectConverters.convertInputJSONToCreatePerfProfile(inputData); - ValidationOutputData validationOutputData = PerformanceProfileUtil.validateAndAddProfile(performanceProfilesMap, performanceProfile); + MetricProfile performanceProfile = Converters.KruizeObjectConverters.convertInputJSONToCreatePerfProfile(inputData); + ValidationOutputData validationOutputData = MetricProfileUtil.validateAndAddProfile(performanceProfilesMap, performanceProfile); if (validationOutputData.isSuccess()) { ValidationOutputData addedToDB = new ExperimentDBService().addPerformanceProfileToDB(performanceProfile); if (addedToDB.isSuccess()) { @@ -124,7 +124,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse response) throw LOGGER.error("Failed to load saved experiment data: {} ", e.getMessage()); } if (performanceProfilesMap.size() > 0) { - Collection values = performanceProfilesMap.values(); + Collection values = performanceProfilesMap.values(); Gson gsonObj = new GsonBuilder() .disableHtmlEscaping() .setPrettyPrinting() diff --git a/src/main/java/com/autotune/analyzer/services/UpdateResults.java b/src/main/java/com/autotune/analyzer/services/UpdateResults.java index 7ae38192e..480b685c3 100644 --- a/src/main/java/com/autotune/analyzer/services/UpdateResults.java +++ b/src/main/java/com/autotune/analyzer/services/UpdateResults.java @@ -18,7 +18,7 @@ import com.autotune.analyzer.exceptions.KruizeResponse; import com.autotune.analyzer.experiment.ExperimentInitiator; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; +import com.autotune.analyzer.metricProfiles.MetricProfile; import com.autotune.analyzer.serviceObjects.FailedUpdateResultsAPIObject; import com.autotune.analyzer.serviceObjects.UpdateResultsAPIObject; import com.autotune.analyzer.utils.AnalyzerConstants; @@ -55,7 +55,7 @@ public class UpdateResults extends HttpServlet { private static final long serialVersionUID = 1L; private static final Logger LOGGER = LoggerFactory.getLogger(UpdateResults.class); - public static ConcurrentHashMap performanceProfilesMap = new ConcurrentHashMap<>(); + public static ConcurrentHashMap metricProfilesMap = new ConcurrentHashMap<>(); private static int requestCount = 0; @Override diff --git a/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java b/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java index 1909fb83d..1f18e5152 100644 --- a/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java +++ b/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java @@ -21,8 +21,8 @@ import com.autotune.analyzer.application.Tunable; import com.autotune.analyzer.kruizeLayer.KruizeLayer; import com.autotune.analyzer.kruizeObject.KruizeObject; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.MetricProfilesDeployment; import com.autotune.common.data.metrics.Metric; import com.autotune.common.data.result.ContainerData; import com.autotune.common.k8sObjects.K8sObject; @@ -52,12 +52,12 @@ private ServiceHelpers() { * @param kruizeObject */ public static void addExperimentDetails(JSONObject experimentJson, KruizeObject kruizeObject) { - PerformanceProfile performanceProfile = PerformanceProfilesDeployment.performanceProfilesMap - .get(kruizeObject.getPerformanceProfile()); + MetricProfile metricProfile = MetricProfilesDeployment.metricProfilesMap + .get(kruizeObject.getMetricProfile()); experimentJson.put(AnalyzerConstants.ServiceConstants.EXPERIMENT_NAME, kruizeObject.getExperimentName()); - experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.DIRECTION, performanceProfile.getSloInfo().getDirection()); - experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.OBJECTIVE_FUNCTION, performanceProfile.getSloInfo().getObjectiveFunction()); - experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.SLO_CLASS, performanceProfile.getSloInfo().getSloClass()); + experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.DIRECTION, metricProfile.getSloInfo().getDirection()); + experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.OBJECTIVE_FUNCTION, metricProfile.getSloInfo().getObjectiveFunction()); + experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.SLO_CLASS, metricProfile.getSloInfo().getSloClass()); experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.EXPERIMENT_ID, kruizeObject.getExperiment_id()); experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.HPO_ALGO_IMPL, kruizeObject.getHpoAlgoImpl()); experimentJson.put(AnalyzerConstants.AutotuneObjectConstants.NAMESPACE, kruizeObject.getNamespace()); @@ -163,9 +163,9 @@ public static void addLayerTunableDetails(JSONArray tunablesArray, KruizeLayer k public static void addFunctionVariablesDetails(JSONObject funcVarJson, KruizeObject kruizeObject) { // Add function_variables info JSONArray functionVariablesArray = new JSONArray(); - PerformanceProfile performanceProfile = PerformanceProfilesDeployment.performanceProfilesMap - .get(kruizeObject.getPerformanceProfile()); - for (Metric functionVariable : performanceProfile.getSloInfo().getFunctionVariables()) { + MetricProfile metricProfile = MetricProfilesDeployment.metricProfilesMap + .get(kruizeObject.getMetricProfile()); + for (Metric functionVariable : metricProfile.getSloInfo().getFunctionVariables()) { JSONObject functionVariableJson = new JSONObject(); functionVariableJson.put(AnalyzerConstants.AutotuneObjectConstants.NAME, functionVariable.getName()); functionVariableJson.put(AnalyzerConstants.AutotuneObjectConstants.VALUE_TYPE, functionVariable.getValueType()); diff --git a/src/main/java/com/autotune/database/helper/DBHelpers.java b/src/main/java/com/autotune/database/helper/DBHelpers.java index 8bae35c82..9964abc91 100644 --- a/src/main/java/com/autotune/database/helper/DBHelpers.java +++ b/src/main/java/com/autotune/database/helper/DBHelpers.java @@ -19,7 +19,7 @@ import com.autotune.analyzer.exceptions.InvalidConversionOfRecommendationEntryException; import com.autotune.analyzer.kruizeObject.KruizeObject; import com.autotune.analyzer.kruizeObject.SloInfo; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; +import com.autotune.analyzer.metricProfiles.MetricProfile; import com.autotune.analyzer.recommendations.ContainerRecommendations; import com.autotune.analyzer.recommendations.objects.MappedRecommendationForTimestamp; import com.autotune.analyzer.serviceObjects.*; @@ -609,7 +609,7 @@ public static List convertRecommendationEntryToRec return listRecommendationsAPIObjectList; } - public static KruizePerformanceProfileEntry convertPerfProfileObjToPerfProfileDBObj(PerformanceProfile performanceProfile) { + public static KruizePerformanceProfileEntry convertPerfProfileObjToPerfProfileDBObj(MetricProfile performanceProfile) { KruizePerformanceProfileEntry kruizePerformanceProfileEntry = null; try { kruizePerformanceProfileEntry = new KruizePerformanceProfileEntry(); @@ -631,8 +631,8 @@ public static KruizePerformanceProfileEntry convertPerfProfileObjToPerfProfileDB return kruizePerformanceProfileEntry; } - public static List convertPerformanceProfileEntryToPerformanceProfileObject(List entries) throws Exception { - List performanceProfiles = new ArrayList<>(); + public static List convertPerformanceProfileEntryToPerformanceProfileObject(List entries) throws Exception { + List performanceProfiles = new ArrayList<>(); int failureThreshHold = entries.size(); int failureCount = 0; for (KruizePerformanceProfileEntry entry : entries) { @@ -640,7 +640,7 @@ public static List convertPerformanceProfileEntryToPerforman JsonNode sloData = entry.getSlo(); String slo_rawJson = sloData.toString(); SloInfo sloInfo = new Gson().fromJson(slo_rawJson, SloInfo.class); - PerformanceProfile performanceProfile = new PerformanceProfile( + MetricProfile performanceProfile = new MetricProfile( entry.getName(), entry.getProfile_version(), entry.getK8s_type(), sloInfo); performanceProfiles.add(performanceProfile); } catch (Exception e) { diff --git a/src/main/java/com/autotune/database/service/ExperimentDBService.java b/src/main/java/com/autotune/database/service/ExperimentDBService.java index 005107ba6..0c9d18bcd 100644 --- a/src/main/java/com/autotune/database/service/ExperimentDBService.java +++ b/src/main/java/com/autotune/database/service/ExperimentDBService.java @@ -19,8 +19,8 @@ import com.autotune.analyzer.experiment.ExperimentInterface; import com.autotune.analyzer.experiment.ExperimentInterfaceImpl; import com.autotune.analyzer.kruizeObject.KruizeObject; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.utils.PerformanceProfileUtil; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.utils.MetricProfileUtil; import com.autotune.analyzer.serviceObjects.*; import com.autotune.analyzer.utils.AnalyzerConstants; import com.autotune.common.data.ValidationOutputData; @@ -127,14 +127,14 @@ public void loadAllRecommendations(Map mainKruizeExperimen } } - public void loadAllPerformanceProfiles(Map performanceProfileMap) throws Exception { + public void loadAllPerformanceProfiles(Map performanceProfileMap) throws Exception { if (performanceProfileMap.isEmpty()) { List entries = experimentDAO.loadAllPerformanceProfiles(); if (null != entries && !entries.isEmpty()) { - List performanceProfiles = DBHelpers.Converters.KruizeObjectConverters.convertPerformanceProfileEntryToPerformanceProfileObject(entries); + List performanceProfiles = DBHelpers.Converters.KruizeObjectConverters.convertPerformanceProfileEntryToPerformanceProfileObject(entries); if (!performanceProfiles.isEmpty()) { performanceProfiles.forEach(performanceProfile -> - PerformanceProfileUtil.addPerformanceProfile(performanceProfileMap, performanceProfile)); + MetricProfileUtil.addMetricProfile(performanceProfileMap, performanceProfile)); } } } @@ -260,7 +260,7 @@ public ValidationOutputData addRecommendationToDB(Map expe return validationOutputData; } - public ValidationOutputData addPerformanceProfileToDB(PerformanceProfile performanceProfile) { + public ValidationOutputData addPerformanceProfileToDB(MetricProfile performanceProfile) { ValidationOutputData validationOutputData = new ValidationOutputData(false, null, null); try { KruizePerformanceProfileEntry kruizePerformanceProfileEntry = DBHelpers.Converters.KruizeObjectConverters.convertPerfProfileObjToPerfProfileDBObj(performanceProfile); @@ -346,15 +346,15 @@ public void loadExperimentAndRecommendationsFromDBByName(Map performanceProfileMap, String performanceProfileName) throws Exception { + public void loadPerformanceProfileFromDBByName(Map performanceProfileMap, String performanceProfileName) throws Exception { List entries = experimentDAO.loadPerformanceProfileByName(performanceProfileName); if (null != entries && !entries.isEmpty()) { - List performanceProfiles = DBHelpers.Converters.KruizeObjectConverters + List performanceProfiles = DBHelpers.Converters.KruizeObjectConverters .convertPerformanceProfileEntryToPerformanceProfileObject(entries); if (!performanceProfiles.isEmpty()) { - for (PerformanceProfile performanceProfile : performanceProfiles) { + for (MetricProfile performanceProfile : performanceProfiles) { if (null != performanceProfile) { - PerformanceProfileUtil.addPerformanceProfile(performanceProfileMap, performanceProfile); + MetricProfileUtil.addMetricProfile(performanceProfileMap, performanceProfile); } } } diff --git a/src/main/java/com/autotune/operator/KruizeOperator.java b/src/main/java/com/autotune/operator/KruizeOperator.java index 61f77da25..7a7f79ceb 100644 --- a/src/main/java/com/autotune/operator/KruizeOperator.java +++ b/src/main/java/com/autotune/operator/KruizeOperator.java @@ -25,9 +25,9 @@ import com.autotune.analyzer.kruizeObject.KruizeObject; import com.autotune.analyzer.kruizeObject.SelectorInfo; import com.autotune.analyzer.kruizeObject.SloInfo; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment; -import com.autotune.analyzer.performanceProfiles.utils.PerformanceProfileUtil; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.MetricProfilesDeployment; +import com.autotune.analyzer.metricProfiles.utils.MetricProfileUtil; import com.autotune.analyzer.utils.AnalyzerConstants; import com.autotune.analyzer.utils.AnalyzerConstants.AutotuneConfigConstants; import com.autotune.analyzer.utils.AnalyzerErrorConstants; @@ -364,7 +364,7 @@ private static KruizeObject getKruizeObject(String autotuneObjectJsonStr) { throw new SloClassNotSupportedException(AnalyzerErrorConstants.AutotuneObjectErrors.SLO_REDUNDANCY_ERROR); } else { // check if the Performance profile with the given name exist - if (null == PerformanceProfilesDeployment.performanceProfilesMap.get(perfProfileName)) { + if (null == MetricProfilesDeployment.metricProfilesMap.get(perfProfileName)) { throw new SloClassNotSupportedException(AnalyzerErrorConstants.AutotuneObjectErrors.MISSING_PERF_PROFILE + perfProfileName); } } @@ -425,15 +425,15 @@ private static KruizeObject getKruizeObject(String autotuneObjectJsonStr) { } public static String setDefaultPerformanceProfile(SloInfo sloInfo, String mode, String targetCluster) { - PerformanceProfile performanceProfile = null; + MetricProfile performanceProfile = null; try { String name = AnalyzerConstants.PerformanceProfileConstants.DEFAULT_PROFILE; double profile_version = AnalyzerConstants.DEFAULT_PROFILE_VERSION; String k8s_type = AnalyzerConstants.DEFAULT_K8S_TYPE; - performanceProfile = new PerformanceProfile(name, profile_version, k8s_type, sloInfo); + performanceProfile = new MetricProfile(name, profile_version, k8s_type, sloInfo); if (null != performanceProfile) { - ValidationOutputData validationOutputData = PerformanceProfileUtil.validateAndAddProfile(PerformanceProfilesDeployment.performanceProfilesMap, performanceProfile); + ValidationOutputData validationOutputData = MetricProfileUtil.validateAndAddProfile(MetricProfilesDeployment.metricProfilesMap, performanceProfile); if (validationOutputData.isSuccess()) { LOGGER.info("Added Performance Profile : {} into the map with version: {}", performanceProfile.getName(), performanceProfile.getProfile_version()); diff --git a/src/main/java/com/autotune/service/InitiateListener.java b/src/main/java/com/autotune/service/InitiateListener.java index 9fff47d27..2be64895e 100644 --- a/src/main/java/com/autotune/service/InitiateListener.java +++ b/src/main/java/com/autotune/service/InitiateListener.java @@ -15,7 +15,7 @@ *******************************************************************************/ package com.autotune.service; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; +import com.autotune.analyzer.metricProfiles.MetricProfile; import com.autotune.analyzer.utils.AnalyzerConstants; import com.autotune.common.parallelengine.executor.KruizeExecutor; import com.autotune.common.parallelengine.queue.KruizeQueue; @@ -149,7 +149,7 @@ public void run() { /* Kruize Performance Profile configuration */ - ConcurrentHashMap performanceProfilesMap = new ConcurrentHashMap<>(); + ConcurrentHashMap performanceProfilesMap = new ConcurrentHashMap<>(); try { new ExperimentDBService().loadAllPerformanceProfiles(performanceProfilesMap); } catch (Exception e) { diff --git a/src/main/java/com/autotune/utils/TrialHelpers.java b/src/main/java/com/autotune/utils/TrialHelpers.java index 78cb6b430..81e0fd525 100644 --- a/src/main/java/com/autotune/utils/TrialHelpers.java +++ b/src/main/java/com/autotune/utils/TrialHelpers.java @@ -23,8 +23,8 @@ import com.autotune.analyzer.kruizeLayer.layers.Layer; import com.autotune.analyzer.kruizeObject.KruizeObject; import com.autotune.analyzer.kruizeObject.SloInfo; -import com.autotune.analyzer.performanceProfiles.PerformanceProfile; -import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment; +import com.autotune.analyzer.metricProfiles.MetricProfile; +import com.autotune.analyzer.metricProfiles.MetricProfilesDeployment; import com.autotune.common.annotations.json.KruizeJSONExclusionStrategy; import com.autotune.common.data.metrics.Metric; import com.autotune.common.data.metrics.MetricResults; @@ -186,8 +186,8 @@ public static ExperimentTrial createDefaultExperimentTrial(int trialNumber, ContainerConfigData configData = new ContainerConfigData(); HashMap podMetricsHashMap = new HashMap<>(); HashMap> containerMetricsHashMap = new HashMap<>(); - PerformanceProfile performanceProfile = PerformanceProfilesDeployment.performanceProfilesMap - .get(kruizeObject.getPerformanceProfile()); + MetricProfile performanceProfile = MetricProfilesDeployment.metricProfilesMap + .get(kruizeObject.getMetricProfile()); SloInfo sloInfo = performanceProfile.getSloInfo(); for (Metric metric : sloInfo.getFunctionVariables()) { podMetricsHashMap.put(metric.getName(), metric);