-
Notifications
You must be signed in to change notification settings - Fork 385
[WIP] Bug 2051180 - Track which pushes are actually backfilled #9662
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
Open
junngo
wants to merge
1
commit into
mozilla:master
Choose a base branch
from
junngo:track-backfilled-push
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
129 changes: 129 additions & 0 deletions
129
treeherder/perf/auto_perf_sheriffing/backfill_tracker.py
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,129 @@ | ||
| import ast | ||
| import json | ||
| import logging | ||
| import re | ||
|
|
||
| import requests | ||
|
|
||
| from treeherder.model.models import JobLog, TaskclusterMetadata | ||
| from treeherder.perf.models import BackfilledPush, BackfillRequest | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class BackfillTracker: | ||
| RE_BACKFILL_DATA = re.compile(r".*?BACKFILL_DATA:\s+({.*})") | ||
|
|
||
| def sync(self): | ||
| pending_requests = BackfillRequest.objects.filter(status=BackfillRequest.PENDING) | ||
| for request in pending_requests: | ||
| try: | ||
| self._sync_one(request) | ||
| except Exception as ex: | ||
| logger.warning(f"Failed to sync BackfillRequest {request.id}: {ex}") | ||
|
|
||
| def _sync_one(self, request: BackfillRequest): | ||
| try: | ||
| tc_metadata = TaskclusterMetadata.objects.get(task_id=request.bk_task_id) | ||
| except TaskclusterMetadata.DoesNotExist: | ||
| logger.info( | ||
| f"BackfillRequest {request.id}: bk_task {request.bk_task_id} not yet ingested, skipping." | ||
| ) | ||
| return | ||
|
|
||
| job = tc_metadata.job | ||
| try: | ||
| job_log = job.job_log.get(name="live_backing_log") | ||
| except JobLog.DoesNotExist: | ||
| logger.warning( | ||
| f"BackfillRequest {request.id}: live_backing_log not found for job {job.id}." | ||
| ) | ||
| request.status = BackfillRequest.FAILED | ||
| request.save() | ||
| return | ||
|
|
||
| if job_log.status != JobLog.PARSED: | ||
| logger.info( | ||
| f"BackfillRequest {request.id}: live_backing_log not yet parsed for job {job.id}, skipping." | ||
| ) | ||
| return | ||
|
|
||
| try: | ||
| response = requests.get(job_log.url, timeout=30) | ||
| response.raise_for_status() | ||
| except requests.RequestException as ex: | ||
| logger.warning( | ||
| f"BackfillRequest {request.id}: Failed to fetch log from {job_log.url}: {ex}" | ||
| ) | ||
| return | ||
|
|
||
| for line in response.text.splitlines(): | ||
| if "Backfill started:" in line: | ||
| parsed = self._parse_backfill_started(line) | ||
| request.label = parsed["label"] | ||
| request.strategy = parsed["strategy"] | ||
| request.slices = parsed["slices"] | ||
| request.target_hg_push_ids = parsed["target_hg_push_ids"] | ||
| request.scanned_push_count = parsed["scanned_push_count"] | ||
| elif "BACKFILL_DATA:" in line: | ||
| match = self.RE_BACKFILL_DATA.match(line) | ||
| if match: | ||
| try: | ||
| entry = json.loads(match.group(1)) | ||
| except json.JSONDecodeError as ex: | ||
| logger.warning( | ||
| f"BackfillRequest {request.id}: Failed to parse BACKFILL_DATA line: {ex}" | ||
| ) | ||
| continue | ||
| try: | ||
| push_id = TaskclusterMetadata.objects.get( | ||
| task_id=entry["decision_task_id"] | ||
| ).job.push_id | ||
| except TaskclusterMetadata.DoesNotExist: | ||
| logger.warning( | ||
| f"BackfillRequest {request.id}: decision task {entry['decision_task_id']} not yet ingested, skipping line." | ||
| ) | ||
| continue | ||
| BackfilledPush.objects.get_or_create( | ||
| backfill_request=request, | ||
| push_id=push_id, | ||
| defaults={"decision_task_id": entry["decision_task_id"]}, | ||
| ) | ||
|
|
||
| if job.state == "completed": | ||
| request.status = BackfillRequest.SYNCED | ||
|
|
||
| request.save() | ||
|
|
||
| @staticmethod | ||
| def _parse_backfill_started(line: str) -> dict: | ||
| content = line[len("Backfill started: ") :] | ||
|
|
||
| label_match = re.search(r"label=([^,]+)", content) | ||
| strategy_match = re.search(r"strategy=([^,]+)", content) | ||
| slices_match = re.search(r"slices=(\d+)", content) | ||
| target_pushes_match = re.search(r"target_pushes=(\[.*?\])", content) | ||
|
|
||
| label = label_match.group(1).strip() if label_match else "" | ||
| strategy_str = strategy_match.group(1).strip() if strategy_match else "standard" | ||
| slices = int(slices_match.group(1)) if slices_match else 0 | ||
|
|
||
| target_hg_push_ids = [] | ||
| if target_pushes_match: | ||
| try: | ||
| raw = ast.literal_eval(target_pushes_match.group(1)) | ||
| target_hg_push_ids = [str(p) for p in raw] | ||
| except (ValueError, SyntaxError) as ex: | ||
| logger.warning(f"Failed to parse target_pushes: {ex}") | ||
|
|
||
| strategy = ( | ||
| BackfillRequest.STANDARD if strategy_str == "standard" else BackfillRequest.SLICED | ||
| ) | ||
|
|
||
| return { | ||
| "label": label, | ||
| "strategy": strategy, | ||
| "slices": slices, | ||
| "target_hg_push_ids": target_hg_push_ids, | ||
| "scanned_push_count": len(target_hg_push_ids), | ||
| } | ||
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
110 changes: 110 additions & 0 deletions
110
treeherder/perf/migrations/0078_backfillrequest_backfilledpush.py
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,110 @@ | ||
| # Generated by Django 6.0.3 on 2026-07-03 07:23 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("model", "0053_push_branch"), | ||
| ("perf", "0077_add_infra_status"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="BackfillRequest", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ("bk_task_id", models.CharField(db_index=True, max_length=255)), | ||
| ("label", models.CharField(blank=True, max_length=255, null=True)), | ||
| ( | ||
| "strategy", | ||
| models.IntegerField( | ||
| blank=True, choices=[(0, "Standard"), (1, "Sliced")], null=True | ||
| ), | ||
| ), | ||
| ("slices", models.IntegerField(blank=True, null=True)), | ||
| ("target_hg_push_ids", models.JSONField(default=list)), | ||
| ("scanned_push_count", models.IntegerField(default=0)), | ||
| ( | ||
| "status", | ||
| models.IntegerField( | ||
| choices=[(0, "Pending"), (1, "Synced"), (2, "Failed")], | ||
| default=0, | ||
| ), | ||
| ), | ||
| ("created", models.DateTimeField(auto_now_add=True)), | ||
| ("last_updated", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "job", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="backfill_requests", | ||
| to="model.job", | ||
| ), | ||
| ), | ||
| ( | ||
| "push", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="backfill_requests", | ||
| to="model.push", | ||
| ), | ||
| ), | ||
| ( | ||
| "repository", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| to="model.repository", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "backfill_request", | ||
| }, | ||
| ), | ||
| migrations.CreateModel( | ||
| name="BackfilledPush", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ("decision_task_id", models.CharField(max_length=255)), | ||
| ("created", models.DateTimeField(auto_now_add=True)), | ||
| ( | ||
| "push", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="+", | ||
| to="model.push", | ||
| ), | ||
| ), | ||
| ( | ||
| "backfill_request", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="backfilled_pushes", | ||
| to="perf.backfillrequest", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "backfilled_push", | ||
| }, | ||
| ), | ||
| ] |
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
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.
This helper will be removed after the format is changed to JSON by https://phabricator.services.mozilla.com/D309317