Skip to content

Commit 205fc06

Browse files
author
Ildar Iskhakov
authored
Merge pull request #1065 from grafana/dev
merge dev to main
2 parents ce0e32a + da51ede commit 205fc06

File tree

7 files changed

+74
-14
lines changed

7 files changed

+74
-14
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## v1.1.11 (2023-01-03)
9+
10+
### Fixed
11+
12+
- Fix error when schedule was not able to load
13+
- Minor fixes
14+
15+
## v1.1.10 (2023-01-03)
16+
17+
### Fixed
18+
19+
- Minor fixes
20+
821
## v1.1.9 (2023-01-03)
922

1023
### Fixed
1124

1225
- Alert group query optimization
1326
- Update RBAC scopes
27+
- Fix error when schedule was not able to load
1428
- Minor bug fixes
1529

1630
## v1.1.8 (2022-12-13)

engine/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ RUN apt-get update && apt-get install -y \
33
python3-dev \
44
gcc \
55
libmariadb-dev \
6+
libpq-dev \
67
netcat \
78
curl \
89
bash

engine/apps/alerts/incident_appearance/renderers/slack_renderer.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
from django.apps import apps
4+
from django.utils.text import Truncator
45

56
from apps.alerts.incident_appearance.renderers.base_renderer import AlertBaseRenderer, AlertGroupBaseRenderer
67
from apps.alerts.incident_appearance.templaters import AlertSlackTemplater
@@ -18,26 +19,31 @@ def templater_class(self):
1819
return AlertSlackTemplater
1920

2021
def render_alert_blocks(self):
22+
BLOCK_SECTION_TEXT_MAX_SIZE = 2800
2123
blocks = []
2224

25+
title = Truncator(str_or_backup(self.templated_alert.title, "Alert"))
2326
blocks.append(
2427
{
2528
"type": "section",
2629
"text": {
2730
"type": "mrkdwn",
28-
"text": str_or_backup(self.templated_alert.title, "Alert"),
31+
"text": title.chars(BLOCK_SECTION_TEXT_MAX_SIZE),
2932
},
3033
}
3134
)
3235
if is_string_with_visible_characters(self.templated_alert.message):
33-
message = self.templated_alert.message
34-
BLOCK_SECTION_TEXT_MAX_SIZE = 2800
35-
if len(message) > BLOCK_SECTION_TEXT_MAX_SIZE:
36-
message = (
37-
message[: BLOCK_SECTION_TEXT_MAX_SIZE - 3] + "... Message has been trimmed. "
38-
"Check the whole content in Web"
39-
)
40-
blocks.append({"type": "section", "text": {"type": "mrkdwn", "text": message}})
36+
message = Truncator(self.templated_alert.message)
37+
truncate_wording = "... Message has been trimmed. Check the whole content in Web"
38+
blocks.append(
39+
{
40+
"type": "section",
41+
"text": {
42+
"type": "mrkdwn",
43+
"text": message.chars(BLOCK_SECTION_TEXT_MAX_SIZE, truncate=truncate_wording),
44+
},
45+
}
46+
)
4147
return blocks
4248

4349
def render_alert_attachments(self):

engine/apps/api/tests/test_schedules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def test_merging_same_shift_events(
11131113

11141114
data = {
11151115
"start": start_date + timezone.timedelta(hours=10),
1116-
"rotation_start": start_date,
1116+
"rotation_start": start_date + timezone.timedelta(hours=10),
11171117
"duration": timezone.timedelta(hours=2),
11181118
"priority_level": 1,
11191119
"frequency": CustomOnCallShift.FREQUENCY_DAILY,

engine/apps/schedules/models/custom_on_call_shift.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,10 @@ def _daily_by_day_to_ical(self, time_zone, start, users_queue):
322322
if all_rotations_checked:
323323
break
324324

325-
# number of weeks used to cover all combinations
326-
week_interval = ((last_start - orig_start).days // 7) or 1
325+
week_interval = 1
326+
if orig_start and last_start:
327+
# number of weeks used to cover all combinations
328+
week_interval = ((last_start - orig_start).days // 7) or 1
327329
counter = 1
328330
for ((user_group_id, day, _), start) in zip(combinations, starting_dates):
329331
users = users_queue[user_group_id]
@@ -367,7 +369,7 @@ def convert_to_ical(self, time_zone="UTC", allow_empty_users=False):
367369
start = self.get_rotation_date(event_ical)
368370

369371
# Make sure we respect the selected days if any when defining start date
370-
if self.frequency is not None and self.by_day:
372+
if self.frequency is not None and self.by_day and start is not None:
371373
start_day = CustomOnCallShift.ICAL_WEEKDAY_MAP[start.weekday()]
372374
if start_day not in self.by_day:
373375
expected_start_day = min(CustomOnCallShift.ICAL_WEEKDAY_REVERSE_MAP[d] for d in self.by_day)

engine/apps/schedules/tests/test_custom_on_call_shift.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,3 +1430,40 @@ def test_rolling_users_shift_convert_to_ical(
14301430

14311431
assert on_call_shift.event_interval == len(rolling_users) * data["interval"]
14321432
assert expected_rrule in ical_data
1433+
1434+
1435+
@pytest.mark.django_db
1436+
def test_rolling_users_event_daily_by_day_start_none_convert_to_ical(
1437+
make_organization_and_user, make_user_for_organization, make_on_call_shift, make_schedule
1438+
):
1439+
organization, user_1 = make_organization_and_user()
1440+
1441+
schedule = make_schedule(organization, schedule_class=OnCallScheduleWeb)
1442+
now = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)
1443+
today_weekday = now.weekday()
1444+
delta_days = (0 - today_weekday) % 7 + (7 if today_weekday == 0 else 0)
1445+
next_week_monday = now + timezone.timedelta(days=delta_days)
1446+
1447+
# MO
1448+
weekdays = [0]
1449+
by_day = [CustomOnCallShift.ICAL_WEEKDAY_MAP[day] for day in weekdays]
1450+
data = {
1451+
"priority_level": 1,
1452+
"start": now + timezone.timedelta(hours=12),
1453+
"rotation_start": next_week_monday,
1454+
"duration": timezone.timedelta(seconds=3600),
1455+
"frequency": CustomOnCallShift.FREQUENCY_DAILY,
1456+
"interval": 1,
1457+
"by_day": by_day,
1458+
"schedule": schedule,
1459+
"until": now,
1460+
}
1461+
rolling_users = [[user_1]]
1462+
on_call_shift = make_on_call_shift(
1463+
organization=organization, shift_type=CustomOnCallShift.TYPE_ROLLING_USERS_EVENT, **data
1464+
)
1465+
on_call_shift.add_rolling_users(rolling_users)
1466+
1467+
ical_data = on_call_shift.convert_to_ical()
1468+
# empty result since there is no event in the defined time range
1469+
assert ical_data == ""

engine/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ https://github.com/grafana/fcm-django/archive/refs/tags/v1.0.12r1.tar.gz
3737
django-mirage-field==1.3.0
3838
django-mysql==4.6.0
3939
PyMySQL==1.0.2
40-
psycopg2-binary==2.9.3
40+
psycopg2==2.9.3
4141
emoji==1.7.0
4242
regex==2021.11.2
4343
psutil==5.9.4

0 commit comments

Comments
 (0)