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
502c0997
Commit
502c0997
authored
Apr 15, 2025
by
zhouwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整告警时间
parent
95f38259
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
+15
-6
FailoverGatewayFilterFactory.java
...yan/securitylink/filter/FailoverGatewayFilterFactory.java
+15
-6
No files found.
src/main/java/com/nanyan/securitylink/filter/FailoverGatewayFilterFactory.java
View file @
502c0997
...
...
@@ -33,8 +33,9 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
private
final
WebClient
.
Builder
webClientBuilder
;
private
final
TokenRouteMappingService
tokenRouteMappingService
;
// 添加错误统计
private
static
final
int
WINDOW_SIZE_SECONDS
=
10
*
6
0
;
// 1分钟窗口
private
static
final
int
WINDOW_SIZE_SECONDS
=
100
;
// 1分钟窗口
private
static
final
double
ERROR_THRESHOLD
=
0.5
;
// 75%错误率阈值
private
static
Long
lastAlarmTime
=
System
.
currentTimeMillis
();
@Autowired
AlertService
alertService
;
private
final
Map
<
String
,
CircularQueue
>
errorStatsMap
=
new
ConcurrentHashMap
<>();
...
...
@@ -113,7 +114,7 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
Long
lastAlarmTime
=
alarmSentMap
.
get
(
primaryUrl
);
// 如果从未发送过告警,或者距离上次告警已经超过冷却时间
if
(
lastAlarmTime
==
null
||
(
currentTime
-
lastAlarmTime
)
>
WINDOW_SIZE_SECONDS
*
1000
)
{
if
(
lastAlarmTime
==
null
||
(
currentTime
-
lastAlarmTime
)
>
20
*
60
*
1000
)
{
String
alarmMessage
=
String
.
format
(
"Service degradation detected: %s has high error rate (%.2f%%), switching to fallback service"
,
primaryUrl
,
errorRate
*
100
);
...
...
@@ -234,9 +235,8 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
ServerHttpRequest
request
=
exchange
.
getRequest
();
String
fullUrl
=
baseUrl
+
(
baseUrl
.
endsWith
(
"/"
)
?
uri
.
substring
(
1
)
:
uri
);
log
.
info
(
"Trying request to: {}"
,
fullUrl
);
log
.
info
(
"Using cached request body: {}"
,
cachedBody
);
log
.
info
(
"Starting {} request to: {}"
,
isSourceRequest
?
"source"
:
"target"
,
fullUrl
);
long
startTime
=
System
.
currentTimeMillis
();
WebClient
.
RequestBodySpec
requestBodySpec
=
webClientBuilder
.
build
()
.
method
(
request
.
getMethod
())
.
uri
(
fullUrl
+
(
request
.
getQueryParams
().
isEmpty
()
?
""
:
...
...
@@ -261,7 +261,16 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
return
requestBodySpec
.
exchange
()
.
flatMap
(
clientResponse
->
handleResponse
(
exchange
,
clientResponse
,
isSourceRequest
,
errorStats
));
.
flatMap
(
clientResponse
->
handleResponse
(
exchange
,
clientResponse
,
isSourceRequest
,
errorStats
))
.
doFinally
(
signalType
->
{
long
endTime
=
System
.
currentTimeMillis
();
long
duration
=
endTime
-
startTime
;
log
.
info
(
"{} request completed: {} - took {}ms, signal: {}"
,
isSourceRequest
?
"Source"
:
"Target"
,
fullUrl
,
duration
,
signalType
);
});
}
private
Mono
<
Void
>
handleResponse
(
ServerWebExchange
exchange
,
...
...
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