damccorm commented on code in PR #24073:
URL: https://github.com/apache/beam/pull/24073#discussion_r1052597624
##########
.test-infra/metrics/sync/github/sync_workflows.py:
##########
@@ -96,64 +115,80 @@ def getToken():
def fetchWorkflowData():
'''Return a json with all the workflows and the latests
ten executions'''
- listOfWorkflows = {}
- workflowsStatus = {}
+ completed = False
+ page = 1
+ workflows = []
+ retryFactor = 1
try:
- url = "https://api.github.com/repos/apache/beam/actions/workflows"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
- response = requests.get(url = url, params = queryOptions)
- jsonResponse = response.json()
- workflows = jsonResponse['workflows']
- for item in workflows:
- path =(item['path'])
- isPostCommit = re.search('(.*)postcommit(.*)',path)
- if isPostCommit:
- result = re.search('/(.*).yml', path)
- path =(result.group(1)) + ".yml"
- GH_WORKFLOWS_YML_FILENAME.append(path)
- listOfWorkflows[(item['id'])] = item['name']
- url = "https://api.github.com/repos/apache/beam/actions/workflows/"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_WORKFLOWS_NUMBER_EXECUTIONS,
- 'page' :'1', 'exclude_pull_request':True }
- #headers = {'Authorization': 'Bearer {}'.format(getToken())}
- for key in listOfWorkflows:
- response = requests.get(url = "{}{}/runs".format(url,key),
+ while not completed:
+ url = "https://api.github.com/repos/apache/beam/actions/workflows"
+ queryOptions = { 'branch' : 'master', 'page': page, 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
+ response = requests.get(url = url, params = queryOptions)
Review Comment:
Please add retries here as well
##########
.test-infra/metrics/sync/github/sync_workflows.py:
##########
@@ -96,64 +115,80 @@ def getToken():
def fetchWorkflowData():
'''Return a json with all the workflows and the latests
ten executions'''
- listOfWorkflows = {}
- workflowsStatus = {}
+ completed = False
+ page = 1
+ workflows = []
+ retryFactor = 1
try:
- url = "https://api.github.com/repos/apache/beam/actions/workflows"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
- response = requests.get(url = url, params = queryOptions)
- jsonResponse = response.json()
- workflows = jsonResponse['workflows']
- for item in workflows:
- path =(item['path'])
- isPostCommit = re.search('(.*)postcommit(.*)',path)
- if isPostCommit:
- result = re.search('/(.*).yml', path)
- path =(result.group(1)) + ".yml"
- GH_WORKFLOWS_YML_FILENAME.append(path)
- listOfWorkflows[(item['id'])] = item['name']
- url = "https://api.github.com/repos/apache/beam/actions/workflows/"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_WORKFLOWS_NUMBER_EXECUTIONS,
- 'page' :'1', 'exclude_pull_request':True }
- #headers = {'Authorization': 'Bearer {}'.format(getToken())}
- for key in listOfWorkflows:
- response = requests.get(url = "{}{}/runs".format(url,key),
+ while not completed:
+ url = "https://api.github.com/repos/apache/beam/actions/workflows"
+ queryOptions = { 'branch' : 'master', 'page': page, 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
+ response = requests.get(url = url, params = queryOptions)
+ jsonResponse = response.json()
+ if jsonResponse['total_count'] >= 100:
Review Comment:
```suggestion
if jsonResponse['total_count'] >= GH_NUMBER_OF_WORKFLOWS:
```
##########
.test-infra/metrics/sync/github/sync_workflows.py:
##########
@@ -96,64 +115,80 @@ def getToken():
def fetchWorkflowData():
'''Return a json with all the workflows and the latests
ten executions'''
- listOfWorkflows = {}
- workflowsStatus = {}
+ completed = False
+ page = 1
+ workflows = []
+ retryFactor = 1
try:
- url = "https://api.github.com/repos/apache/beam/actions/workflows"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
- response = requests.get(url = url, params = queryOptions)
- jsonResponse = response.json()
- workflows = jsonResponse['workflows']
- for item in workflows:
- path =(item['path'])
- isPostCommit = re.search('(.*)postcommit(.*)',path)
- if isPostCommit:
- result = re.search('/(.*).yml', path)
- path =(result.group(1)) + ".yml"
- GH_WORKFLOWS_YML_FILENAME.append(path)
- listOfWorkflows[(item['id'])] = item['name']
- url = "https://api.github.com/repos/apache/beam/actions/workflows/"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_WORKFLOWS_NUMBER_EXECUTIONS,
- 'page' :'1', 'exclude_pull_request':True }
- #headers = {'Authorization': 'Bearer {}'.format(getToken())}
- for key in listOfWorkflows:
- response = requests.get(url = "{}{}/runs".format(url,key),
+ while not completed:
+ url = "https://api.github.com/repos/apache/beam/actions/workflows"
+ queryOptions = { 'branch' : 'master', 'page': page, 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
+ response = requests.get(url = url, params = queryOptions)
+ jsonResponse = response.json()
+ if jsonResponse['total_count'] >= 100:
+ page = page + 1
+ workflowsPage = jsonResponse['workflows']
+ workflows.append(workflowsPage)
+ else:
+ completed = True
+ workflowsPage = jsonResponse['workflows']
+ workflows.append(workflowsPage)
+ for pageItem in workflows:
+ for item in pageItem:
+ path =item['path']
+ isPostCommit = re.search('(.*)postcommit(.*)',path)
+ if isPostCommit:
+ result = re.search('/(.*).yml', path)
+ path =(result.group(1)) + ".yml"
+ workflowObject = Workflow(item['id'],item['name'],path)
+ WORKFLOWS_OBJECT_LIST.append(workflowObject)
+ url = "https://api.github.com/repos/apache/beam/actions/workflows/"
+ queryOptions = { 'branch' : 'master', 'per_page' :
GH_WORKFLOWS_NUMBER_EXECUTIONS,
+ 'page' :'1', 'exclude_pull_request':True }
+ #headers = {'Authorization': 'Bearer {}'.format(getToken())}
+ for workflow in WORKFLOWS_OBJECT_LIST:
+ requestSucceeded = False
+ while not requestSucceeded:
Review Comment:
We should also add a retry limit - we should give up if we've been retrying
for longer than an hour and receive another error code so that we don't spin
here forever.
##########
.test-infra/metrics/sync/github/sync_workflows.py:
##########
@@ -0,0 +1,197 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+'''
+This module queries GitHub to collect Beam-related workflows metrics and put
them in
+PostgreSQL.
+This Script is running every 3 hours in a cloud function in
apache-beam-testing project.
+This cloud function is triggered by a pubsub topic.
+You can found the cloud function in the next link
Review Comment:
```suggestion
You can find the cloud function in the next link
```
Nit
##########
.test-infra/metrics/sync/github/sync_workflows.py:
##########
@@ -96,64 +115,80 @@ def getToken():
def fetchWorkflowData():
'''Return a json with all the workflows and the latests
ten executions'''
- listOfWorkflows = {}
- workflowsStatus = {}
+ completed = False
+ page = 1
+ workflows = []
+ retryFactor = 1
try:
- url = "https://api.github.com/repos/apache/beam/actions/workflows"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
- response = requests.get(url = url, params = queryOptions)
- jsonResponse = response.json()
- workflows = jsonResponse['workflows']
- for item in workflows:
- path =(item['path'])
- isPostCommit = re.search('(.*)postcommit(.*)',path)
- if isPostCommit:
- result = re.search('/(.*).yml', path)
- path =(result.group(1)) + ".yml"
- GH_WORKFLOWS_YML_FILENAME.append(path)
- listOfWorkflows[(item['id'])] = item['name']
- url = "https://api.github.com/repos/apache/beam/actions/workflows/"
- queryOptions = { 'branch' : 'master', 'per_page' :
GH_WORKFLOWS_NUMBER_EXECUTIONS,
- 'page' :'1', 'exclude_pull_request':True }
- #headers = {'Authorization': 'Bearer {}'.format(getToken())}
- for key in listOfWorkflows:
- response = requests.get(url = "{}{}/runs".format(url,key),
+ while not completed:
+ url = "https://api.github.com/repos/apache/beam/actions/workflows"
+ queryOptions = { 'branch' : 'master', 'page': page, 'per_page' :
GH_NUMBER_OF_WORKFLOWS }
+ response = requests.get(url = url, params = queryOptions)
+ jsonResponse = response.json()
+ if jsonResponse['total_count'] >= 100:
+ page = page + 1
+ workflowsPage = jsonResponse['workflows']
+ workflows.append(workflowsPage)
+ else:
+ completed = True
+ workflowsPage = jsonResponse['workflows']
+ workflows.append(workflowsPage)
+ for pageItem in workflows:
+ for item in pageItem:
+ path =item['path']
+ isPostCommit = re.search('(.*)postcommit(.*)',path)
+ if isPostCommit:
+ result = re.search('/(.*).yml', path)
+ path =(result.group(1)) + ".yml"
+ workflowObject = Workflow(item['id'],item['name'],path)
+ WORKFLOWS_OBJECT_LIST.append(workflowObject)
+ url = "https://api.github.com/repos/apache/beam/actions/workflows/"
+ queryOptions = { 'branch' : 'master', 'per_page' :
GH_WORKFLOWS_NUMBER_EXECUTIONS,
+ 'page' :'1', 'exclude_pull_request':True }
+ #headers = {'Authorization': 'Bearer {}'.format(getToken())}
Review Comment:
```suggestion
url = "https://api.github.com/repos/apache/beam/actions/workflows/"
queryOptions = { 'branch' : 'master', 'per_page' :
GH_WORKFLOWS_NUMBER_EXECUTIONS,
'page' :'1', 'exclude_pull_request':True }
```
--
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]