feat(sub): report why a subscription balancer emits nothing (#7209)

A subscription balancer whose inbounds were deleted, disabled, changed to a protocol with no JSON outbound, left without clients or closed by their hosts simply vanished from the JSON subscription, and nothing in the panel or the log said why.

GET /panel/api/sub-balancers now returns a problems[] array per balancer with stable codes: unknown_inbound, disabled_inbound, json_incapable_protocol, inbound_without_clients, hosts_excluded_from_json and no_members. Settings -> Sub Balancers shows a warning tag whose tooltip names each cause and the affected inbounds, and the log records a balancer's problems when they change instead of on every listing.

The advisories are read from the stored rows and never change what a subscription emits: a balancer with no usable member is still omitted. The list of JSON-incapable protocols is pinned to the renderer, the subscription allowlist and the form by tests.
This commit is contained in:
amirim
2026-11-28 09:23:14 +03:00
committed by GitHub
parent eb99820dd8
commit e071f220e9
30 changed files with 1419 additions and 13 deletions
+119 -2
View File
@@ -5636,6 +5636,112 @@
],
"type": "object"
},
"SubBalancerProblem": {
"description": "SubBalancerProblem is one reason a balancer cannot emit what an operator expects.\nAdvisories never change the emitted config, and per-client losses are out of scope.",
"properties": {
"code": {
"example": "unknown_inbound",
"type": "string"
},
"detail": {
"example": "amneziawg",
"type": "string"
},
"inboundIds": {
"example": [
7,
9
],
"items": {
"type": "integer"
},
"type": "array"
}
},
"required": [
"code"
],
"type": "object"
},
"SubBalancerWithProblems": {
"description": "SubBalancerWithProblems embeds the row by value so it marshals flat; Problems is\nalways non-nil so the response shape is stable.",
"properties": {
"createdAt": {
"example": 1710000000000,
"format": "int64",
"type": "integer"
},
"enabled": {
"description": "No gorm default:true — a bool default makes an explicit false at insert\ncollapse back to the column default (zero value is skipped).",
"example": true,
"type": "boolean"
},
"id": {
"example": 1,
"type": "integer"
},
"inboundIds": {
"example": [
1,
3
],
"items": {
"type": "integer"
},
"type": "array"
},
"memberWeights": {
"additionalProperties": {
"type": "number"
},
"description": "inboundId -> leastLoad weight; absent entries mean 1.0. Only meaningful\nwith Strategy \"leastLoad\" — xray ignores costs on every other strategy.",
"type": "object"
},
"problems": {
"items": {
"$ref": "#/components/schemas/SubBalancerProblem"
},
"type": "array"
},
"remark": {
"example": "auto-fastest",
"maxLength": 256,
"type": "string"
},
"sortOrder": {
"example": 1,
"minimum": 1,
"type": "integer"
},
"strategy": {
"enum": [
"leastLoad",
"leastPing",
"random",
"roundRobin"
],
"example": "random",
"type": "string"
},
"updatedAt": {
"example": 1710000000000,
"format": "int64",
"type": "integer"
}
},
"required": [
"createdAt",
"enabled",
"id",
"inboundIds",
"problems",
"remark",
"sortOrder",
"strategy",
"updatedAt"
],
"type": "object"
},
"TgBotCapabilities": {
"description": "TgBotCapabilities is the browser-safe shape of the bot's own capabilities.",
"properties": {
@@ -17811,8 +17917,9 @@
"tags": [
"Subscription Balancers"
],
"summary": "List all subscription balancers in sort order (sort_order asc, id asc).",
"summary": "List all subscription balancers in sort order, with problems[] advisories.",
"operationId": "get_panel_api_sub_balancers",
"description": "Each balancer carries a problems[] array of diagnostic advisories: unknown_inbound, disabled_inbound, json_incapable_protocol, inbound_without_clients, hosts_excluded_from_json, no_members. Advisories never change the emitted config — a balancer with no resolvable member is still omitted from the JSON subscription. sort_order asc, id asc.",
"responses": {
"200": {
"description": "Successful response",
@@ -17830,7 +17937,7 @@
"obj": {
"type": "array",
"items": {
"$ref": "#/components/schemas/SubBalancer"
"$ref": "#/components/schemas/SubBalancerWithProblems"
}
}
}
@@ -17847,6 +17954,16 @@
3
],
"memberWeights": {},
"problems": [
{
"code": "unknown_inbound",
"detail": "amneziawg",
"inboundIds": [
7,
9
]
}
],
"remark": "auto-fastest",
"sortOrder": 1,
"strategy": "random",