Skip to content

Commit 19f7220

Browse files
committed
chore: adjust testURL priority
1 parent 3249572 commit 19f7220

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

adapter/outboundgroup/parser.go

+31-29
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,29 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
8888
}
8989
groupOption.ExpectedStatus = status
9090

91+
if len(groupOption.Use) != 0 {
92+
PDs, err := getProviders(providersMap, groupOption.Use)
93+
if err != nil {
94+
return nil, fmt.Errorf("%s: %w", groupName, err)
95+
}
96+
97+
// if test URL is empty, use the first health check URL of providers
98+
if groupOption.URL == "" {
99+
for _, pd := range PDs {
100+
if pd.HealthCheckURL() != "" {
101+
groupOption.URL = pd.HealthCheckURL()
102+
break
103+
}
104+
}
105+
if groupOption.URL == "" {
106+
groupOption.URL = C.DefaultTestURL
107+
}
108+
} else {
109+
addTestUrlToProviders(PDs, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval))
110+
}
111+
providers = append(providers, PDs...)
112+
}
113+
91114
if len(groupOption.Proxies) != 0 {
92115
ps, err := getProxies(proxyMap, groupOption.Proxies)
93116
if err != nil {
@@ -98,49 +121,28 @@ func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, provide
98121
return nil, fmt.Errorf("%s: %w", groupName, errDuplicateProvider)
99122
}
100123

101-
if groupOption.Interval == 0 {
102-
groupOption.Interval = 300
103-
}
104-
105124
if groupOption.URL == "" {
106125
groupOption.URL = C.DefaultTestURL
107126
}
108127

128+
// select don't need auto health check
129+
if groupOption.Type != "select" && groupOption.Type != "relay" {
130+
if groupOption.Interval == 0 {
131+
groupOption.Interval = 300
132+
}
133+
}
134+
109135
hc := provider.NewHealthCheck(ps, groupOption.URL, uint(groupOption.TestTimeout), uint(groupOption.Interval), groupOption.Lazy, expectedStatus)
110136

111137
pd, err := provider.NewCompatibleProvider(groupName, ps, hc)
112138
if err != nil {
113139
return nil, fmt.Errorf("%s: %w", groupName, err)
114140
}
115141

116-
providers = append(providers, pd)
142+
providers = append([]types.ProxyProvider{pd}, providers...)
117143
providersMap[groupName] = pd
118144
}
119145

120-
if len(groupOption.Use) != 0 {
121-
list, err := getProviders(providersMap, groupOption.Use)
122-
if err != nil {
123-
return nil, fmt.Errorf("%s: %w", groupName, err)
124-
}
125-
126-
if groupOption.URL == "" {
127-
for _, p := range list {
128-
if p.HealthCheckURL() != "" {
129-
groupOption.URL = p.HealthCheckURL()
130-
}
131-
break
132-
}
133-
134-
if groupOption.URL == "" {
135-
groupOption.URL = C.DefaultTestURL
136-
}
137-
}
138-
139-
// different proxy groups use different test URL
140-
addTestUrlToProviders(list, groupOption.URL, expectedStatus, groupOption.Filter, uint(groupOption.Interval))
141-
providers = append(providers, list...)
142-
}
143-
144146
var group C.ProxyAdapter
145147
switch groupOption.Type {
146148
case "url-test":

0 commit comments

Comments
 (0)