Bug 1725165 - Display old alerts in graphs view (#7315)

* Bug 1725165 - Display old alerts in graphs view

* unit tests and changes

* cleanup extra endpoint

* fix-lint-errors

* add timerange tests

* Resolve comments

* Bug 1725165 - Fixed failing tests

Co-authored-by: bacasandrei <beatrice.raluca.acasandrei@gmail.com>
This commit is contained in:
Alexandru Irimovici 2022-02-22 17:35:57 +02:00 коммит произвёл GitHub
Родитель deccc196fb
Коммит 067c58ad21
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 132 добавлений и 9 удалений

Просмотреть файл

@ -1,4 +1,5 @@
import datetime
import uuid
from datetime import datetime, timedelta
import pytest
from django.urls import reverse
@ -32,7 +33,7 @@ def test_perf_alert_summary_onhold(test_repository_onhold, test_perf_framework):
repository=test_repository_onhold,
revision='1234abcd{}'.format(i),
author='foo@bar.com',
time=datetime.datetime.now(),
time=datetime.now(),
)
return PerformanceAlertSummary.objects.create(
@ -41,7 +42,7 @@ def test_perf_alert_summary_onhold(test_repository_onhold, test_perf_framework):
prev_push_id=1,
push_id=2,
manually_created=False,
created=datetime.datetime.now(),
created=datetime.now(),
)
@ -325,7 +326,7 @@ def test_bug_number_and_timestamp_on_overriding(
authorized_sheriff_client, test_perf_alert_summary_with_bug
):
assert test_perf_alert_summary_with_bug.bug_number == 123456
assert test_perf_alert_summary_with_bug.bug_updated < datetime.datetime.now()
assert test_perf_alert_summary_with_bug.bug_updated < datetime.now()
bug_linking_time = test_perf_alert_summary_with_bug.bug_updated
@ -403,6 +404,109 @@ def test_cannot_add_unregistered_tag_to_a_summary(
assert test_perf_alert_summary.performance_tags.count() == 1
def test_timerange_with_summary_outside_range(
client, create_push, test_repository, test_perf_alert_summary, test_perf_alert_summary_2
):
# 30 days timerange
timerange_to_test = 30 * 24 * 60 * 60
past_date = datetime.now() - timedelta(weeks=9)
test_perf_alert_summary.push = create_push(
test_repository, revision=uuid.uuid4(), time=past_date
)
test_perf_alert_summary.save()
test_perf_alert_summary_2.push.time = datetime.now()
test_perf_alert_summary_2.push.save()
resp = client.get(
reverse('performance-alert-summaries-list'),
data={
'framework': 1,
'timerange': timerange_to_test,
},
)
assert resp.status_code == 200
retrieved_summaries = resp.json()['results']
summary_ids = [summary['id'] for summary in retrieved_summaries]
assert test_perf_alert_summary_2.id in summary_ids
assert len(summary_ids) == 1
def test_timerange_with_all_summaries_in_range(
client, create_push, test_repository, test_perf_alert_summary, test_perf_alert_summary_2
):
# 7 days timerange
timerange_to_test = 7 * 24 * 60 * 60
past_date = datetime.now() - timedelta(days=2)
test_perf_alert_summary.push = create_push(
test_repository, revision=uuid.uuid4(), time=past_date
)
test_perf_alert_summary.save()
test_perf_alert_summary_2.push.time = datetime.now()
test_perf_alert_summary_2.push.save()
resp = client.get(
reverse('performance-alert-summaries-list'),
data={
'framework': 1,
'timerange': timerange_to_test,
},
)
assert resp.status_code == 200
retrieved_summaries = resp.json()['results']
summary_ids = [summary['id'] for summary in retrieved_summaries]
assert test_perf_alert_summary.id in summary_ids
assert test_perf_alert_summary_2.id in summary_ids
assert len(summary_ids) == 2
def test_pagesize_is_limited_from_params(
client, test_perf_alert_summary, test_perf_alert_summary_2
):
resp = client.get(
reverse('performance-alert-summaries-list'),
data={
'framework': 1,
'limit': 1,
},
)
assert resp.status_code == 200
retrieved_summaries = resp.json()['results']
summary_ids = [summary['id'] for summary in retrieved_summaries]
assert test_perf_alert_summary_2.id in summary_ids
assert len(summary_ids) == 1
def test_pagesize_with_limit_higher_than_total_summaries(
client, test_perf_alert_summary, test_perf_alert_summary_2
):
resp = client.get(
reverse('performance-alert-summaries-list'),
data={
'framework': 1,
'limit': 5,
},
)
assert resp.status_code == 200
resp_json = resp.json()
assert resp_json['next'] is None
assert resp_json['previous'] is None
retrieved_summaries = resp_json['results']
summary_ids = [summary['id'] for summary in retrieved_summaries]
assert test_perf_alert_summary.id in summary_ids
assert test_perf_alert_summary_2.id in summary_ids
assert len(summary_ids) == 2
@pytest.fixture
def related_alert(test_perf_alert_summary, test_perf_alert_summary_2, test_perf_signature_2):
return create_perf_alert(

Просмотреть файл

@ -322,6 +322,8 @@ class PerformanceDatumViewSet(viewsets.ViewSet):
class AlertSummaryPagination(pagination.PageNumberPagination):
ordering = ('-created', '-id')
page_size_query_param = 'limit'
max_page_size = 100
page_size = 10
@ -335,6 +337,7 @@ class PerformanceAlertSummaryFilter(django_filters.FilterSet):
hide_improvements = django_filters.BooleanFilter(method='_hide_improvements')
hide_related_and_invalid = django_filters.BooleanFilter(method='_hide_related_and_invalid')
with_assignee = django_filters.CharFilter(method='_with_assignee')
timerange = django_filters.NumberFilter(method='_timerange')
def _filter_text(self, queryset, name, value):
sep = Value(' ')
@ -401,6 +404,11 @@ class PerformanceAlertSummaryFilter(django_filters.FilterSet):
def _with_assignee(self, queryset, name, value):
return queryset.filter(assignee__username=value)
def _timerange(self, queryset, name, value):
return queryset.filter(
push__time__gt=datetime.datetime.utcfromtimestamp(int(time.time() - int(value)))
)
class Meta:
model = PerformanceAlertSummary
fields = [
@ -413,6 +421,7 @@ class PerformanceAlertSummaryFilter(django_filters.FilterSet):
'hide_improvements',
'hide_related_and_invalid',
'with_assignee',
'timerange',
]

Просмотреть файл

@ -18,6 +18,7 @@ import {
} from '../../helpers/constants';
import { processSelectedParam, createGraphData } from '../perf-helpers/helpers';
import {
alertSummaryLimit,
endpoints,
graphColors,
graphSymbols,
@ -201,14 +202,16 @@ class GraphsView extends React.Component {
};
createGraphObject = async (seriesData) => {
const { colors, symbols } = this.state;
const { colors, symbols, timeRange } = this.state;
const alertSummaries = await Promise.all(
seriesData.map((series) =>
this.getAlertSummaries(series.signature_id, series.repository_id),
),
);
const commonAlerts = await Promise.all(
seriesData.map((series) => this.getCommonAlerts(series.framework_id)),
seriesData.map((series) =>
this.getCommonAlerts(series.framework_id, timeRange.value),
),
);
const newColors = [...colors];
const newSymbols = [...symbols];
@ -226,12 +229,14 @@ class GraphsView extends React.Component {
};
getAlertSummaries = async (signatureId, repository) => {
const { errorMessages } = this.state;
const { errorMessages, timeRange } = this.state;
const data = await getData(
createApiUrl(endpoints.alertSummary, {
alerts__series_signature: signatureId,
repository,
limit: alertSummaryLimit,
timerange: timeRange.value,
}),
);
const response = processResponse(data, 'alertSummaries', errorMessages);
@ -243,8 +248,12 @@ class GraphsView extends React.Component {
return [];
};
getCommonAlerts = async (frameworkId) => {
const params = { framework: frameworkId };
getCommonAlerts = async (frameworkId, timeRange) => {
const params = {
framework: frameworkId,
limit: alertSummaryLimit,
timerange: timeRange,
};
const url = getApiUrl(
`${endpoints.alertSummary}${createQueryParams(params)}`,
);

Просмотреть файл

@ -29,6 +29,7 @@ export const endpoints = {
performanceTags: '/performance/tag/',
};
export const alertSummaryLimit = 30;
export const noiseMetricTitle = 'noise metric';
export const backfillRetriggeredTitle =
'This alert was retriggered by the backfill bot.';