Skip to content

Commit

Permalink
Merge branch 'mvp_demo' into adding-updater-abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhar316 committed Dec 9, 2024
2 parents 9e1d5e0 + ead46b3 commit 9bdc3fb
Show file tree
Hide file tree
Showing 27 changed files with 674 additions and 258 deletions.
6 changes: 6 additions & 0 deletions design/KruizeConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,9 @@ The following environment variables are set using the `kubectl apply` command wi
- Value: "true"
- Details: This flag is added for getting the details of the inputs passed to the APIs and the corresponding response
generated by it. This helps us in debugging the API easily in case of failures.
- **isROSEnabled**
- Description: This flag enables the remote APIs such a updateResults and the corresponding DB Tables. If set to false, the corresponding APIs and the DB tables are not supported.
- value: "false"
- Details:
- Default value: False.
Bulk API functionality is supported when the value is set to either True or False.
4 changes: 3 additions & 1 deletion migrations/kruize_local_ddl.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
create table IF NOT EXISTS kruize_lm_experiments (experiment_id varchar(255) not null, cluster_name varchar(255), experiment_name varchar(255), extended_data jsonb, meta_data jsonb, mode varchar(255), performance_profile varchar(255), status varchar(255), target_cluster varchar(255), version varchar(255),experiment_type varchar(255),datasource varchar(255),creation_date timestamp(6) ,updated_date timestamp(6) , primary key (experiment_id));
create table IF NOT EXISTS kruize_authentication (id serial, authentication_type varchar(255), credentials jsonb, service_type varchar(255), primary key (id));
create table IF NOT EXISTS kruize_datasources (version varchar(255), name varchar(255), provider varchar(255), serviceName varchar(255), namespace varchar(255), url varchar(255), authentication_id serial, FOREIGN KEY (authentication_id) REFERENCES kruize_authentication(id), primary key (name));
create table IF NOT EXISTS kruize_dsmetadata (id serial, version varchar(255), datasource_name varchar(255), cluster_name varchar(255), namespace varchar(255), workload_type varchar(255), workload_name varchar(255), container_name varchar(255), container_image_name varchar(255), primary key (id));
alter table kruize_experiments add column experiment_type varchar(255), add column metadata_id bigint references kruize_dsmetadata(id), alter column datasource type varchar(255);
alter table kruize_lm_experiments add column metadata_id bigint references kruize_dsmetadata(id);
alter table if exists kruize_lm_experiments add constraint UK_lm_experiment_name unique (experiment_name);
create table IF NOT EXISTS kruize_metric_profiles (api_version varchar(255), kind varchar(255), metadata jsonb, name varchar(255) not null, k8s_type varchar(255), profile_version float(53) not null, slo jsonb, primary key (name));
alter table kruize_recommendations add column experiment_type varchar(255);
1 change: 1 addition & 0 deletions src/main/java/com/autotune/Autotune.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static void main(String[] args) {
InitializeDeployment.setup_deployment_info();
// Configure AWS CloudWatch
CloudWatchAppender.configureLoggerForCloudWatchLog();
LOGGER.info("ROS enabled : {}" ,KruizeDeploymentInfo.is_ros_enabled);
// Read and execute the DDLs here
executeDDLs(AnalyzerConstants.ROS_DDL_SQL);
if (KruizeDeploymentInfo.local == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.autotune.analyzer.kruizeObject.KruizeObject;
import com.autotune.analyzer.performanceProfiles.PerformanceProfile;
import com.autotune.analyzer.performanceProfiles.PerformanceProfilesDeployment;
import com.autotune.analyzer.recommendations.ContainerRecommendations;
import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.analyzer.utils.AnalyzerErrorConstants;
Expand Down Expand Up @@ -90,7 +89,11 @@ public void validate(List<KruizeObject> kruizeExptList) {
if (validationOutputData.isSuccess()) {
String expName = kruizeObject.getExperimentName();
try {
new ExperimentDBService().loadExperimentFromDBByName(mainKruizeExperimentMAP, expName);
if (KruizeDeploymentInfo.is_ros_enabled && kruizeObject.getTarget_cluster().equalsIgnoreCase(AnalyzerConstants.REMOTE)) { // todo call this in function and use across every where
new ExperimentDBService().loadExperimentFromDBByName(mainKruizeExperimentMAP, expName);
} else {
new ExperimentDBService().loadLMExperimentFromDBByName(mainKruizeExperimentMAP, expName);
}
} catch (Exception e) {
LOGGER.error("Loading saved experiment {} failed: {} ", expName, e.getMessage());
}
Expand All @@ -108,7 +111,7 @@ public void validate(List<KruizeObject> kruizeExptList) {
} else {
// fetch the Performance / Metric Profile from the DB
try {
if (!KruizeDeploymentInfo.local) {
if (KruizeDeploymentInfo.is_ros_enabled && target_cluster.equalsIgnoreCase(AnalyzerConstants.REMOTE)) { // todo call this in function and use across every where
new ExperimentDBService().loadPerformanceProfileFromDBByName(performanceProfilesMap, kruizeObject.getPerformanceProfile());
} else {
new ExperimentDBService().loadMetricProfileFromDBByName(performanceProfilesMap, kruizeObject.getPerformanceProfile());
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class KruizeObject implements ExperimentTypeAware {
@SerializedName("datasource")
private String datasource;
@SerializedName(KruizeConstants.JSONKeys.EXPERIMENT_TYPE) //TODO: to be used in future
private String experimentType;
private AnalyzerConstants.ExperimentType experimentType;
private String namespace; // TODO: Currently adding it at this level with an assumption that there is only one entry in k8s object needs to be changed
private String mode; //Todo convert into Enum
@SerializedName("target_cluster")
Expand Down Expand Up @@ -122,10 +122,10 @@ public KruizeObject() {
* Sets default terms for a KruizeObject.
* This method initializes a map with predefined terms like "SHORT_TERM", "MEDIUM_TERM", and "LONG_TERM".
* Each term is defined by a Terms object containing: Name of the term (e.g., "SHORT_TERM"), Duration (in days) to
be considered under that term, Threshold for the duration.
be considered under that term, Threshold for the duration.
* Note: Currently, specific term names like "daily", "weekly", and "fortnightly" are not defined.
* This method also requires implementing CustomResourceDefinition yaml for managing terms. This
functionality is not currently included.
functionality is not currently included.
@param terms A map to store the default terms with term name as the key and Terms object as the value.
@param kruizeObject The KruizeObject for which the default terms are being set.
*/
Expand Down Expand Up @@ -301,24 +301,14 @@ public void setDataSource(String datasource) {
this.datasource = datasource;
}

@Override
public String getExperimentType() {
public AnalyzerConstants.ExperimentType getExperimentType() {
return experimentType;
}

public void setExperimentType(String experimentType) {
public void setExperimentType(AnalyzerConstants.ExperimentType experimentType) {
this.experimentType = experimentType;
}

@Override
public boolean isNamespaceExperiment() {
return ExperimentTypeUtil.isNamespaceExperiment(experimentType);
}

@Override
public boolean isContainerExperiment() {
return ExperimentTypeUtil.isContainerExperiment(experimentType);
}

@Override
public String toString() {
Expand Down Expand Up @@ -347,4 +337,14 @@ public String toString() {
", kubernetes_objects=" + kubernetes_objects +
'}';
}

@Override
public boolean isNamespaceExperiment() {
return ExperimentTypeUtil.isNamespaceExperiment(experimentType);
}

@Override
public boolean isContainerExperiment() {
return ExperimentTypeUtil.isContainerExperiment(experimentType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,21 @@ public void setKruizeObject(KruizeObject kruizeObject) {
this.kruizeObject = kruizeObject;
}

private KruizeObject createKruizeObject() {
private KruizeObject createKruizeObject(String target_cluster) {
Map<String, KruizeObject> mainKruizeExperimentMAP = new ConcurrentHashMap<>();
KruizeObject kruizeObject = new KruizeObject();
try {
new ExperimentDBService().loadExperimentFromDBByName(mainKruizeExperimentMAP, experimentName);

if (KruizeDeploymentInfo.is_ros_enabled){
if(null == target_cluster || target_cluster.equalsIgnoreCase(AnalyzerConstants.REMOTE)){
new ExperimentDBService().loadExperimentFromDBByName(mainKruizeExperimentMAP, experimentName);
}else{
new ExperimentDBService().loadLMExperimentFromDBByName(mainKruizeExperimentMAP, experimentName);
}
}else{
new ExperimentDBService().loadLMExperimentFromDBByName(mainKruizeExperimentMAP, experimentName);
}

if (null != mainKruizeExperimentMAP.get(experimentName)) {
kruizeObject = mainKruizeExperimentMAP.get(experimentName);
kruizeObject.setValidation_data(new ValidationOutputData(true, null, null));
Expand Down Expand Up @@ -259,7 +269,7 @@ public String validate_local() { //TODO Instead of relying on the 'lo
* @param calCount The count of incoming requests.
* @return The KruizeObject containing the prepared recommendations.
*/
public KruizeObject prepareRecommendations(int calCount) throws FetchMetricsError {
public KruizeObject prepareRecommendations(int calCount, String target_cluster) throws FetchMetricsError {
Map<String, KruizeObject> mainKruizeExperimentMAP = new ConcurrentHashMap<>();
Map<String, Terms> terms = new HashMap<>();
ValidationOutputData validationOutputData;
Expand All @@ -269,7 +279,7 @@ public KruizeObject prepareRecommendations(int calCount) throws FetchMetricsErro
intervalEndTimeStr);
setInterval_end_time(interval_end_time);
}
KruizeObject kruizeObject = createKruizeObject();
KruizeObject kruizeObject = createKruizeObject(target_cluster);
if (!kruizeObject.getValidation_data().isSuccess())
return kruizeObject;
setKruizeObject(kruizeObject);
Expand Down Expand Up @@ -2388,7 +2398,7 @@ private void prepareIntervalResults(Map<Timestamp, IntervalResults> dataResultsM
* @param maxDateQuery maxDateQuery metric to be filtered out
* @param experimentType experiment type
*/
public List<Metric> filterMetricsBasedOnExpTypeAndK8sObject(PerformanceProfile metricProfile, String maxDateQuery, String experimentType) {
public List<Metric> filterMetricsBasedOnExpTypeAndK8sObject(PerformanceProfile metricProfile, String maxDateQuery, AnalyzerConstants.ExperimentType experimentType) {
String namespace = KruizeConstants.JSONKeys.NAMESPACE;
String container = KruizeConstants.JSONKeys.CONTAINER;
return metricProfile.getSloInfo().getFunctionVariables().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import com.autotune.analyzer.recommendations.NamespaceRecommendations;
import com.autotune.analyzer.recommendations.objects.MappedRecommendationForTimestamp;
import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.analyzer.utils.AnalyzerErrorConstants;
import com.autotune.analyzer.utils.ExperimentTypeUtil;
import com.autotune.common.data.ValidationOutputData;
import com.autotune.common.data.metrics.AggregationFunctions;
import com.autotune.common.data.metrics.Metric;
Expand All @@ -23,6 +21,8 @@
import com.autotune.common.k8sObjects.K8sObject;
import com.autotune.utils.KruizeConstants;
import com.autotune.utils.Utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.Gson;
import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -31,12 +31,9 @@

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;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class Converters {
private Converters() {
Expand Down Expand Up @@ -70,7 +67,7 @@ public static KruizeObject convertCreateExperimentAPIObjToKruizeObject(CreateExp
// namespace recommendations experiment type
k8sObject = createNamespaceExperiment(kubernetesAPIObject);
}
LOGGER.debug("Experiment Type: " + createExperimentAPIObject.getExperimentType());
LOGGER.debug("Experiment Type: {}", createExperimentAPIObject.getExperimentType());
k8sObjectList.add(k8sObject);
}
kruizeObject.setKubernetes_objects(k8sObjectList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class CreateExperimentAPIObject extends BaseSO implements ExperimentTypeA
@SerializedName(KruizeConstants.JSONKeys.DATASOURCE) //TODO: to be used in future
private String datasource;
@SerializedName(KruizeConstants.JSONKeys.EXPERIMENT_TYPE) //TODO: to be used in future
private String experimentType;
private AnalyzerConstants.ExperimentType experimentType;
private AnalyzerConstants.ExperimentStatus status;
private String experiment_id; // this id is UUID and getting set at createExperiment API
private ValidationOutputData validationData; // This object indicates if this API object is valid or invalid
Expand Down Expand Up @@ -151,25 +151,14 @@ public void setDatasource(String datasource) {
this.datasource = datasource;
}

@Override
public String getExperimentType() {
public AnalyzerConstants.ExperimentType getExperimentType() {
return experimentType;
}

public void setExperimentType(String experimentType) {
public void setExperimentType(AnalyzerConstants.ExperimentType experimentType) {
this.experimentType = experimentType;
}

@Override
public boolean isNamespaceExperiment() {
return ExperimentTypeUtil.isNamespaceExperiment(experimentType);
}

@Override
public boolean isContainerExperiment() {
return ExperimentTypeUtil.isContainerExperiment(experimentType);
}

@Override
public String toString() {
return "CreateExperimentAPIObject{" +
Expand All @@ -186,5 +175,15 @@ public String toString() {
", recommendationSettings=" + recommendationSettings +
'}';
}

@Override
public boolean isNamespaceExperiment() {
return ExperimentTypeUtil.isNamespaceExperiment(experimentType);
}

@Override
public boolean isContainerExperiment() {
return ExperimentTypeUtil.isContainerExperiment(experimentType);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*******************************************************************************/
package com.autotune.analyzer.serviceObjects;

import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.analyzer.utils.ExperimentTypeAware;
import com.autotune.analyzer.utils.ExperimentTypeUtil;
import com.autotune.utils.KruizeConstants;
Expand All @@ -26,7 +27,7 @@ public class ListRecommendationsAPIObject extends BaseSO implements ExperimentTy
@SerializedName(KruizeConstants.JSONKeys.CLUSTER_NAME)
private String clusterName;
@SerializedName(KruizeConstants.JSONKeys.EXPERIMENT_TYPE)
private String experimentType;
private AnalyzerConstants.ExperimentType experimentType;

@SerializedName(KruizeConstants.JSONKeys.KUBERNETES_OBJECTS)
private List<KubernetesAPIObject> kubernetesObjects;
Expand All @@ -47,12 +48,11 @@ public void setKubernetesObjects(List<KubernetesAPIObject> kubernetesObjects) {
this.kubernetesObjects = kubernetesObjects;
}

@Override
public String getExperimentType() {
public AnalyzerConstants.ExperimentType getExperimentType() {
return experimentType;
}

public void setExperimentType(String experimentType) {
public void setExperimentType(AnalyzerConstants.ExperimentType experimentType) {
this.experimentType = experimentType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.analyzer.utils.AnalyzerErrorConstants;
import com.autotune.common.data.ValidationOutputData;
import com.autotune.common.data.result.ContainerData;
import com.autotune.common.data.result.NamespaceData;
import com.autotune.common.k8sObjects.K8sObject;
import com.autotune.database.dao.ExperimentDAO;
import com.autotune.database.dao.ExperimentDAOImpl;
import com.autotune.database.service.ExperimentDBService;
Expand All @@ -47,7 +44,10 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -101,9 +101,9 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
createExperimentAPIObject.setExperiment_id(Utils.generateID(createExperimentAPIObject.toString()));
createExperimentAPIObject.setStatus(AnalyzerConstants.ExperimentStatus.IN_PROGRESS);
// validating the kubernetes objects and experiment type
for (KubernetesAPIObject kubernetesAPIObject: createExperimentAPIObject.getKubernetesObjects()) {
for (KubernetesAPIObject kubernetesAPIObject : createExperimentAPIObject.getKubernetesObjects()) {
if (createExperimentAPIObject.isContainerExperiment()) {
createExperimentAPIObject.setExperimentType(AnalyzerConstants.ExperimentTypes.CONTAINER_EXPERIMENT);
createExperimentAPIObject.setExperimentType(AnalyzerConstants.ExperimentType.CONTAINER);
// check if namespace data is also set for container-type experiments
if (null != kubernetesAPIObject.getNamespaceAPIObjects()) {
throw new InvalidExperimentType(AnalyzerErrorConstants.APIErrors.CreateExperimentAPI.NAMESPACE_DATA_NOT_NULL_FOR_CONTAINER_EXP);
Expand Down
Loading

0 comments on commit 9bdc3fb

Please sign in to comment.