Skip to content
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

feat: add sync test results task #501

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

joseph-sentry
Copy link
Contributor

@joseph-sentry joseph-sentry commented Jun 12, 2024

Depends on: codecov/shared#247
Fixes: codecov/engineering-team#1648 and codecov/engineering-team#1647

Requires risky migration from codecov/shared@05641f5 to be run

Copy link

sentry-io bot commented Jun 12, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: tasks/test_results_processor.py

Function Unhandled Issue
process_individual_upload FileNotInStorageError: File test_results/v1/raw/2024-06-12/25D3451FB922A5B3C2F2E4A374E5B8F0/82d1fcecc7d1aecafa3152c12e01... ...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

@codecov-staging
Copy link

codecov-staging bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 96.82540% with 4 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
+ Coverage   97.49%   97.55%   +0.06%     
==========================================
  Files         418      421       +3     
  Lines       35009    35125     +116     
==========================================
+ Hits        34131    34266     +135     
+ Misses        878      859      -19     
Flag Coverage Δ
integration 97.55% <96.82%> (+0.06%) ⬆️
latest-uploader-overall 97.55% <96.82%> (+0.06%) ⬆️
unit 97.55% <96.82%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.71% <96.42%> (+0.16%) ⬆️
OutsideTasks 97.74% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
celery_config.py 70.51% <100.00%> (+0.38%) ⬆️
database/models/reports.py 99.46% <100.00%> (+<0.01%) ⬆️
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/test_results_processor.py 99.31% <ø> (ø)
tasks/tests/unit/test_backfill_test_instances.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_sync_test_results.py 100.00% <100.00%> (ø)
tasks/backfill_test_instances.py 97.05% <95.00%> (+97.05%) ⬆️
tasks/sync_test_results.py 96.66% <96.66%> (ø)
tasks/tests/unit/conftest.py 76.86% <94.59%> (+6.45%) ⬆️

@codecov-qa
Copy link

codecov-qa bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 96.82540% with 4 lines in your changes missing coverage. Please review.

Project coverage is 97.55%. Comparing base (8eb5cc4) to head (8fad8c4).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
+ Coverage   97.49%   97.55%   +0.06%     
==========================================
  Files         418      421       +3     
  Lines       35009    35125     +116     
==========================================
+ Hits        34131    34266     +135     
+ Misses        878      859      -19     
Flag Coverage Δ
integration 97.55% <96.82%> (+0.06%) ⬆️
latest-uploader-overall 97.55% <96.82%> (+0.06%) ⬆️
unit 97.55% <96.82%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.71% <96.42%> (+0.16%) ⬆️
OutsideTasks 97.74% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
celery_config.py 70.51% <100.00%> (+0.38%) ⬆️
database/models/reports.py 99.46% <100.00%> (+<0.01%) ⬆️
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/test_results_processor.py 99.31% <ø> (ø)
tasks/tests/unit/test_backfill_test_instances.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_sync_test_results.py 100.00% <100.00%> (ø)
tasks/backfill_test_instances.py 97.05% <95.00%> (+97.05%) ⬆️
tasks/sync_test_results.py 96.66% <96.66%> (ø)
tasks/tests/unit/conftest.py 76.86% <94.59%> (+6.45%) ⬆️

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 96.82540% with 4 lines in your changes missing coverage. Please review.

Project coverage is 97.57%. Comparing base (8eb5cc4) to head (8fad8c4).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
+ Coverage   97.51%   97.57%   +0.06%     
==========================================
  Files         449      452       +3     
  Lines       35732    35848     +116     
==========================================
+ Hits        34844    34979     +135     
+ Misses        888      869      -19     
Flag Coverage Δ
integration 97.55% <96.82%> (+0.06%) ⬆️
latest-uploader-overall 97.55% <96.82%> (+0.06%) ⬆️
unit 97.55% <96.82%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.76% <96.42%> (+0.16%) ⬆️
OutsideTasks 97.74% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
celery_config.py 70.51% <100.00%> (+0.38%) ⬆️
database/models/reports.py 99.46% <100.00%> (+<0.01%) ⬆️
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/test_results_processor.py 99.31% <ø> (ø)
tasks/tests/unit/test_backfill_test_instances.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_sync_test_results.py 100.00% <100.00%> (ø)
tasks/backfill_test_instances.py 97.05% <95.00%> (+97.05%) ⬆️
tasks/sync_test_results.py 96.66% <96.66%> (ø)
tasks/tests/unit/conftest.py 76.86% <94.59%> (+6.45%) ⬆️

