-
Notifications
You must be signed in to change notification settings - Fork 13.3k
bugfix:修复 HTTP TPS 限流时 metrics 采集的问题 #14072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks for your this PR. 🙏 感谢您提交的PR。 🙏 |
| @NacosWebBean | ||
| public class HttpTpsPointRegistry implements ApplicationListener<ContextRefreshedEvent> { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't change the indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KomachiSion done
|
|
|
@luky116 CI can't pass please fix it. |
Please do not create a Pull Request without creating an issue first.
What is the purpose of the change
本次 PR 修复了 HTTP TPS(每秒事务数)控制相关的两个问题:
修复 Spring Boot 中 TPS 点重复注册问题:在 Spring Boot 应用中,
ContextRefreshedEvent会被触发两次 - 一次是根 ApplicationContext,一次是 Web ApplicationContext。之前的方法,优先注册的是 根 context,导致本地带了 @TpsControl 注释的方法没注册上。本次修复确保只处理根上下文,并添加了异常处理和重试能力。使用正确的 HTTP 状态码:当 TPS 超过限制时,将 HTTP 状态码从 503 (Service Unavailable) 改为 429 (Too Many Requests),这是根据 RFC 6585 标准用于限流场景的标准 HTTP 状态码。
添加 TPS 超限的 HTTP 指标记录:为 TPS 超限场景添加了 Micrometer 指标记录,以支持更好的监控和可观测性;按照之前的逻辑,如果被限流拦截,并不会记录 metrics
Brief changelog
HttpTpsPointRegistry.java:
NacosHttpTpsFilter.java:
recordHttpMetrics()方法使用 Micrometer 记录指标generate503Response()重命名为generate429Response()以提高可读性Verifying this change
测试重复注册修复:
测试 HTTP 状态码:
测试指标记录:
http.server.requests计时器被记录,包含:status=429exception=TpsOverLimitExceptionoutcome=TPS_OVER_LIMIT_ERRORmethod和uri标签Follow this checklist to help us incorporate your contribution quickly and easily:
[ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=trueto make sure basic checks pass. Runmvn clean install -DskipITsto make sure unit-test pass. Runmvn clean test-compile failsafe:integration-testto make sure integration-test pass.