Skip to content

feat: add command to recompute tree_tests_rollup#1874

Open
gustavobtflores wants to merge 2 commits intokernelci:mainfrom
gustavobtflores:feat/tree-tests-rollup-populate-command
Open

feat: add command to recompute tree_tests_rollup#1874
gustavobtflores wants to merge 2 commits intokernelci:mainfrom
gustavobtflores:feat/tree-tests-rollup-populate-command

Conversation

@gustavobtflores
Copy link
Copy Markdown
Contributor

@gustavobtflores gustavobtflores commented Apr 23, 2026

Description

Adds a new management command to recompute tree_tests_rollup and ProcessedListingItems from source data. This enables backfilling or rebuilding rollup aggregations when needed, with options to filter by checkout, time range, or limit.

Changes

  • Add populate_tree_tests_rollup management command with filtering options (--checkout-id, --since-days, --limit) and dry-run mode
  • Fix type annotations for the rollup dictionary in helper functions

How to test

  1. Stop the process_pending_aggregations command if running
  2. Run the new command in dry-run mode: poetry run python manage.py populate_tree_tests_rollup --since-days=7 --dry-run
  3. Process a specific checkout: poetry run python manage.py populate_tree_tests_rollup --checkout-id=<uuid>
  4. Restart process_pending_aggregations after completion

Closes #1882

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a one-off Django management command to (re)populate tree_tests_rollup from existing Tests/Builds/Incidents data, and centralizes the rollup processed-item key hashing helper so both streaming aggregation and backfill paths use the same key generator.

Changes:

  • Introduces populate_tree_tests_rollup management command to recompute/upsert tree_tests_rollup and upsert corresponding ProcessedListingItems entries.
  • Moves get_rollup_key() into process_pending_helpers and reuses it from process_pending_aggregations.
  • Tightens typing in process_pending_helpers to use RollupKey for rollup dictionaries.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
backend/kernelCI_app/management/commands/process_pending_aggregations.py Imports shared get_rollup_key() instead of defining a local version.
backend/kernelCI_app/management/commands/populate_tree_tests_rollup.py New command that aggregates tests into rollup buckets and writes rollup + processed markers.
backend/kernelCI_app/management/commands/helpers/process_pending_helpers.py Adds shared get_rollup_key() and updates rollup typing to use RollupKey.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/kernelCI_app/management/commands/populate_tree_tests_rollup.py Outdated
Comment thread backend/kernelCI_app/management/commands/populate_tree_tests_rollup.py Outdated
Comment thread backend/kernelCI_app/management/commands/populate_tree_tests_rollup.py Outdated
Comment thread backend/kernelCI_app/management/commands/populate_tree_tests_rollup.py Outdated
Comment thread backend/kernelCI_app/management/commands/populate_tree_tests_rollup.py Outdated
@gustavobtflores gustavobtflores marked this pull request as draft April 24, 2026 12:28
@gustavobtflores gustavobtflores force-pushed the feat/tree-tests-rollup-populate-command branch 2 times, most recently from 1b8f800 to a3099d0 Compare April 28, 2026 19:22
@gustavobtflores gustavobtflores changed the title Feat/tree tests rollup populate command feat: add command to recompute tree_tests_rollup Apr 29, 2026
@gustavobtflores gustavobtflores marked this pull request as ready for review April 29, 2026 13:12
@gustavobtflores gustavobtflores added Backend Most or all of the changes for this issue will be in the backend code. Ingester The issue relates to the ingester tool, including the command itself and related functions. labels Apr 29, 2026
@gustavobtflores gustavobtflores force-pushed the feat/tree-tests-rollup-populate-command branch from a3099d0 to 6467279 Compare April 30, 2026 13:31
) -> None:
"""Merge chunk rollup data into the accumulator."""
for key, data in chunk_rollup.items():
if key in accumulator:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we just set the default to be a dict full of zeros?

raise CommandError(f"Checkout with id={checkout_id} not found")

if limit is not None:
checkouts_qs = checkouts_qs[:limit]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkouts_qs[:None] should give you the whole list, we can avoid this conditional

@gustavobtflores gustavobtflores force-pushed the feat/tree-tests-rollup-populate-command branch from 6467279 to 52725fe Compare April 30, 2026 17:08
Copy link
Copy Markdown
Collaborator

@MarceloRobert MarceloRobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to have worked well in my tests

@gustavobtflores gustavobtflores force-pushed the feat/tree-tests-rollup-populate-command branch from 52725fe to 3a10c51 Compare April 30, 2026 21:34
values = [
(
*key,
data["pass_tests"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we use query named args? to avoid having to create these tuples? It could also improve readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend Most or all of the changes for this issue will be in the backend code. Ingester The issue relates to the ingester tool, including the command itself and related functions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add management command to recompute tree_tests_rollup from source data

4 participants