Skip to content

Commit

Permalink
555
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Oct 17, 2024
1 parent e647e49 commit 76f000b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions dbm-services/mysql/db-simulation/app/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (tf *TmysqlParseFile) doSingleVersion(dbtype string, mysqlVersion string) (

select {
case err := <-errChan:
logger.Error("failed to do sytax check:%s", err.Error())
return err
case <-signalChan:
logger.Info("analyze the parsing result done")
Expand Down
20 changes: 12 additions & 8 deletions dbm-services/mysql/db-simulation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/gin-contrib/pprof"
"github.com/gin-contrib/requestid"
"github.com/gin-gonic/gin"
"github.com/samber/lo"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"

"dbm-services/common/go-pubpkg/apm/metric"
Expand Down Expand Up @@ -129,7 +130,7 @@ func (w bodyLogWriter) Write(b []byte) (int, error) {
return w.ResponseWriter.Write(b)
}

// BodyLogMiddleware TODO
// BodyLogMiddleware 记录返回的body
func returnRessponeMiddleware(c *gin.Context) {
blw := &bodyLogWriter{body: bytes.NewBufferString(""), ResponseWriter: c.Writer}
c.Writer = blw
Expand All @@ -141,13 +142,16 @@ func returnRessponeMiddleware(c *gin.Context) {
var rp handler.Response
if blw.body == nil {
rp = handler.Response{}
} else {
if err := json.Unmarshal(blw.body.Bytes(), &rp); err != nil {
logger.Error("unmarshal respone body failed %s", err.Error())
return
}
return
}
if err := json.Unmarshal(blw.body.Bytes(), &rp); err != nil {
return
}
if err := model.UpdateTbRequestLog(rp.RequestID, map[string]interface{}{"respone_code": statusCode, "update_time": time.Now()}); err != nil {
logger.Warn("update request respone failed %s", err.Error())
if lo.IsNotEmpty(rp.RequestID) {
if err := model.UpdateTbRequestLog(rp.RequestID, map[string]interface{}{
"response_code": statusCode,
"update_time": time.Now()}); err != nil {
logger.Warn("update request response failed %s", err.Error())
}
}
}
4 changes: 2 additions & 2 deletions dbm-services/mysql/db-simulation/model/tb_request_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type TbRequestRecord struct {
User string `gorm:"column:user;type:varchar(32);not null" json:"user"`
// 请求路径
Path string `gorm:"column:path;type:varchar(32);not null" json:"path"`
// respone code
ResponeCode int `gorm:"column:respone_code;type:int(11);not null" json:"respone_code"`
// response code
ResponeCode int `gorm:"column:response_code;type:int(11);not null" json:"response_code"`
// 请求来源Ip
SourceIP string `gorm:"column:source_ip;type:varchar(32);not null" json:"source_ip"`
UpdateTime time.Time `gorm:"column:update_time;type:timestamp;default:CURRENT_TIMESTAMP()" json:"update_time"`
Expand Down

0 comments on commit 76f000b

Please sign in to comment.