Compare commits

...
Author SHA1 Message Date
Andrew Ferlitsch f8fcffdd8f fix: rm test_filter 2023-05-12 17:23:52 +00:00
Andrew Ferlitsch 096fabb08a fix: review comments 2023-05-12 16:48:29 +00:00
Andrew Ferlitsch 0817440e37 fix: filtering 2023-05-10 21:35:04 +00:00
Andrew Ferlitsch e969e20133 fix: debug select algo 2023-05-09 04:52:21 +00:00
Andrew Ferlitsch 5c77c5310b fix: debug select algo 2023-05-09 04:32:32 +00:00
Andrew Ferlitsch d44c87754d fix: debug select algo 2023-05-09 04:24:44 +00:00
Andrew Ferlitsch 18556fe865 fix: debug select algo 2023-05-09 04:20:55 +00:00
Andrew Ferlitsch 2374262ef4 fix: debug 2023-05-09 04:14:16 +00:00
Andrew Ferlitsch 3d580d4a4f fix: debug 2023-05-09 04:08:30 +00:00
Andrew Ferlitsch e0cb78fe41 fix: debug 2023-05-09 04:03:32 +00:00
Andrew Ferlitsch 9c3b69093a fix: debug 2023-05-09 03:47:37 +00:00
Andrew Ferlitsch 27dd3c1747 fix: debug 2023-05-09 02:02:23 +00:00
Andrew Ferlitsch 9b2928ec2f fix: debug 2023-05-09 01:58:01 +00:00
Andrew Ferlitsch bbd837d882 fix: selection algo 2023-05-09 01:46:55 +00:00
Andrew Ferlitsch 4479b96de0 fix: selection algo 2023-05-09 01:32:57 +00:00
Andrew Ferlitsch d7d1188798 fix: selection algo 2023-05-09 01:27:03 +00:00
Andrew Ferlitsch 7747ead696 fix: selection algo 2023-05-09 01:22:27 +00:00
Andrew Ferlitsch 93087894eb fix: selection algo 2023-05-09 01:06:37 +00:00
Andrew Ferlitsch 3bab071137 fix: selection algo 2023-05-09 01:00:03 +00:00
Andrew Ferlitsch 0b4e1413d3 fix: selection algo 2023-05-08 22:21:28 +00:00
Andrew Ferlitsch ac8ff2627d fix: selection algo 2023-05-08 22:13:00 +00:00
Andrew Ferlitsch a07adaff7f fix: selection algo 2023-05-08 22:03:21 +00:00
Andrew Ferlitsch 10d9bd0b41 fix: selection algo 2023-05-08 21:58:59 +00:00
Andrew Ferlitsch c83df460b7 fix: selection algo 2023-05-08 21:39:44 +00:00
Andrew Ferlitsch 1baf380b40 fix: selection algo 2023-05-08 21:16:25 +00:00
Andrew Ferlitsch 6789870a61 fix: selection algo 2023-05-08 21:02:15 +00:00
Andrew Ferlitsch b0189a834e fix: build results dir 2023-05-08 20:19:39 +00:00
Andrew Ferlitsch 2a3f617d7d fix: build results dir 2023-05-08 20:13:21 +00:00
Andrew Ferlitsch c39bb2d0a8 feat: read accumulative result files 2023-05-08 19:24:18 +00:00
2 changed files with 43 additions and 33 deletions
@@ -137,7 +137,11 @@ changed_notebooks = execute_changed_notebooks_helper.get_changed_notebooks(
results_bucket = f"{args.artifacts_bucket}"
results_file = f"{args.build_id}.json"
# artifacts_bucket may get set by trigger to a full gs:// folder path
if results_bucket.startswith("gs://"):
results_bucket = results_bucket[5:]
results_bucket = results_bucket.split('/')[0]
results_file = f"build_results/{args.build_id}.json"
if args.test_percent == 100:
notebooks = changed_notebooks
@@ -158,7 +162,6 @@ else:
staging_bucket=args.staging_bucket,
artifacts_bucket=args.artifacts_bucket,
results_file=results_file,
accumulative_results=accumulative_results,
should_parallelize=args.should_parallelize,
timeout=args.timeout,
variable_project_id=args.variable_project_id,
@@ -95,8 +95,20 @@ def load_results(results_bucket: str,
print("Loading existing accumulative results ...")
accumulative_results = {}
try:
content = util.download_blob_into_memory(results_bucket, results_file, download_as_text=True)
accumulative_results = json.loads(content)
client = storage.Client()
bucket = client.bucket(results_bucket)
build_results_dir = os.path.dirname(results_file)
blobs = client.list_blobs(results_bucket, prefix=build_results_dir)
for blob in blobs:
content = util.download_blob_into_memory(results_bucket, blob.name, download_as_text=True)
build_results = json.loads(content)
for notebook in build_results:
if notebook in accumulative_results:
accumulative_results[notebook] += build_results[notebook]
else:
accumulative_results[notebook] = build_results[notebook]
print(accumulative_results)
except Exception as e:
print(e)
@@ -118,7 +130,15 @@ def select_notebook(changed_notebook: str,
pass_count = 1
fail_count = 0
return (random.randint(1, 100) * (1 + (fail_count / (pass_count + fail_count))) < test_percent)
inferred_failure_rate = fail_count / (pass_count + fail_count)
# If failure rate is high, the chance of testing should be higher
should_test_due_to_failure = random.uniform(0, 1) < inferred_failure_rate
# Additionally, only test a percentage of these
should_test_due_to_random_subset = random.uniform(0, 1) < test_percent
return should_test_due_to_failure and should_test_due_to_random_subset
def _process_notebook(
@@ -379,39 +399,30 @@ def get_changed_notebooks(
return notebooks
def _save_results(results: List[NotebookExecutionResult],
accumulative_results: Dict[str,Any],
artifacts_bucket: str,
results_file: str):
artifacts_bucket = artifacts_bucket.replace("gs://", "").split('/')[0]
print("Updating accumulative results ...")
print("Updating build results ...")
build_results = {}
for result in results:
if result.path in accumulative_results:
accumulative_results[result.path]['duration'] = result.duration.total_seconds()
accumulative_results[result.path]['start_time'] = str(result.start_time)
if result.is_pass:
accumulative_results[result.path]['passed'] += 1
else:
accumulative_results[result.path]['failed'] += 1
print(f"updating {result.path}")
if result.is_pass:
pass_count = 1
fail_count = 0
else:
if result.is_pass:
pass_count = 1
fail_count = 0
else:
pass_count = 0
fail_count = 1
accumulative_results[result.path] = {
'duration': result.duration.total_seconds(),
'start_time': str(result.start_time),
'passed': pass_count,
'failed': fail_count
}
print(f"adding {result.path}")
pass_count = 0
fail_count = 1
build_results[result.path] = {
'duration': result.duration.total_seconds(),
'start_time': str(result.start_time),
'passed': pass_count,
'failed': fail_count
}
print(f"adding {result.path}")
print("Saving accumulative results ...")
content = json.dumps(accumulative_results)
content = json.dumps(build_results)
client = storage.Client()
bucket = client.get_bucket(artifacts_bucket)
@@ -425,7 +436,6 @@ def process_and_execute_notebooks(
staging_bucket: str,
artifacts_bucket: str,
results_file: str,
accumulative_results: List[NotebookExecutionResult],
should_parallelize: bool,
timeout: int,
variable_project_id: str,
@@ -455,8 +465,6 @@ def process_and_execute_notebooks(
Required. The GCS staging bucket to write executed notebooks to.
results_file (str):
Required: The path to the artifacts bucket to save results
accumulative_results (List):
Required: The in-memory previous accumulative notebook CI/CD test results.
variable_project_id (str):
Required. The value for PROJECT_ID to inject into notebooks.
variable_region (str):
@@ -578,7 +586,6 @@ def process_and_execute_notebooks(
print(log_contents)
_save_results(results_sorted,
accumulative_results,
artifacts_bucket,
results_file)