andreydevyatkin commented on code in PR #30424:
URL: https://github.com/apache/beam/pull/30424#discussion_r1508075573
##########
.test-infra/metrics/sync/github/github_runs_prefetcher/code/main.py:
##########
@@ -143,6 +144,41 @@ def enhance_workflow(workflow):
print(f"No yaml file found for workflow: {workflow.name}")
+async def check_workflow_flakiness(workflow):
+ def filter_workflow_runs(run, issue):
+ started_at = datetime.strptime(run.started_at, "%Y-%m-%dT%H:%M:%SZ")
+ closed_at = datetime.strptime(issue["closed_at"], "%Y-%m-%dT%H:%M:%SZ")
+ if started_at > closed_at:
+ return True
+ return False
+
+ if not len(workflow.runs):
+ return False
+
+ url = f"https://api.github.com/repos/{GIT_ORG}/beam/issues"
+ headers = {"Authorization": get_token()}
+ semaphore = asyncio.Semaphore(5)
+ workflow_runs = workflow.runs
+ params = {
+ "state": "closed",
+ "labels": f"flaky_test,workflow_id: {workflow.id}",
+ }
+ response = await fetch(url, semaphore, params, headers)
+ if len(response):
+ print(f"Found a recently closed issue for the {workflow.name}
workflow")
+ workflow_runs = [run for run in workflow_runs if
filter_workflow_runs(run, response[0])]
+
+ print(f"Number of workflow runs to consider: {len(workflow_runs)}")
+ success_rate = 1.0
+ if len(workflow_runs):
+ failed_runs = list(filter(lambda r: r.status == "failure",
workflow_runs))
+ print(f"Number of failed workflow runs: {len(failed_runs)}")
+ success_rate -= (len(failed_runs) / len(workflow_runs))
+
+ print(f"Success rate: {success_rate}")
+ return True if success_rate < workflow.threshold else False
Review Comment:
Added a limit on the min number of runs to consider
https://github.com/apache/beam/pull/30424/files#diff-a99a5e5ac1dc4bf7f4d42360354deec95414d660122bd96214d190b92fee2340R172
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]