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

[WIP] Adds cluster_name parameter to listRecommendations API #944

Conversation

shreyabiradar07
Copy link
Contributor

@shreyabiradar07 shreyabiradar07 commented Sep 13, 2023

This PR fixes #940

  • Enhancement of /listRecommendations API by adding cluster_name query parameter to retrieve recommendations for a specific cluster based on its name

@khansaad khansaad added enhancement New feature or request remote_monitoring API Requires API Changes labels Sep 14, 2023
@khansaad khansaad added this to the Kruize 0.0.20_rm Release milestone Sep 14, 2023
@khansaad khansaad linked an issue Sep 14, 2023 that may be closed by this pull request
@khansaad khansaad self-requested a review September 14, 2023 07:35
@shreyabiradar07 shreyabiradar07 force-pushed the add_clusterName_parameter branch from 2a4d524 to 214e623 Compare September 29, 2023 08:46
@shreyabiradar07 shreyabiradar07 marked this pull request as ready for review October 3, 2023 13:00
@@ -145,7 +146,60 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
String.format(AnalyzerErrorConstants.APIErrors.ListRecommendationsAPI.INVALID_EXPERIMENT_NAME_MSG, experimentName)
);
}
} else {
}else if(null != clusterName){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be space after braces and Parantheses

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

try {
new ExperimentDBService().loadExperimentsAndRecommendationsFromDBByClusterName(mKruizeExperimentMap, clusterName);
} catch (Exception e) {
LOGGER.error("Loading saved cluster {} failed: {} ", clusterName, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should be:
LOGGER.error("Loading experiments and recommendations based on cluster {} failed: {} ", clusterName, e.getMessage());

String.format(AnalyzerErrorConstants.APIErrors.ListRecommendationsAPI.INVALID_CLUSTER_NAME_MSG, clusterName)
);
}
}else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Space here as well and re-check all other places

List<KruizeResultsEntry> loadResultsByExperimentName(String experimentName, String cluster_name, Timestamp interval_start_time, Integer limitRows) throws Exception;

// Load all results for a particular clusterName
List<KruizeResultsEntry> loadResultsByClusterName(String clusterName, Timestamp interval_start_time, Integer limitRows) throws Exception;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not required. You can remove this.

.setParameter("clusterName", clusterName).list();
statusValue = "success";
} catch (Exception e) {
LOGGER.error("Not able to load cluster {} due to {}", clusterName, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the Logger error message here as well as per the changes I suggested above.

@@ -498,6 +520,36 @@ public List<KruizeResultsEntry> loadResultsByExperimentName(String experimentNam
}
return kruizeResultsEntries;
}
@Override
public List<KruizeResultsEntry> loadResultsByClusterName(String clusterName, Timestamp interval_end_time, Integer limitRows) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this whole implementation as well, we aren't using this anywhere.

@@ -23,8 +24,11 @@ public static final class SQLQUERY {
KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.INTERVAL_START_TIME, KruizeConstants.JSONKeys.INTERVAL_END_TIME);
public static final String SELECT_FROM_RESULTS_BY_EXP_NAME_AND_END_TIME = String.format("from KruizeResultsEntry k WHERE k.cluster_name = :%s and k.experiment_name = :%s and k.interval_end_time = :%s", KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.INTERVAL_END_TIME);
public static final String SELECT_FROM_RESULTS_BY_EXP_NAME_AND_MAX_END_TIME = String.format("from KruizeResultsEntry k WHERE k.cluster_name = :%s and k.experiment_name = :%s and k.interval_end_time = (SELECT MAX(e.interval_end_time) FROM KruizeResultsEntry e where e.experiment_name = :%s )", KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME);
public static final String SELECT_FROM_RESULTS_BY_CLUSTER_NAME = "from KruizeResultsEntry k WHERE k.cluster_name = :clusterName";
public static final String SELECT_FROM_RESULTS_BY_CLUSTER_NAME_AND_DATE_RANGE = String.format("from KruizeResultsEntry k WHERE k.cluster_name = :%s and k.interval_end_time <= :%s ORDER BY k.interval_end_time DESC", KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.INTERVAL_END_TIME, KruizeConstants.JSONKeys.INTERVAL_START_TIME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these constants can be removed as well

@@ -189,6 +189,53 @@ public void loadRecommendationsFromDBByName(Map<String, KruizeObject> mainKruize
}
}
}
// Todo - confirm if experimentResultData to be changed to clusterResultData
public void loadResultsFromDBByClusterName(Map<String, KruizeObject> mainKruizeExperimentMap, String clusterName, Timestamp interval_end_time, Integer limitRows) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method isn't required as well, can be removed.

}
}
if (failureThreshHold > 0 && failureCount == failureThreshHold) {
throw new Exception("Experiments of cluster " + clusterName + " unable to load from DB.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this exception message so that it makes more sense

@@ -313,6 +388,16 @@ public void loadExperimentAndRecommendationsFromDBByName(Map<String, KruizeObjec
loadRecommendationsFromDBByName(mainKruizeExperimentMap, experimentName);
}

public void loadExperimentsAndResultsFromDBByClusterName(Map<String, KruizeObject> mainKruizeExperimentMap, String clusterName) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this as well.

@shreyabiradar07 shreyabiradar07 force-pushed the add_clusterName_parameter branch from 5dc255e to 117fa52 Compare November 27, 2023 08:02
@shreyabiradar07
Copy link
Contributor Author

@khansaad - I have incorporated review comments and rebased branch 'add_clusterName_parameter' onto 'mvp_demo'.
Can you please review the updated PR?

@rbadagandi1 rbadagandi1 removed this from the Kruize 0.0.23_rm Release milestone Jun 3, 2024
@dinogun
Copy link
Contributor

dinogun commented Oct 3, 2024

Closing stale PRs

@dinogun dinogun closed this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Requires API Changes enhancement New feature or request remote_monitoring
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[API] Add an API to list Recommendations for a given cluster.
4 participants