Commit b4d4ebcc authored by leitao.zhang's avatar leitao.zhang

调用记录

parent c91916a4
package dao
import "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
import (
"time"
)
type ServiceRequestRecord struct {
Id int `json:"id" xorm:"id"`
ServiceId int `json:"service_id" xorm:"service_id"`
ApplyId int `json:"apply_id" xorm:"apply_id"`
UserId string `json:"user_id" xorm:"user_id"`
RequestTime tools.JsonTime `json:"request_time" xorm:"request_time created"`
DateDay int `json:"date_day" xorm:"date_day"`
DateMonth int `json:"date_month" xorm:"date_month"`
DateYear int `json:"date_year" xorm:"date_year"`
Status int `json:"status" xorm:"status"`
Error string `json:"error" xorm:"error"`
ReqUrl string `json:"req_url" xorm:"req_url"`
//Id int `json:"id" xorm:"id"`
ServiceId int `json:"service_id" xorm:"service_id"`
ApplyId int `json:"apply_id" xorm:"apply_id"`
UserId string `json:"user_id" xorm:"user_id"`
RequestTime time.Time `json:"request_time" xorm:"request_time created"`
DateDay int `json:"date_day" xorm:"date_day"`
DateMonth int `json:"date_month" xorm:"date_month"`
DateYear int `json:"date_year" xorm:"date_year"`
Status int `json:"status" xorm:"status"`
Error string `json:"error" xorm:"error"`
ReqUrl string `json:"req_url" xorm:"req_url"`
}
func (s ServiceRequestRecord) TableName() string {
......
......@@ -18,7 +18,6 @@ import (
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/request"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/tables"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools/dataconvertutil"
"log"
"time"
......@@ -91,7 +90,7 @@ func GetExpire() time.Duration {
//记录调用痕迹
func RecordCall(proxyData model.ProxyData, status int, res []byte) {
acc := dao.ServiceRequestRecord{}
redis, err := client.GetRedisClient()
db, err := client.GetConnect()
if err != nil {
fmt.Println(err.Error())
return
......@@ -99,7 +98,7 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) {
if status != 200 {
acc.Error = string(res)
}
acc.RequestTime = tools.JsonTime(time.Now())
acc.RequestTime = time.Now()
acc.ApplyId = cast.ToInt(proxyData.ApplyId)
acc.UserId = proxyData.ApplyUserId
acc.ServiceId = cast.ToInt(proxyData.ServiceId)
......@@ -110,13 +109,18 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) {
acc.DateYear = time.Now().Year()
acc.Status = status
b, _ := json.Marshal(acc)
if errs := redis.Conn.RPush(config.CallRecord, b).Err(); errs != nil {
err = errs
fmt.Println("rpush data to list failed:", errs.Error())
return
if _, err = db.Insert(&acc); err != nil {
fmt.Println(err)
}
fmt.Println("调用记录进入队列")
//b, _ := json.Marshal(acc)
//if errs := redis.Conn.RPush(config.CallRecord, b).Err(); errs != nil {
// err = errs
// fmt.Println("rpush data to list failed:", errs.Error())
// return
//}
//fmt.Println("调用记录进入队列")
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment