Update internal alert group details API docs (#2995)

Related to https://github.com/grafana/oncall/issues/2982
This commit is contained in:
Matias Bordese 2023-09-11 10:25:00 -03:00 committed by GitHub
parent 4b0bb86ce4
commit 971384b50e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 1 deletions

View file

@ -62,6 +62,22 @@ def generate_public_primary_key_for_alert_group():
return new_public_primary_key
class LogRecordUser(typing.TypedDict):
username: str
pk: str
avatar: str
avatar_full: str
class LogRecords(typing.TypedDict):
time: str # humanized delta relative to now
action: str # human-friendly description
realm: typing.Literal["user_notification", "alert_group", "resolution_note"]
type: int # depending on realm, check type choices
created_at: str # timestamp
author: LogRecordUser
class Permalinks(typing.TypedDict):
slack: typing.Optional[str]
telegram: typing.Optional[str]
@ -1741,7 +1757,7 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models.
else:
return "Acknowledged"
def render_after_resolve_report_json(self):
def render_after_resolve_report_json(self) -> list[LogRecords]:
from apps.alerts.models import AlertGroupLogRecord, ResolutionNote
from apps.base.models import UserNotificationPolicyLogRecord

View file

@ -354,6 +354,66 @@ class AlertGroupView(
obj = self.enrich([obj])[0]
return obj
def retrieve(self, request, pk, *args, **kwargs):
"""Return alert group details.
It is worth mentioning that `render_after_resolve_report_json` property will return a list
of log entries including actions involving the alert group, notifications triggered for a user
and resolution notes updates.
A few additional notes about the possible values for each key in the logs:
- `time`: humanized time delta respect to now when the action took place
- `action`: human-readable description of the action
- `realm`: resource involved in the action; one of three possible values:
`alert_group`, `user_notification`, `resolution_note`
- `type`: integer value indicating the type of action (see below)
- `created_at`: timestamp corresponding to when the action happened
- `author`: details about the user performing the action
Possible `type` values depending on the realm value:
For `alert_group`:
- 0: Acknowledged
- 1: Unacknowledged
- 2: Invite
- 3: Stop invitation
- 4: Re-invite
- 5: Escalation triggered
- 6: Invitation triggered
- 7: Silenced
- 8: Attached
- 9: Unattached
- 10: Custom button triggered
- 11: Unacknowledged by timeout
- 12: Failed attachment
- 13: Incident resolved
- 14: Incident unresolved
- 15: Unsilenced
- 16: Escalation finished
- 17: Escalation failed
- 18: Acknowledge reminder triggered
- 19: Wiped
- 20: Deleted
- 21: Incident registered
- 22: A route is assigned to the incident
- 23: Trigger direct paging escalation
- 24: Unpage a user
- 25: Restricted
For `user_notification`:
- 0: Personal notification triggered
- 1: Personal notification finished
- 2: Personal notification success,
- 3: Personal notification failed
For `resolution_note`:
- 0: slack
- 1: web
"""
return super().retrieve(request, pk, *args, **kwargs)
def enrich(self, alert_groups):
"""
This method performs select_related and prefetch_related (using setup_eager_loading) as well as in-memory joins