Skip to content

Commit 39cb6f2

Browse files
authored
v1.9.3
2 parents 6d922f6 + 4872588 commit 39cb6f2

23 files changed

+66
-248
lines changed

.github/workflows/e2e-tests.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,14 @@ jobs:
144144
git clone https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/grafana/ops-devenv.git
145145
git clone https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/grafana/gops-labels.git
146146
147-
- name: Tilt CI - standard and expensive E2E tests
147+
- name: Tilt CI - Expensive E2E tests
148148
if: inputs.run-expensive-tests
149149
shell: bash
150150
env:
151151
E2E_TESTS_CMD: "cd ../../grafana-plugin && yarn test:e2e-expensive"
152152
GRAFANA_VERSION: ${{ inputs.grafana_version }}
153+
GF_FEATURE_TOGGLES_ENABLE: "externalServiceAccounts"
154+
ONCALL_API_URL: "http://oncall-dev-engine:8080"
153155
GRAFANA_ADMIN_USERNAME: "irm"
154156
GRAFANA_ADMIN_PASSWORD: "irm"
155157
BROWSERS: ${{ inputs.browsers }}

.github/workflows/expensive-e2e-tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
# - 9.3.16
2525
# - 9.4.13
2626
# - 9.5.7
27-
- 10.0.11
2827
- 10.1.7
28+
- 10.3.3
2929
# TODO: fix issues with running e2e tests against Grafana v10.2.x and v10.3.x
3030
# - 10.2.4
3131
# - latest
@@ -55,7 +55,7 @@ jobs:
5555
#
5656
- uses: slackapi/[email protected]
5757
with:
58-
channel-id: gops-oncall-dev
58+
channel-id: gops-irm-dev
5959
# yamllint disable rule:line-length
6060
payload: |
6161
{

.github/workflows/linting-and-tests.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,16 @@ jobs:
239239
end-to-end-tests:
240240
name: Standard e2e tests
241241
uses: ./.github/workflows/e2e-tests.yml
242+
strategy:
243+
matrix:
244+
grafana_version:
245+
- 10.1.7
246+
- 10.3.3
247+
# TODO: fix issues with running e2e tests against Grafana v10.2.x and latest
248+
# - 10.2.4
249+
# - latest
250+
fail-fast: false
242251
with:
243-
# TODO: fix issues with running e2e tests against Grafana v10.2.x and v10.3.x
244-
grafana_version: 10.1.7
245-
# grafana_version: 10.3.3
252+
grafana_version: ${{ matrix.grafana_version }}
246253
run-expensive-tests: false
247254
browsers: "chromium"

Tiltfile

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load('ext://uibutton', 'cmd_button', 'location', 'text_input', 'bool_input')
22
load("ext://configmap", "configmap_create")
33

4+
grafana_url = os.getenv("GRAFANA_URL", "http://grafana:3000")
45
running_under_parent_tiltfile = os.getenv("TILT_PARENT", "false") == "true"
56
twilio_values=[
67
"oncall.twilio.accountSid=" + os.getenv("TWILIO_ACCOUNT_SID", ""),
@@ -29,6 +30,14 @@ def plugin_json():
2930
return plugin_file
3031
return 'NOT_A_PLUGIN'
3132

33+
def extra_env():
34+
return {
35+
"GF_APP_URL": grafana_url,
36+
"GF_SERVER_ROOT_URL": grafana_url,
37+
"GF_FEATURE_TOGGLES_ENABLE": "externalServiceAccounts",
38+
"ONCALL_API_URL": "http://oncall-dev-engine:8080"
39+
}
40+
3241

3342
allow_k8s_contexts(["kind-kind"])
3443

@@ -83,8 +92,6 @@ def load_grafana():
8392
# The user/pass that you will login to Grafana with
8493
grafana_admin_user_pass = os.getenv("GRAFANA_ADMIN_USER_PASS", "oncall")
8594
grafana_version = os.getenv("GRAFANA_VERSION", "latest")
86-
grafana_url = os.getenv("GRAFANA_URL", "http://grafana:3000")
87-
8895

8996
if 'plugin' in profiles:
9097
k8s_resource(

engine/apps/alerts/models/alert_group.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models.
201201
resolved_by_user: typing.Optional["User"]
202202
root_alert_group: typing.Optional["AlertGroup"]
203203
silenced_by_user: typing.Optional["User"]
204-
slack_log_message: typing.Optional["SlackMessage"]
205204
slack_messages: "RelatedManager['SlackMessage']"
206205
users: "RelatedManager['User']"
207206
labels: "RelatedManager['AlertGroupAssociatedLabel']"
@@ -396,6 +395,7 @@ def status(self) -> int:
396395
related_name="wiped_alert_groups",
397396
)
398397

398+
# TODO: drop this column in future release
399399
slack_log_message = models.OneToOneField(
400400
"slack.SlackMessage",
401401
on_delete=models.SET_NULL,

engine/apps/alerts/signals.py

-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
AlertGroupSlackRepresentative.on_alert_group_action_triggered,
3737
)
3838

39-
alert_group_update_log_report_signal.connect(
40-
AlertGroupSlackRepresentative.on_alert_group_update_log_report,
41-
)
42-
4339
alert_group_update_resolution_note_signal.connect(
4440
AlertGroupSlackRepresentative.on_alert_group_update_resolution_note,
4541
)

engine/apps/slack/representatives/alert_group_representative.py

+1-39
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,7 @@ def on_alert_group_action_triggered_async(log_record_id):
9090
autoretry_for=(Exception,), retry_backoff=True, max_retries=1 if settings.DEBUG else None
9191
)
9292
def on_alert_group_update_log_report_async(alert_group_id):
93-
from apps.alerts.models import AlertGroup
94-
95-
alert_group = AlertGroup.objects.get(pk=alert_group_id)
96-
logger.debug(f"Start on_alert_group_update_log_report for alert_group {alert_group_id}")
97-
organization = alert_group.channel.organization
98-
if alert_group.slack_message and organization.slack_team_identity:
99-
logger.debug(f"Process on_alert_group_update_log_report for alert_group {alert_group_id}")
100-
UpdateLogReportMessageStep = ScenarioStep.get_step("distribute_alerts", "UpdateLogReportMessageStep")
101-
step = UpdateLogReportMessageStep(organization.slack_team_identity, organization)
102-
step.process_signal(alert_group)
103-
else:
104-
logger.debug(f"Drop on_alert_group_update_log_report for alert_group {alert_group_id}")
105-
logger.debug(f"Finish on_alert_group_update_log_report for alert_group {alert_group_id}")
93+
return "Deprecated, will be removed after queue cleanup"
10694

10795

10896
class AlertGroupSlackRepresentative(AlertGroupAbstractRepresentative):
@@ -173,32 +161,6 @@ def on_alert_group_action_triggered(cls, **kwargs):
173161
logger.debug(f"SLACK on_alert_group_action_triggered: async {log_record_id} {force_sync}")
174162
on_alert_group_action_triggered_async.apply_async((log_record_id,))
175163

176-
@classmethod
177-
def on_alert_group_update_log_report(cls, **kwargs):
178-
from apps.alerts.models import AlertGroup
179-
180-
alert_group = kwargs["alert_group"]
181-
182-
if isinstance(alert_group, AlertGroup):
183-
alert_group_id = alert_group.pk
184-
else:
185-
alert_group_id = alert_group
186-
try:
187-
alert_group = AlertGroup.objects.get(pk=alert_group_id)
188-
except AlertGroup.DoesNotExist as e:
189-
logger.warning(f"SLACK update log report: alert group {alert_group_id} has been deleted")
190-
raise e
191-
192-
logger.debug(
193-
f"Received alert_group_update_log_report signal in SLACK representative for alert_group {alert_group_id}"
194-
)
195-
196-
if alert_group.notify_in_slack_enabled is False:
197-
logger.debug(f"Skipping alert_group {alert_group_id} since notify_in_slack is disabled")
198-
return
199-
200-
on_alert_group_update_log_report_async.apply_async((alert_group_id,))
201-
202164
@classmethod
203165
def on_alert_group_update_resolution_note(cls, **kwargs):
204166
alert_group = kwargs["alert_group"]

engine/apps/slack/scenarios/distribute_alerts.py

+1-86
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime
55

66
from django.core.cache import cache
7-
from django.utils import timezone
87

98
from apps.alerts.constants import ActionSource
109
from apps.alerts.incident_appearance.renderers.constants import DEFAULT_BACKUP_TITLE
@@ -14,25 +13,17 @@
1413
from apps.slack.chatops_proxy_routing import make_private_metadata, make_value
1514
from apps.slack.constants import CACHE_UPDATE_INCIDENT_SLACK_MESSAGE_LIFETIME
1615
from apps.slack.errors import (
17-
SlackAPICantUpdateMessageError,
1816
SlackAPIChannelArchivedError,
19-
SlackAPIChannelInactiveError,
2017
SlackAPIChannelNotFoundError,
2118
SlackAPIError,
22-
SlackAPIInvalidAuthError,
2319
SlackAPIMessageNotFoundError,
2420
SlackAPIRatelimitError,
2521
SlackAPIRestrictedActionError,
2622
SlackAPITokenError,
2723
)
2824
from apps.slack.scenarios import scenario_step
29-
from apps.slack.scenarios.slack_renderer import AlertGroupLogSlackRenderer
3025
from apps.slack.slack_formatter import SlackFormatter
31-
from apps.slack.tasks import (
32-
post_or_update_log_report_message_task,
33-
send_message_to_thread_if_bot_not_in_channel,
34-
update_incident_slack_message,
35-
)
26+
from apps.slack.tasks import send_message_to_thread_if_bot_not_in_channel, update_incident_slack_message
3627
from apps.slack.types import (
3728
Block,
3829
BlockActionType,
@@ -95,7 +86,6 @@ def process_signal(self, alert: Alert) -> None:
9586
else:
9687
# check if alert group was posted to slack before posting message to thread
9788
if not alert.group.skip_escalation_in_slack:
98-
self._send_log_report_message(alert.group, channel_id)
9989
self._send_message_to_thread_if_bot_not_in_channel(alert.group, channel_id)
10090
else:
10191
# check if alert group was posted to slack before updating its message
@@ -208,11 +198,6 @@ def _send_debug_mode_notice(self, alert_group: AlertGroup, channel_id: str) -> N
208198
blocks=blocks,
209199
)
210200

211-
def _send_log_report_message(self, alert_group: AlertGroup, channel_id: str) -> None:
212-
post_or_update_log_report_message_task.apply_async(
213-
(alert_group.pk, self.slack_team_identity.pk),
214-
)
215-
216201
def _send_message_to_thread_if_bot_not_in_channel(self, alert_group: AlertGroup, channel_id: str) -> None:
217202
send_message_to_thread_if_bot_not_in_channel.apply_async(
218203
(alert_group.pk, self.slack_team_identity.pk, channel_id),
@@ -895,76 +880,6 @@ def process_signal(self, log_record: AlertGroupLogRecord) -> None:
895880
message.delete()
896881

897882

898-
class UpdateLogReportMessageStep(scenario_step.ScenarioStep):
899-
def process_signal(self, alert_group: AlertGroup) -> None:
900-
if alert_group.skip_escalation_in_slack or alert_group.channel.is_rate_limited_in_slack:
901-
return
902-
903-
self.update_log_message(alert_group)
904-
905-
def update_log_message(self, alert_group: AlertGroup) -> None:
906-
slack_message = alert_group.slack_message
907-
if slack_message is None:
908-
logger.info(
909-
f"Cannot update log message for alert_group {alert_group.pk} because SlackMessage doesn't exist"
910-
)
911-
return None
912-
913-
slack_log_message = alert_group.slack_log_message
914-
915-
if slack_log_message is not None:
916-
# prevent too frequent updates
917-
if timezone.now() <= slack_log_message.last_updated + timezone.timedelta(seconds=5):
918-
return
919-
920-
attachments = AlertGroupLogSlackRenderer.render_incident_log_report_for_slack(alert_group)
921-
logger.debug(
922-
f"Update log message for alert_group {alert_group.pk}, slack_log_message {slack_log_message.pk}"
923-
)
924-
try:
925-
self._slack_client.chat_update(
926-
channel=slack_message.channel_id,
927-
text="Alert Group log",
928-
ts=slack_log_message.slack_id,
929-
attachments=attachments,
930-
)
931-
except SlackAPIRatelimitError as e:
932-
if not alert_group.channel.is_rate_limited_in_slack:
933-
alert_group.channel.start_send_rate_limit_message_task(e.retry_after)
934-
except SlackAPIMessageNotFoundError:
935-
alert_group.slack_log_message = None
936-
alert_group.save(update_fields=["slack_log_message"])
937-
except (
938-
SlackAPITokenError,
939-
SlackAPIChannelNotFoundError,
940-
SlackAPIChannelArchivedError,
941-
SlackAPIChannelInactiveError,
942-
SlackAPIInvalidAuthError,
943-
SlackAPICantUpdateMessageError,
944-
):
945-
pass
946-
else:
947-
slack_log_message.last_updated = timezone.now()
948-
slack_log_message.save(update_fields=["last_updated"])
949-
logger.debug(
950-
f"Finished update log message for alert_group {alert_group.pk}, "
951-
f"slack_log_message {slack_log_message.pk}"
952-
)
953-
# check how much time has passed since slack message was created
954-
# to prevent eternal loop of restarting update log message task
955-
elif timezone.now() <= slack_message.created_at + timezone.timedelta(minutes=5):
956-
logger.debug(
957-
f"Update log message failed for alert_group {alert_group.pk}: "
958-
f"log message does not exist yet. Restarting post_or_update_log_report_message_task..."
959-
)
960-
post_or_update_log_report_message_task.apply_async(
961-
(alert_group.pk, self.slack_team_identity.pk, True),
962-
countdown=3,
963-
)
964-
else:
965-
logger.debug(f"Update log message failed for alert_group {alert_group.pk}: " f"log message does not exist.")
966-
967-
968883
STEPS_ROUTING: ScenarioRoute.RoutingSteps = [
969884
{
970885
"payload_type": PayloadType.INTERACTIVE_MESSAGE,

engine/apps/slack/scenarios/slack_renderer.py

-14
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,3 @@ def render_alert_group_future_log_report_text(alert_group: "AlertGroup"):
3939
for plan_line in escalation_policies_plan[time]:
4040
result += f"*{humanize.naturaldelta(time)}:* {plan_line}\n"
4141
return result
42-
43-
@staticmethod
44-
def render_incident_log_report_for_slack(alert_group: "AlertGroup"):
45-
attachments = []
46-
past = AlertGroupLogSlackRenderer.render_alert_group_past_log_report_text(alert_group)
47-
future = AlertGroupLogSlackRenderer.render_alert_group_future_log_report_text(alert_group)
48-
text = past + future
49-
if len(text) > 0:
50-
attachments.append(
51-
{
52-
"text": text,
53-
}
54-
)
55-
return attachments

engine/apps/slack/tasks.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
SlackAPITokenError,
2121
SlackAPIUsergroupNotFoundError,
2222
)
23-
from apps.slack.scenarios.scenario_step import ScenarioStep
2423
from apps.slack.utils import (
2524
get_cache_key_update_incident_slack_message,
2625
get_populate_slack_channel_task_id_key,
@@ -289,27 +288,7 @@ def populate_slack_user_identities(organization_pk):
289288
autoretry_for=(Exception,), retry_backoff=True, max_retries=1 if settings.DEBUG else None
290289
)
291290
def post_or_update_log_report_message_task(alert_group_pk, slack_team_identity_pk, update=False):
292-
logger.debug(f"Start post_or_update_log_report_message_task for alert_group {alert_group_pk}")
293-
from apps.alerts.models import AlertGroup
294-
from apps.slack.models import SlackTeamIdentity
295-
296-
UpdateLogReportMessageStep = ScenarioStep.get_step("distribute_alerts", "UpdateLogReportMessageStep")
297-
298-
slack_team_identity = SlackTeamIdentity.objects.get(pk=slack_team_identity_pk)
299-
alert_group = AlertGroup.objects.get(pk=alert_group_pk)
300-
step = UpdateLogReportMessageStep(slack_team_identity, alert_group.channel.organization)
301-
302-
if alert_group.skip_escalation_in_slack or alert_group.channel.is_rate_limited_in_slack:
303-
return
304-
305-
if update: # flag to prevent multiple posting log message to slack
306-
step.update_log_message(alert_group)
307-
else:
308-
# don't post a new message, as it is available from the button
309-
# this is an intermediate step, so we will only update posted messages but not post new ones
310-
# once majority of messages are updated, we can remove this step (https://github.com/grafana/oncall/pull/4686)
311-
pass
312-
logger.debug(f"Finish post_or_update_log_report_message_task for alert_group {alert_group_pk}")
291+
return "Deprecated, will be removed after queue cleanup"
313292

314293

315294
@shared_dedicated_queue_retry_task(

0 commit comments

Comments
 (0)