|
4 | 4 | import urllib |
5 | 5 | from collections import namedtuple |
6 | 6 | from functools import partial |
7 | | -from urllib.parse import urljoin |
8 | 7 |
|
9 | 8 | from celery import uuid as celery_uuid |
10 | 9 | from django.conf import settings |
|
13 | 12 | from django.db.models import JSONField, Q, QuerySet |
14 | 13 | from django.utils import timezone |
15 | 14 | from django.utils.functional import cached_property |
| 15 | +from django_deprecate_fields import deprecate_field |
16 | 16 |
|
17 | 17 | from apps.alerts.constants import ActionSource, AlertGroupState |
18 | 18 | from apps.alerts.escalation_snapshot import EscalationSnapshotMixin |
|
27 | 27 | send_alert_group_signal_for_delete, |
28 | 28 | unsilence_task, |
29 | 29 | ) |
| 30 | +from apps.grafana_plugin.ui_url_builder import UIURLBuilder |
30 | 31 | from apps.metrics_exporter.tasks import update_metrics_for_alert_group |
31 | 32 | from apps.slack.slack_formatter import SlackFormatter |
32 | 33 | from apps.user_management.models import User |
33 | | -from common.constants.plugin_ids import PluginID |
34 | 34 | from common.public_primary_keys import generate_public_primary_key, increase_public_primary_key_length |
35 | 35 | from common.utils import clean_markup, str_or_backup |
36 | 36 |
|
@@ -201,7 +201,6 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models. |
201 | 201 | personal_log_records: "RelatedManager['UserNotificationPolicyLogRecord']" |
202 | 202 | resolution_notes: "RelatedManager['ResolutionNote']" |
203 | 203 | resolution_note_slack_messages: "RelatedManager['ResolutionNoteSlackMessage']" |
204 | | - resolved_by_alert: typing.Optional["Alert"] |
205 | 204 | resolved_by_user: typing.Optional["User"] |
206 | 205 | root_alert_group: typing.Optional["AlertGroup"] |
207 | 206 | silenced_by_user: typing.Optional["User"] |
@@ -289,12 +288,16 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models. |
289 | 288 | related_name="resolved_alert_groups", |
290 | 289 | ) |
291 | 290 |
|
292 | | - resolved_by_alert = models.ForeignKey( |
293 | | - "alerts.Alert", |
294 | | - on_delete=models.SET_NULL, |
295 | | - null=True, |
296 | | - default=None, |
297 | | - related_name="resolved_alert_groups", |
| 291 | + # NOTE: see https://raintank-corp.slack.com/archives/C07RGREUH4Z/p1728494111646319 |
| 292 | + # This field should eventually be dropped as it's no longer being set/read anywhere |
| 293 | + resolved_by_alert = deprecate_field( |
| 294 | + models.ForeignKey( |
| 295 | + "alerts.Alert", |
| 296 | + on_delete=models.SET_NULL, |
| 297 | + null=True, |
| 298 | + default=None, |
| 299 | + related_name="resolved_alert_groups", |
| 300 | + ) |
298 | 301 | ) |
299 | 302 |
|
300 | 303 | resolved_at = models.DateTimeField(blank=True, null=True) |
@@ -543,17 +546,19 @@ def permalinks(self) -> Permalinks: |
543 | 546 |
|
544 | 547 | @property |
545 | 548 | def web_link(self) -> str: |
546 | | - return urljoin(self.channel.organization.web_link, f"alert-groups/{self.public_primary_key}") |
| 549 | + return UIURLBuilder(self.channel.organization).alert_group_detail(self.public_primary_key) |
547 | 550 |
|
548 | 551 | @property |
549 | 552 | def declare_incident_link(self) -> str: |
550 | | - """Generate a link for AlertGroup to declare Grafana Incident by click""" |
551 | | - incident_link = urljoin(self.channel.organization.grafana_url, f"a/{PluginID.INCIDENT}/incidents/declare/") |
| 553 | + """ |
| 554 | + Generate a link for AlertGroup to declare Grafana Incident by click |
| 555 | + """ |
552 | 556 | caption = urllib.parse.quote_plus("OnCall Alert Group") |
553 | 557 | title = urllib.parse.quote_plus(self.web_title_cache) if self.web_title_cache else DEFAULT_BACKUP_TITLE |
554 | 558 | title = title[:2000] # set max title length to avoid exceptions with too long declare incident link |
555 | 559 | link = urllib.parse.quote_plus(self.web_link) |
556 | | - return urljoin(incident_link, f"?caption={caption}&url={link}&title={title}") |
| 560 | + |
| 561 | + return UIURLBuilder(self.channel.organization).declare_incident(f"?caption={caption}&url={link}&title={title}") |
557 | 562 |
|
558 | 563 | @property |
559 | 564 | def happened_while_maintenance(self): |
|
0 commit comments