Skip to content

Commit 73c67ea

Browse files
committed
pr-feedback
1 parent 286f7e2 commit 73c67ea

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed

.ci/metrics/metrics.py

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,28 @@ class GaugeMetric:
4848
time_ns: int
4949

5050

51-
# Fetches a page of the build list using the GraphQL BuildKite API.
52-
# Returns the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE last **finished** builds by
53-
# default, or the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE **finished** builds older
54-
# than the one pointer by
55-
# |cursor| if provided.
56-
# The |cursor| value is taken from the previous page returned by the API.
57-
# The returned data had the following format:
58-
# [
59-
# {
60-
# "cursor": <value>,
61-
# "number": <build-number>,
62-
# }
63-
# ]
64-
def buildkite_fetch_page_build_list(buildkite_token, after_cursor=None):
51+
def buildkite_fetch_page_build_list(
52+
buildkite_token: str, after_cursor: str = None
53+
) -> list[dict[str, str]]:
54+
"""Fetches a page of the build list using the GraphQL BuildKite API. Returns the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE last **finished** builds by default, or the BUILDKITE_GRAPHQL_BUILDS_PER_PAGE **finished** builds older than the one pointer by |cursor| if provided.
55+
The |cursor| value is taken from the previous page returned by the API.
56+
57+
The returned data had the following format:
58+
59+
Args:
60+
buildkite_token: the secret token to authenticate GraphQL requests.
61+
after_cursor: cursor after which to start the page fetch.
62+
63+
Returns:
64+
Returns most recents builds after cursor (if set) with the following format:
65+
[
66+
{
67+
"cursor": <value>,
68+
"number": <build-number>,
69+
}
70+
]
71+
"""
72+
6573
BUILDKITE_GRAPHQL_QUERY = """
6674
query OrganizationShowQuery {{
6775
organization(slug: "llvm-project") {{
@@ -103,17 +111,29 @@ def buildkite_fetch_page_build_list(buildkite_token, after_cursor=None):
103111
return [{**x["node"], "cursor": x["cursor"]} for x in builds]
104112

105113

106-
# Returns all the info associated with the provided |build_number|.
107-
# Note: for unknown reasons, graphql returns no jobs for a given build, while
108-
# this endpoint does, hence why this uses this API instead of graphql.
109-
def buildkite_get_build_info(build_number):
114+
def buildkite_get_build_info(build_number: str) -> dict:
115+
"""Returns all the info associated with the provided build number.
116+
Note: for unknown reasons, graphql returns no jobs for a given build, while this endpoint does, hence why this uses this API instead of graphql.
117+
118+
Args:
119+
build_number: which build number to fetch info for.
120+
121+
Returns:
122+
The info for the target build, a JSON dictionnary.
123+
"""
124+
110125
URL = "https://buildkite.com/llvm-project/github-pull-requests/builds/{}.json"
111126
return requests.get(URL.format(build_number)).json()
112127

113128

114-
# returns the last BUILDKITE_GRAPHQL_BUILDS_PER_PAGE builds by default, or
115-
# until the build pointed by |last_cursor| is found.
116-
def buildkite_get_builds_up_to(buildkite_token, last_cursor=None):
129+
def buildkite_get_builds_up_to(buildkite_token: str, last_cursor: str = None) -> list:
130+
"""Returns the last BUILDKITE_GRAPHQL_BUILDS_PER_PAGE builds by default, or
131+
until the build pointed by |last_cursor| is found.
132+
133+
Args:
134+
buildkite_token: the secret token to authenticate GraphQL requests.
135+
last_cursor: the cursor to stop at if set. If None, a full page is fetched.
136+
"""
117137
output = []
118138
cursor = None
119139

@@ -137,13 +157,17 @@ def buildkite_get_builds_up_to(buildkite_token, last_cursor=None):
137157
return output
138158

139159

140-
# Returns a (metrics, cursor) tuple.
141-
# Returns the BuildKite workflow metrics up to the build pointed by |last_cursor|.
142-
# If |last_cursor| is None, no metrics are returned.
143-
# The returned cursor is either:
144-
# - the last processed build.
145-
# - the last build if no initial cursor was provided.
146-
def buildkite_get_metrics(buildkite_token, last_cursor=None):
160+
def buildkite_get_metrics(
161+
buildkite_token: str, last_cursor: str = None
162+
) -> (list[JobMetrics], str):
163+
"""Returns a tuple with:
164+
- the metrics to record until |last_cursor| is reached, or none if last cursor is None.
165+
- the cursor of the most recent build processed.
166+
167+
Args:
168+
buildkite_token: the secret token to authenticate GraphQL requests.
169+
last_cursor: the cursor to stop at if set. If None, a full page is fetched.
170+
"""
147171
builds = buildkite_get_builds_up_to(buildkite_token, last_cursor)
148172
# Don't return any metrics if last_cursor is None.
149173
# This happens when the program starts.

0 commit comments

Comments
 (0)