Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Support For Default DataSource and Removing Monitoring Agent #1095

Open
wants to merge 11 commits into
base: kruize_local_poc
Choose a base branch
from
6 changes: 2 additions & 4 deletions src/main/java/com/autotune/Autotune.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
package com.autotune;

import com.autotune.analyzer.Analyzer;
import com.autotune.analyzer.exceptions.DefaultDataSourceNotFoundException;
import com.autotune.analyzer.exceptions.K8sTypeNotSupportedException;
import com.autotune.analyzer.exceptions.KruizeErrorHandler;
import com.autotune.analyzer.exceptions.MonitoringAgentNotFoundException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotSupportedException;
import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.common.datasource.DataSourceCollection;
import com.autotune.common.datasource.DataSourceInfo;
Expand Down Expand Up @@ -123,8 +122,7 @@ public static void main(String[] args) {
// DataSourceManager dataSourceManager = new DataSourceManager();
// dataSourceManager.saveDataFromAllSourcesToDB(dataSourceCollection.getDataSourcesCollection());

} catch (Exception | K8sTypeNotSupportedException | MonitoringAgentNotSupportedException |
MonitoringAgentNotFoundException e) {
} catch (Exception | K8sTypeNotSupportedException | DefaultDataSourceNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*******************************************************************************/
package com.autotune.analyzer.exceptions;

public class MonitoringAgentNotFoundException extends Throwable
public class DefaultDataSourceNotFoundException extends Throwable
{
public MonitoringAgentNotFoundException() {
public DefaultDataSourceNotFoundException() {
}

public MonitoringAgentNotFoundException(String message) {
public DefaultDataSourceNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public LayerPresenceQuery(String datasource,
String layerPresenceQuery,
String layerPresenceKey) throws MonitoringAgentNotSupportedException {

if (KruizeSupportedTypes.MONITORING_AGENTS_SUPPORTED.contains(datasource)) {
if (KruizeSupportedTypes.DATASOURCE_PROVIDERS_SUPPORTED.contains(datasource)) {
this.dataSource = datasource;
} else {
throw new MonitoringAgentNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private ValidationOutputData validatePerformanceProfileData(PerformanceProfile p
String expression = null;
for (Metric functionVariable : sloInfo.getFunctionVariables()) {
// Check if datasource is supported
if (!KruizeSupportedTypes.MONITORING_AGENTS_SUPPORTED.contains(functionVariable.getDatasource().toLowerCase())) {
if (!KruizeSupportedTypes.DATASOURCE_PROVIDERS_SUPPORTED.contains(functionVariable.getDatasource().toLowerCase())) {
errorString.append(AnalyzerConstants.AutotuneObjectConstants.FUNCTION_VARIABLE)
.append(functionVariable.getName())
.append(AnalyzerErrorConstants.AutotuneObjectErrors.DATASOURCE_NOT_SUPPORTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static void addLayerTunableDetails(JSONArray tunablesArray, KruizeLayer k
if (sloClass == null || tunable.sloClassList.contains(sloClass)) {
JSONObject tunableJson = new JSONObject();
addTunable(tunableJson, tunable);
String tunableQuery = tunable.getQueries().get(KruizeDeploymentInfo.monitoring_agent);
String tunableQuery = tunable.getQueries().get(KruizeDeploymentInfo.defaultDataSource.getProvider());
String query = AnalyzerConstants.NONE;
if (tunableQuery != null && !tunableQuery.isEmpty()) {
query = tunableQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.autotune.common.data.ValidationOutputData;
import com.autotune.common.exceptions.*;
import com.autotune.common.utils.CommonUtils;
import com.autotune.operator.KruizeDeploymentInfo;
import com.autotune.database.service.ExperimentDBService;
import com.autotune.utils.KruizeConstants;
import org.json.JSONArray;
Expand All @@ -41,6 +42,7 @@ public class DataSourceCollection {
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceCollection.class);
private static DataSourceCollection dataSourceCollectionInstance = new DataSourceCollection();
private HashMap<String, DataSourceInfo> dataSourceCollection;
private String defaultDataSource = KruizeConstants.DataSourceConstants.DEFAULT_DATASOURCE_NAME;

private DataSourceCollection() {
this.dataSourceCollection = new HashMap<>();
Expand All @@ -62,6 +64,33 @@ public HashMap<String, DataSourceInfo> getDataSourcesCollection() {
return dataSourceCollection;
}

/**
* Returns the object of default dataSource
* @return DataSourceInfo object
*/
public DataSourceInfo getDefaultDataSource() {
return dataSourceCollection.get(defaultDataSource);
}

/**
* Update or set the default data source
* @param updatedDefaultDataSourceName String name of the new default data source
*/
public void setDefaultDataSource(String updatedDefaultDataSourceName) {
try {
LOGGER.info(KruizeConstants.DataSourceConstants.DataSourceInfoMsgs.UPDATING_DEFAULT_DATASOURCE + updatedDefaultDataSourceName);
if (dataSourceCollection.containsKey(updatedDefaultDataSourceName)) {
defaultDataSource = updatedDefaultDataSourceName;
KruizeDeploymentInfo.setDefaultDataSource();
LOGGER.info(KruizeConstants.DataSourceConstants.DataSourceSuccessMsgs.DEFAULT_DATASOURCE_UPDATED);
} else {
throw new DataSourceNotExist(KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.DATASOURCE_NOT_EXIST);
}
} catch (DataSourceNotExist e) {
LOGGER.error(e.getMessage());
}
}

/**
* Adds datasource to collection
* @param datasource DataSourceInfo object containing details of datasource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.autotune.common.datasource;

import com.autotune.analyzer.exceptions.MonitoringAgentNotFoundException;
import com.autotune.analyzer.exceptions.TooManyRecursiveCallsException;
import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.common.datasource.prometheus.PrometheusDataOperatorImpl;
Expand Down Expand Up @@ -177,33 +176,6 @@ public ArrayList<String> getAppsForLayer(DataSourceInfo dataSource, String query
return valuesList;
}

/**
* TODO: monitoring agent will be replaced by default datasource later
* returns DataSourceInfo objects for default datasource which is currently monitoring agent
* @return DataSourceInfo objects
*/
public static DataSourceInfo getMonitoringAgent(String dataSource) throws MonitoringAgentNotFoundException, MalformedURLException {
String monitoringAgentEndpoint;
DataSourceInfo monitoringAgent = null;

if (dataSource.toLowerCase().equals(KruizeDeploymentInfo.monitoring_agent)) {
monitoringAgentEndpoint = KruizeDeploymentInfo.monitoring_agent_endpoint;
// Monitoring agent endpoint not set in the configmap
if (monitoringAgentEndpoint == null || monitoringAgentEndpoint.isEmpty()) {
monitoringAgentEndpoint = getServiceEndpoint(KruizeDeploymentInfo.monitoring_service);
}
if (dataSource.equals(AnalyzerConstants.PROMETHEUS_DATA_SOURCE)) {
monitoringAgent = new DataSourceInfo(KruizeDeploymentInfo.monitoring_agent, AnalyzerConstants.PROMETHEUS_DATA_SOURCE, new URL(monitoringAgentEndpoint));
}
}

if (monitoringAgent == null) {
LOGGER.error("Datasource " + dataSource + " not supported");
}

return monitoringAgent;
}

/**
* TODO: To find a suitable place for this function later
* Gets the service endpoint for the datasource service through the cluster IP
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/autotune/jobs/CreatePartition.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.autotune.jobs;

import com.autotune.analyzer.exceptions.K8sTypeNotSupportedException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotFoundException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotSupportedException;
import com.autotune.analyzer.exceptions.DefaultDataSourceNotFoundException;
import com.autotune.database.dao.ExperimentDAOImpl;
import com.autotune.database.helper.DBConstants;
import com.autotune.database.init.KruizeHibernateUtil;
Expand Down Expand Up @@ -47,8 +46,7 @@ public static void main(String[] args) {
timerAddBulkResultsDB.stop(MetricsConfig.timerAddBulkResultsDB);
}
}
} catch (Exception | K8sTypeNotSupportedException | MonitoringAgentNotSupportedException |
MonitoringAgentNotFoundException e) {
} catch (Exception | K8sTypeNotSupportedException | DefaultDataSourceNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/autotune/jobs/RetentionPartition.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.autotune.jobs;

import com.autotune.analyzer.exceptions.K8sTypeNotSupportedException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotFoundException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotSupportedException;
import com.autotune.analyzer.exceptions.DefaultDataSourceNotFoundException;
import com.autotune.database.init.KruizeHibernateUtil;
import com.autotune.database.dao.ExperimentDAOImpl;
import com.autotune.operator.InitializeDeployment;
import com.autotune.operator.KruizeDeploymentInfo;
Expand All @@ -18,8 +18,7 @@ public static void main(String[] args) {
try {
InitializeDeployment.setup_deployment_info();
new ExperimentDAOImpl().deletePartitions(KruizeDeploymentInfo.delete_partition_threshold_in_days);
} catch (Exception | K8sTypeNotSupportedException | MonitoringAgentNotSupportedException |
MonitoringAgentNotFoundException e) {
} catch (Exception | K8sTypeNotSupportedException | DefaultDataSourceNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
Expand Down
29 changes: 11 additions & 18 deletions src/main/java/com/autotune/operator/InitializeDeployment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*******************************************************************************/
package com.autotune.operator;

import com.autotune.analyzer.exceptions.DefaultDataSourceNotFoundException;
import com.autotune.analyzer.exceptions.K8sTypeNotSupportedException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotFoundException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotSupportedException;
import com.autotune.common.datasource.*;
import com.autotune.utils.KruizeConstants;
import com.google.gson.Gson;
Expand All @@ -42,28 +41,22 @@ private InitializeDeployment() {

}

public static void setup_deployment_info() throws Exception, K8sTypeNotSupportedException, MonitoringAgentNotSupportedException, MonitoringAgentNotFoundException {
public static void setup_deployment_info() throws Exception, K8sTypeNotSupportedException, DefaultDataSourceNotFoundException {
setConfigValues(KruizeConstants.CONFIG_FILE, KruizeConstants.KRUIZE_CONFIG_ENV_NAME.class);
setConfigValues(KruizeConstants.DBConstants.CONFIG_FILE, KruizeConstants.DATABASE_ENV_NAME.class);

DataSourceCollection dataSourceCollection = DataSourceCollection.getInstance();
dataSourceCollection.addDataSourcesFromConfigFile(KruizeConstants.CONFIG_FILE);

KruizeDeploymentInfo.setCluster_type(KruizeDeploymentInfo.cluster_type);
KruizeDeploymentInfo.setKubernetesType(KruizeDeploymentInfo.k8s_type);
KruizeDeploymentInfo.setAuth_type(KruizeDeploymentInfo.auth_type);
KruizeDeploymentInfo.setMonitoring_agent(KruizeDeploymentInfo.monitoring_agent);
KruizeDeploymentInfo.setMonitoringAgentService(KruizeDeploymentInfo.monitoring_service);
String monitoring_agent_endpoint = KruizeDeploymentInfo.monitoring_agent_endpoint;
String monitoring_agent = KruizeDeploymentInfo.monitoring_agent;
String monitoring_agent_service = KruizeDeploymentInfo.monitoring_service;
//If no endpoint was specified in the configmap
if (monitoring_agent_endpoint == null || monitoring_agent_endpoint.isEmpty()) {
if (monitoring_agent == null || monitoring_agent_service == null) {
throw new MonitoringAgentNotFoundException();
} else {
// Fetch endpoint from service cluster IP
monitoring_agent_endpoint = DataSourceOperatorImpl.getMonitoringAgent(monitoring_agent).getUrl().toString();
}
KruizeDeploymentInfo.setDefaultDataSource();
DataSourceInfo defaultDataSource = KruizeDeploymentInfo.defaultDataSource;
// If no default datasource was specified in the configmap
if (defaultDataSource == null) {
LOGGER.error(KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.DEFAULT_DATASOURCE_NOT_FOUND);
}
KruizeDeploymentInfo.setMonitoring_agent_endpoint(monitoring_agent_endpoint);

KruizeDeploymentInfo.setLayerTable();

KruizeDeploymentInfo.initiateEventLogging();
Expand Down
45 changes: 10 additions & 35 deletions src/main/java/com/autotune/operator/KruizeDeploymentInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.autotune.analyzer.kruizeLayer.layers.GenericLayer;
import com.autotune.analyzer.kruizeLayer.layers.HotspotLayer;
import com.autotune.analyzer.kruizeLayer.layers.QuarkusLayer;
import com.autotune.common.datasource.DataSourceCollection;
import com.autotune.common.datasource.DataSourceInfo;
import com.autotune.utils.KruizeSupportedTypes;
import com.autotune.utils.KubeEventLogger;
import org.slf4j.Logger;
Expand Down Expand Up @@ -54,9 +56,7 @@ public class KruizeDeploymentInfo {
public static String settings_hibernate_show_sql;
public static String settings_hibernate_time_zone;
public static String autotune_mode;
public static String monitoring_agent;
public static String monitoring_service;
public static String monitoring_agent_endpoint;
public static DataSourceInfo defaultDataSource;
public static String cluster_type;
public static String k8s_type; // ABC
public static String auth_type;
Expand Down Expand Up @@ -91,17 +91,6 @@ public static Class getLayer(String layerName) {
return tunableLayerPair.get(layerName);
}


public static void setMonitoring_agent_endpoint(String monitoring_agent_endpoint) {
if (monitoring_agent_endpoint.endsWith("/")) {
KruizeDeploymentInfo.monitoring_agent_endpoint =
monitoring_agent_endpoint.substring(0, monitoring_agent_endpoint.length() - 1);
} else {
KruizeDeploymentInfo.monitoring_agent_endpoint = monitoring_agent_endpoint;
}
}


public static void setCluster_type(String cluster_type) throws ClusterTypeNotSupportedException {
if (cluster_type != null)
cluster_type = cluster_type.toLowerCase();
Expand Down Expand Up @@ -145,33 +134,19 @@ public static void setAuth_type(String auth_type) {
}
}


public static void setMonitoring_agent(String monitoring_agent) throws MonitoringAgentNotSupportedException {
if (monitoring_agent != null)
monitoring_agent = monitoring_agent.toLowerCase();

if (KruizeSupportedTypes.MONITORING_AGENTS_SUPPORTED.contains(monitoring_agent)) {
KruizeDeploymentInfo.monitoring_agent = monitoring_agent;
} else {
LOGGER.error("Monitoring agent {} is not supported", monitoring_agent);
throw new MonitoringAgentNotSupportedException();
}
}


public static void setMonitoringAgentService(String monitoringAgentService) {
if (monitoringAgentService != null)
KruizeDeploymentInfo.monitoring_service = monitoringAgentService.toLowerCase();
public static void setDefaultDataSource() {
KruizeDeploymentInfo.defaultDataSource = DataSourceCollection.getInstance().getDefaultDataSource();
}

public static void logDeploymentInfo() {
LOGGER.info("Cluster Type: {}", KruizeDeploymentInfo.cluster_type);
LOGGER.info("Kubernetes Type: {}", KruizeDeploymentInfo.k8s_type);
LOGGER.info("Auth Type: {}", KruizeDeploymentInfo.auth_type);
LOGGER.info("Monitoring Agent: {}", KruizeDeploymentInfo.monitoring_agent);
LOGGER.info("Monitoring Agent URL: {}", KruizeDeploymentInfo.monitoring_agent_endpoint);
LOGGER.info("Monitoring agent service: {}\n\n", KruizeDeploymentInfo.monitoring_service);
if (null != KruizeDeploymentInfo.defaultDataSource) {
LOGGER.info("Default Datasource: {}", KruizeDeploymentInfo.defaultDataSource.getName());
LOGGER.info("Default Datasource URL: {}", KruizeDeploymentInfo.defaultDataSource.getUrl());
LOGGER.info("Default Datasource Provider: {}\n\n", KruizeDeploymentInfo.defaultDataSource.getProvider());
}
}


}
10 changes: 7 additions & 3 deletions src/main/java/com/autotune/operator/KruizeOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.autotune.analyzer.utils.AnalyzerConstants.AutotuneConfigConstants;
import com.autotune.analyzer.utils.AnalyzerErrorConstants;
import com.autotune.common.data.ValidationOutputData;
import com.autotune.common.datasource.DataSourceCollection;
import com.autotune.common.datasource.DataSourceInfo;
import com.autotune.common.datasource.DataSourceOperatorImpl;
import com.autotune.common.exceptions.DataSourceNotExist;
Expand Down Expand Up @@ -495,7 +496,7 @@ private static KruizeLayer getAutotuneConfig(String autotuneConfigResource, Cust
for (Object query : layerPresenceQueryJson) {
JSONObject queryJson = (JSONObject) query;
String datasource = queryJson.getString(AnalyzerConstants.AutotuneConfigConstants.DATASOURCE);
if (datasource.equalsIgnoreCase(KruizeDeploymentInfo.monitoring_agent)) {
if (datasource.equalsIgnoreCase(KruizeDeploymentInfo.defaultDataSource.getProvider())) {
layerPresenceQueryStr = queryJson.getString(AnalyzerConstants.AutotuneConfigConstants.QUERY);
layerPresenceKey = queryJson.getString(AnalyzerConstants.AutotuneConfigConstants.KEY);
// Replace the queryvariables in the query
Expand Down Expand Up @@ -668,8 +669,11 @@ private static void addQueryLayer(KruizeLayer layer, KruizeObject kruizeObject)
}
DataSourceInfo autotuneDataSource = null;
try {
autotuneDataSource = DataSourceOperatorImpl.getMonitoringAgent(KruizeDeploymentInfo.monitoring_agent);
} catch (MonitoringAgentNotFoundException e) {
autotuneDataSource = DataSourceCollection.getInstance().getDefaultDataSource();
if (autotuneDataSource == null){
throw new DefaultDataSourceNotFoundException(KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.DEFAULT_DATASOURCE_NOT_FOUND);
}
} catch (DefaultDataSourceNotFoundException e) {
e.printStackTrace();
}
ArrayList<String> appsForAllQueries = new ArrayList<>();
Expand Down
Loading
Loading