This repository was archived by the owner on May 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: implement cache rollup task using TA timeseries models #1135
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| from datetime import UTC | ||
| from io import BytesIO | ||
|
|
||
| import polars as pl | ||
| import shared.storage | ||
|
|
||
| from django_scaffold import settings | ||
| from services.test_analytics.ta_timeseries import ( | ||
| get_branch_summary, | ||
| get_summary, | ||
| get_testrun_branch_summary_via_testrun, | ||
| ) | ||
|
|
||
|
|
||
| def rollup_blob_path(repoid: int, branch: str | None = None) -> str: | ||
| return ( | ||
| f"test_analytics/branch_rollups/{repoid}/{branch}.arrow" | ||
| if branch | ||
| else f"test_analytics/repo_rollups/{repoid}.arrow" | ||
| ) | ||
|
|
||
|
|
||
| POLARS_SCHEMA = [ | ||
| "computed_name", | ||
| ("flags", pl.List(pl.String)), | ||
| "failing_commits", | ||
| "last_duration", | ||
| "avg_duration", | ||
| "pass_count", | ||
| "fail_count", | ||
| "flaky_fail_count", | ||
| "skip_count", | ||
| ("updated_at", pl.Datetime(time_zone=UTC)), | ||
| "timestamp_bin", | ||
| ] | ||
|
|
||
|
|
||
| def cache_rollups(repoid: int, branch: str | None = None): | ||
| storage_service = shared.storage.get_appropriate_storage_service(repoid) | ||
| serialized_table: BytesIO | ||
|
|
||
| if branch: | ||
| if branch in {"main", "master", "develop"}: | ||
| summaries = get_branch_summary(repoid, branch) | ||
| else: | ||
| summaries = get_testrun_branch_summary_via_testrun(repoid, branch) | ||
| else: | ||
| summaries = get_summary(repoid) | ||
|
|
||
| data = [ | ||
| { | ||
| "computed_name": summary.computed_name, | ||
| "flags": summary.flags, | ||
| "failing_commits": summary.failing_commits, | ||
| "last_duration": summary.last_duration_seconds, | ||
| "avg_duration": summary.avg_duration_seconds, | ||
| "pass_count": summary.pass_count, | ||
| "fail_count": summary.fail_count, | ||
| "flaky_fail_count": summary.flaky_fail_count, | ||
| "skip_count": summary.skip_count, | ||
| "updated_at": summary.updated_at, | ||
| "timestamp_bin": summary.timestamp_bin.date(), | ||
| } | ||
| for summary in summaries | ||
| ] | ||
|
|
||
| serialized_table = pl.DataFrame( | ||
| data, | ||
| POLARS_SCHEMA, | ||
| orient="row", | ||
| ).write_ipc(None) | ||
|
|
||
| serialized_table.seek(0) | ||
|
|
||
| storage_service.write_file( | ||
| settings.GCS_BUCKET_NAME, rollup_blob_path(repoid, branch), serialized_table | ||
| ) | ||
42 changes: 42 additions & 0 deletions
42
services/test_analytics/tests/snapshots/ta_cache_rollups__cache_test_rollups__0.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "computed_name": [ | ||
| "computed_name2", | ||
| "computed_name" | ||
| ], | ||
| "flags": [ | ||
| [ | ||
| "test-rollups2" | ||
| ], | ||
| [ | ||
| "test-rollups" | ||
| ] | ||
| ], | ||
| "failing_commits": [ | ||
| 2, | ||
| 1 | ||
| ], | ||
| "last_duration": [ | ||
| 200.0, | ||
| 100.0 | ||
| ], | ||
| "avg_duration": [ | ||
| 200.0, | ||
| 100.0 | ||
| ], | ||
| "pass_count": [ | ||
| 0, | ||
| 0 | ||
| ], | ||
| "fail_count": [ | ||
| 2, | ||
| 1 | ||
| ], | ||
| "flaky_fail_count": [ | ||
| 0, | ||
| 0 | ||
| ], | ||
| "skip_count": [ | ||
| 0, | ||
| 0 | ||
| ] | ||
| } |
43 changes: 43 additions & 0 deletions
43
...lytics/tests/snapshots/ta_cache_rollups__cache_test_rollups_use_timeseries_branch__0.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| { | ||
| "computed_name": [ | ||
| "computed_name", | ||
| "computed_name2" | ||
| ], | ||
| "flags": [ | ||
| [ | ||
| "test-rollups" | ||
| ], | ||
| [ | ||
| "test-rollups", | ||
| "test-rollups2" | ||
| ] | ||
| ], | ||
| "failing_commits": [ | ||
| 0, | ||
| 1 | ||
| ], | ||
| "last_duration": [ | ||
| 100.0, | ||
| 1.0 | ||
| ], | ||
| "avg_duration": [ | ||
| 100.0, | ||
| 50.5 | ||
| ], | ||
| "pass_count": [ | ||
| 1, | ||
| 1 | ||
| ], | ||
| "fail_count": [ | ||
| 0, | ||
| 1 | ||
| ], | ||
| "flaky_fail_count": [ | ||
| 0, | ||
| 0 | ||
| ], | ||
| "skip_count": [ | ||
| 0, | ||
| 0 | ||
| ] | ||
| } |
42 changes: 42 additions & 0 deletions
42
...nalytics/tests/snapshots/ta_cache_rollups__cache_test_rollups_use_timeseries_main__0.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "computed_name": [ | ||
| "computed_name2", | ||
| "computed_name" | ||
| ], | ||
| "flags": [ | ||
| [ | ||
| "test-rollups2" | ||
| ], | ||
| [ | ||
| "test-rollups" | ||
| ] | ||
| ], | ||
| "failing_commits": [ | ||
| 2, | ||
| 1 | ||
| ], | ||
| "last_duration": [ | ||
| 200.0, | ||
| 100.0 | ||
| ], | ||
| "avg_duration": [ | ||
| 200.0, | ||
| 100.0 | ||
| ], | ||
| "pass_count": [ | ||
| 0, | ||
| 0 | ||
| ], | ||
| "fail_count": [ | ||
| 2, | ||
| 1 | ||
| ], | ||
| "flaky_fail_count": [ | ||
| 0, | ||
| 0 | ||
| ], | ||
| "skip_count": [ | ||
| 0, | ||
| 0 | ||
| ] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
Repositoryhas a dedicated field for the main branch, we should probably use that instead of hardcoding a set here.If you still want to hardcode the list, better to define it as a top level const so its more discoverable.
Uh oh!
There was an error while loading. Please reload this page.
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.
it would make sense to do this, except we want to use the continuous aggregates, and to do this we would need to access the
repo.branchfrom timescale, which isn't possible right now. I have ideas on how to do this in the future, but for now, I think this will be good enough for most of our users.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.
that does make sense, yes.
maybe a boolean
is_main_branchor something that you feed in when processing, at which time you have access to the repo metadata.