Skip to content

Commit 3a9530e

Browse files
feat(config): introduce optional checks in health checks and update example configurations
- Added support for optional checks in the health check system, allowing certain checks to be marked as warnings instead of failures. - Updated the RunConfig struct to include an OptionalChecks field for specifying these checks. - Modified example configuration files to include "optional_checks" for better flexibility in health checks. - Enhanced the UI to reflect the status of optional checks, providing clearer feedback on their results. This update improves the robustness of health checks and enhances user experience by clearly distinguishing between critical and non-critical checks.
1 parent ccf3d59 commit 3a9530e

14 files changed

Lines changed: 132 additions & 16 deletions

File tree

cmd/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ func checkCmd() *cobra.Command {
180180
// Read run.json to know the core, then call core.Check.
181181
// For now: just verify run.json parses and referenced config files exist.
182182
path := filepath.Join(args[0], "run.json")
183-
if _, err := os.Stat(path); err != nil {
183+
pathJ2 := filepath.Join(args[0], "run.json.j2")
184+
_, err1 := os.Stat(path)
185+
_, err2 := os.Stat(pathJ2)
186+
if err1 != nil && err2 != nil {
184187
return fmt.Errorf("run.json not found in %s", args[0])
185188
}
186189
fmt.Println("OK")
@@ -270,10 +273,17 @@ func findExamples(root string) ([]string, error) {
270273
if err != nil || d.IsDir() {
271274
return nil
272275
}
273-
if d.Name() != "run.json" {
276+
if d.Name() != "run.json" && d.Name() != "run.json.j2" {
274277
return nil
275278
}
276279
dir := filepath.Join(root, filepath.Dir(path))
280+
// A dir with both run.json and run.json.j2 is visited twice; the .j2
281+
// is the source of truth, so skip the plain run.json in that case.
282+
if d.Name() == "run.json" {
283+
if _, err := os.Stat(filepath.Join(dir, "run.json.j2")); err == nil {
284+
return nil
285+
}
286+
}
277287
// Skip "inheritance-only" run.json files that have no config files
278288
// alongside them (no .json/.j2/.tpl other than run.json itself).
279289
if !hasConfigFiles(dir) {

examples/sing-box/shadowsocks/run.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
],
1515

1616
"checks": ["dns", "http", "quic"],
17+
"optional_checks": ["quic"],
1718
"timeout_sec": 30,
1819
}

examples/sing-box/vless-xhttp/run.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
],
1717

1818
"checks": ["dns", "http", "quic", "speedtest"],
19+
"optional_checks": ["quic"],
1920
"timeout_sec": 30,
2021
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{% extends "../templates/base/client.json.j2" %}
2+
3+
{% block outbound %}
4+
{
5+
"tag": "proxy",
6+
"protocol": "vless",
7+
"settings": {
8+
"vnext": [
9+
{
10+
"address": "{{ SERVER }}",
11+
"port": {{ PORT }},
12+
"users": [{"id": "{{ UUID }}", "encryption": "{{ VLESS_ENC }}", "flow": "{{ VLESS_FLOW }}"}]
13+
}
14+
]
15+
},
16+
"streamSettings": {
17+
"network": "tcp",
18+
{% include "../templates/tls/client.tpl" %}
19+
"tcpSettings": {}
20+
}
21+
}
22+
{% endblock %}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
// VLESS + XTLS-Vision (xray-core) — raw TCP + TLS + xtls-rprx-vision flow.
3+
// This is the canonical "one good protocol" setup: VLESS over TCP with
4+
// real TLS and the Vision flow control (anti-active-probing). Inherits
5+
// binary paths and deploy settings from ../run.json and ../../run.json.
6+
"name": "VLESS + Vision (xray)",
7+
"server_config": "server",
8+
"client_config": "client",
9+
"tls": true,
10+
11+
"vars": [
12+
{
13+
"TITLE": "vless-vision",
14+
"TLS": "1",
15+
"VLESS_ENC": "none",
16+
"VLESS_DEC": "none",
17+
"VLESS_FLOW": "xtls-rprx-vision",
18+
"HOST_NAME": "127.0.0.1",
19+
"SNI_NAME": "127.0.0.1",
20+
},
21+
],
22+
23+
"checks": ["dns", "http", "quic", "speedtest"],
24+
"optional_checks": ["quic"],
25+
"timeout_sec": 30,
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% extends "../templates/base/server.json.j2" %}
2+
3+
{% block inbound %}
4+
{
5+
"tag": "proxy-in",
6+
"port": {{ PORT }},
7+
"listen": "{{ SERVER }}",
8+
"protocol": "vless",
9+
"settings": {
10+
"clients": [
11+
{
12+
"id": "{{ UUID }}",
13+
"flow": "{{ VLESS_FLOW }}"
14+
}
15+
],
16+
"decryption": "{{ VLESS_DEC }}"
17+
},
18+
"streamSettings": {
19+
"network": "tcp",
20+
{% include "../templates/tls/server.tpl" %}
21+
"tcpSettings": {}
22+
}
23+
}
24+
{% endblock %}

examples/xray/vless-xhttp/run.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
},
2727
],
2828
"checks": ["dns", "http", "quic", "speedtest"],
29+
"optional_checks": ["quic"],
2930
"timeout_sec": 30
3031
}

examples/xray/vless-xhttp/run.json.j2

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
"client_config": "client",
77
"tls": true,
88

9+
// NOTE: xtls-rprx-vision flow is NOT valid over xHTTP — it requires raw
10+
// TCP+TLS. See the vless-vision example for that. xHTTP uses flow "".
911
"vars": [
10-
{% for flow in ",xtls-rprx-vision"|split:"," %}
1112
{
12-
"TITLE": "{% if flow %}vless-flow{% else %}plain-tls{% endif %}",
13+
"TITLE": "plain-tls",
1314
"TLS": "1",
1415
"VLESS_ENC": "none",
1516
"VLESS_DEC": "none",
16-
"VLESS_FLOW": "{{ flow }}",
17+
"VLESS_FLOW": "",
1718
"HOST_NAME": "127.0.0.1",
1819
"SNI_NAME": "127.0.0.1",
1920
},
20-
{% endfor %}
2121
],
2222

2323
"checks": ["dns", "http", "quic", "speedtest"],
24+
"optional_checks": ["quic"],
2425
"timeout_sec": 30,
2526
}

hiddify-health

16 Bytes
Binary file not shown.

internal/health/health.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ func (c *Config) defaults() {
8686
type Result struct {
8787
Name string
8888
OK bool
89+
// Optional marks a check whose failure is a warning, not a run failure.
90+
Optional bool
8991
Duration time.Duration
9092
Err error
9193
// Extra human-readable detail (throughput, ping stats, …).

0 commit comments

Comments
 (0)