Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sl-gateway
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhouwei
sl-gateway
Commits
db84f301
Commit
db84f301
authored
Apr 25, 2025
by
zhouwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改统计错误率的时间窗口
parent
e89fb371
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
AppConfig.java
src/main/java/com/nanyan/securitylink/config/AppConfig.java
+7
-0
FailoverGatewayFilterFactory.java
...yan/securitylink/filter/FailoverGatewayFilterFactory.java
+5
-3
No files found.
src/main/java/com/nanyan/securitylink/config/AppConfig.java
View file @
db84f301
...
...
@@ -15,6 +15,13 @@ public class AppConfig {
@Value
(
"${gateway.request.timeout:30000}"
)
private
Integer
requestTimeout
;
@Value
(
"${gateway.window.time:600000}"
)
private
Integer
windowsTime
;
public
Integer
getWindowsTime
()
{
return
windowsTime
;
}
public
Integer
getRequestTimeout
()
{
return
requestTimeout
;
}
...
...
src/main/java/com/nanyan/securitylink/filter/FailoverGatewayFilterFactory.java
View file @
db84f301
...
...
@@ -61,16 +61,18 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
// 内部类:环形队列,用于记录请求结果
private
static
class
CircularQueue
{
AppConfig
appConfig
;
private
final
long
[]
timestamps
;
private
final
boolean
[]
results
;
// true表示成功,false表示失败
private
int
currentIndex
=
0
;
private
final
int
capacity
;
private
final
Object
lock
=
new
Object
();
public
CircularQueue
(
int
capacity
)
{
public
CircularQueue
(
int
capacity
,
AppConfig
appConfig
)
{
this
.
capacity
=
capacity
;
this
.
timestamps
=
new
long
[
capacity
];
this
.
results
=
new
boolean
[
capacity
];
this
.
appConfig
=
appConfig
;
}
public
void
add
(
boolean
success
)
{
...
...
@@ -84,7 +86,7 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
public
double
getErrorRate
()
{
synchronized
(
lock
)
{
long
currentTime
=
System
.
currentTimeMillis
();
long
oneMinuteAgo
=
currentTime
-
WINDOW_SIZE_SECONDS
*
1000
;
long
oneMinuteAgo
=
currentTime
-
appConfig
.
getWindowsTime
()
;
int
totalRequests
=
0
;
int
failedRequests
=
0
;
...
...
@@ -104,7 +106,7 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
private
CircularQueue
getOrCreateErrorStats
(
String
primaryUrl
)
{
return
errorStatsMap
.
computeIfAbsent
(
primaryUrl
,
k
->
new
CircularQueue
(
WINDOW_SIZE_SECONDS
*
10
));
// 存储10次/秒的采样
k
->
new
CircularQueue
(
WINDOW_SIZE_SECONDS
*
10
,
appConfig
));
// 存储10次/秒的采样
}
private
boolean
shouldSkipPrimary
(
String
primaryUrl
)
{
...
...
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