-
Notifications
You must be signed in to change notification settings - Fork 57
fix(backend): stop task-manager event queries from flipping to a quadratic generic plan #10379
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
base: stable
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -396,17 +396,30 @@ async def query_events( | |||||||||
| limit: int, | ||||||||||
| filters: InfrahubEventFilter, | ||||||||||
| offset: int | None = None, | ||||||||||
| include_total: bool = True, | ||||||||||
| ) -> PrefectEventResponse: | ||||||||||
| body = {"limit": limit, "filter": filters.model_dump(mode="json", exclude_none=True), "offset": offset} | ||||||||||
| body = { | ||||||||||
| "limit": limit, | ||||||||||
| "filter": filters.model_dump(mode="json", exclude_none=True), | ||||||||||
| "offset": offset, | ||||||||||
| "include_total": include_total, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Retry due to https://github.com/PrefectHQ/prefect/issues/16299 | ||||||||||
| for _ in range(1, 5): | ||||||||||
| for attempt in range(1, 5): | ||||||||||
| prefect_error: PrefectHTTPStatusError | None = None | ||||||||||
| try: | ||||||||||
| response = await client._client.post("/infrahub/events/filter", json=body) | ||||||||||
| break | ||||||||||
| except PrefectHTTPStatusError as exc: | ||||||||||
| prefect_error = exc | ||||||||||
| # Each failed attempt can hide up to a full task-manager request timeout, | ||||||||||
| # so a silent loop here turns into a multi-minute stall for the caller. | ||||||||||
| log.warning( | ||||||||||
| "Event query to the task manager failed, retrying", | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: On the fourth failed POST, this warning says the query is retrying even though the loop has exhausted all attempts and raises after the sleep. Emit a terminal-failure message for Prompt for AI agents
Suggested change
|
||||||||||
| attempt=attempt, | ||||||||||
| status_code=exc.response.status_code, | ||||||||||
| ) | ||||||||||
| await asyncio.sleep(0.1) | ||||||||||
|
|
||||||||||
| if prefect_error: | ||||||||||
|
|
@@ -438,8 +451,14 @@ async def query( | |||||||||
| # returning data that will only be discarded | ||||||||||
| limit = 1 | ||||||||||
|
|
||||||||||
| # The count is an unbounded aggregate over the whole filter window and is by far | ||||||||||
| # the most expensive part of the endpoint, so only ask for it when selected. | ||||||||||
| include_total = "count" in fields | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Custom agent: Flag AI Slop and Fabricated Changes The new selection-dependent Prompt for AI agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Prompt for AI agents |
||||||||||
|
|
||||||||||
| async with get_client(sync_client=False) as client: | ||||||||||
| response = await cls.query_events(client=client, filters=event_filter, limit=limit, offset=offset) | ||||||||||
| response = await cls.query_events( | ||||||||||
| client=client, filters=event_filter, limit=limit, offset=offset, include_total=include_total | ||||||||||
| ) | ||||||||||
| nodes = [{"node": event.to_graphql()} for event in response.events] | ||||||||||
|
|
||||||||||
| return {"count": response.count, "edges": nodes} | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed intermittent multi-second to multi-minute stalls of the activity log. The task manager's Postgres connections switched the event queries to a generic prepared-statement plan after five executions, which degraded the unbounded count that backs every activity-log page from milliseconds to a quadratic join. The event-filter endpoint now forces per-execution planning for its own transaction only, and the count is only computed when the GraphQL query selects it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Custom agent: Flag AI Slop and Fabricated Changes
When the caller omits
count, this new branch skips the expensive aggregate and returns0, but no regression test exercises that behavior. Add an event-query test withoutcountthat verifies the response count and prevents the count query from running.Prompt for AI agents