incident.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package types
  2. import "time"
  3. const URLParamIncidentID URLParam = "incident_id"
  4. type SeverityType string
  5. const (
  6. SeverityCritical SeverityType = "critical"
  7. SeverityNormal SeverityType = "normal"
  8. )
  9. type InvolvedObjectKind string
  10. const (
  11. InvolvedObjectDeployment InvolvedObjectKind = "deployment"
  12. InvolvedObjectJob InvolvedObjectKind = "job"
  13. InvolvedObjectPod InvolvedObjectKind = "pod"
  14. )
  15. type IncidentStatus string
  16. const (
  17. IncidentStatusResolved IncidentStatus = "resolved"
  18. IncidentStatusActive IncidentStatus = "active"
  19. )
  20. type IncidentMeta struct {
  21. ID string `json:"id" form:"required"`
  22. ReleaseName string `json:"release_name" form:"required"`
  23. ReleaseNamespace string `json:"release_namespace" form:"required"`
  24. ChartName string `json:"chart_name" form:"required"`
  25. CreatedAt time.Time `json:"created_at" form:"required"`
  26. UpdatedAt time.Time `json:"updated_at" form:"required"`
  27. LastSeen *time.Time `json:"last_seen" form:"required"`
  28. Status IncidentStatus `json:"status" form:"required"`
  29. Summary string `json:"summary" form:"required"`
  30. ShortSummary string `json:"short_summary"`
  31. Severity SeverityType `json:"severity" form:"required"`
  32. InvolvedObjectKind InvolvedObjectKind `json:"involved_object_kind" form:"required"`
  33. InvolvedObjectName string `json:"involved_object_name" form:"required"`
  34. InvolvedObjectNamespace string `json:"involved_object_namespace" form:"required"`
  35. ShouldViewLogs bool `json:"should_view_logs"`
  36. Revision string `json:"revision"`
  37. PorterDocLink string `json:"porter_doc_link"`
  38. }
  39. // PaginationRequest allows for conveniently specifying pagination parameters. These can be parsed from a url using gorilla/schema.
  40. type PaginationRequest struct {
  41. Page int64 `schema:"page"`
  42. }
  43. type PaginationResponse struct {
  44. NumPages int64 `json:"num_pages" form:"required"`
  45. CurrentPage int64 `json:"current_page" form:"required"`
  46. NextPage int64 `json:"next_page" form:"required"`
  47. }
  48. type ListIncidentsRequest struct {
  49. *PaginationRequest
  50. Status *IncidentStatus `schema:"status"`
  51. ReleaseName *string `schema:"release_name"`
  52. ReleaseNamespace *string `schema:"release_namespace"`
  53. }
  54. type ListIncidentsResponse struct {
  55. Incidents []*IncidentMeta `json:"incidents" form:"required"`
  56. Pagination *PaginationResponse `json:"pagination"`
  57. }
  58. type GetIncidentResponse *Incident
  59. type Incident struct {
  60. *IncidentMeta
  61. Pods []string `json:"pods" form:"required"`
  62. Detail string `json:"detail" form:"required"`
  63. }
  64. type IncidentEvent struct {
  65. ID string `json:"id" form:"required"`
  66. LastSeen *time.Time `json:"last_seen" form:"required"`
  67. PodName string `json:"pod_name" form:"required"`
  68. PodNamespace string `json:"pod_namespace" form:"required"`
  69. Summary string `json:"summary" form:"required"`
  70. Detail string `json:"detail" form:"required"`
  71. Revision string `json:"revision"`
  72. }
  73. type ListIncidentEventsRequest struct {
  74. *PaginationRequest
  75. IncidentID *string `schema:"incident_id"`
  76. PodName *string `schema:"pod_name"`
  77. PodNamespace *string `schema:"pod_namespace"`
  78. Summary *string `schema:"summary"`
  79. PodPrefix *string `schema:"pod_prefix"`
  80. }
  81. type ListIncidentEventsResponse struct {
  82. Events []*IncidentEvent `json:"events" form:"required"`
  83. Pagination *PaginationResponse `json:"pagination"`
  84. }
  85. type GetLogRequest struct {
  86. Limit uint `schema:"limit"`
  87. StartRange *time.Time `schema:"start_range"`
  88. EndRange *time.Time `schema:"end_range"`
  89. SearchParam string `schema:"search_param"`
  90. Revision string `schema:"revision"`
  91. PodSelector string `schema:"pod_selector" form:"required"`
  92. Namespace string `schema:"namespace"`
  93. Direction string `schema:"direction"`
  94. }
  95. type GetPodValuesRequest struct {
  96. StartRange *time.Time `schema:"start_range"`
  97. EndRange *time.Time `schema:"end_range"`
  98. Namespace string `schema:"namespace"`
  99. MatchPrefix string `schema:"match_prefix"`
  100. Revision string `schema:"revision"`
  101. }
  102. type GetRevisionValuesRequest struct {
  103. StartRange *time.Time `schema:"start_range"`
  104. EndRange *time.Time `schema:"end_range"`
  105. MatchPrefix string `schema:"match_prefix"`
  106. }
  107. type LogLine struct {
  108. Timestamp *time.Time `json:"timestamp"`
  109. Line string `json:"line"`
  110. }
  111. type GetLogResponse struct {
  112. BackwardContinueTime *time.Time `json:"backward_continue_time"`
  113. ForwardContinueTime *time.Time `json:"forward_continue_time"`
  114. Logs []LogLine `json:"logs"`
  115. }
  116. type GetKubernetesEventRequest struct {
  117. Limit uint `schema:"limit"`
  118. StartRange *time.Time `schema:"start_range"`
  119. EndRange *time.Time `schema:"end_range"`
  120. Revision string `schema:"revision"`
  121. PodSelector string `schema:"pod_selector" form:"required"`
  122. Namespace string `schema:"namespace" form:"required"`
  123. }
  124. type KubernetesEventLine struct {
  125. Timestamp *time.Time `json:"timestamp"`
  126. Event string `json:"event"`
  127. }
  128. type GetKubernetesEventResponse struct {
  129. ContinueTime *time.Time `json:"continue_time"`
  130. Events []KubernetesEventLine `json:"events"`
  131. }
  132. type EventType string
  133. const (
  134. EventTypeIncident EventType = "incident"
  135. EventTypeIncidentResolved EventType = "incident_resolved"
  136. EventTypeDeploymentStarted EventType = "deployment_started"
  137. EventTypeDeploymentFinished EventType = "deployment_finished"
  138. EventTypeDeploymentErrored EventType = "deployment_errored"
  139. )
  140. type Event struct {
  141. Type EventType `json:"type"`
  142. Version string `json:"version"`
  143. ReleaseName string `json:"release_name"`
  144. ReleaseNamespace string `json:"release_namespace"`
  145. Timestamp *time.Time `json:"timestamp"`
  146. Data map[string]interface{} `json:"data"`
  147. }
  148. type ListEventsRequest struct {
  149. *PaginationRequest
  150. ReleaseName *string `schema:"release_name"`
  151. ReleaseNamespace *string `schema:"release_namespace"`
  152. Type *string `schema:"type"`
  153. }
  154. type ListEventsResponse struct {
  155. Events []*Event `json:"events" form:"required"`
  156. Pagination *PaginationResponse `json:"pagination"`
  157. }
  158. type ListJobEventsRequest struct {
  159. *PaginationRequest
  160. ReleaseName *string `schema:"release_name"`
  161. ReleaseNamespace *string `schema:"release_namespace"`
  162. Type *string `schema:"type"`
  163. JobName string `schema:"job_name" form:"required"`
  164. }