Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
apaas-meshproxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gzga-jzapi
apaas-meshproxy
Commits
31add993
Commit
31add993
authored
Jun 22, 2020
by
张宇迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis记录调用痕迹用于定时任务计次
parent
0a619de1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
10 deletions
+40
-10
src/client/redis.go
src/client/redis.go
+5
-0
src/config/conf.go
src/config/conf.go
+2
-0
src/handler/proxyhandler.go
src/handler/proxyhandler.go
+11
-3
src/service/field.go
src/service/field.go
+22
-7
No files found.
src/client/redis.go
View file @
31add993
...
@@ -92,3 +92,8 @@ func (r Redis) Del(key string) error {
...
@@ -92,3 +92,8 @@ func (r Redis) Del(key string) error {
bmd
:=
r
.
Conn
.
Del
(
strings
.
ToUpper
(
key
))
bmd
:=
r
.
Conn
.
Del
(
strings
.
ToUpper
(
key
))
return
bmd
.
Err
()
return
bmd
.
Err
()
}
}
func
(
r
Redis
)
RPush
(
key
string
,
value
interface
{})
(
err
error
)
{
key
=
fmt
.
Sprintf
(
"%s-%s"
,
strings
.
ToUpper
(
r
.
Prefix
),
strings
.
ToUpper
(
key
))
bmd
:=
r
.
Conn
.
RPush
(
strings
.
ToUpper
(
key
),
value
)
return
bmd
.
Err
()
}
src/config/conf.go
View file @
31add993
...
@@ -12,6 +12,8 @@ var (
...
@@ -12,6 +12,8 @@ var (
)
)
const
CallRecord
string
=
"callRecord"
const
CallRecord
string
=
"callRecord"
const
SvcTag
string
=
"SVC"
const
ApplyTag
string
=
"APPLY"
var
ProxyConf
=
struct
{
var
ProxyConf
=
struct
{
MeshId
string
`json:"meshId"`
MeshId
string
`json:"meshId"`
...
...
src/handler/proxyhandler.go
View file @
31add993
...
@@ -54,10 +54,18 @@ func Proxy(c *gin.Context) {
...
@@ -54,10 +54,18 @@ func Proxy(c *gin.Context) {
if
sensitiveflag
==
false
{
if
sensitiveflag
==
false
{
res
=
service
.
SensitiveFilter
(
proxyData
,
res
)
res
=
service
.
SensitiveFilter
(
proxyData
,
res
)
}
}
//调用痕迹进入队列
//service.RecordCall(proxyData, resp.StatusCode, respbody)
//服务调用计次
//服务调用计次
service
.
CallCounts
(
proxyData
)
err
=
service
.
CallCounts
(
proxyData
)
if
err
!=
nil
{
Return
(
err
.
Error
())
return
nil
}
////申请调用计次
err
=
service
.
ApplyCallCounts
(
proxyData
)
if
err
!=
nil
{
Return
(
err
.
Error
())
return
nil
}
Return
(
res
)
Return
(
res
)
return
nil
return
nil
}))
}))
...
...
src/service/field.go
View file @
31add993
...
@@ -35,7 +35,7 @@ func QueryCallsCount(filter model.ProxyData) (call bool, sensitiveCall bool, err
...
@@ -35,7 +35,7 @@ func QueryCallsCount(filter model.ProxyData) (call bool, sensitiveCall bool, err
return
return
}
}
date
:=
time
.
Now
()
.
Format
(
config
.
LocalDateFormat
)
date
:=
time
.
Now
()
.
Format
(
config
.
LocalDateFormat
)
key
:=
fmt
.
Sprintf
(
"%
s-%s"
,
date
,
filter
.
Apply_id
)
key
:=
fmt
.
Sprintf
(
"%
d-%s"
,
filter
.
Apply_id
,
date
)
countStr
,
err
:=
redis
.
Get
(
key
)
countStr
,
err
:=
redis
.
Get
(
key
)
if
err
!=
nil
&&
err
.
Error
()
!=
`redis: nil`
{
if
err
!=
nil
&&
err
.
Error
()
!=
`redis: nil`
{
return
return
...
@@ -123,16 +123,14 @@ func CallCounts(proxyData model.ProxyData) (err error) {
...
@@ -123,16 +123,14 @@ func CallCounts(proxyData model.ProxyData) (err error) {
date
:=
time
.
Now
()
.
Format
(
config
.
LocalDateFormat
)
date
:=
time
.
Now
()
.
Format
(
config
.
LocalDateFormat
)
aMonBefore
:=
time
.
Now
()
.
AddDate
(
0
,
-
1
,
0
)
.
Format
(
config
.
LocalDateFormat
)
aMonBefore
:=
time
.
Now
()
.
AddDate
(
0
,
-
1
,
0
)
.
Format
(
config
.
LocalDateFormat
)
str
,
err
:=
redis
.
Get
(
string
(
proxyData
.
Service_id
))
str
,
err
:=
redis
.
Get
(
fmt
.
Sprintf
(
"%s-%d"
,
config
.
SvcTag
,
proxyData
.
Service_id
))
if
err
!=
nil
&&
err
.
Error
()
!=
`redis: nil`
{
if
err
!=
nil
&&
err
.
Error
()
!=
`redis: nil`
{
return
return
}
}
if
err
!=
nil
{
return
}
dateMap
:=
make
(
map
[
string
]
int
)
dateMap
:=
make
(
map
[
string
]
int
)
if
str
!=
""
{
if
str
!=
""
{
err
=
json
.
Unmarshal
([]
byte
(
str
),
dateMap
)
err
=
json
.
Unmarshal
([]
byte
(
str
),
&
dateMap
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
@@ -150,7 +148,24 @@ func CallCounts(proxyData model.ProxyData) (err error) {
...
@@ -150,7 +148,24 @@ func CallCounts(proxyData model.ProxyData) (err error) {
}
else
{
}
else
{
dateMap
[
date
]
=
1
dateMap
[
date
]
=
1
}
}
err
=
redis
.
Set
(
string
(
proxyData
.
Service_id
),
dateMap
,
-
1
)
content
,
err
:=
json
.
Marshal
(
dateMap
)
//fmt.Sprintf("SVCID-%d",proxyData.Service_id)
err
=
redis
.
Set
(
fmt
.
Sprintf
(
"%s-%d"
,
config
.
SvcTag
,
proxyData
.
Service_id
),
content
,
-
1
)
return
}
/*
申请调用记录
*/
func
ApplyCallCounts
(
proxyData
model
.
ProxyData
)
(
err
error
)
{
redis
,
err
:=
client
.
GetRedisClient
()
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
return
}
date
:=
time
.
Now
()
.
Format
(
config
.
LocalDateTimeFormat
)
err
=
redis
.
RPush
(
fmt
.
Sprintf
(
"%s-%d"
,
config
.
ApplyTag
,
proxyData
.
Apply_id
),
[]
byte
(
date
))
fmt
.
Println
(
"rpush data to list failed:"
,
err
)
return
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment