Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mvp_demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dinogun committed Jan 23, 2024
2 parents 26e278a + 59f23f7 commit a655ac5
Show file tree
Hide file tree
Showing 7 changed files with 20,321 additions and 15 deletions.
105 changes: 102 additions & 3 deletions .github/workflows/test-on-comment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,63 @@ name: Kruize Remote monitoring functional tests
on:
issue_comment:
types: [created]
issue_type: [pull_request]
pull_request_review:
types: [submitted]

jobs:
functest:

# Only run this if the user asked us to
if: github.event.comment.body == 'run functional tests'
if: contains(github.event.comment.body, 'run functional tests')

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Get workflow run info
run: |
echo "url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
echo "id=$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
echo "url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
echo "id=$GITHUB_RUN_ID"
id: workflow_run_info

- name: Debug Comment Content
run: echo "Comment :${{ github.event.comment.body }}"


- uses: actions/github-script@v6
id: get-pr
with:
script: |
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
}
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
try {
const result = await github.rest.pulls.get(request)
return result.data
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
- name: Check out code
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head

- name: Setup Minikube
uses: manusa/[email protected]
with:
minikube version: 'v1.16.0'
kubernetes version: 'v1.19.2'

- name: Build crc
run: |
echo Build crc
./build.sh -i autotune_operator:test_build
docker images | grep autotune
- name: Install Prometheus on minikube
run: |
echo Install Prometheus on minikube
Expand Down Expand Up @@ -60,3 +95,67 @@ jobs:
name: kruize_test_results
path: ./kruize_test_results.tar
retention-days: 2

reportFailure:
runs-on: ubuntu-latest
needs: [functest]
if: failure()
steps:
- name: Create comment
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
comment_body = `
@${{ github.actor }} Build(s) failed.
Workflow Run ID: [${{ needs.functest.outputs.workflow_id }}](${{ needs.functest.outputs.workflow_url }})
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment_body
})
reportCancelled:
runs-on: ubuntu-latest
needs: [functest]
if: cancelled()
steps:
- name: Create comment
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
comment_body = `
@${{ github.actor }} Build(s) cancelled.
Workflow Run ID: [${{ needs.functest.outputs.workflow_id }}](${{ needs.functest.outputs.workflow_url }})
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment_body
})
reportSuccess:
runs-on: ubuntu-latest
needs: [functest]
if: success()
steps:
- name: Create comment
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
comment_body = `
@${{ github.actor }} Build(s) successful.
Workflow Run ID: [${{ needs.functest.outputs.workflow_id }}](${{ needs.functest.outputs.workflow_url }})
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment_body
})
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public List<KruizeResultsEntry> addToDBAndFetchFailedResults(List<KruizeResultsE
String statusValue = "failure";
Timer.Sample timerAddBulkResultsDB = Timer.start(MetricsConfig.meterRegistry());
try (Session session = KruizeHibernateUtil.getSessionFactory().openSession()) {
tx = session.beginTransaction();
for (KruizeResultsEntry entry : kruizeResultsEntries) {
tx = session.beginTransaction();
try {
session.persist(entry);
session.flush();
Expand Down Expand Up @@ -199,16 +199,13 @@ public List<KruizeResultsEntry> addToDBAndFetchFailedResults(List<KruizeResultsE
entry.setErrorReasons(List.of(e.getMessage()));
failedResultsEntries.add(entry);
}
tx.commit();
tx = session.beginTransaction();
} catch (Exception e) {
entry.setErrorReasons(List.of(e.getMessage()));
failedResultsEntries.add(entry);
} finally {
tx.commit();
tx = session.beginTransaction();
}
}
tx.commit();
statusValue = "success";
} catch (Exception e) {
LOGGER.error("Not able to save experiment due to {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def main(argv):

# Fetch listExperiments
list_exp_json_file_before = list_exp_json_dir + "/list_exp_json_before_" + str(i) + ".json"
response = list_experiments()
# assign params to be passed in listExp
results = "true"
recommendations = "true"
latest = "false"
experiment_name = None
response = list_experiments(results, recommendations, latest, experiment_name)
if response.status_code == SUCCESS_200_STATUS_CODE:
list_exp_json = response.json()
else:
Expand Down Expand Up @@ -173,7 +178,11 @@ def main(argv):

# Fetch listExperiments
list_exp_json_file_after = list_exp_json_dir + "/list_exp_json_after_" + str(i) + ".json"
response = list_experiments()
results = "true"
recommendations = "true"
latest = "false"
experiment_name = None
response = list_experiments(results, recommendations, latest, experiment_name)
if response.status_code == SUCCESS_200_STATUS_CODE:
list_exp_json = response.json()
else:
Expand Down
22 changes: 17 additions & 5 deletions tests/scripts/remote_monitoring_tests/helpers/kruize.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,25 @@ def create_performance_profile(perf_profile_json_file):

# Description: This function obtains the experiments from Kruize Autotune using listExperiments API
# Input Parameters: None
def list_experiments():
PARAMS = {'results': "true", 'recommendations': "true", "latest": "false"}
def list_experiments(results=None, recommendations=None, latest=None, experiment_name=None):
print("\nListing the experiments...")
url = URL + "/listExperiments"
print("URL = ", url)
query_params = {}

response = requests.get(url=url, params=PARAMS)
if experiment_name is not None:
query_params['experiment_name'] = experiment_name
if latest is not None:
query_params['latest'] = latest
if results is not None:
query_params['results'] = results
if recommendations is not None:
query_params['recommendations'] = recommendations

query_string = "&".join(f"{key}={value}" for key, value in query_params.items())

url = URL + "/listExperiments"
if query_string:
url += "?" + query_string
print("URL = ", url)
response = requests.get(url)
print("Response status code = ", response.status_code)
return response
26 changes: 26 additions & 0 deletions tests/scripts/remote_monitoring_tests/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
SUCCESS_200_STATUS_CODE = 200
ERROR_STATUS_CODE = 400
ERROR_409_STATUS_CODE = 409
DUPLICATE_RECORDS_COUNT = 5

SUCCESS_STATUS = "SUCCESS"
ERROR_STATUS = "ERROR"
UPDATE_RESULTS_SUCCESS_MSG = "Results added successfully! View saved results at /listExperiments."
UPDATE_RESULTS_DATE_PRECEDE_ERROR_MSG = "The Start time should precede the End time!"
UPDATE_RESULTS_INVALID_METRIC_VALUE_ERROR_MSG = "Performance profile: avg cannot be negative or blank for the metric variable: "
UPDATE_RESULTS_INVALID_METRIC_FORMAT_ERROR_MSG = "Performance profile: Format value should be among these values: [cores, MiB]"
UPDATE_RESULTS_FAILED_RECORDS_MSG = f"Out of a total of 100 records, {DUPLICATE_RECORDS_COUNT} failed to save"
DUPLICATE_RECORDS_MSG = "An entry for this record already exists!"
CREATE_EXP_SUCCESS_MSG = "Experiment registered successfully with Kruize. View registered experiments at /listExperiments"
CREATE_EXP_BULK_ERROR_MSG = "At present, the system does not support bulk entries!"
UPDATE_RECOMMENDATIONS_MANDATORY_DEFAULT_MESSAGE = 'experiment_name is mandatory'
Expand Down Expand Up @@ -335,6 +338,29 @@ 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(expected_results_count, list_exp_json):

# Get the count of objects in all results arrays
list_exp_results_count = count_results_objects(list_exp_json)
print("results_count = ", expected_results_count)
print("list_exp_results_count = ", list_exp_results_count)

assert expected_results_count == list_exp_results_count


# Function to count objects in results arrays
def count_results_objects(list_exp_json):
count = 0
container_count = 1
for k8s_object in list_exp_json.get("kubernetes_objects", []):
container_count = len(k8s_object.get("containers"))
for container in k8s_object.get("containers", {}).values():
results = container.get("results", {})
count += len(results)

return count/container_count


def validate_kubernetes_obj(create_exp_kubernetes_obj, update_results_kubernetes_obj, update_results_json,
list_reco_kubernetes_obj, expected_duration_in_hours, test_name):
# Validate type, name, namespace
Expand Down
Loading

0 comments on commit a655ac5

Please sign in to comment.