Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/perfalert/test_alert_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def test_summary_status_invalid_with_only_invalid_alerts(
)

assert test_perf_alert_summary.status == PerformanceAlertSummary.INVALID
assert test_perf_alert_summary.resolution == "invalid"


def test_summary_status_infra_with_only_infra_alerts(test_perf_alert_summary, test_perf_signature):
Expand All @@ -243,6 +244,7 @@ def test_summary_status_infra_with_only_infra_alerts(test_perf_alert_summary, te
)

assert test_perf_alert_summary.status == PerformanceAlertSummary.INFRA
assert test_perf_alert_summary.resolution == "infra"


def test_summary_status_invalid_with_mixed_invalid_and_infra_alerts(
Expand Down Expand Up @@ -275,6 +277,7 @@ def test_summary_status_invalid_with_mixed_invalid_and_infra_alerts(
)

assert test_perf_alert_summary.status == PerformanceAlertSummary.INVALID
assert test_perf_alert_summary.resolution == "invalid"


def test_summary_status_preserves_terminal_states_on_acknowledgement(
Expand All @@ -291,6 +294,7 @@ def test_summary_status_preserves_terminal_states_on_acknowledgement(
)

assert test_perf_alert_summary.status == PerformanceAlertSummary.FIXED
assert test_perf_alert_summary.resolution == "valid"


def test_summary_status_reassigned_with_only_reassigned_alerts(
Expand All @@ -305,6 +309,7 @@ def test_summary_status_reassigned_with_only_reassigned_alerts(
)

assert test_perf_alert_summary.status == PerformanceAlertSummary.REASSIGNED
assert test_perf_alert_summary.resolution == "reassigned"


def test_summary_status_downstream_with_only_downstream_alerts(
Expand All @@ -319,3 +324,27 @@ def test_summary_status_downstream_with_only_downstream_alerts(
)

assert test_perf_alert_summary.status == PerformanceAlertSummary.DOWNSTREAM
assert test_perf_alert_summary.resolution == "downstream"


def test_summary_resolution_follows_alert_status_changes(
test_perf_alert_summary, test_perf_signature
):
alert = create_perf_alert(
summary=test_perf_alert_summary,
series_signature=test_perf_signature,
status=PerformanceAlert.ACKNOWLEDGED,
is_regression=True,
)
test_perf_alert_summary.refresh_from_db()
assert test_perf_alert_summary.resolution == "valid"

alert.status = PerformanceAlert.INVALID
alert.save()
test_perf_alert_summary.refresh_from_db()
assert test_perf_alert_summary.resolution == "invalid"

alert.status = PerformanceAlert.UNTRIAGED
alert.save()
test_perf_alert_summary.refresh_from_db()
assert test_perf_alert_summary.resolution is None
61 changes: 61 additions & 0 deletions tests/ui/perfherder/alerts-view/alerts_test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
alertBackfillResultVisual,
alertBackfillResultStatusMap,
notSupportedAlertFiltersMessage,
summaryStatusMap,
} from '../../../../ui/perfherder/perf-helpers/constants';
import repos from '../../mock/repositories';
import { getApiUrl } from '../../../../ui/helpers/url';
Expand Down Expand Up @@ -306,6 +307,66 @@ test('an unknown changeType in the URL falls back to all types', async () => {
).toBe(false);
});

test('selecting a resolution sends resolution to the API and widens the untriaged status', async () => {
fetchMock.resetHistory();
const { findByText, getAllByText } = alertsView();

fireEvent.click(await findByText('all resolutions'));
const validOption = await waitFor(() => {
const option = getAllByText('valid').find((element) =>
element.closest('.dropdown-item'),
);
expect(option).toBeDefined();
return option;
});
fireEvent.click(validOption);

await waitFor(() =>
expect(
fetchMock.calls().some(([url]) => url.includes('resolution=valid')),
).toBe(true),
);
const resolutionCall = fetchMock
.calls()
.find(([url]) => url.includes('resolution=valid'));
expect(resolutionCall[0]).not.toMatch(/[?&]status=/);
});

test('resolution in the URL initialises the resolution dropdown and is sent to the API', async () => {
fetchMock.resetHistory();
const { findByText } = alertsView('?resolution=infra');

await findByText('infra');
await waitFor(() =>
expect(
fetchMock.calls().some(([url]) => url.includes('resolution=infra')),
).toBe(true),
);
const resolutionCall = fetchMock
.calls()
.find(([url]) => url.includes('resolution=infra'));
expect(resolutionCall[0]).not.toMatch(/[?&]status=/);
});

test('an untriaged status with a resolution in the URL falls back to all statuses', async () => {
fetchMock.resetHistory();
const { findByText } = alertsView(
`?status=${summaryStatusMap['untriaged regressions']}&resolution=valid`,
);

await findByText('all statuses');
await waitFor(() =>
expect(
fetchMock.calls().some(([url]) => url.includes('resolution=valid')),
).toBe(true),
);
const resolutionCall = fetchMock
.calls()
.find(([url]) => url.includes('resolution=valid'));
expect(resolutionCall[0]).not.toMatch(/[?&]status=/);
expect(resolutionCall[0]).not.toMatch(/untriaged_regressions/);
});

test('selecting a severity from the severity dropdown sends severity to the API', async () => {
const { findByText, getAllByText } = alertsView();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ test('should sort all frameworks after clicking', async () => {

const filterElement = alertsViewControls.render();
const filterElementChildren = filterElement.props.children[0];

expect(filterElementChildren.props.dropdownOptions[1].options).toEqual([
expect(filterElementChildren.props.dropdownOptions[2].options).toEqual([
'framework-a',
'framework-b',
'framework-c',
Expand Down
73 changes: 73 additions & 0 deletions tests/webapp/api/test_performance_alertsummary_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def test_alert_summaries_get(
"duplicated_summaries",
"severity",
"change_type",
"resolution",
}
assert len(resp.json()["results"][0]["alerts"]) == 1
assert set(resp.json()["results"][0]["alerts"][0].keys()) == {
Expand Down Expand Up @@ -375,6 +376,7 @@ def test_alert_summaries_get_onhold(
"duplicated_summaries",
"severity",
"change_type",
"resolution",
}
assert len(resp.json()["results"][0]["alerts"]) == 1
assert set(resp.json()["results"][0]["alerts"][0].keys()) == {
Expand Down Expand Up @@ -436,6 +438,10 @@ def test_alert_summaries_put(
assert resp.status_code == 200
assert PerformanceAlertSummary.objects.get(id=1).status == 1

resp = client.put(reverse("performance-alert-summaries-list") + "1/", {"status": 3})
assert resp.status_code == 200
assert PerformanceAlertSummary.objects.get(id=1).resolution == "invalid"

# verify we can set assignee
client.force_authenticate(user=test_sheriff)
resp = client.put(
Expand Down Expand Up @@ -884,6 +890,46 @@ def test_cannot_add_unregistered_tag_to_a_summary(
assert test_perf_alert_summary.performance_tags.count() == 1


def test_backed_out_status_sets_valid_resolution(
client, authorized_sheriff_client, test_perf_alert_summary
):
resp = authorized_sheriff_client.put(
reverse("performance-alert-summaries-list") + "1/",
{"status": PerformanceAlertSummary.BACKED_OUT},
)
assert resp.status_code == 200

test_perf_alert_summary.refresh_from_db()
assert test_perf_alert_summary.resolution == "valid"

resp = client.get(
reverse("performance-alert-summaries-list"),
data={"resolution": "valid"},
)
assert resp.status_code == 200

retrieved_summaries = resp.json()["results"]
assert [summary["id"] for summary in retrieved_summaries] == [test_perf_alert_summary.id]


def test_alert_summary_resolution_is_read_only(
authorized_sheriff_client, test_perf_alert_summary, test_perf_signature
):
create_perf_alert(
summary=test_perf_alert_summary,
series_signature=test_perf_signature,
status=PerformanceAlert.INVALID,
)

resp = authorized_sheriff_client.put(
reverse("performance-alert-summaries-list") + "1/", {"resolution": "valid"}
)
assert resp.status_code == 200

test_perf_alert_summary.refresh_from_db()
assert test_perf_alert_summary.resolution == "invalid"


def test_timerange_with_summary_outside_range(
client, create_push, test_repository, test_perf_alert_summary, test_perf_alert_summary_2
):
Expand Down Expand Up @@ -1272,6 +1318,33 @@ def test_alert_summaries_filter_with_bug_resolution(
assert summary_ids == [test_perf_alert_summary.id]


def test_alert_summaries_filter_by_resolution(
client, test_perf_alert_summary, test_perf_alert_summary_2
):
test_perf_alert_summary.resolution = "valid"
test_perf_alert_summary.save()

test_perf_alert_summary_2.resolution = "infra"
test_perf_alert_summary_2.save()

resp = client.get(
reverse("performance-alert-summaries-list"),
data={"resolution": "valid"},
)
assert resp.status_code == 200

retrieved_summaries = resp.json()["results"]
summary_ids = [summary["id"] for summary in retrieved_summaries]

assert summary_ids == [test_perf_alert_summary.id]

resp = client.get(
reverse("performance-alert-summaries-list"),
data={"resolution": "not-a-resolution"},
)
assert resp.status_code == 400


def test_untriaged_regressions_filter(
client,
test_perf_alert_summary,
Expand Down
10 changes: 3 additions & 7 deletions tests/webapp/api/test_performance_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def test_perf_tags_get(authorized_sheriff_client, test_perf_tag, test_perf_tag_2
resp = authorized_sheriff_client.get(reverse("performance-tags-list"))
assert resp.status_code == 200

assert len(resp.json()) == 2

assert resp.json()[0]["id"] == test_perf_tag.id
assert resp.json()[0]["name"] == test_perf_tag.name

assert resp.json()[1]["id"] == test_perf_tag_2.id
assert resp.json()[1]["name"] == test_perf_tag_2.name
tags = {tag["id"]: tag["name"] for tag in resp.json()}
assert tags[test_perf_tag.id] == test_perf_tag.name
assert tags[test_perf_tag_2.id] == test_perf_tag_2.name
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 6.0.8 on 2026-11-11 16:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('perf', '0088_alert_confidence_level'),
]

operations = [
migrations.AddField(
model_name='performancealertsummary',
name='resolution',
field=models.CharField(choices=[('valid', 'Valid'), ('invalid', 'Invalid'), ('infra', 'Infra'), ('downstream', 'Downstream'), ('reassigned', 'Reassigned')], default=None, max_length=20, null=True),
),
migrations.AddField(
model_name='performancealertsummarytesting',
name='resolution',
field=models.CharField(choices=[('valid', 'Valid'), ('invalid', 'Invalid'), ('infra', 'Infra'), ('downstream', 'Downstream'), ('reassigned', 'Reassigned')], default=None, max_length=20, null=True),
),
migrations.AddField(
model_name='performancetelemetryalertsummary',
name='resolution',
field=models.CharField(choices=[('valid', 'Valid'), ('invalid', 'Invalid'), ('infra', 'Infra'), ('downstream', 'Downstream'), ('reassigned', 'Reassigned')], default=None, max_length=20, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from django.db import migrations

RESOLUTION_BY_STATUS = {
1: "downstream",
2: "reassigned",
3: "invalid",
4: "valid",
5: "valid",
6: "valid",
7: "valid",
9: "infra",
}
BACKED_OUT_STATUS = 8
BACKED_OUT_TAG = "backed-out"
SUMMARY_MODELS = (
"PerformanceAlertSummary",
"PerformanceAlertSummaryTesting",
"PerformanceTelemetryAlertSummary",
)


def backfill_resolution(apps, schema_editor):
for model_name in SUMMARY_MODELS:
model = apps.get_model("perf", model_name)
for status, resolution in RESOLUTION_BY_STATUS.items():
model.objects.filter(status=status, resolution__isnull=True).update(
resolution=resolution
)

PerformanceAlertSummary = apps.get_model("perf", "PerformanceAlertSummary")
PerformanceTag = apps.get_model("perf", "PerformanceTag")
tag, _ = PerformanceTag.objects.get_or_create(name=BACKED_OUT_TAG)

backed_out_summaries = PerformanceAlertSummary.objects.filter(
status=BACKED_OUT_STATUS, resolution__isnull=True
)
summary_ids = list(backed_out_summaries.values_list("id", flat=True))
if not summary_ids:
return

backed_out_summaries.update(resolution="valid")

through = PerformanceTag.alert_summaries.through
through.objects.bulk_create(
[
through(performancetag_id=tag.id, performancealertsummary_id=summary_id)
for summary_id in summary_ids
],
ignore_conflicts=True,
)


class Migration(migrations.Migration):
dependencies = [
("perf", "0089_performancealertsummary_resolution_and_more"),
]

operations = [
migrations.RunPython(backfill_resolution, migrations.RunPython.noop),
]
Loading
Loading