summaryrefslogtreecommitdiffstats
path: root/.github/scripts/analytics/data_mart_queries/muted_tests_with_issue_and_area.sql
blob: 39ca47395bde595e1cec1e1e01e3ecdf804c0820 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- Mart slice: how far back ``tests_monitor.date_window`` is included (not ``mute_config.json``).
$mart_history_days = 365;

-- Mart filter: branch/build_type slice for this dashboard (not necessarily all CI matrix branches).
$mart_branch = 'main';
$stable_branches_ge_26_re = '^stable-(2[6-9]|[3-9][0-9])(-.+)?$';

-- Must match ``manual_unmute_ttl_calendar_days`` in ``.github/config/mute_config.json`` (fast-unmute deadline).
$manual_unmute_ttl_calendar_days = 3;

$normalize = ($raw_area) -> {
    $parts = String::SplitToList(Cast($raw_area AS String), '/');
    RETURN Cast(
        IF(ListLength($parts) >= 2, $parts[0] || '/' || $parts[1], Cast($raw_area AS String))
    AS Utf8);
};

$area_fallback = (
    SELECT owner_team AS owner_team, MIN($normalize(area)) AS area
    FROM `test_results/analytics/area_to_owner_mapping`
    GROUP BY owner_team
);

$gim_latest = (
    SELECT
        full_name AS full_name,
        branch AS branch,
        build_type AS build_type,
        github_issue_url AS github_issue_url,
        github_issue_number AS github_issue_number,
        github_issue_state AS github_issue_state,
        github_issue_state_reason AS github_issue_state_reason,
        github_issue_created_at AS github_issue_created_at,
        area_override AS area_override,
        area_override_since AS area_override_since,
        info AS github_issue_info
    FROM (
        SELECT
            g.full_name AS full_name,
            g.branch AS branch,
            g.build_type AS build_type,
            g.github_issue_url AS github_issue_url,
            g.github_issue_number AS github_issue_number,
            g.github_issue_state AS github_issue_state,
            g.github_issue_state_reason AS github_issue_state_reason,
            g.github_issue_created_at AS github_issue_created_at,
            g.area_override AS area_override,
            g.area_override_since AS area_override_since,
            g.info AS info,
            ROW_NUMBER() OVER (
                PARTITION BY g.full_name, g.branch, g.build_type
                ORDER BY g.github_issue_created_at DESC, g.github_issue_number DESC
            ) AS rn
        FROM `test_results/analytics/github_issue_mapping` AS g
    ) AS g_rnk
    WHERE g_rnk.rn = 1
);

$mfu = (
    SELECT
        full_name AS full_name,
        branch AS branch,
        build_type AS build_type,
        github_issue_number AS mfu_issue_number,
        requested_at AS mfu_since,
        window_days AS mfu_window_days,
        requested_at + $manual_unmute_ttl_calendar_days * Interval("P1D") AS mfu_expires_at
    FROM `test_mute/fast_unmute_active`
);

SELECT
    tm.state_filtered AS state_filtered,
    tm.test_name AS test_name,
    tm.suite_folder AS suite_folder,
    tm.full_name AS full_name,
    tm.date_window AS date_window,
    tm.build_type AS build_type,
    tm.branch AS branch,
    tm.days_ago_window AS days_ago_window,
    tm.pass_count AS pass_count,
    tm.mute_count AS mute_count,
    tm.fail_count AS fail_count,
    tm.skip_count AS skip_count,
    tm.owner AS owner,
    tm.is_muted AS is_muted,
    tm.is_test_chunk AS is_test_chunk,
    tm.state AS state,
    tm.previous_state AS previous_state,
    tm.state_change_date AS state_change_date,
    tm.days_in_state AS days_in_state,
    tm.previous_mute_state AS previous_mute_state,
    tm.mute_state_change_date AS mute_state_change_date,
    tm.days_in_mute_state AS days_in_mute_state,
    tm.previous_state_filtered AS previous_state_filtered,
    tm.state_change_date_filtered AS state_change_date_filtered,
    tm.days_in_state_filtered AS days_in_state_filtered,
    Coalesce(
        tm.effective_owner_team,
        Unicode::ToLower(Cast(Coalesce(String::ReplaceAll(tm.owner, 'TEAM:@ydb-platform/', ''), '') AS Utf8))
    ) AS owner_team,
    Coalesce(tm.effective_area, $normalize(Coalesce(af.area, 'area/-'))) AS area,
    tm.previous_effective_owner_team AS previous_effective_owner_team,
    tm.effective_owner_team_changed_date AS effective_owner_team_changed_date,
    gim.github_issue_url AS github_issue_url,
    gim.github_issue_number AS github_issue_number,
    gim.github_issue_state AS github_issue_state,
    gim.github_issue_state_reason AS github_issue_state_reason,
    gim.github_issue_created_at AS github_issue_created_at,
    gim.area_override AS area_override,
    gim.area_override_since AS area_override_since,
    gim.github_issue_info AS github_issue_info,
    JSON_VALUE(gim.github_issue_info, '$.assignees[0].login') AS github_issue_assignee,
    CAST(CASE WHEN mfu.full_name IS NOT NULL THEN 1 ELSE 0 END AS Uint8) AS is_manual_fast_unmute,
    mfu.mfu_since AS manual_fast_unmute_since,
    mfu.mfu_window_days AS manual_fast_unmute_window_days,
    mfu.mfu_expires_at AS manual_fast_unmute_expires_at,
    mfu.mfu_issue_number AS manual_fast_unmute_issue_number
FROM `test_results/analytics/tests_monitor` AS tm
LEFT JOIN $area_fallback AS af
    ON Unicode::ToLower(Cast(Coalesce(String::ReplaceAll(tm.owner, 'TEAM:@ydb-platform/', ''), '') AS Utf8)) = af.owner_team
LEFT JOIN $gim_latest AS gim
    ON tm.full_name = gim.full_name
    AND tm.branch = gim.branch
    AND tm.build_type = gim.build_type
LEFT JOIN $mfu AS mfu
    ON tm.full_name = mfu.full_name
    AND tm.branch = mfu.branch
    AND tm.build_type = mfu.build_type
WHERE tm.date_window >= CurrentUtcDate() - $mart_history_days * Interval("P1D")
    AND (
        tm.branch = $mart_branch
        OR Re2::Match($stable_branches_ge_26_re)(CAST(tm.branch AS String))
    )
    AND tm.is_test_chunk = 0
    AND tm.is_muted = 1
    AND tm.state != 'Skipped';