Commit d9b96fc6 authored by 张宇迪's avatar 张宇迪

update

parent 78b7028e
......@@ -11,6 +11,8 @@ var (
EsHost []string
)
const CallRecord string = "callRecord"
var ProxyConf = struct {
MeshId string `json:"meshId"`
Url string `json:"url"`
......
package dao
import "gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
type Service_request_record struct {
Id int `json:"id" xorm:"id"`
Service_id int `json:"service_id" xorm:"service_id"`
Apply_id int `json:"apply_id" xorm:"apply_id"`
User_id string `json:"user_id" xorm:"user_id"`
Request_time tools.JsonTime `json:"request_time" xorm:"request_time created"`
Date_day int `json:"date_day" xorm:"date_day"`
Date_month int `json:"date_month" xorm:"date_month"`
Date_year int `json:"date_year" xorm:"date_year"`
Status int `json:"status" xorm:"status"`
Error string `json:"error" xorm:"error"`
}
func (s Service_request_record) TableName() string {
return "service_request_record"
}
......@@ -51,7 +51,8 @@ func Proxy(c *gin.Context) {
if sensitiveflag == false {
res = service.SensitiveFilter(proxyData, res)
}
//调用痕迹进入队列
service.RecordCall(proxyData, resp.StatusCode, res)
Return(res)
return nil
}))
......@@ -60,7 +61,6 @@ func Proxy(c *gin.Context) {
c.Request.RequestURI = proxyData.RealUrl
c.Request.Host = getHost(proxyData.RealUrl)
f.ServeHTTP(c.Writer, c.Request)
}
func Return(res interface{}) {
......
......@@ -16,9 +16,9 @@ import (
)
var (
argPort = pflag.Int("port", 8088, "")
argPort = pflag.Int("port", 8011, "")
argPrefix = pflag.String("prefix", "/bgmesh/fiddler", "")
redisUrl = pflag.String("redisUrl", "redis://localhost:6333", "")
redisUrl = pflag.String("redisUrl", "redis://localhost:63793", "")
redisTag = pflag.String("redisTag", "apaas-mesh-proxy", "")
confPath = pflag.String("confPath", "/app/config/proxy.json", "")
dbURL = pflag.String("dbURL", "host=localhost port=5432 user=postgres password=passwd123 dbname=apaas sslmode=disable", "")
......
......@@ -6,4 +6,7 @@ type ProxyData struct {
Count int `json:"count" xorm:"count"`
Sensituve_word string `json:"sensituve_word" xorm:"sensituve_word"`
Sensitive_count int `json:"sensitive_count" xorm:"sensitive_count"`
Apply_id int `json:"apply_id" xorm:"apply_id"`
Service_id int `json:"service_id" xorm:"service_id"`
User_id string `json:"user_id" xorm:"user_id"`
}
......@@ -12,7 +12,10 @@ import (
"errors"
"fmt"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/client"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/config"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/dao"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/model"
"gitlab.wodcloud.com/apaas/apaas-meshproxy/src/tools"
"strconv"
"time"
)
......@@ -77,6 +80,40 @@ func GetExpire() time.Duration {
return subMin
}
//记录调用痕迹
func RecordCall(proxyData model.ProxyData, status int, res interface{}) {
acc := dao.Service_request_record{}
redis, err := client.GetRedisClient()
if err != nil {
fmt.Println(err.Error())
return
}
if status != 200 {
acc.Error = string(res.([]byte))
}
acc.Request_time = tools.JsonTime(time.Now())
acc.Apply_id = proxyData.Apply_id
acc.User_id = proxyData.User_id
acc.Service_id = proxyData.Service_id
acc.Date_day = time.Now().Day()
fmt.Println(time.Now().Month().String())
//acc.Date_month,err = strconv.Atoi(time.Now().Month().String())
//if err!=nil{
// fmt.Println(err.Error())
// return
//}
acc.Date_year = 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
}
fmt.Println("调用记录进入队列")
return
}
//过滤返回字段
func FiledFilter(proxyData model.ProxyData, respbody []byte) interface{} {
model := make(map[string]interface{})
......@@ -250,7 +287,7 @@ func GetRealPath(appId string) (res model.ProxyData, err error) {
}
has, err := db.
Select(`service_apply.res_fields as res_fields,service.req_url as req_url,service_request_spcs.count as count,service_safe_config.sensituve_word as sensituve_word
,service_request_spcs.sensitive_count as sensitive_count`).
,service_request_spcs.sensitive_count as sensitive_count,service_apply.service_id as service_id,service_apply.id as apply_id,service_apply.user_id as user_id`).
Table(`service`).
Join(`left`, `service_apply`, `service_apply.service_id = service.id`).
Join(`left`, `service_request_spcs`, `service_request_spcs.id = service_apply.request_spcs_id`).
......
......@@ -22,9 +22,3 @@ type JsonDate time.Time
func (j JsonDate) MarshalJSON() ([]byte, error) {
return []byte(`"` + time.Time(j).Format(config.LocalDateFormat) + `"`), nil
}
type JsonTime time.Time
func (j JsonTime) MarshalJSON() ([]byte, error) {
return []byte(`"` + time.Time(j).Format(conf.LocalDateTimeFormat) + `"`), nil
}
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