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

Add and update tests for the listRecommendations and UpdateRecommendations APIs #981

Merged
merged 12 commits into from
Nov 7, 2023

Conversation

khansaad
Copy link
Contributor

This PR fixes #978

  • Update existing tests to match with the new API structure
  • Add notification code checks

@khansaad khansaad added the test label Oct 12, 2023
@khansaad khansaad added this to the Kruize 0.0.20_rm Release milestone Oct 12, 2023
@khansaad khansaad self-assigned this Oct 12, 2023
@khansaad khansaad linked an issue Oct 12, 2023 that may be closed by this pull request
@khansaad khansaad changed the title WIP: Add and update tests for the listRecommendations and UpdateRecommendations APIs Add and update tests for the listRecommendations and UpdateRecommendations APIs Oct 26, 2023
@khansaad khansaad marked this pull request as ready for review October 26, 2023 11:33
@khansaad khansaad requested a review from chandrams October 30, 2023 07:07
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['112101'][
'message'] == 'Cost Recommendations Available'
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['111000'][
'message'] == 'Recommendations Are Available'
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define the expected messages in utils.py and reference it wherever needed.

short_term_recommendation_current = None
if "current" in short_term_recommendation:
short_term_recommendation_current = short_term_recommendation["current"]
if INFO_COST_RECOMMENDATIONS_AVAILABLE_CODE in short_term_recommendation["notifications"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, please include tests and schema changes for medium and long term recommendation validation too

@@ -227,8 +227,8 @@ def test_update_valid_recommendations_just_endtime_input_after_results_after_cre
data = response.json()
assert response.status_code == SUCCESS_STATUS_CODE
assert data[0]['experiment_name'] == experiment_name
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['112101'][
'message'] == 'Cost Recommendations Available'
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['111000'][
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the codes be replaced with the variables defined in utils.py

"notifications": {
"112101": {
"111000": {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see notification codes doc with this code and a few other codes are missing, can you please check and update the doc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the doc in mvp_demo is updated, we will need to update the doc in the remote_monitoring branch

@@ -68,7 +68,9 @@
CRITICAL_MEMORY_LIMIT_NOT_SET_CODE = "524002"

INFO_COST_RECOMMENDATIONS_AVAILABLE_CODE = "112101"
INFO_PERFORMANCE_RECOMMENDATIONS_AVAILABLE_CODE = "112102"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this being used anywhere. Please include tests for validating the notification codes.

"""
Test Description: This test validates list recommendations for multiple experiments posted using different json files
and query with only the parameter latest and with both latest=true and latest=false
Test Description: This test validates medium term list recommendations for multiple experiments posted using different json files
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the description as this tests all terms

@@ -598,8 +606,8 @@ def test_list_recommendations_exp_name_and_monitoring_end_time(test_name, monito
data = response.json()
assert response.status_code == SUCCESS_STATUS_CODE
assert data[0]['experiment_name'] == experiment_name
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['112101'][
'message'] == 'Cost Recommendations Available'
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['111000'][
Copy link
Contributor

Choose a reason for hiding this comment

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

Use variable instead of notification code

@@ -448,8 +456,8 @@ def test_list_recommendations_exp_name_and_latest(latest, cluster_type):
data = response.json()
assert response.status_code == SUCCESS_STATUS_CODE
assert data[0]['experiment_name'] == experiment_name
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['112101'][
'message'] == 'Cost Recommendations Available'
assert data[0]['kubernetes_objects'][0]['containers'][0]['recommendations']['notifications']['111000'][
Copy link
Contributor

Choose a reason for hiding this comment

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

Use variable instead of notification code

for engine_entry in engines_list:
if engine_entry in terms_obj[term]["recommendation_engines"]:
engine_obj = terms_obj[term]["recommendation_engines"][engine_entry]
validate_config(engine_obj["config"])
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, include validate_variations here

dinogun and others added 2 commits November 3, 2023 18:40
@khansaad khansaad requested review from chandrams and dinogun November 3, 2023 13:32
engine_obj = terms_obj[term]["recommendation_engines"][engine_entry]
validate_config(engine_obj["config"])
current_config = list_reco_container["recommendations"]["data"][interval_end_time]["current"]

Copy link
Contributor

Choose a reason for hiding this comment

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

@khansaad - For loop to verify all the terms is required as the long term test would have all 3 terms and medium term will have short term as well and it needs to be validated

@khansaad khansaad requested a review from chandrams November 6, 2023 14:27
experiment_name = None
response = list_recommendations(experiment_name, latest)

list_reco_json = response.json()
assert response.status_code == SUCCESS_200_STATUS_CODE

# Validate the json against the json schema
errorMsg = validate_list_reco_json(list_reco_json, list_reco_json_schema)
errorMsg = validate_list_reco_json(list_reco_json, medium_term_list_reco_json_schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be reco_json_schema. Have you tested the changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.
Also, Ran the complete functional tests, didn't find any issues in that.

Copy link
Contributor

@chandrams chandrams left a comment

Choose a reason for hiding this comment

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

LGTM

@dinogun dinogun merged commit 27e24ae into kruize:mvp_demo Nov 7, 2023
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Testing Performance Profile changes
3 participants