-
Notifications
You must be signed in to change notification settings - Fork 29
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
add percent changes to test results and flakes aggregates #829
base: main
Are you sure you want to change the base?
Conversation
this commit also adds the LastDuration field to the TestResult GQL model. The reason we're using latest_run and not the updated_at field of the object is because in the future we want to parse the timestamp from the JUnit XML file so latest_run will be tied to that and not the time at which we process the test results.
- TestResultsHeaders represents the information displayed in the Test Analytics UI that is related to test results, total duration of tests, accumulated duration of the 5% slowest tests, total number of failures, and total number of skips - a field of type TestResultsHeaders was added to the Repository model
- rename the TestResultsHeaders GQL model to TestResultsAggregates - create the FlakeAggregates that contains flakeCount and flakeRate and uses the flaky_failure_count field from the DailyTestRollup
we want to be able to filter by flaky tests, failed tests and the slowest tests, because we want the clickable headers in the UI
This adds PercentChange fields to both the TestResultsAggregates and the FlakeAggregates. These work by getting the aggregates for the previous historical period and comparing them with the ones for the current historical period and getting a percentage difference.
❌ 29 Tests Failed:
View the top 3 failed tests by shortest run time
To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
❌ 29 Tests Failed:
View the top 3 failed tests by shortest run time
To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time. ❌ Failed Test Results:Completed 2303 tests with View the full list of failed testspytest
|
❌ 29 Tests Failed:
View the top 3 failed tests by shortest run time
To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
|
||
flake_aggregates = ariadne_load_local_graphql(__file__, "flake_aggregates.graphql") | ||
|
||
__all__ = ["get_current_license", "flake_aggregates_bindable"] |
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.
do we need get_current_license here?
__file__, "test_results_aggregates.graphql" | ||
) | ||
|
||
__all__ = ["get_current_license", "test_results_aggregates_bindable"] |
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.
Similar story with if we need get_current_license
return obj["flake_rate"] | ||
|
||
|
||
@flake_aggregates_bindable.field("flakeCountPercentChange") |
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.
nit: would personally organize these in "bunches" like flakeCount together and then flakeRate together vs. all the counts and all the %'s
I could see either approach tho
|
||
|
||
@flake_aggregates_bindable.field("flakeRatePercentChange") | ||
def resolve_flake_rate_percent_change(obj, _) -> float | None: |
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.
in what situation would we return None for these? Vs. returning 0
repository: Repository, | ||
info: GraphQLResolveInfo, | ||
): | ||
queryset = await sync_to_async(generate_test_results_aggregates)( |
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.
nit: can you just do a return await here for both of these resolvers?
@@ -25,6 +25,16 @@ def resolve_failure_rate(test, info) -> float | None: | |||
return test["failure_rate"] | |||
|
|||
|
|||
@test_result_bindable.field("flakeRate") | |||
def resolve_flake_rate(test, info) -> float | None: |
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.
when would we want these to return None vs. 0?
|
||
@test_results_aggregates_bindable.field("slowestTestsRunTimePercentChange") | ||
def resolve_slowest_tests_run_time_percent_change(obj, _) -> float | None: | ||
return obj.get("slowest_tests_duration_percent_change") |
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.
nit: why is this called duration vs. runTime like the other? and to make resolver name
|
||
|
||
@test_results_aggregates_bindable.field("totalRunTimePercentChange") | ||
def resolve_run_time_percent_change(obj, _) -> float | None: |
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.
Similarly when would these be None vs. 0?
commits_where_fail: list[str] | None | ||
average_duration: float | None | ||
def slow_test_threshold(num_tests: int): | ||
threshold = floor(num_tests * (100 - SLOW_TEST_PERCENTILE) * 0.01) |
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.
nit: / 100 is a little easier to understand what we're doing here vs. * .01
def slow_test_threshold(num_tests: int): | ||
threshold = floor(num_tests * (100 - SLOW_TEST_PERCENTILE) * 0.01) | ||
if threshold == 0: | ||
if num_tests < (1 / ((100 - SLOW_TEST_PERCENTILE) * 0.01)): |
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.
Is this line needed? When would this statement be false if we're taking the floor already on line 30
repoid: int, | ||
branch: str | None = None, | ||
history: dt.timedelta | None = None, | ||
parameter: GENERATE_TEST_RESULT_PARAM | None = None, | ||
) -> QuerySet: | ||
""" | ||
Function that retrieves aggregated information about all tests in a given repository, for a given time range, optionally filtered by branch name. | ||
The fields it calculates are: the test failure rate, commits where this test failed, and average duration of the test. |
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.
as well as last duration, flake rate, etc
branch=branch | ||
) | ||
totals = totals.filter(branch=branch) | ||
print(parameter) |
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.
Reminder prints
test_ids = [flake.test_id for flake in flakes] | ||
|
||
totals = totals.filter(test_id__in=test_ids) | ||
case GENERATE_TEST_RESULT_PARAM.FAILED: |
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.
Question: do cases in python automatically have break statements built in?
|
||
|
||
def percent_diff(a: int | float, b: int | float) -> int | float: | ||
c = (a - b) / b * 100 |
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.
nit: just return this instead of doing variable assignment
) -> dict[str, int | float]: | ||
diff_dict = {} | ||
|
||
for s in ls: |
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.
nit: list comprehension
) -> dict[str, float | int] | None: | ||
repo = Repository.objects.get(repoid=repoid) | ||
time_ago = ( | ||
(dt.datetime.now(dt.UTC) - history) if history is not None else thirty_days_ago |
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.
we can simplify these if else's a bit if we set History to be a const dependent on it's value being passed in OR dt.timedelta(days=30)
so then we can just do time_ago = (
(dt.datetime.now(dt.UTC) - history) and double_time_ago = time_ago -
history
WIth something like history = history or dt.timedelta(days=30)
test_rollups = test_rollups.filter(date__lte=until.date()) | ||
|
||
if len(test_rollups) == 0: | ||
assert 0 == 2 |
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.
reminder remove assert
This adds PercentChange fields to both the TestResultsAggregates
and the FlakeAggregates. These work by getting the aggregates
for the previous historical period and comparing them with the
ones for the current historical period and getting a percentage difference.