incident.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. // You may either provide the pod selector directly, or the chart name,
  96. // in which case we will attempt to find the correct pod within the timeframe.
  97. type GetChartLogsWithinTimeRangeRequest struct {
  98. ChartName string `schema:"chart_name"`
  99. Limit uint `schema:"limit"`
  100. StartRange time.Time `schema:"start_range,omitempty"`
  101. EndRange time.Time `schema:"end_range,omitempty"`
  102. SearchParam string `schema:"search_param"`
  103. Revision string `schema:"revision"`
  104. Namespace string `schema:"namespace"`
  105. PodSelector string `schema:"pod_selector"`
  106. }
  107. type GetPodValuesRequest struct {
  108. StartRange *time.Time `schema:"start_range"`
  109. EndRange *time.Time `schema:"end_range"`
  110. Namespace string `schema:"namespace"`
  111. MatchPrefix string `schema:"match_prefix"`
  112. Revision string `schema:"revision"`
  113. }
  114. type GetRevisionValuesRequest struct {
  115. StartRange *time.Time `schema:"start_range"`
  116. EndRange *time.Time `schema:"end_range"`
  117. MatchPrefix string `schema:"match_prefix"`
  118. }
  119. type LogLine struct {
  120. Timestamp *time.Time `json:"timestamp"`
  121. Line string `json:"line"`
  122. }
  123. type GetLogResponse struct {
  124. BackwardContinueTime *time.Time `json:"backward_continue_time,omitempty"`
  125. ForwardContinueTime *time.Time `json:"forward_continue_time,omitempty"`
  126. Logs []LogLine `json:"logs,omitempty"`
  127. }
  128. type GetKubernetesEventRequest struct {
  129. Limit uint `schema:"limit"`
  130. StartRange *time.Time `schema:"start_range"`
  131. EndRange *time.Time `schema:"end_range"`
  132. Revision string `schema:"revision"`
  133. PodSelector string `schema:"pod_selector" form:"required"`
  134. Namespace string `schema:"namespace" form:"required"`
  135. }
  136. type KubernetesEventLine struct {
  137. Timestamp *time.Time `json:"timestamp"`
  138. Event string `json:"event"`
  139. }
  140. type GetKubernetesEventResponse struct {
  141. ContinueTime *time.Time `json:"continue_time"`
  142. Events []KubernetesEventLine `json:"events"`
  143. }
  144. type EventType string
  145. const (
  146. EventTypeIncident EventType = "incident"
  147. EventTypeIncidentResolved EventType = "incident_resolved"
  148. EventTypeDeploymentStarted EventType = "deployment_started"
  149. EventTypeDeploymentFinished EventType = "deployment_finished"
  150. EventTypeDeploymentErrored EventType = "deployment_errored"
  151. )
  152. type Event struct {
  153. Type EventType `json:"type"`
  154. Version string `json:"version"`
  155. ReleaseName string `json:"release_name"`
  156. ReleaseNamespace string `json:"release_namespace"`
  157. Timestamp *time.Time `json:"timestamp"`
  158. Data map[string]interface{} `json:"data"`
  159. }
  160. type ListEventsRequest struct {
  161. *PaginationRequest
  162. ReleaseName *string `schema:"release_name"`
  163. ReleaseNamespace *string `schema:"release_namespace"`
  164. Type *string `schema:"type"`
  165. }
  166. type ListEventsResponse struct {
  167. Events []*Event `json:"events" form:"required"`
  168. Pagination *PaginationResponse `json:"pagination"`
  169. }
  170. type ListJobEventsRequest struct {
  171. *PaginationRequest
  172. ReleaseName *string `schema:"release_name"`
  173. ReleaseNamespace *string `schema:"release_namespace"`
  174. Type *string `schema:"type"`
  175. JobName string `schema:"job_name" form:"required"`
  176. }