Files
go-admin/config/settings.yml
zhangwenjian 5648bd1dcf feat: state the shutdown budget at start-up
The three budgets are spent one after the other, so what has to fit inside the
orchestrator's grace period is their sum - and nothing said what that sum was.
Working it out meant reading a configuration file, remembering which fields
were absent, and knowing what each one falls back to.

Start-up now prints it: the three values and the total, taken from the resolved
budget rather than from the file. A field left out still costs its default, so
adding up what was written down understates the total by exactly the fields
nobody wrote - which is the arithmetic somebody doing this by hand gets wrong.

Whether the total fits is a separate question, and the framework cannot answer
it alone: `docker stop` allows ten seconds and Kubernetes thirty, three times
apart. A fixed threshold would have warned about the manifest this repository
is about to ship. So extend.shutdown.grace is optional, nothing reads it during
a shutdown, and when it is absent the line says so and prints both reference
values instead of judging.

When it is set and the budget does not fit, the warning names the shortfall:
how many more seconds are needed. A minimum, not a target - this is somebody
else's deployment under constraints this process cannot see, and asking them to
leave headroom on top is not this line's business. Equal does not fit either;
the grace period is when SIGKILL is sent, so a budget that ends exactly then
leaves the last callback no time to return.
2026-09-06 21:49:17 +08:00

128 lines
6.0 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
settings:
application:
# dev开发环境 test测试环境 prod线上环境
mode: dev
# 服务器ip,默认使用 0.0.0.0
host: 0.0.0.0
# 服务名称
name: testApp
# 端口号
port: 8000 # 服务端口号
readtimeout: 1
writertimeout: 2
# 数据权限功能开关
enabledp: false
logger:
# 日志存放路径
path: temp/logs
# 日志输出,file:文件,default:命令行,其他:命令行
stdout: '' #控制台日志,启用后,不输出到文件
# 日志等级, trace, debug, info, warn, error, fatal
level: trace
# 数据库日志开关
enableddb: false
jwt:
# token 密钥,生产环境时及的修改
secret: go-admin
# token 过期时间 单位:秒
timeout: 3600
database:
# 数据库类型 mysql, sqlite3, postgres, sqlserver
# sqlserver: sqlserver://用户名:密码@地址?database=数据库名
driver: mysql
# 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
# 连接池。不配置这几项时走 Go 的默认值,其中 MaxIdleConns 默认只有 2
# 高并发下几乎每个请求都要新建 TCP 连接、用完立刻关闭,本机端口很快耗尽,
# 表现为 "can't assign requested address" 且请求全部失败——不是变慢,是不可用。
#
# maxOpenConns 是单个实例的连接上限,多实例部署时总连接数是它乘以实例数,
# 需要小于数据库的 max_connectionsMySQL 默认 151)。
# connMaxLifeTime 单位为秒,应小于数据库的 wait_timeoutMySQL 默认 28800),
# 否则会复用到已被服务端关闭的连接。
maxIdleConns: 20
maxOpenConns: 100
connMaxLifeTime: 3600
# databases:
# 'locaohost:8000':
# driver: mysql
# # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
# source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
# registers:
# - sources:
# - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
gen:
# 代码生成读取的数据库名称
dbname: dbname
# 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径
frontpath: ../go-admin-ui/src
extend: # 扩展项使用说明
demo:
name: data
# rateLimit 全局入站限流。不配置时为 200 QPS,与此前写死在
# common/middleware/sentinel.go 里的值一致,升级不会改变行为。
# 填 0 关闭限流——部署在自带限流的网关后面时用得上。
# 超出阈值的请求返回 HTTP 429(旧版本返回 200,只在 body 里写 code:500
# 会被负载均衡、监控和压测统计成成功)。
rateLimit:
inboundQPS: 200
# shutdown budgets, in seconds. The three are spent one after the other,
# and their sum has to stay inside the stop grace period the orchestrator
# allows - once it is up, SIGKILL arrives part-way through the cleanup
# callbacks, which is worse than not draining at all.
shutdown:
# How long to keep serving normally after a stop signal arrives. For that
# long /ready answers 503 and keep-alive is switched off, which is what
# gives a load balancer time to take this instance out of rotation before
# the listener closes.
#
# What to set depends on who removes this instance and on what basis. A
# load balancer that polls /ready itself needs at least "check interval x
# failure threshold + however long removal takes to apply". A Kubernetes
# Service removes the endpoint when the Pod is deleted, concurrently with
# SIGTERM and regardless of what the probe returns, so here this covers
# the delay in that removal reaching every node.
#
# 0 by default: a deployment that leaves this alone shuts down exactly as
# it did before this section existed. It also means /ready never reports
# draining - the flip and the closed listener are microseconds apart, and
# no poller reads anything in between.
drain: 0
# How long to wait for in-flight requests once the listener is closed.
server: 5
# How long the BeforeExit cleanup callbacks get after that.
cleanup: 3
# The stop grace period the orchestrator gives this process - `docker stop
# --timeout`, or terminationGracePeriodSeconds. Nothing reads it during a
# shutdown; start-up uses it to say whether the three budgets above fit
# inside it, and warns when they do not. Left out, nothing is compared:
# the reference values are 10s for docker and 30s for Kubernetes, three
# times apart, and a fixed threshold would warn about correct
# configurations.
#grace: 30
cache:
# redis:
# addr: 127.0.0.1:6379
# password: xxxxxx
# db: 2
# key存在即可
memory: ''
queue:
memory:
# poolSize 是队列的缓冲长度,不是并发度。队列满时 Append 会丢弃该消息并
# 返回错误,而不是阻塞等待,所以这个值实际是「开始丢消息的临界点」。
#
# 每个 stream 只有一个消费 goroutine,而登录日志、操作日志的消费要写数据库,
# 吞吐受限于单条写入耗时。突发流量高于消费速度时,缓冲区是唯一的缓解手段。
# 压测中默认的 100 丢弃率超过 60%,1000 为 0。
#
# 仅在 logger.enableddb 为 true 时才会真正入队。
poolSize: 1000
# redis:
# addr: 127.0.0.1:6379
# password: xxxxxx
# group: go-admin # 消费组,同一应用的多个实例必须用同一个值
# key_prefix: go-admin # 加在 stream key 前面,多个应用共用一个 redis 时用于隔离
# max_attempts: 5 # 消息投递失败的最大重试次数
locker:
redis: