Skip to content

Commit

Permalink
Merge pull request kruize#1354 from msvinaykumar/queryErrorHandling
Browse files Browse the repository at this point in the history
Resolve issue where error is not being returned to the caller.
  • Loading branch information
dinogun authored Oct 29, 2024
2 parents 6d38f2f + 24bfb4e commit 46df0b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public DataSourceManager() {
* @param steps the interval between data points in a range query
* @return
*/
public DataSourceMetadataInfo importMetadataFromDataSource(DataSourceInfo dataSourceInfo,String uniqueKey,long startTime,long endTime,int steps) {
public DataSourceMetadataInfo importMetadataFromDataSource(DataSourceInfo dataSourceInfo,String uniqueKey,long startTime,long endTime,int steps) throws Exception {
try {
if (null == dataSourceInfo) {
throw new DataSourceDoesNotExist(KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.MISSING_DATASOURCE_INFO);
Expand All @@ -67,8 +67,9 @@ public DataSourceMetadataInfo importMetadataFromDataSource(DataSourceInfo dataSo
return dataSourceMetadataInfo;
} catch (Exception e) {
LOGGER.error(e.getMessage());
throw e;
}
return null;

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*******************************************************************************/
package com.autotune.common.datasource;

import com.autotune.common.data.dataSourceQueries.PromQLDataSourceQueries;
import com.autotune.common.data.dataSourceMetadata.DataSourceMetadataHelper;
import com.autotune.common.data.dataSourceMetadata.*;
import com.autotune.common.data.dataSourceQueries.PromQLDataSourceQueries;
import com.autotune.utils.KruizeConstants;
import com.google.gson.JsonArray;
import org.slf4j.Logger;
Expand All @@ -28,7 +27,7 @@
/**
* DataSourceMetadataOperator is an abstraction with CRUD operations to manage DataSourceMetadataInfo Object
* representing JSON for a given data source
*
* <p>
* TODO -
* object is currently stored in memory going forward need to store cluster metadata in Kruize DB
* Implement methods to support update and delete operations for periodic update of DataSourceMetadataInfo
Expand All @@ -37,27 +36,34 @@ public class DataSourceMetadataOperator {
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceMetadataOperator.class);
private static final DataSourceMetadataOperator dataSourceMetadataOperatorInstance = new DataSourceMetadataOperator();
private DataSourceMetadataInfo dataSourceMetadataInfo;
private DataSourceMetadataOperator() { this.dataSourceMetadataInfo = null; }
public static DataSourceMetadataOperator getInstance() { return dataSourceMetadataOperatorInstance; }

private DataSourceMetadataOperator() {
this.dataSourceMetadataInfo = null;
}

public static DataSourceMetadataOperator getInstance() {
return dataSourceMetadataOperatorInstance;
}

/**
* Creates and populates metadata for a data source based on the provided DataSourceInfo object.
*
* <p>
* Currently supported DataSourceProvider - Prometheus
*
* @param dataSourceInfo The DataSourceInfo object containing information about the data source.
* @param uniqueKey this is used as labels in query example container="xyz" namespace="abc"
* @param startTime Get metadata from starttime to endtime
* @param endTime Get metadata from starttime to endtime
* @param steps the interval between data points in a range query
* TODO - support multiple data sources
* @param uniqueKey this is used as labels in query example container="xyz" namespace="abc"
* @param startTime Get metadata from starttime to endtime
* @param endTime Get metadata from starttime to endtime
* @param steps the interval between data points in a range query
* TODO - support multiple data sources
*/
public DataSourceMetadataInfo createDataSourceMetadata(DataSourceInfo dataSourceInfo, String uniqueKey, long startTime, long endTime, int steps) {
public DataSourceMetadataInfo createDataSourceMetadata(DataSourceInfo dataSourceInfo, String uniqueKey, long startTime, long endTime, int steps) throws Exception {
return processQueriesAndPopulateDataSourceMetadataInfo(dataSourceInfo, uniqueKey, startTime, endTime, steps);
}

/**
* Retrieves DataSourceMetadataInfo object.
*
* @return DataSourceMetadataInfo containing metadata about the data source if found, otherwise null.
*/
public DataSourceMetadataInfo getDataSourceMetadataInfo(DataSourceInfo dataSourceInfo) {
Expand Down Expand Up @@ -88,23 +94,24 @@ public DataSourceMetadataInfo getDataSourceMetadataInfo(DataSourceInfo dataSourc
* Updates the metadata information of a data source with the provided DataSourceInfo object,
* while preserving existing metadata information.
*
* @param dataSourceInfo The DataSourceInfo object containing information about the
* data source to be updated.
*
* TODO - Currently Create and Update functions have identical functionalities, based on UI workflow and requirements
* need to further enhance updateDataSourceMetadata() to support namespace, workload level granular updates
* @param dataSourceInfo The DataSourceInfo object containing information about the
* data source to be updated.
* <p>
* TODO - Currently Create and Update functions have identical functionalities, based on UI workflow and requirements
* need to further enhance updateDataSourceMetadata() to support namespace, workload level granular updates
*/
public DataSourceMetadataInfo updateDataSourceMetadata(DataSourceInfo dataSourceInfo, String uniqueKey, long startTime, long endTime, int steps) {
public DataSourceMetadataInfo updateDataSourceMetadata(DataSourceInfo dataSourceInfo, String uniqueKey, long startTime, long endTime, int steps) throws Exception {
return processQueriesAndPopulateDataSourceMetadataInfo(dataSourceInfo, uniqueKey, startTime, endTime, steps);
}

/**
* Deletes the metadata information of a data source with the provided DataSourceInfo object,
* @param dataSourceInfo The DataSourceInfo object containing information about the
* metadata to be deleted.
*
* @param dataSourceInfo The DataSourceInfo object containing information about the
* metadata to be deleted.
*/
public void deleteDataSourceMetadata(DataSourceInfo dataSourceInfo) {
try{
try {
if (null == dataSourceMetadataInfo) {
LOGGER.debug(KruizeConstants.DataSourceConstants.DataSourceMetadataErrorMsgs.DATASOURCE_METADATA_INFO_NOT_AVAILABLE);
return;
Expand All @@ -126,15 +133,15 @@ public void deleteDataSourceMetadata(DataSourceInfo dataSourceInfo) {
* Fetches and processes metadata related to namespaces, workloads, and containers of a given datasource and populates the
* DataSourceMetadataInfo object
*
* @param dataSourceInfo The DataSourceInfo object containing information about the data source
* @param uniqueKey this is used as labels in query example container="xyz" namespace="abc"
* @param startTime Get metadata from starttime to endtime
* @param endTime Get metadata from starttime to endtime
* @param steps the interval between data points in a range query
* @param dataSourceInfo The DataSourceInfo object containing information about the data source
* @param uniqueKey this is used as labels in query example container="xyz" namespace="abc"
* @param startTime Get metadata from starttime to endtime
* @param endTime Get metadata from starttime to endtime
* @param steps the interval between data points in a range query
* @return DataSourceMetadataInfo object with populated metadata fields
* todo rename processQueriesAndFetchClusterMetadataInfo
*/
public DataSourceMetadataInfo processQueriesAndPopulateDataSourceMetadataInfo(DataSourceInfo dataSourceInfo, String uniqueKey, long startTime, long endTime, int steps) {
public DataSourceMetadataInfo processQueriesAndPopulateDataSourceMetadataInfo(DataSourceInfo dataSourceInfo, String uniqueKey, long startTime, long endTime, int steps) throws Exception {
DataSourceMetadataHelper dataSourceDetailsHelper = new DataSourceMetadataHelper();
/**
* Get DataSourceOperatorImpl instance on runtime based on dataSource provider
Expand Down Expand Up @@ -214,6 +221,7 @@ public DataSourceMetadataInfo processQueriesAndPopulateDataSourceMetadataInfo(Da
HashMap<String, HashMap<String, DataSourceContainer>> datasourceContainers = new HashMap<>();
JsonArray containerDataResultArray = op.getResultArrayForQuery(dataSourceInfo,
containerQuery);
LOGGER.debug("containerDataResultArray: {}", containerDataResultArray);

if (op.validateResultArray(containerDataResultArray)) {
datasourceContainers = dataSourceDetailsHelper.getContainerInfo(containerDataResultArray);
Expand All @@ -224,7 +232,7 @@ public DataSourceMetadataInfo processQueriesAndPopulateDataSourceMetadataInfo(Da
return getDataSourceMetadataInfo(dataSourceInfo);
} catch (Exception e) {
LOGGER.error(e.getMessage());
throw e;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ public JsonArray getResultArrayForQuery(DataSourceInfo dataSource, String query)
}
} catch (JsonParseException e) {
LOGGER.error(e.getMessage());
throw e;
} catch (NullPointerException e) {
LOGGER.error(e.getMessage());
throw e;
}
return null;
}
Expand Down

0 comments on commit 46df0b8

Please sign in to comment.