Skip to content

Include recent failures data in test reports response

Erick Bajao requested to merge eb-test-failure-history-mvc-api into master

What does this MR do?

This is part of the work for #241759 (closed)

Originally based on the PoC MR: !44047 (closed)

But there's a slight change in behavior wherein we only return the failures count for the project's default branch, which is most of the time master.

This changes test_reports.json response wherein failed test cases will have their recent_failures defined. The format of recent_failures is:

{
  count: 3,
  base_branch: 'master'
}

Example if under existing_failures:

existing_failures: [
  ...
  name: "User #login"
  recent_failures: {count: 1, base_branch: "master"}
  ...
}

This way the frontend will have a way to know which default branch was used.

The work is split into 2 MRs:

  1. Storing the failure data (!45027 (merged))
  2. Fetching the failure data (This MR)

Local result for EXPLAIN ANALYZE

This is the query generated by the call to Ci::TestCaseFailure.recent_failures_count:

SELECT COUNT(ci_test_case_failures.id) AS count_ci_test_case_failures_id, "key_hash" AS key_hash FROM "ci_test_case_failures"
INNER JOIN "ci_test_cases" ON "ci_test_cases"."id" = "ci_test_case_failures"."test_case_id"
WHERE "ci_test_cases"."project_id" = 21
AND "ci_test_cases"."key_hash" IN ('0029c4566b00182c1ad2761d530c1b0dd47049a6c4c7e9289f6605b421a5a152', '00a8903138f4117755cd6371ac6f5df02eae5cff30ab7c887aac1204295c606c', '01aa6e78b631deea04bc0cce05ca68dd3d3b072dbc7ec6f3e638a1f01cb2483e')
AND "ci_test_case_failures"."failed_at" BETWEEN '2020-09-30 17:23:44.384927' AND '2020-10-14 17:23:44.385069'
GROUP BY "key_hash";

Here's the query plan:

                                                                                                                                     QUERY PLAN                                                                                                                                   
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 HashAggregate  (cost=10.58..10.59 rows=1 width=73) (actual time=0.599..0.600 rows=3 loops=1)
   Group Key: ci_test_cases.key_hash
   ->  Nested Loop  (cost=0.83..10.54 rows=7 width=73) (actual time=0.568..0.591 rows=21 loops=1)
         ->  Index Scan using index_ci_test_cases_on_project_id_and_key_hash on ci_test_cases  (cost=0.41..5.27 rows=1 width=73) (actual time=0.551..0.557 rows=3 loops=1)
               Index Cond: ((project_id = 21) AND (key_hash = ANY ('{0029c4566b00182c1ad2761d530c1b0dd47049a6c4c7e9289f6605b421a5a152,00a8903138f4117755cd6371ac6f5df02eae5cff30ab7c887aac1204295c606c,01aa6e78b631deea04bc0cce05ca68dd3d3b072dbc7ec6f3e638a1f01cb2483e}'::text[])))
         ->  Index Scan using index_test_case_failures_unique_columns on ci_test_case_failures  (cost=0.42..5.20 rows=7 width=16) (actual time=0.008..0.009 rows=7 loops=3)
               Index Cond: ((test_case_id = ci_test_cases.id) AND (failed_at >= '2020-09-30 17:23:44.384927+08'::timestamp with time zone) AND (failed_at <= '2020-10-14 17:23:44.385069+08'::timestamp with time zone))
 Planning Time: 7.309 ms
 Execution Time: 0.659 ms
(9 rows)

gitlabhq_development=# select count(1) from ci_test_cases;
 count
-------
 10000
(1 row)

gitlabhq_development=# select count(1) from ci_test_case_failures;
 count
--------
 170000
(1 row)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Erick Bajao

Merge request reports