alertLastIncidentActivationInfo.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import TimeSince from 'sentry/components/timeSince';
  2. import {t, tct} from 'sentry/locale';
  3. import getDuration from 'sentry/utils/duration/getDuration';
  4. import {hasActiveIncident} from 'sentry/views/alerts/list/rules/utils';
  5. import {
  6. type CombinedAlerts,
  7. CombinedAlertType,
  8. type CronRule,
  9. type IssueAlert,
  10. type MetricAlert,
  11. type UptimeAlert,
  12. } from 'sentry/views/alerts/types';
  13. import {scheduleAsText} from 'sentry/views/monitors/utils/scheduleAsText';
  14. interface Props {
  15. rule: CombinedAlerts;
  16. }
  17. /**
  18. * Displays the time since the last uptime incident given an uptime alert rule
  19. */
  20. function LastUptimeIncident({rule}: {rule: UptimeAlert}) {
  21. // TODO(davidenwang): Once we have a lastTriggered field returned from
  22. // backend, display that info here
  23. return tct('Actively monitoring every [interval]', {
  24. interval: getDuration(rule.intervalSeconds),
  25. });
  26. }
  27. function LastCronMonitorIncident({rule}: {rule: CronRule}) {
  28. // TODO(evanpurkhiser): Would probably be better if we had a way to get the
  29. // most recent incident.
  30. return tct('Expected [interval]', {
  31. interval: scheduleAsText(rule.config),
  32. });
  33. }
  34. /**
  35. * Displays the last time an issue alert was triggered
  36. */
  37. function LastIssueTrigger({rule}: {rule: IssueAlert}) {
  38. if (!rule.lastTriggered) {
  39. return t('Alert not triggered yet');
  40. }
  41. return (
  42. <div>{tct('Triggered [at]', {at: <TimeSince date={rule.lastTriggered} />})}</div>
  43. );
  44. }
  45. /**
  46. * Displays the last incident for continuous alerts
  47. */
  48. function LastMetricAlertIncident({rule}: {rule: MetricAlert}) {
  49. if (!rule.latestIncident) {
  50. return t('Alert not triggered yet');
  51. }
  52. const activeIncident = hasActiveIncident(rule);
  53. if (activeIncident) {
  54. return (
  55. <div>
  56. {tct('Triggered [at]', {
  57. at: <TimeSince date={rule.latestIncident.dateCreated} />,
  58. })}
  59. </div>
  60. );
  61. }
  62. return (
  63. <div>
  64. {tct('Resolved [at]', {at: <TimeSince date={rule.latestIncident.dateClosed!} />})}
  65. </div>
  66. );
  67. }
  68. export default function AlertLastIncidentActivationInfo({rule}: Props) {
  69. // eslint-disable-next-line default-case
  70. switch (rule.type) {
  71. case CombinedAlertType.UPTIME:
  72. return <LastUptimeIncident rule={rule} />;
  73. case CombinedAlertType.CRONS:
  74. return <LastCronMonitorIncident rule={rule} />;
  75. case CombinedAlertType.ISSUE:
  76. return <LastIssueTrigger rule={rule} />;
  77. case CombinedAlertType.METRIC:
  78. return <LastMetricAlertIncident rule={rule} />;
  79. }
  80. }