trace.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package apis
  2. import (
  3. "go-admin/app/observe/service"
  4. "go-admin/app/observe/service/dto"
  5. "go-admin/utils"
  6. "net/http"
  7. "github.com/gin-gonic/gin"
  8. )
  9. type Trace struct {
  10. utils.OtApi
  11. }
  12. // List Traces列表
  13. func (t Trace) List(c *gin.Context) {
  14. req := new(dto.TraceListReq)
  15. svc := new(service.Trace)
  16. if err := t.Init(c, req, &svc.OtService); err != nil {
  17. return
  18. }
  19. result := make([]dto.TraceListResp, 0)
  20. var count int64
  21. if err := svc.GetPage(c, req, &result, &count); err != nil {
  22. t.Error(http.StatusInternalServerError, err, err.Error())
  23. return
  24. }
  25. t.PageOK(result, int(count), req.PageIndex, req.PageSize, "success")
  26. }
  27. // Detail Trace详情,即span列表,用于树型图展示
  28. func (t Trace) Detail(c *gin.Context) {
  29. req := new(dto.TraceDetailReq)
  30. svc := new(service.Trace)
  31. if err := t.Init(c, req, &svc.OtService); err != nil {
  32. return
  33. }
  34. result := new(dto.TraceDetailResp)
  35. if err := svc.GetSpans(c, req, result); err != nil {
  36. t.Error(http.StatusInternalServerError, err, err.Error())
  37. return
  38. }
  39. t.OK(result, "ok")
  40. }
  41. func (t Trace) Graph(c *gin.Context) {
  42. param := new(dto.TraceGraphReq)
  43. svc := new(service.Trace)
  44. err := t.MakeContext(c).MakeDB().Bind(param).MakeService(&svc.OtService).Errors
  45. if err != nil {
  46. t.Error(http.StatusInternalServerError, err, err.Error())
  47. return
  48. }
  49. result := new(dto.TraceGraphResp)
  50. if err := svc.GetTraceGraph(c, param, result); err != nil {
  51. t.Error(http.StatusInternalServerError, err, err.Error())
  52. return
  53. }
  54. t.OK(result, "ok")
  55. }
  56. func (t Trace) DBSlowTop(c *gin.Context) {
  57. req := new(dto.TraceDBSlowTopReq)
  58. svc := new(service.Trace)
  59. if err := t.Init(c, req, &svc.OtService); err != nil {
  60. return
  61. }
  62. resp := make([]dto.TraceDBSlowTopResp, 0)
  63. if err := svc.DBSlowTop(req, &resp); err != nil {
  64. t.Error(http.StatusInternalServerError, err, err.Error())
  65. return
  66. }
  67. t.OK(resp, "success")
  68. }