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

Fix UpdateResultsAPI duplicate record issue #1051

Merged
merged 7 commits into from
Nov 23, 2023

Conversation

khansaad
Copy link
Contributor

This PR fixes the duplicate record mismatch issue after hitting the updateResults API. We were seeing a difference in the number of records getting saved in the DB.

@khansaad khansaad added the bug Something isn't working label Nov 21, 2023
@khansaad khansaad added this to the Kruize 0.0.19.5_rm Release milestone Nov 21, 2023
@khansaad khansaad self-assigned this Nov 21, 2023
@dinogun
Copy link
Contributor

dinogun commented Nov 21, 2023

@khansaad as mentioned we need to add the appropriate negative tests to handle this scenario. @chandrams please review

@@ -335,6 +337,34 @@ def validate_reco_json(create_exp_json, update_results_json, list_reco_json, exp
list_reco_kubernetes_obj, expected_duration_in_hours, test_name)


def validate_list_exp_results_count(update_results_json, list_exp_json):
Copy link
Contributor

Choose a reason for hiding this comment

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

This function should accept expected_results_count as a parameter

print("list_exp_results_count = ", list_exp_results_count)
print("net_count = ", net_count)

assert net_count == DUPLICATE_RECORDS_COUNT
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 to assert list_exp_results_count against expected_results_count

results = container.get("results", {})
count += len(results)

return count/container_count
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we take only integer part here?

# Description: This function obtains the experiment details including the results from Kruize Autotune using
# listExperiments API
# Input Parameters: experiment_name
def list_experiments_with_results(experiment_name: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have a list_experiments function, pass experiment_name, results, recommendations and latest as parameters and accordingly set the PARAMS before calling the API similar to list_recommendations

data = response.json()
assert response.status_code == ERROR_STATUS_CODE
assert data['status'] == ERROR_STATUS
assert data['message'] == UPDATE_RESULTS_FAILED_RECORDS_MSG
Copy link
Contributor

Choose a reason for hiding this comment

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

Also validate the failed records data error messages - "An entry for this record already exists!"

Signed-off-by: Saad Khan <[email protected]>
error_messages = [error['message'] for item in data['data'] for error in item['errors']]
error_messages_code = [error['httpcode'] for item in data['data'] for error in item['errors']]

assert DUPLICATE_RECORDS_MSG in error_messages
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to validate each error message or http code and use equals here

assert data['status'] == ERROR_STATUS
assert data['message'] == UPDATE_RESULTS_FAILED_RECORDS_MSG

response = list_experiments("true", None, "false", experiment_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Assign the values to variables and pass those variables for better readability. Also update any other references to list_experiments in other tests.

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 59f23f7 into kruize:master Nov 23, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants