incident.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. Namespace string `schema:"namespace"`
  104. PodSelector string `schema:"pod_selector"`
  105. Direction string `schema:"direction"`
  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. Metadata LogMetadata `json:"metadata"`
  123. }
  124. type LogMetadata struct {
  125. PodName string `json:"pod_name"`
  126. PodNamespace string `json:"pod_namespace"`
  127. Revision string `json:"revision"`
  128. OutputStream string `json:"output_stream"`
  129. AppName string `json:"app_name"`
  130. }
  131. type GetLogResponse struct {
  132. BackwardContinueTime *time.Time `json:"backward_continue_time,omitempty"`
  133. ForwardContinueTime *time.Time `json:"forward_continue_time,omitempty"`
  134. Logs []LogLine `json:"logs,omitempty"`
  135. }
  136. type GetKubernetesEventRequest struct {
  137. Limit uint `schema:"limit"`
  138. StartRange *time.Time `schema:"start_range"`
  139. EndRange *time.Time `schema:"end_range"`
  140. Revision string `schema:"revision"`
  141. PodSelector string `schema:"pod_selector" form:"required"`
  142. Namespace string `schema:"namespace" form:"required"`
  143. }
  144. type KubernetesEventLine struct {
  145. Timestamp *time.Time `json:"timestamp"`
  146. Event string `json:"event"`
  147. }
  148. type GetKubernetesEventResponse struct {
  149. ContinueTime *time.Time `json:"continue_time"`
  150. Events []KubernetesEventLine `json:"events"`
  151. }
  152. type EventType string
  153. const (
  154. EventTypeIncident EventType = "incident"
  155. EventTypeIncidentResolved EventType = "incident_resolved"
  156. EventTypeDeploymentStarted EventType = "deployment_started"
  157. EventTypeDeploymentFinished EventType = "deployment_finished"
  158. EventTypeDeploymentErrored EventType = "deployment_errored"
  159. )
  160. type Event struct {
  161. Type EventType `json:"type"`
  162. Version string `json:"version"`
  163. ReleaseName string `json:"release_name"`
  164. ReleaseNamespace string `json:"release_namespace"`
  165. Timestamp *time.Time `json:"timestamp"`
  166. Data map[string]interface{} `json:"data"`
  167. }
  168. type ListEventsRequest struct {
  169. *PaginationRequest
  170. ReleaseName *string `schema:"release_name"`
  171. ReleaseNamespace *string `schema:"release_namespace"`
  172. Type *string `schema:"type"`
  173. }
  174. type ListEventsResponse struct {
  175. Events []*Event `json:"events" form:"required"`
  176. Pagination *PaginationResponse `json:"pagination"`
  177. }
  178. type ListJobEventsRequest struct {
  179. *PaginationRequest
  180. ReleaseName *string `schema:"release_name"`
  181. ReleaseNamespace *string `schema:"release_namespace"`
  182. Type *string `schema:"type"`
  183. JobName string `schema:"job_name" form:"required"`
  184. }