This change has been scanned for critical changes. Learn more

Copy link

codecov-public-qa bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 96.82540% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 97.55%. Comparing base (8eb5cc4) to head (8fad8c4).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found ☺️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
+ Coverage   97.49%   97.55%   +0.06%     
==========================================
  Files         418      421       +3     
  Lines       35009    35125     +116     
==========================================
+ Hits        34131    34266     +135     
+ Misses        878      859      -19     
Flag Coverage Δ
integration 97.55% <96.82%> (+0.06%) ⬆️
latest-uploader-overall 97.55% <96.82%> (+0.06%) ⬆️
unit 97.55% <96.82%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.71% <96.42%> (+0.16%) ⬆️
OutsideTasks 97.74% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
celery_config.py 70.51% <100.00%> (+0.38%) ⬆️
database/models/reports.py 99.46% <100.00%> (+<0.01%) ⬆️
tasks/__init__.py 100.00% <100.00%> (ø)
tasks/test_results_processor.py 99.31% <ø> (ø)
tasks/tests/unit/test_backfill_test_instances.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_sync_test_results.py 100.00% <100.00%> (ø)
tasks/backfill_test_instances.py 97.05% <95.00%> (+97.05%) ⬆️
tasks/sync_test_results.py 96.66% <96.66%> (ø)
tasks/tests/unit/conftest.py 76.86% <94.59%> (+6.45%) ⬆️

branch=None,
commitid=None,
test_instance_list = (
TestInstance.objects.select_related("upload__report__commit")
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to see we're using the django models! 🥇

for test_instance in chunk:
for i in range(0, test_instance_list.count(), 1000):
updates = []
thing = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rename this to something more meaningful 😅, seems to me this is something like "test_instances_without_identifiers" or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops 😅, test_instances_without_identifiers sounds good


log = logging.getLogger(__name__)

# TODO: turn these into Django ORM calls
Copy link
Contributor

@adrian-codecov adrian-codecov Jun 18, 2024

Choose a reason for hiding this comment

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

I think it should be this or close to this

from django.db.models import Avg, Case, When, Value
from django.db.models.functions import Now
from django.utils import timezone
from datetime import timedelta

... some code

thirty_days_ago = timezone.now() - timedelta(days=30)

failure_rate_queryset = TestInstance.objects.filter(
    repoid=<repoid>,
    created_at__gt=thirty_days_ago,
    outcome__in=['pass', 'failure', 'error']
).values('test_id').annotate(
    failure_rate=Avg(
        Case(
            When(outcome='pass', then=Value(0.0)),
            When(outcome__in=['failure', 'error'], then=Value(1.0)),
            output_field=FloatField()
        )
    )
)

commit_agg_queryset = TestInstance.objects.filter(
    repoid=<repoid>,
    created_at__gt=thirty_days_ago,
    outcome__in=['failure', 'error']
).values('test_id').annotate(
    commits=ArrayAgg('commitid', distinct=True)
)

Copy link
Contributor

@adrian-codecov adrian-codecov left a comment

Choose a reason for hiding this comment

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

Have we tested this in staging? Idk if we have test instances there though

@joseph-sentry
Copy link
Contributor Author

Have we tested this in staging? Idk if we have test instances there though

I think we do have test instances on there, I will see if I can test it out on there

@joseph-sentry joseph-sentry force-pushed the joseph/failure-rate branch 2 times, most recently from 53d3d60 to bf10be5 Compare June 19, 2024 17:27
@joseph-sentry joseph-sentry marked this pull request as draft June 25, 2024 22:22
@joseph-sentry joseph-sentry force-pushed the joseph/failure-rate branch 2 times, most recently from 8c41bce to 034fd8d Compare June 28, 2024 14:45
@joseph-sentry joseph-sentry marked this pull request as ready for review July 2, 2024 13:44
failure rate and commits where failed will be populated by the sync
test resuls task

we are denormalizing the repoid onto the test instance model for perf
reasons
This task should be run when we want to update the failure rate
and commits where failed in the Test model.
this task will populate the fields of test instances that are missing
information since they were created before we added the fields
Signed-off-by: joseph-sentry <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Failed Tests] Commits where a failed test failed over 30 days
2 participants