-
Notifications
You must be signed in to change notification settings - Fork 124
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
[Cherry Pick] Enable canary report generation #634
Changes from 45 commits
8a2eefe
fbf91ac
0e973cf
76f1bb6
8c3662d
3d97489
5e657e3
ae0609e
ebd48b4
8c6efd9
045b498
4ca26b4
ff4c386
b5f838d
bc81c59
e4bd53b
77bd0a7
3be38a8
147debd
02db0e1
fadb8e7
10350bf
76a15e4
a8891c1
09104dc
fc4cd2d
7c8b247
d2e4595
fd2154b
868da1e
7111dc4
bd1d95a
112ec17
abd90bc
c9a6132
bebf9b0
350b322
92dc0b2
b81c41c
95ab554
3a61765
25aa392
5e930d3
2e395b4
fe09879
f703021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import boto3 | ||
from datetime import datetime | ||
import xml.etree.ElementTree as ET | ||
import os | ||
|
||
|
||
xml_path = "../canary/integration_tests.xml" | ||
|
||
|
||
def readXML_and_publish_metrics_to_cw(): | ||
if os.path.isfile(xml_path): | ||
tree = ET.parse(xml_path) | ||
testsuite = tree.find("testsuite") | ||
failures = testsuite.attrib["failures"] | ||
tests = testsuite.attrib["tests"] | ||
successes = int(tests) - int(failures) | ||
else: | ||
failures = 0 | ||
successes = 0 | ||
tests = 1 | ||
|
||
timestamp = datetime.now().strftime("%Y-%m-%dT%H:%M:%S") | ||
|
||
print(f"Failures: {failures}") | ||
print(f"Total tests: {tests}") | ||
print(f"Success: {successes}") | ||
|
||
# push to cloudwatch | ||
cw_client = boto3.client("cloudwatch") | ||
project_name = "CodeBuild-Run-All-Tests" | ||
|
||
cluster_name = os.getenv("CLUSTER_NAME") | ||
print(f"CLUSTER_NAME: {cluster_name}") | ||
# Define the metric data | ||
metric_data = [ | ||
{ | ||
"MetricName": "failures", | ||
"Timestamp": timestamp, | ||
"Dimensions": [ | ||
{"Name": "CodeBuild Project Name", "Value": project_name}, | ||
], | ||
"Value": int(failures), | ||
"Unit": "Count", | ||
}, | ||
{ | ||
"MetricName": "total_tests", | ||
"Timestamp": timestamp, | ||
"Dimensions": [ | ||
{"Name": "CodeBuild Project Name", "Value": project_name}, | ||
], | ||
"Value": int(tests), | ||
"Unit": "Count", | ||
}, | ||
{ | ||
"MetricName": "successes", | ||
"Timestamp": timestamp, | ||
"Dimensions": [ | ||
{"Name": "CodeBuild Project Name", "Value": project_name}, | ||
], | ||
"Value": int(successes), | ||
"Unit": "Count", | ||
}, | ||
] | ||
|
||
# Use the put_metric_data method to push the metric data to CloudWatch | ||
try: | ||
response = cw_client.put_metric_data( | ||
Namespace="Canary_Metrics", MetricData=metric_data | ||
) | ||
if response["ResponseMetadata"]["HTTPStatusCode"] == 200: | ||
print("Successfully pushed data to CloudWatch") | ||
# return 200 status code if successful | ||
return 200 | ||
else: | ||
# raise exception if the status code is not 200 | ||
raise Exception( | ||
"Unexpected response status code: {}".format( | ||
response["ResponseMetadata"]["HTTPStatusCode"] | ||
) | ||
) | ||
except Exception as e: | ||
print("Error pushing data to CloudWatch: {}".format(e)) | ||
# raise exception if there was an error pushing data to CloudWatch | ||
raise | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format using black. couple of extra lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatted with black |
||
|
||
def main(): | ||
readXML_and_publish_metrics_to_cw() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,6 @@ | |
# Script configuration | ||
set -euo pipefail | ||
|
||
function onError { | ||
echo "Run test FAILED. Exiting." | ||
} | ||
trap onError ERR | ||
|
||
export CANARY_TEST_DIR=${REPO_PATH}/tests/canary | ||
export E2E_TEST_DIR=${REPO_PATH}/tests/e2e | ||
|
@@ -31,6 +27,10 @@ mkdir -p $E2E_TEST_DIR/.metadata/ | |
cp metadata-canary $E2E_TEST_DIR/.metadata/ | ||
|
||
cd $E2E_TEST_DIR | ||
pytest tests/test_sanity_portforward.py -s -q --metadata .metadata/metadata-canary --region $CLUSTER_REGION --installation_option $INSTALLATION_OPTION | ||
|
||
function push_to_cloudwatch { | ||
echo "Pushing Codebuild stats to Cloudwatch." | ||
python ../canary/scripts/push_stats_to_cloudwatch.py | ||
} | ||
trap push_to_cloudwatch EXIT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this code above line 13 since failure can happen in any command |
||
pytest tests/test_sanity_portforward.py -s -q --metadata .metadata/metadata-canary --region $CLUSTER_REGION --installation_option $INSTALLATION_OPTION --junitxml ../canary/integration_tests.xml | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,6 @@ def on_create(): | |
install_kubeflow(installation_option, deployment_option, cluster) | ||
|
||
def on_delete(): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: revert? or coming from black |
||
uninstall_kubeflow(installation_option, deployment_option) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove