incident.go 8.1 KB

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