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

调用记录

parent c91916a4
package dao package dao
import "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools" import (
"time"
)
type ServiceRequestRecord struct { type ServiceRequestRecord struct {
Id int `json:"id" xorm:"id"` //Id int `json:"id" xorm:"id"`
ServiceId int `json:"service_id" xorm:"service_id"` ServiceId int `json:"service_id" xorm:"service_id"`
ApplyId int `json:"apply_id" xorm:"apply_id"` ApplyId int `json:"apply_id" xorm:"apply_id"`
UserId string `json:"user_id" xorm:"user_id"` UserId string `json:"user_id" xorm:"user_id"`
RequestTime tools.JsonTime `json:"request_time" xorm:"request_time created"` RequestTime time.Time `json:"request_time" xorm:"request_time created"`
DateDay int `json:"date_day" xorm:"date_day"` DateDay int `json:"date_day" xorm:"date_day"`
DateMonth int `json:"date_month" xorm:"date_month"` DateMonth int `json:"date_month" xorm:"date_month"`
DateYear int `json:"date_year" xorm:"date_year"` DateYear int `json:"date_year" xorm:"date_year"`
Status int `json:"status" xorm:"status"` Status int `json:"status" xorm:"status"`
Error string `json:"error" xorm:"error"` Error string `json:"error" xorm:"error"`
ReqUrl string `json:"req_url" xorm:"req_url"` ReqUrl string `json:"req_url" xorm:"req_url"`
} }
func (s ServiceRequestRecord) TableName() string { func (s ServiceRequestRecord) TableName() string {
......
...@@ -18,7 +18,6 @@ import ( ...@@ -18,7 +18,6 @@ import (
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model" "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/request"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model/tables" "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" "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools/dataconvertutil"
"log" "log"
"time" "time"
...@@ -91,7 +90,7 @@ func GetExpire() time.Duration { ...@@ -91,7 +90,7 @@ func GetExpire() time.Duration {
//记录调用痕迹 //记录调用痕迹
func RecordCall(proxyData model.ProxyData, status int, res []byte) { func RecordCall(proxyData model.ProxyData, status int, res []byte) {
acc := dao.ServiceRequestRecord{} acc := dao.ServiceRequestRecord{}
redis, err := client.GetRedisClient() db, err := client.GetConnect()
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return
...@@ -99,7 +98,7 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) { ...@@ -99,7 +98,7 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) {
if status != 200 { if status != 200 {
acc.Error = string(res) acc.Error = string(res)
} }
acc.RequestTime = tools.JsonTime(time.Now()) acc.RequestTime = time.Now()
acc.ApplyId = cast.ToInt(proxyData.ApplyId) acc.ApplyId = cast.ToInt(proxyData.ApplyId)
acc.UserId = proxyData.ApplyUserId acc.UserId = proxyData.ApplyUserId
acc.ServiceId = cast.ToInt(proxyData.ServiceId) acc.ServiceId = cast.ToInt(proxyData.ServiceId)
...@@ -110,13 +109,18 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) { ...@@ -110,13 +109,18 @@ func RecordCall(proxyData model.ProxyData, status int, res []byte) {
acc.DateYear = time.Now().Year() acc.DateYear = time.Now().Year()
acc.Status = status acc.Status = status
b, _ := json.Marshal(acc)
if errs := redis.Conn.RPush(config.CallRecord, b).Err(); errs != nil { if _, err = db.Insert(&acc); err != nil {
err = errs fmt.Println(err)
fmt.Println("rpush data to list failed:", errs.Error())
return
} }
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 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