mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-29 14:04:46 +03:00
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:
@@ -1444,6 +1444,38 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"strategy": "random",
|
||||
"updatedAt": 1710000000000
|
||||
},
|
||||
"SubBalancerProblem": {
|
||||
"code": "unknown_inbound",
|
||||
"detail": "amneziawg",
|
||||
"inboundIds": [
|
||||
7,
|
||||
9
|
||||
]
|
||||
},
|
||||
"SubBalancerWithProblems": {
|
||||
"createdAt": 1710000000000,
|
||||
"enabled": true,
|
||||
"id": 1,
|
||||
"inboundIds": [
|
||||
1,
|
||||
3
|
||||
],
|
||||
"memberWeights": {},
|
||||
"problems": [
|
||||
{
|
||||
"code": "unknown_inbound",
|
||||
"detail": "amneziawg",
|
||||
"inboundIds": [
|
||||
7,
|
||||
9
|
||||
]
|
||||
}
|
||||
],
|
||||
"remark": "auto-fastest",
|
||||
"sortOrder": 1,
|
||||
"strategy": "random",
|
||||
"updatedAt": 1710000000000
|
||||
},
|
||||
"TgBotCapabilities": {
|
||||
"groupPrivacy": false,
|
||||
"inlineEnabled": true,
|
||||
|
||||
@@ -5610,6 +5610,112 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
],
|
||||
"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 -\u003e 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": {
|
||||
|
||||
@@ -1270,6 +1270,25 @@ export interface SubBalancer {
|
||||
updatedAt: number;
|
||||
}
|
||||
|
||||
export interface SubBalancerProblem {
|
||||
code: string;
|
||||
detail?: string;
|
||||
inboundIds?: number[];
|
||||
}
|
||||
|
||||
export interface SubBalancerWithProblems {
|
||||
createdAt: number;
|
||||
enabled: boolean;
|
||||
id: number;
|
||||
inboundIds: number[];
|
||||
memberWeights?: Record<number, number>;
|
||||
problems: SubBalancerProblem[];
|
||||
remark: string;
|
||||
sortOrder: number;
|
||||
strategy: string;
|
||||
updatedAt: number;
|
||||
}
|
||||
|
||||
export interface TgBotCapabilities {
|
||||
groupPrivacy: boolean;
|
||||
inlineEnabled: boolean;
|
||||
|
||||
@@ -1348,6 +1348,27 @@ export const SubBalancerSchema = z.object({
|
||||
});
|
||||
export type SubBalancer = z.infer<typeof SubBalancerSchema>;
|
||||
|
||||
export const SubBalancerProblemSchema = z.object({
|
||||
code: z.string(),
|
||||
detail: z.string().optional(),
|
||||
inboundIds: z.array(z.number().int()).optional(),
|
||||
});
|
||||
export type SubBalancerProblem = z.infer<typeof SubBalancerProblemSchema>;
|
||||
|
||||
export const SubBalancerWithProblemsSchema = z.object({
|
||||
createdAt: z.number().int(),
|
||||
enabled: z.boolean(),
|
||||
id: z.number().int(),
|
||||
inboundIds: z.array(z.number().int()),
|
||||
memberWeights: z.record(z.number().int(), z.number()).optional(),
|
||||
problems: z.array(z.lazy(() => SubBalancerProblemSchema)),
|
||||
remark: z.string().max(256),
|
||||
sortOrder: z.number().int().min(1),
|
||||
strategy: z.enum(['leastLoad', 'leastPing', 'random', 'roundRobin']),
|
||||
updatedAt: z.number().int(),
|
||||
});
|
||||
export type SubBalancerWithProblems = z.infer<typeof SubBalancerWithProblemsSchema>;
|
||||
|
||||
export const TgBotCapabilitiesSchema = z.object({
|
||||
groupPrivacy: z.boolean(),
|
||||
inlineEnabled: z.boolean(),
|
||||
|
||||
@@ -3013,8 +3013,10 @@ export const sections: readonly Section[] = [
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/panel/api/sub-balancers',
|
||||
summary: 'List all subscription balancers in sort order (sort_order asc, id asc).',
|
||||
responseSchema: 'SubBalancer',
|
||||
summary: 'List all subscription balancers in sort order, with problems[] advisories.',
|
||||
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.',
|
||||
responseSchema: 'SubBalancerWithProblems',
|
||||
responseSchemaArray: true,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ import type { AllSetting } from '@/models/setting';
|
||||
import { onNumber } from '@/utils/onNumber';
|
||||
import { SettingListItem } from '@/components/ui';
|
||||
import { useMediaQuery } from '@/hooks/useMediaQuery';
|
||||
import type { SubBalancer, SubBalancerFormValues } from '@/schemas/subBalancer';
|
||||
import type { SubBalancer, SubBalancerFormValues, SubBalancerProblem } from '@/schemas/subBalancer';
|
||||
import { PingConfigSchema, type PingConfigObject } from '@/schemas/observatory';
|
||||
import { DEFAULT_BURST_OBSERVATORY } from '@/pages/xray/balancers/balancer-helpers';
|
||||
import SubBalancerFormModal from './SubBalancerFormModal';
|
||||
@@ -56,6 +56,25 @@ function parsePingConfig(raw: string): PingConfigObject {
|
||||
}
|
||||
}
|
||||
|
||||
function ProblemTooltip({
|
||||
problems,
|
||||
inboundLabels,
|
||||
}: {
|
||||
problems: SubBalancerProblem[];
|
||||
inboundLabels: Map<number, string>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div>
|
||||
{problems.map((p) => {
|
||||
const ids = (p.inboundIds ?? []).map((id) => inboundLabels.get(id) ?? `#${id}`).join(', ');
|
||||
const base = t(`pages.settings.subBalancers.problem.${p.code}`);
|
||||
return <div key={p.code}>{ids ? `${base}: ${ids}` : base}</div>;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface SubscriptionBalancersTabProps {
|
||||
allSetting: AllSetting;
|
||||
updateSetting: (patch: Partial<AllSetting>) => void;
|
||||
@@ -149,6 +168,22 @@ export default function SubscriptionBalancersTab({
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('pages.settings.subBalancers.problems'),
|
||||
key: 'problems',
|
||||
width: 150,
|
||||
render: (_: unknown, r: SubBalancer) => {
|
||||
const problems = r.problems ?? [];
|
||||
if (problems.length === 0) return null;
|
||||
return (
|
||||
<Tooltip title={<ProblemTooltip problems={problems} inboundLabels={inboundLabels} />}>
|
||||
<Tag color="warning">
|
||||
{t('pages.settings.subBalancers.problemsCount', { count: problems.length })}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('pages.settings.subBalancers.enabled'),
|
||||
dataIndex: 'enabled',
|
||||
|
||||
@@ -3,6 +3,23 @@ import { z } from 'zod';
|
||||
export const SubBalancerStrategySchema = z.enum(['leastLoad', 'leastPing', 'random', 'roundRobin']);
|
||||
export type SubBalancerStrategy = z.infer<typeof SubBalancerStrategySchema>;
|
||||
|
||||
export const SubBalancerProblemCodeSchema = z.enum([
|
||||
'unknown_inbound',
|
||||
'disabled_inbound',
|
||||
'json_incapable_protocol',
|
||||
'inbound_without_clients',
|
||||
'hosts_excluded_from_json',
|
||||
'no_members',
|
||||
]);
|
||||
export type SubBalancerProblemCode = z.infer<typeof SubBalancerProblemCodeSchema>;
|
||||
|
||||
export const SubBalancerProblemSchema = z.object({
|
||||
code: SubBalancerProblemCodeSchema,
|
||||
inboundIds: z.array(z.number()).optional(),
|
||||
detail: z.string().optional(),
|
||||
});
|
||||
export type SubBalancerProblem = z.infer<typeof SubBalancerProblemSchema>;
|
||||
|
||||
export const SubBalancerSchema = z.object({
|
||||
id: z.number(),
|
||||
remark: z.string(),
|
||||
@@ -11,6 +28,8 @@ export const SubBalancerSchema = z.object({
|
||||
memberWeights: z.record(z.string(), z.number()).nullish(),
|
||||
sortOrder: z.number(),
|
||||
enabled: z.boolean(),
|
||||
// Advisories from the list API; create/update responses omit them.
|
||||
problems: z.array(SubBalancerProblemSchema).optional(),
|
||||
createdAt: z.number().optional(),
|
||||
updatedAt: z.number().optional(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user