diff --git a/src/main/java/com/autotune/Autotune.java b/src/main/java/com/autotune/Autotune.java index 97d0a2c55..d68c3304d 100644 --- a/src/main/java/com/autotune/Autotune.java +++ b/src/main/java/com/autotune/Autotune.java @@ -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; @@ -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); } diff --git a/src/main/java/com/autotune/analyzer/exceptions/MonitoringAgentNotFoundException.java b/src/main/java/com/autotune/analyzer/exceptions/DefaultDataSourceNotFoundException.java similarity index 83% rename from src/main/java/com/autotune/analyzer/exceptions/MonitoringAgentNotFoundException.java rename to src/main/java/com/autotune/analyzer/exceptions/DefaultDataSourceNotFoundException.java index 8afee71f3..84d38b9c8 100644 --- a/src/main/java/com/autotune/analyzer/exceptions/MonitoringAgentNotFoundException.java +++ b/src/main/java/com/autotune/analyzer/exceptions/DefaultDataSourceNotFoundException.java @@ -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); } } diff --git a/src/main/java/com/autotune/analyzer/kruizeLayer/LayerPresenceQuery.java b/src/main/java/com/autotune/analyzer/kruizeLayer/LayerPresenceQuery.java index b4df72b5e..c2b367027 100644 --- a/src/main/java/com/autotune/analyzer/kruizeLayer/LayerPresenceQuery.java +++ b/src/main/java/com/autotune/analyzer/kruizeLayer/LayerPresenceQuery.java @@ -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(); diff --git a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileValidation.java b/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileValidation.java index 0f99f8890..19ae8122f 100644 --- a/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileValidation.java +++ b/src/main/java/com/autotune/analyzer/performanceProfiles/PerformanceProfileValidation.java @@ -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); diff --git a/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java b/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java index 1909fb83d..ce9b3c091 100644 --- a/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java +++ b/src/main/java/com/autotune/analyzer/utils/ServiceHelpers.java @@ -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; diff --git a/src/main/java/com/autotune/common/datasource/DataSourceCollection.java b/src/main/java/com/autotune/common/datasource/DataSourceCollection.java index f1497c21f..5f9e0bbde 100644 --- a/src/main/java/com/autotune/common/datasource/DataSourceCollection.java +++ b/src/main/java/com/autotune/common/datasource/DataSourceCollection.java @@ -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; @@ -41,6 +42,7 @@ public class DataSourceCollection { private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceCollection.class); private static DataSourceCollection dataSourceCollectionInstance = new DataSourceCollection(); private HashMap dataSourceCollection; + private String defaultDataSource = KruizeConstants.DataSourceConstants.DEFAULT_DATASOURCE_NAME; private DataSourceCollection() { this.dataSourceCollection = new HashMap<>(); @@ -62,6 +64,33 @@ public HashMap 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 diff --git a/src/main/java/com/autotune/common/datasource/DataSourceOperatorImpl.java b/src/main/java/com/autotune/common/datasource/DataSourceOperatorImpl.java index 775c3b023..4759b4eb8 100644 --- a/src/main/java/com/autotune/common/datasource/DataSourceOperatorImpl.java +++ b/src/main/java/com/autotune/common/datasource/DataSourceOperatorImpl.java @@ -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; @@ -177,33 +176,6 @@ public ArrayList 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 diff --git a/src/main/java/com/autotune/jobs/CreatePartition.java b/src/main/java/com/autotune/jobs/CreatePartition.java index 347d7d7a3..74389ea90 100644 --- a/src/main/java/com/autotune/jobs/CreatePartition.java +++ b/src/main/java/com/autotune/jobs/CreatePartition.java @@ -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; @@ -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); } diff --git a/src/main/java/com/autotune/jobs/RetentionPartition.java b/src/main/java/com/autotune/jobs/RetentionPartition.java index a65ba1603..e34cfaaaf 100644 --- a/src/main/java/com/autotune/jobs/RetentionPartition.java +++ b/src/main/java/com/autotune/jobs/RetentionPartition.java @@ -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; @@ -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); } diff --git a/src/main/java/com/autotune/operator/InitializeDeployment.java b/src/main/java/com/autotune/operator/InitializeDeployment.java index 1adc58560..3a7e38cdc 100644 --- a/src/main/java/com/autotune/operator/InitializeDeployment.java +++ b/src/main/java/com/autotune/operator/InitializeDeployment.java @@ -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; @@ -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(); diff --git a/src/main/java/com/autotune/operator/KruizeDeploymentInfo.java b/src/main/java/com/autotune/operator/KruizeDeploymentInfo.java index 8e1aad7ea..19e49fbb0 100644 --- a/src/main/java/com/autotune/operator/KruizeDeploymentInfo.java +++ b/src/main/java/com/autotune/operator/KruizeDeploymentInfo.java @@ -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; @@ -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; @@ -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(); @@ -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()); + } } - } diff --git a/src/main/java/com/autotune/operator/KruizeOperator.java b/src/main/java/com/autotune/operator/KruizeOperator.java index c1a23d26a..8229452d9 100644 --- a/src/main/java/com/autotune/operator/KruizeOperator.java +++ b/src/main/java/com/autotune/operator/KruizeOperator.java @@ -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; @@ -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 @@ -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 appsForAllQueries = new ArrayList<>(); diff --git a/src/main/java/com/autotune/utils/KruizeConstants.java b/src/main/java/com/autotune/utils/KruizeConstants.java index 81944870b..ae9efab80 100644 --- a/src/main/java/com/autotune/utils/KruizeConstants.java +++ b/src/main/java/com/autotune/utils/KruizeConstants.java @@ -336,6 +336,7 @@ private Memory() { public static class DataSourceConstants { public static final String DATASOURCE_NAME = "name"; + public static final String DEFAULT_DATASOURCE_NAME = "prometheus"; public static final String DATASOURCE_PROVIDER = "provider"; public static final String DATASOURCE_SERVICE_NAME = "serviceName"; public static final String DATASOURCE_SERVICE_NAMESPACE = "namespace"; @@ -347,6 +348,7 @@ public static class DataSourceConstants { public static class DataSourceInfoMsgs { public static final String ADDING_DATASOURCE = "Trying to add the datasource to collection: "; + public static final String UPDATING_DEFAULT_DATASOURCE = "Trying to update the default datasource: "; public static final String VERIFYING_DATASOURCE_REACHABILITY = "Verifying datasource reachability status: "; public static final String CHECKING_AVAILABLE_DATASOURCE = "Checking available datasources:"; private DataSourceInfoMsgs() { @@ -355,6 +357,7 @@ private DataSourceInfoMsgs() { public static class DataSourceSuccessMsgs { public static final String DATASOURCE_ADDED = "Datasource added to the collection successfully."; + public static final String DEFAULT_DATASOURCE_UPDATED = "Default datasource is updated successfully."; public static final String DATASOURCE_FOUND = "Datasource found: "; public static final String DATASOURCE_SERVICEABLE = "Datasource is serviceable."; private DataSourceSuccessMsgs() { @@ -379,7 +382,10 @@ private DataSourceErrorMsgs() { public static final String DATASOURCE_NOT_SUPPORTED = "Datasource is not supported: "; public static final String SERVICE_NOT_FOUND = "Can not find service with specified name."; public static final String ENDPOINT_NOT_FOUND = "Service endpoint not found."; + public static final String INVALID_DEFAULT_DATASOURCE_NAME = "Invalid default datasource name."; + public static final String DEFAULT_DATASOURCE_NOT_FOUND = "Default datasource is not set."; public static final String MISSING_DATASOURCE_INFO = "Datasource is missing, add a valid Datasource"; + } public static class DataSourceQueryJSONKeys { @@ -555,9 +561,6 @@ public static final class KRUIZE_CONFIG_ENV_NAME { public static final String K8S_TYPE = "k8stype"; public static final String AUTH_TYPE = "authtype"; public static final String AUTH_TOKEN = "authtoken"; - public static final String MONITORING_AGENT = "monitoringagent"; - public static final String MONITORING_SERVICE = "monitoringservice"; - public static final String MONITORING_AGENT_ENDPOINT = "monitoringendpoint"; public static final String CLUSTER_TYPE = "clustertype"; public static final String AUTOTUNE_MODE = "autotunemode"; public static final String EM_ONLY_MODE = "emonly"; diff --git a/src/main/java/com/autotune/utils/KruizeSupportedTypes.java b/src/main/java/com/autotune/utils/KruizeSupportedTypes.java index 73091557f..ada24d640 100644 --- a/src/main/java/com/autotune/utils/KruizeSupportedTypes.java +++ b/src/main/java/com/autotune/utils/KruizeSupportedTypes.java @@ -29,7 +29,7 @@ private KruizeSupportedTypes() { } public static final Set DIRECTIONS_SUPPORTED = new HashSet<>(Arrays.asList("minimize", "maximize")); - public static final Set MONITORING_AGENTS_SUPPORTED = + public static final Set DATASOURCE_PROVIDERS_SUPPORTED = new HashSet<>(Arrays.asList("prometheus")); public static final Set MODES_SUPPORTED = diff --git a/src/main/java/com/autotune/utils/TrialHelpers.java b/src/main/java/com/autotune/utils/TrialHelpers.java index 5e922a9a0..a390d6b51 100644 --- a/src/main/java/com/autotune/utils/TrialHelpers.java +++ b/src/main/java/com/autotune/utils/TrialHelpers.java @@ -28,6 +28,7 @@ import com.autotune.common.annotations.json.KruizeJSONExclusionStrategy; import com.autotune.common.data.metrics.Metric; import com.autotune.common.data.metrics.MetricResults; +import com.autotune.common.datasource.DataSourceCollection; import com.autotune.common.datasource.DataSourceInfo; import com.autotune.common.trials.*; import com.autotune.experimentManager.exceptions.IncompatibleInputJSONException; @@ -145,9 +146,9 @@ public static ExperimentTrial createDefaultExperimentTrial(int trialNumber, trialNumber, trialResultUrl.toString()); - DataSourceInfo datasourceInfo = new DataSourceInfo(KruizeDeploymentInfo.monitoring_agent, KruizeConstants.SupportedDatasources.PROMETHEUS, new URL(KruizeDeploymentInfo.monitoring_agent_endpoint)); + DataSourceInfo datasourceInfo = KruizeDeploymentInfo.defaultDataSource; HashMap datasourceInfoHashMap = new HashMap<>(); - datasourceInfoHashMap.put(KruizeDeploymentInfo.monitoring_agent, datasourceInfo); //Change key value as per YAML input + datasourceInfoHashMap.put(KruizeConstants.DataSourceConstants.DEFAULT_DATASOURCE_NAME, datasourceInfo); //Change key value as per YAML input DeploymentTracking deploymentTracking = new DeploymentTracking(); DeploymentSettings deploymentSettings = new DeploymentSettings(deploymentPolicy, deploymentTracking); @@ -201,7 +202,7 @@ public static ExperimentTrial createDefaultExperimentTrial(int trialNumber, LOGGER.error("ERROR: tunable is null for tunableName: " + tunableName); } ApplicationServiceStack applicationServiceStack = kruizeExperiment.getApplicationDeployment().getApplicationServiceStackMap().get(tunable.getStackName()); - String tunableQuery = tunable.getQueries().get(KruizeDeploymentInfo.monitoring_agent); + String tunableQuery = tunable.getQueries().get(KruizeDeploymentInfo.defaultDataSource.getProvider()); Class classRef = KruizeDeploymentInfo.getLayer(tunable.getLayerName()); try { Object inst = classRef.getDeclaredConstructor().newInstance(); @@ -220,7 +221,7 @@ public static ExperimentTrial createDefaultExperimentTrial(int trialNumber, if (tunableQuery != null && !tunableQuery.isEmpty()) { Metric queryMetric = new Metric(tunable.getName(), tunableQuery, - KruizeDeploymentInfo.monitoring_agent, + KruizeDeploymentInfo.defaultDataSource.getProvider(), tunable.getValueType(), null); if (containerMetricsHashMap != null && !containerMetricsHashMap.isEmpty()