Skip to content
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

fix(bot): GraphQL API call failures breaking merge loop #740

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions bot/kodiak/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,26 @@ async def evaluate_pr(
log.info("polling")
await asyncio.sleep(POLL_RATE_SECONDS)
continue
except ApiCallException as e:
# if we have some api exception, it's likely a temporary error that
# can be resolved by calling GitHub again.
if api_call_retries_remaining:
api_call_errors.append(
APICallError(
api_name=e.method,
http_status=str(e.status_code),
response_body=str(e.response),
)
return
except ApiCallException as e:
# if we have some api exception, it's likely a temporary error that
# can be resolved by calling GitHub again.
if api_call_retries_remaining:
api_call_errors.append(
APICallError(
api_name=e.method,
http_status=str(e.status_code),
response_body=str(e.response),
)
api_call_retries_remaining -= 1
log.info("problem contacting remote api. retrying")
continue
log.warning("api_call_retries_remaining", exc_info=True)
)
api_call_retries_remaining -= 1
log.info("problem contacting remote api. retrying")
continue
log.warning("api_call_retries_remaining", exc_info=True)
return
except asyncio.TimeoutError:
# On timeout we add the PR to the back of the queue to try again.
# We're in a while loop, so we won't loose our spot if we're merging.
log.warning("mergeable_timeout", exc_info=True)
await requeue_callback()

Expand Down
16 changes: 7 additions & 9 deletions bot/kodiak/queries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import kodiak.app_config as conf
from kodiak.config import V1, MergeMethod
from kodiak.errors import ApiCallException
from kodiak.queries.commits import Commit, CommitConnection, GitActor
from kodiak.queries.commits import User as PullRequestCommitUser
from kodiak.queries.commits import get_commits
Expand Down Expand Up @@ -858,7 +859,7 @@ async def send_query(
query: str,
variables: Mapping[str, Union[str, int, None]],
installation_id: str,
) -> Optional[GraphQLResponse]:
) -> GraphQLResponse:
log = self.log

token = await get_token_for_install(
Expand All @@ -877,7 +878,11 @@ async def send_query(
res.raise_for_status()
except http.HTTPError:
log.warning("github api request error", res=res, exc_info=True)
return None
raise ApiCallException(
method="github/graphql",
http_status_code=res.status_code,
response=res.content,
)
return cast(GraphQLResponse, res.json())

async def get_api_features(self) -> ApiFeatures | None:
Expand Down Expand Up @@ -907,9 +912,6 @@ async def get_api_features(self) -> ApiFeatures | None:
variables=dict(),
installation_id=self.installation_id,
)
if res is None:
self.log.warning("failed to fetching api features")
return None
errors = res.get("errors")
data = res.get("data")
if errors or not data:
Expand Down Expand Up @@ -1034,8 +1036,6 @@ async def get_config_for_ref(
),
installation_id=self.installation_id,
)
if res is None:
return None
data = res.get("data")
if data is None:
self.log.error("could not fetch default branch name", res=res)
Expand Down Expand Up @@ -1085,8 +1085,6 @@ async def get_event_info(self, pr_number: int) -> Optional[EventInfoResponse]:
variables=dict(owner=self.owner, repo=self.repo, PRNumber=pr_number),
installation_id=self.installation_id,
)
if res is None:
return None

data = res.get("data")
if data is None:
Expand Down