Преглед на файлове

wip:打印等待线程池时间

wangkaiyue преди 2 години
родител
ревизия
d8e4eabe91
променени са 3 файла, в които са добавени 6 реда и са изтрити 3 реда
  1. 3 1
      internal/cmd/cmd.go
  2. 2 1
      internal/consts/consts.go
  3. 1 1
      internal/service/middle.go

+ 3 - 1
internal/cmd/cmd.go

@@ -7,6 +7,7 @@ import (
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/net/ghttp"
 	"github.com/gogf/gf/v2/os/gcmd"
+	"time"
 )
 
 var (
@@ -18,8 +19,9 @@ var (
 			s := g.Server()
 			s.Use(service.Middleware)
 			s.BindHandler("/*", func(r *ghttp.Request) {
-				queryLevel := r.GetCtxVar(consts.QueryLevelKey).Int()
+				queryLevel, now := r.GetCtxVar(consts.QueryLevelKey).Int(), time.Now()
 				rp, err := service.EsProxyManager.GetProxy(r.Context(), queryLevel)
+				r.SetCtxVar(consts.QueryWaitPoolTime, time.Now().Sub(now).Seconds()) //记录等待时长
 				if err != nil {
 					r.Response.Status = 500
 					g.Log().Errorf(r.Context(), "GetProxy Error:%v", err)

+ 2 - 1
internal/consts/consts.go

@@ -16,5 +16,6 @@ const (
 	QueryLevelAggs                          //聚合查询
 	QueryLevelComplex                       //复杂查询
 
-	QueryLevelKey = "queryLevel"
+	QueryLevelKey     = "queryLevel"
+	QueryWaitPoolTime = "waitPoolTime"
 )

+ 1 - 1
internal/service/middle.go

@@ -28,7 +28,7 @@ func Middleware(r *ghttp.Request) {
 	queryLevel := getQueryLevel(bodyBytes)
 	r.SetCtxVar(consts.QueryLevelKey, queryLevel)
 	r.Middleware.Next()
-	g.Log().Infof(r.Context(), "status:%d  time:%fs  level:%d  from:%s  query:%s", r.Response.Status, time.Since(now).Seconds(), queryLevel, r.GetClientIp(), string(bodyBytes))
+	g.Log().Infof(r.Context(), "status:%d  time:%fs  waitPool:%fs  level:%d  from:%s  query:%s", r.Response.Status, time.Since(now).Seconds(), r.GetCtxVar(consts.QueryWaitPoolTime).Float64(), queryLevel, r.GetClientIp(), string(bodyBytes))
 }
 
 var (