|
3 | 3 |
|
4 | 4 | import sentry_sdk
|
5 | 5 | from asgiref.sync import async_to_sync
|
| 6 | +from celery import group |
6 | 7 | from shared.celery_config import compute_comparison_task_name
|
7 | 8 | from shared.components import Component
|
8 | 9 | from shared.helpers.flag import Flag
|
9 |
| -from shared.reports.readonly import ReadOnlyReport |
10 | 10 | from shared.torngit.exceptions import TorngitRateLimitError
|
11 | 11 | from shared.yaml import UserYaml
|
12 | 12 |
|
|
16 | 16 | from database.models.reports import ReportLevelTotals, RepositoryFlag
|
17 | 17 | from helpers.comparison import minimal_totals
|
18 | 18 | from helpers.github_installation import get_installation_name_for_owner_for_task
|
| 19 | +from rollouts import PARALLEL_COMPONENT_COMPARISON |
19 | 20 | from services.archive import ArchiveService
|
20 |
| -from services.comparison import ComparisonContext, ComparisonProxy, FilteredComparison |
21 |
| -from services.comparison.types import Comparison, FullCommit |
| 21 | +from services.comparison import ComparisonProxy, FilteredComparison |
| 22 | +from services.comparison_utils import get_comparison_proxy |
22 | 23 | from services.report import ReportService
|
23 | 24 | from services.yaml import get_current_yaml, get_repo_yaml
|
24 | 25 | from tasks.base import BaseCodecovTask
|
| 26 | +from tasks.compute_component_comparison import compute_component_comparison_task |
25 | 27 |
|
26 | 28 | log = logging.getLogger(__name__)
|
27 | 29 |
|
@@ -54,10 +56,11 @@ def run_impl(
|
54 | 56 | installation_name_to_use = get_installation_name_for_owner_for_task(
|
55 | 57 | self.name, repo.owner
|
56 | 58 | )
|
57 |
| - |
58 |
| - comparison_proxy = self.get_comparison_proxy( |
59 |
| - comparison, current_yaml, installation_name_to_use |
| 59 | + report_service = ReportService( |
| 60 | + current_yaml, gh_app_installation_name=installation_name_to_use |
60 | 61 | )
|
| 62 | + |
| 63 | + comparison_proxy = get_comparison_proxy(comparison, report_service) |
61 | 64 | if not comparison_proxy.has_head_report():
|
62 | 65 | comparison.error = CompareCommitError.missing_head_report.value
|
63 | 66 | comparison.state = CompareCommitState.error.value
|
@@ -241,10 +244,31 @@ def compute_component_comparisons(
|
241 | 244 | component_count=len(components),
|
242 | 245 | ),
|
243 | 246 | )
|
244 |
| - for component in components: |
245 |
| - self.compute_component_comparison( |
246 |
| - db_session, comparison, comparison_proxy, component |
247 |
| - ) |
| 247 | + if PARALLEL_COMPONENT_COMPARISON.check_value( |
| 248 | + comparison.compare_commit.repoid, default=False |
| 249 | + ): |
| 250 | + self.parallel_compute_component_comparison(comparison.id, components) |
| 251 | + else: |
| 252 | + for component in components: |
| 253 | + self.compute_component_comparison( |
| 254 | + db_session, comparison, comparison_proxy, component |
| 255 | + ) |
| 256 | + |
| 257 | + @sentry_sdk.trace |
| 258 | + def parallel_compute_component_comparison( |
| 259 | + self, |
| 260 | + comparison_id: int, |
| 261 | + components: list[Component], |
| 262 | + ): |
| 263 | + task_group = group( |
| 264 | + [ |
| 265 | + compute_component_comparison_task.s( |
| 266 | + comparison_id, component.component_id |
| 267 | + ) |
| 268 | + for component in components |
| 269 | + ] |
| 270 | + ) |
| 271 | + task_group.apply_async() |
248 | 272 |
|
249 | 273 | def compute_component_comparison(
|
250 | 274 | self,
|
@@ -288,38 +312,6 @@ def compute_component_comparison(
|
288 | 312 | db_session.add(component_comparison)
|
289 | 313 | db_session.flush()
|
290 | 314 |
|
291 |
| - @sentry_sdk.trace |
292 |
| - def get_comparison_proxy( |
293 |
| - self, comparison, current_yaml, installation_name_to_use: str | None = None |
294 |
| - ): |
295 |
| - compare_commit = comparison.compare_commit |
296 |
| - base_commit = comparison.base_commit |
297 |
| - report_service = ReportService( |
298 |
| - current_yaml, gh_app_installation_name=installation_name_to_use |
299 |
| - ) |
300 |
| - base_report = report_service.get_existing_report_for_commit( |
301 |
| - base_commit, report_class=ReadOnlyReport |
302 |
| - ) |
303 |
| - compare_report = report_service.get_existing_report_for_commit( |
304 |
| - compare_commit, report_class=ReadOnlyReport |
305 |
| - ) |
306 |
| - # No access to the PR so we have to assume the base commit did not need |
307 |
| - # to be adjusted. |
308 |
| - patch_coverage_base_commitid = base_commit.commitid |
309 |
| - return ComparisonProxy( |
310 |
| - Comparison( |
311 |
| - head=FullCommit(commit=compare_commit, report=compare_report), |
312 |
| - project_coverage_base=FullCommit( |
313 |
| - commit=base_commit, report=base_report |
314 |
| - ), |
315 |
| - patch_coverage_base_commitid=patch_coverage_base_commitid, |
316 |
| - enriched_pull=None, |
317 |
| - ), |
318 |
| - context=ComparisonContext( |
319 |
| - gh_app_installation_name=installation_name_to_use |
320 |
| - ), |
321 |
| - ) |
322 |
| - |
323 | 315 | @sentry_sdk.trace
|
324 | 316 | def store_results(self, comparison, impacted_files):
|
325 | 317 | repository = comparison.compare_commit.repository
|
|
0 commit comments