-
Notifications
You must be signed in to change notification settings - Fork 41
Enable custom canary reporting to cloudwatch #229
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
Merged
jsitu777
merged 11 commits into
aws-controllers-k8s:main
from
jsitu777:enable-cloudwatch-canary
Apr 4, 2023
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b90a857
enable custom canary reporting to cloudwatch
jsitu777 e967c8a
rename cloudwatch metrics namespace
jsitu777 a1414b1
print out success testsin console
jsitu777 b9e52f3
change directory for python script
jsitu777 3bd1609
change directory for python script
jsitu777 a7f392b
nested push to cloudwatch method in cleanup
jsitu777 792409d
print xml file not exists at error
jsitu777 e635f61
Merge remote-tracking branch 'upstream/main' into enable-cloudwatch-c…
jsitu777 b70aa2b
grab project name from env variable
jsitu777 43ed633
addressed comments
jsitu777 09c999d
change number of test when test log is not found
jsitu777 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import boto3 | ||
| from datetime import datetime | ||
| import xml.etree.ElementTree as ET | ||
| import os | ||
|
|
||
|
|
||
| xml_path = "../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: | ||
| print("f{xml_path} does not exists.") | ||
| print(os.getcwd()) | ||
| 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 = os.getenv("PROJECT_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 | ||
|
|
||
|
|
||
| def main(): | ||
| readXML_and_publish_metrics_to_cw() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,9 +63,14 @@ function cleanup { | |
| export PYTHONPATH=.. | ||
| python service_cleanup.py | ||
|
|
||
| #push to metrics to cloudwatch | ||
|
||
| echo "Pushing Codebuild stats to Cloudwatch." | ||
| cd $SCRIPTS_DIR | ||
| python push_stats_to_cloudwatch.py | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
|
|
||
| # Update kubeconfig | ||
| aws --region $CLUSTER_REGION eks update-kubeconfig --name $CLUSTER_NAME | ||
|
|
||
|
|
@@ -87,7 +92,7 @@ pushd $E2E_DIR | |
|
|
||
| # run tests | ||
| echo "Run Tests" | ||
| pytest_args=( -n 15 --dist loadfile --log-cli-level INFO ) | ||
| pytest_args=( -n 15 --dist loadfile --log-cli-level INFO --junitxml ../canary/integration_tests.xml) | ||
| if [[ $SERVICE_REGION =~ ^(eu-north-1|eu-west-3)$ ]]; then | ||
| # If select_regions_1 true we run the notebook_instance test | ||
| pytest_args+=(-m "canary or select_regions_1") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.